From b8b4896952cd3037ed370d8c1de1ec88b0766a29 Mon Sep 17 00:00:00 2001 From: Siddhesh Ghadi Date: Mon, 8 Jul 2024 18:14:29 +0530 Subject: [PATCH] Return map instead of slice for annotations Signed-off-by: Siddhesh Ghadi --- controller/appcontroller.go | 2 +- go.mod | 2 +- go.sum | 6 +++--- server/application/application.go | 6 +++--- util/settings/settings.go | 8 ++++---- util/settings/settings_test.go | 13 +++++-------- 6 files changed, 17 insertions(+), 20 deletions(-) diff --git a/controller/appcontroller.go b/controller/appcontroller.go index 7c061feaaa169..36a2f4375a0e1 100644 --- a/controller/appcontroller.go +++ b/controller/appcontroller.go @@ -757,7 +757,7 @@ func (ctrl *ApplicationController) hideSecretData(app *appv1.Application, compar resDiff := res.Diff if res.Kind == kube.SecretKind && res.Group == "" { var err error - target, live, err = diff.HideSecretData(res.Target, res.Live, ctrl.settingsMgr.GetHideSecretAnnotations()...) + target, live, err = diff.HideSecretData(res.Target, res.Live, ctrl.settingsMgr.GetHideSecretAnnotations()) if err != nil { return nil, fmt.Errorf("error hiding secret data: %w", err) } diff --git a/go.mod b/go.mod index 0880ef0ee84e7..7db719d724ed2 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/argoproj/argo-cd/v2 go 1.22.0 -replace github.com/argoproj/gitops-engine => github.com/svghadi/gitops-engine v0.0.0-20240514135501-7e8d80bb263f +replace github.com/argoproj/gitops-engine => github.com/svghadi/gitops-engine v0.0.0-20240708123951-d98e37ac4a1b require ( code.gitea.io/sdk/gitea v0.19.0 diff --git a/go.sum b/go.sum index 7be6ab46071b2..2e793bf1bec07 100644 --- a/go.sum +++ b/go.sum @@ -83,8 +83,6 @@ github.com/antonmedv/expr v1.15.1/go.mod h1:0E/6TxnOlRNp81GMzX9QfDPAmHo2Phg00y4J github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/appscode/go v0.0.0-20191119085241-0887d8ec2ecc/go.mod h1:OawnOmAL4ZX3YaPdN+8HTNwBveT1jMsqP74moa9XUbE= -github.com/argoproj/gitops-engine v0.7.1-0.20240917171920-72bcdda3f0a5 h1:K/e+NsNmE4BccRu21QpqUxkTHxU9YWjU3M775Ck+V/E= -github.com/argoproj/gitops-engine v0.7.1-0.20240917171920-72bcdda3f0a5/go.mod h1:b1vuwkyMUszyUK+USUJqC8vJijnQsEPNDpC+sDdDLtM= github.com/argoproj/notifications-engine v0.4.1-0.20240606074338-0802cd427621 h1:Yg1nt+D2uDK1SL2jSlfukA4yc7db184TTN7iWy3voRE= github.com/argoproj/notifications-engine v0.4.1-0.20240606074338-0802cd427621/go.mod h1:N0A4sEws2soZjEpY4hgZpQS8mRIEw6otzwfkgc3g9uQ= github.com/argoproj/pkg v0.13.7-0.20230626144333-d56162821bd1 h1:qsHwwOJ21K2Ao0xPju1sNuqphyMnMYkyB3ZLoLtxWpo= @@ -914,7 +912,7 @@ github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5J github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -ðgithub.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= @@ -930,6 +928,8 @@ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/svghadi/gitops-engine v0.0.0-20240708123951-d98e37ac4a1b h1:JQ5myNkZxbHw/69GGQsHMEqO8rm0CSrVr/rSnVt/PT0= +github.com/svghadi/gitops-engine v0.0.0-20240708123951-d98e37ac4a1b/go.mod h1:xMIbuLg9Qj2e0egTy+8NcukbhRaVmWwK9vm3aAQZoi4= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= diff --git a/server/application/application.go b/server/application/application.go index b910457e7523a..04628dc8f5d99 100644 --- a/server/application/application.go +++ b/server/application/application.go @@ -550,7 +550,7 @@ func (s *Server) GetManifests(ctx context.Context, q *application.ApplicationMan return nil, fmt.Errorf("error unmarshaling manifest into unstructured: %w", err) } if obj.GetKind() == kube.SecretKind && obj.GroupVersionKind().Group == "" { - obj, _, err = diff.HideSecretData(obj, nil, s.settingsMgr.GetHideSecretAnnotations()...) + obj, _, err = diff.HideSecretData(obj, nil, s.settingsMgr.GetHideSecretAnnotations()) if err != nil { return nil, fmt.Errorf("error hiding secret data: %w", err) } @@ -676,7 +676,7 @@ func (s *Server) GetManifestsWithFiles(stream application.ApplicationService_Get return fmt.Errorf("error unmarshaling manifest into unstructured: %w", err) } if obj.GetKind() == kube.SecretKind && obj.GroupVersionKind().Group == "" { - obj, _, err = diff.HideSecretData(obj, nil, s.settingsMgr.GetHideSecretAnnotations()...) + obj, _, err = diff.HideSecretData(obj, nil, s.settingsMgr.GetHideSecretAnnotations()) if err != nil { return fmt.Errorf("error hiding secret data: %w", err) } @@ -1375,7 +1375,7 @@ func (s *Server) GetResource(ctx context.Context, q *application.ApplicationReso func (s *Server) replaceSecretValues(obj *unstructured.Unstructured) (*unstructured.Unstructured, error) { if obj.GetKind() == kube.SecretKind && obj.GroupVersionKind().Group == "" { - _, obj, err := diff.HideSecretData(nil, obj, s.settingsMgr.GetHideSecretAnnotations()...) + _, obj, err := diff.HideSecretData(nil, obj, s.settingsMgr.GetHideSecretAnnotations()) if err != nil { return nil, err } diff --git a/util/settings/settings.go b/util/settings/settings.go index 39d9c0bbfe62f..125efc5ccb184 100644 --- a/util/settings/settings.go +++ b/util/settings/settings.go @@ -2320,12 +2320,12 @@ func (mgr *SettingsManager) GetExcludeEventLabelKeys() []string { return labelKeys } -func (mgr *SettingsManager) GetHideSecretAnnotations() []string { - annotsKeys := []string{} +func (mgr *SettingsManager) GetHideSecretAnnotations() map[string]bool { + annotsKeys := make(map[string]bool) argoCDCM, err := mgr.getConfigMap() if err != nil { log.Error(fmt.Errorf("failed getting configmap: %v", err)) - return annotsKeys + return nil } if value, ok := argoCDCM.Data[hideSecretAnnotations]; ok { annots := strings.Split(value, "\n") @@ -2333,7 +2333,7 @@ func (mgr *SettingsManager) GetHideSecretAnnotations() []string { a = regexp.MustCompile(`^\s*-`).ReplaceAllString(a, "") a := strings.TrimSpace(a) if a != "" { - annotsKeys = append(annotsKeys, a) + annotsKeys[a] = true } } } diff --git a/util/settings/settings_test.go b/util/settings/settings_test.go index 2731de180f7f0..9b25a90bf5812 100644 --- a/util/settings/settings_test.go +++ b/util/settings/settings_test.go @@ -1730,24 +1730,24 @@ func TestSettingsManager_GetHideSecretAnnotations(t *testing.T) { tests := []struct { name string input string - output []string + output map[string]bool }{ { name: "Empty input", input: "", - output: []string{}, + output: map[string]bool{}, }, { name: "Correct format", input: `- example.com/token-secret.value - token`, - output: []string{"example.com/token-secret.value", "token"}, + output: map[string]bool{"example.com/token-secret.value": true, "token": true}, }, { name: "Partially correct format with each key on new line - returns correct keys", input: ` example.com/token-secret.value -token`, - output: []string{"example.com/token-secret.value", "token"}, + output: map[string]bool{"example.com/token-secret.value": true, "token": true}, }, } for _, tt := range tests { @@ -1757,10 +1757,7 @@ func TestSettingsManager_GetHideSecretAnnotations(t *testing.T) { }) keys := settingsManager.GetHideSecretAnnotations() assert.Equal(t, len(tt.output), len(keys)) - - for i := range tt.output { - assert.Equal(t, tt.output[i], keys[i]) - } + assert.Equal(t, tt.output, keys) }) } }