Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose secrets for notification templates (#3455) #3466

Merged
merged 4 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions utils/record/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,11 @@ func NewAPIFactorySettings(arInformer argoinformers.AnalysisRunInformer) api.Set
InitGetVars: func(cfg *api.Config, configMap *corev1.ConfigMap, secret *corev1.Secret) (api.GetVars, error) {
return func(obj map[string]any, dest services.Destination) map[string]any {

var vars = map[string]any{"rollout": obj, "time": timeExprs}
var vars = map[string]any{
"rollout": obj,
"time": timeExprs,
"secrets": secret.Data,
}

if arInformer == nil {
log.Infof("Notification is not set for analysisRun Informer: %s", dest)
Expand All @@ -313,7 +317,12 @@ func NewAPIFactorySettings(arInformer argoinformers.AnalysisRunInformer) api.Set

}

vars = map[string]any{"rollout": obj, "analysisRuns": arsObj, "time": timeExprs}
vars = map[string]any{
"rollout": obj,
"analysisRuns": arsObj,
"time": timeExprs,
"secrets": secret.Data,
}
return vars
}, nil
},
Expand Down
18 changes: 17 additions & 1 deletion utils/record/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,18 @@ func TestNewAPIFactorySettings(t *testing.T) {
},
}

expectedSecrets := map[string][]byte{
"notification-secret": []byte("secret-value"),
}

notificationsSecret := corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "argocd-notifications-secret",
zachaller marked this conversation as resolved.
Show resolved Hide resolved
Namespace: "default",
},
Data: expectedSecrets,
}

type expectedFunc func(obj map[string]interface{}, ar any) map[string]interface{}
type arInformerFunc func([]*v1alpha1.AnalysisRun) argoinformers.AnalysisRunInformer

Expand All @@ -506,6 +518,7 @@ func TestNewAPIFactorySettings(t *testing.T) {
"rollout": obj,
"analysisRuns": ar,
"time": timeExprs,
"secrets": expectedSecrets,
}
},
},
Expand All @@ -531,6 +544,7 @@ func TestNewAPIFactorySettings(t *testing.T) {
"rollout": obj,
"analysisRuns": nil,
"time": timeExprs,
"secrets": expectedSecrets,
}
},
},
Expand All @@ -545,6 +559,7 @@ func TestNewAPIFactorySettings(t *testing.T) {
return map[string]interface{}{
"rollout": obj,
"time": timeExprs,
"secrets": expectedSecrets,
}
},
},
Expand All @@ -570,6 +585,7 @@ func TestNewAPIFactorySettings(t *testing.T) {
"rollout": obj,
"analysisRuns": nil,
"time": timeExprs,
"secrets": expectedSecrets,
}
},
},
Expand All @@ -579,7 +595,7 @@ func TestNewAPIFactorySettings(t *testing.T) {
t.Run(test.name, func(t *testing.T) {

settings := NewAPIFactorySettings(test.arInformer(test.ars))
getVars, err := settings.InitGetVars(nil, nil, nil)
getVars, err := settings.InitGetVars(nil, nil, &notificationsSecret)
require.NoError(t, err)
if err != nil {
t.Errorf("Unexpected error: %v", err)
Expand Down
Loading