Skip to content

Commit

Permalink
Return map instead of slice for annotations
Browse files Browse the repository at this point in the history
Signed-off-by: Siddhesh Ghadi <sghadi1203@gmail.com>
  • Loading branch information
svghadi committed Jul 8, 2024
1 parent 9af8621 commit 1bc8297
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion controller/appcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,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)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/argoproj/argo-cd/v2

go 1.21.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.18.0
Expand Down
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,6 @@ github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apache/thrift v0.16.0/go.mod h1:PHK3hniurgQaNMZYaCLEqXKsYK8upmhPbmdP2FXSqgU=
github.com/appscode/go v0.0.0-20191119085241-0887d8ec2ecc/go.mod h1:OawnOmAL4ZX3YaPdN+8HTNwBveT1jMsqP74moa9XUbE=
github.com/argoproj/gitops-engine v0.7.1-0.20240628155502-fa0e8d60a3a4 h1:xctch+EYCzsz012kNrdK3eRALf+/ZLhWJAWG0xfxpl8=
github.com/argoproj/gitops-engine v0.7.1-0.20240628155502-fa0e8d60a3a4/go.mod h1:xMIbuLg9Qj2e0egTy+8NcukbhRaVmWwK9vm3aAQZoi4=
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=
Expand Down Expand Up @@ -1693,7 +1691,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=
Expand All @@ -1709,6 +1707,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/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
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=
Expand Down
6 changes: 3 additions & 3 deletions server/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions util/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2261,20 +2261,20 @@ 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))

Check failure on line 2268 in util/settings/settings.go

View workflow job for this annotation

GitHub Actions / Lint Go code

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
return annotsKeys
return nil
}
if value, ok := argoCDCM.Data[hideSecretAnnotations]; ok {
annots := strings.Split(value, "\n")
for _, a := range annots {
a = regexp.MustCompile(`^\s*-`).ReplaceAllString(a, "")
a := strings.TrimSpace(a)
if a != "" {
annotsKeys = append(annotsKeys, a)
annotsKeys[a] = true
}
}
}
Expand Down
13 changes: 5 additions & 8 deletions util/settings/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1607,24 +1607,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 {
Expand All @@ -1634,10 +1634,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)
})
}
}

0 comments on commit 1bc8297

Please sign in to comment.