From 64a7cfc29dab96376e084927e82a0262f9aa2a25 Mon Sep 17 00:00:00 2001 From: Daniel Ward Date: Mon, 26 Oct 2020 14:19:00 -0400 Subject: [PATCH] fixed type scope as requested --- api/v1/syncedsecret_types.go | 6 ++++-- config/crd/bases/secrets.contentful.com_syncedsecrets.yaml | 5 +++-- config/samples/secrets_v1_syncedsecret_specified_type.yaml | 2 +- pkg/k8ssecret/secret.go | 4 ++-- pkg/k8ssecret/secret_test.go | 5 +++-- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/api/v1/syncedsecret_types.go b/api/v1/syncedsecret_types.go index 01a7a3d..dc0fcc3 100644 --- a/api/v1/syncedsecret_types.go +++ b/api/v1/syncedsecret_types.go @@ -81,6 +81,10 @@ type SyncedSecretSpec struct { // DataFrom // +optional DataFrom *DataFrom `json:"dataFrom,omitempty"` + + // Type + // +optional + Type corev1.SecretType `json:"type,omitempty"` } // SyncedSecretStatus defines the observed state of SyncedSecret @@ -105,8 +109,6 @@ type SyncedSecret struct { Spec SyncedSecretSpec `json:"spec,omitempty"` Status SyncedSecretStatus `json:"status,omitempty"` - - Type corev1.SecretType `json:"type,omitempty"` } // +kubebuilder:object:root=true diff --git a/config/crd/bases/secrets.contentful.com_syncedsecrets.yaml b/config/crd/bases/secrets.contentful.com_syncedsecrets.yaml index a9b674b..c3b7f4c 100644 --- a/config/crd/bases/secrets.contentful.com_syncedsecrets.yaml +++ b/config/crd/bases/secrets.contentful.com_syncedsecrets.yaml @@ -92,6 +92,9 @@ spec: secretMetadata: description: Secret Metadata type: object + type: + description: Type + type: string type: object status: description: SyncedSecretStatus defines the observed state of SyncedSecret @@ -107,8 +110,6 @@ spec: required: - currentVersionID type: object - type: - type: string type: object version: v1 versions: diff --git a/config/samples/secrets_v1_syncedsecret_specified_type.yaml b/config/samples/secrets_v1_syncedsecret_specified_type.yaml index 87c9cec..17484f2 100644 --- a/config/samples/secrets_v1_syncedsecret_specified_type.yaml +++ b/config/samples/secrets_v1_syncedsecret_specified_type.yaml @@ -1,10 +1,10 @@ apiVersion: secrets.contentful.com/v1 kind: SyncedSecret -type: kubernetes.io/dockerconfigjson metadata: name: syncedsecret-sample-ks namespace: kube-secret-syncer spec: + type: kubernetes.io/dockerconfigjson secretMetadata: name: demo-service-secret namespace: kube-secret-syncer diff --git a/pkg/k8ssecret/secret.go b/pkg/k8ssecret/secret.go index 3a4008d..5df43b1 100644 --- a/pkg/k8ssecret/secret.go +++ b/pkg/k8ssecret/secret.go @@ -154,8 +154,8 @@ func GenerateK8SSecret( } secretType := corev1.SecretTypeOpaque - if cs.Type != "" { - secretType = cs.Type + if cs.Spec.Type != "" { + secretType = cs.Spec.Type } secret := &corev1.Secret{ diff --git a/pkg/k8ssecret/secret_test.go b/pkg/k8ssecret/secret_test.go index 106a925..0094077 100644 --- a/pkg/k8ssecret/secret_test.go +++ b/pkg/k8ssecret/secret_test.go @@ -160,7 +160,8 @@ func TestGenerateSecret(t *testing.T) { "field2": []byte("value2"), }, }, - }, { + }, + { name: "it should support fields with a hardcoded value for Secret Type", have: have{ SyncedSecret: secretsv1.SyncedSecret{ @@ -187,8 +188,8 @@ func TestGenerateSecret(t *testing.T) { }, }, IAMRole: _s("iam_role"), + Type: "kubernetes.io/dockerconfigjson", }, - Type: "kubernetes.io/dockerconfigjson", }, err: nil, cachedSecrets: secretsmanager.Secrets{"cachedSecret1": {}, "cachedSecret2": {}},