Skip to content

Commit

Permalink
Ignore restart on a given rollout or deployment (#20)
Browse files Browse the repository at this point in the history
* Pass 1 : parameter ignore metadata

Signed-off-by: Viraj Kulkarni <[email protected]>

* Pass 2 : Updated name

Signed-off-by: Viraj Kulkarni <[email protected]>

* Pass 2 : Add additional test for code coverage

Signed-off-by: Viraj Kulkarni <[email protected]>

---------

Signed-off-by: Viraj Kulkarni <[email protected]>
Co-authored-by: Viraj Kulkarni <[email protected]>
  • Loading branch information
virajrk and Viraj Kulkarni authored May 3, 2024
1 parent 4c7e2b9 commit abe59e1
Show file tree
Hide file tree
Showing 4 changed files with 66 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.IgnoreMetadataKey, "flippy-ignore-key", "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 IgnoreMetadataKey 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.IgnoreMetadataKey]

if ok && strings.ToLower(flippyIgnore) == "true" {
return false
}

match := 0
for key, value := range subsetMap {
masterValue, ok := masterMap[key]
Expand Down
55 changes: 55 additions & 0 deletions pkg/k8s-utils/utils/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package utils

import (
"github.com/keikoproj/flippy/pkg/common"
"github.com/tj/assert"
"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.IgnoreMetadataKey = tt.args
}
if got := IsStringMapSubset(masterMap, subsetMap); got != tt.want {
t.Errorf("IsStringMapSubset() = %v, want %v", got, tt.want)
}
})
}
}

func TestIsStringMapSubsetNegative(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["test5"] = "test"

got := IsStringMapSubset(masterMap, subsetMap)
assert.Equal(t, false, got)
}

0 comments on commit abe59e1

Please sign in to comment.