From fa0cb5908830865af481cfa670f530c5082f74d1 Mon Sep 17 00:00:00 2001 From: Ivan Malopinsky Date: Wed, 17 Apr 2019 17:39:28 -0400 Subject: [PATCH] add namespace filtering --- LICENSE | 2 +- main.go | 22 ++++++++++++++++++++-- main_test.go | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/LICENSE b/LICENSE index f266579..51a7970 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2018 Better Mortgage +Copyright (c) 2018-2019 Better Mortgage Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/main.go b/main.go index 85c16ce..8879968 100644 --- a/main.go +++ b/main.go @@ -131,16 +131,34 @@ func filterObjectsByLabel(objects []runtime.Object, label string) []runtime.Obje return filteredObjects } +func filterObjectsByNamespace(objects []runtime.Object, namespace string) []runtime.Object { + if namespace == "" { + return objects + } + + filteredObjects := make([]runtime.Object, 0, 1) + for _, o := range objects { + metadata, _ := getObjectMetadata(o) + if metadata.GetNamespace() == namespace { + filteredObjects = append(filteredObjects, o) + } + } + + return filteredObjects +} + func main() { //todo: exit status, write to stderr, embed version and build flag.Usage = func() { fmt.Println("Usage: kubechange -l