Skip to content

Commit

Permalink
feat: expose secrets for notification templates (argoproj#3455) (argo…
Browse files Browse the repository at this point in the history
…proj#3466)

* feat: expose secrets for notification templates

Signed-off-by: Etien Roznik <[email protected]>

* feat: expose secrets for notification templates

Signed-off-by: Etien Roznik <[email protected]>

---------

Signed-off-by: Etien Roznik <[email protected]>
  • Loading branch information
eroznik authored Mar 28, 2024
1 parent 633819b commit 86a2df6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
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: "argo-rollouts-notification-secret",
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

0 comments on commit 86a2df6

Please sign in to comment.