Skip to content

Commit

Permalink
Pass 1 : parameter ignore metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Viraj Kulkarni committed May 2, 2024
1 parent 4c7e2b9 commit 1b39e16
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"flag"
"github.com/keikoproj/flippy/pkg/common"
"os"
"time"

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions pkg/common/Constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ type RestartObjects struct {
NamespaceObjects map[string][]string
RestartConfig crdv1.StatusCheckConfig
}

var IgnoreMetadata string
7 changes: 7 additions & 0 deletions pkg/k8s-utils/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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]
Expand Down
39 changes: 39 additions & 0 deletions pkg/k8s-utils/utils/utils_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}

0 comments on commit 1b39e16

Please sign in to comment.