diff --git a/main.go b/main.go index 19803fe..a3e707a 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ package main import ( "flag" + "github.com/keikoproj/flippy/pkg/common" "os" "time" @@ -61,6 +62,7 @@ func main() { "Enable leader election for controller manager. "+ "Enabling this will ensure there is only one active controller manager.") flag.DurationVar(&flagReconcilerTime, "reconciler-time", 10*time.Hour, "The flippy reconciler time.") + flag.StringVar(&common.IgnoreMetadata, "ignore-metadata", "flippy-ignore", "Annotation (Rollout/Deployment) and Label (Namespace) to be ignored") opts := zap.Options{ Development: true, diff --git a/pkg/common/Constants.go b/pkg/common/Constants.go index 4e7bf8b..29bcca0 100644 --- a/pkg/common/Constants.go +++ b/pkg/common/Constants.go @@ -23,3 +23,5 @@ type RestartObjects struct { NamespaceObjects map[string][]string RestartConfig crdv1.StatusCheckConfig } + +var IgnoreMetadata string diff --git a/pkg/k8s-utils/utils/utils.go b/pkg/k8s-utils/utils/utils.go index 163145c..07f375d 100644 --- a/pkg/k8s-utils/utils/utils.go +++ b/pkg/k8s-utils/utils/utils.go @@ -4,6 +4,7 @@ import ( "io/ioutil" "log" "os" + "strings" "github.com/argoproj/argo-rollouts/pkg/client/clientset/versioned" "github.com/keikoproj/flippy/pkg/common" @@ -73,6 +74,12 @@ func StringArrayContains(s []string, str string) bool { } func IsStringMapSubset(masterMap map[string]string, subsetMap map[string]string) bool { + flippyIgnore, ok := masterMap[common.IgnoreMetadata] + + if ok && strings.ToLower(flippyIgnore) == "true" { + return false + } + match := 0 for key, value := range subsetMap { masterValue, ok := masterMap[key] diff --git a/pkg/k8s-utils/utils/utils_test.go b/pkg/k8s-utils/utils/utils_test.go new file mode 100644 index 0000000..a6946b8 --- /dev/null +++ b/pkg/k8s-utils/utils/utils_test.go @@ -0,0 +1,39 @@ +package utils + +import ( + "github.com/keikoproj/flippy/pkg/common" + "testing" +) + +func TestIsStringMapSubset(t *testing.T) { + + masterMap := make(map[string]string) + masterMap["test1"] = "test" + masterMap["test2"] = "" + masterMap["test3"] = "true" + masterMap["test4"] = "false" + + subsetMap := make(map[string]string) + subsetMap["test1"] = "test" + + tests := []struct { + name string + args string + want bool + }{ + {"No addition to label", "empty", true}, + {"Addition to label to ignore flippy with empty value", "test2", true}, + {"Addition to label to ignore flippy", "test3", false}, + {"Addition to label to ignore flippy with default value", "test4", true}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if tt.args != "empty" { + common.IgnoreMetadata = tt.args + } + if got := IsStringMapSubset(masterMap, subsetMap); got != tt.want { + t.Errorf("IsStringMapSubset() = %v, want %v", got, tt.want) + } + }) + } +}