Skip to content

Commit

Permalink
ROX-27209: Create external secrets for quay image pull secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
kovayur committed Nov 29, 2024
1 parent 6a0cf5e commit 23bace9
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ spec:
remoteRef:
key: "secured-cluster"
property: "sensor_key"
{{- if and (ne .Values.pullSecret "") .Values.createPullSecret }}
{{- if and .Values.pullSecret .Values.createPullSecret }}
---
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,25 @@ spec:
remoteRef:
key: "/fleetshard-sync/aws_role_arn"
{{- end }}
{{- with .Values.fleetshardSync.tenantImagePullSecret }}
{{- if and .create .name }}
---
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: {{ .name }}
namespace: {{ $.Release.Namespace }}
spec:
secretStoreRef:
name: {{ $.Values.global.secretStore.aws.secretsManagerSecretStoreName }}
kind: ClusterSecretStore
target:
name: {{ .name }}
creationPolicy: Owner
data:
- secretKey: {{ .key }} # pragma: allowlist secret
remoteRef:
key: "quay/rhacs-eng"
property: ".dockerconfigjson"
{{- end }}
{{- end }}
1 change: 1 addition & 0 deletions dp-terraform/helm/rhacs-terraform/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fleetshardSync:
tenantImagePullSecret:
name: ""
key: .dockerconfigjson
create: false
printCentralUpdateDiff: false
argoCdNamespace: openshift-gitops

Expand Down
61 changes: 61 additions & 0 deletions dp-terraform/test/helm_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,67 @@ func TestHelmTemplate_FleetshardSyncDeployment_Image(t *testing.T) {
}
}

func TestHelmTemplate_FleetshardSync_ImagePullSecret(t *testing.T) {
t.Parallel()

tests := []struct {
name string
pullSecret string
createPullSecret string
wantPullSecret bool
}{
{
name: "should not create secret when pull secret is not set and createPullSecret is false",
pullSecret: "",
createPullSecret: "false",
wantPullSecret: false,
},
{
name: "should not create secret when pull secret is set and createPullSecret is false",
pullSecret: "quay-image-pull-secret",
createPullSecret: "false",
wantPullSecret: false,
},
{
name: "should not create secret when pull secret is not set and createPullSecret is true",
pullSecret: "",
createPullSecret: "true",
wantPullSecret: false,
},
{
name: "should create secret when pull secret is set and createPullSecret is true",
pullSecret: "quay-image-pull-secret",
createPullSecret: "true",
wantPullSecret: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
values := map[string]string{
"secured-cluster.enabled": "false",
"fleetshardSync.managedDB.enabled": "false",
"fleetshardSync.tenantImagePullSecret.create": tt.createPullSecret,
}
if tt.pullSecret != "" {
values["fleetshardSync.tenantImagePullSecret.name"] = tt.pullSecret // pragma: allowlist secret
}

output := renderTemplate(t, values, "templates/fleetshard-sync-secret.yaml")
allRange := strings.Split(output, "---")
for _, rawOutput := range allRange[1:] {
var secret corev1.Secret
helm.UnmarshalK8SYaml(t, rawOutput, &secret)
if secret.Name == tt.pullSecret {
require.True(t, tt.wantPullSecret)
return
}
}
require.False(t, tt.wantPullSecret)
})
}
}

func TestHelmTemplate_SecuredCluster_ImagePullSecret(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 23bace9

Please sign in to comment.