diff --git a/pkg/apis/meta/v1/zz_generated.deepcopy.go b/pkg/apis/meta/v1/zz_generated.deepcopy.go index af4d465..fbb7300 100755 --- a/pkg/apis/meta/v1/zz_generated.deepcopy.go +++ b/pkg/apis/meta/v1/zz_generated.deepcopy.go @@ -18,8 +18,6 @@ limitations under the License. package v1 -import () - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Condition) DeepCopyInto(out *Condition) { *out = *in diff --git a/pkg/apis/secretmanager/v1alpha1/externalsecret_types.go b/pkg/apis/secretmanager/v1alpha1/externalsecret_types.go index 33d1c92..650022e 100644 --- a/pkg/apis/secretmanager/v1alpha1/externalsecret_types.go +++ b/pkg/apis/secretmanager/v1alpha1/externalsecret_types.go @@ -18,6 +18,7 @@ import ( smmeta "github.com/itscontained/secret-manager/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" ) // ExternalSecretSpec defines the desired state of ExternalSecret @@ -37,7 +38,7 @@ type ExternalSecretSpec struct { // +kubebuilder:validation:Format=any // +kubebuilder:pruning:PreserveUnknownFields // +optional - Template []byte `json:"template,omitempty"` + Template runtime.RawExtension `json:"template,omitempty"` // Data is a list of references to secret values. // +optional diff --git a/pkg/apis/secretmanager/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/secretmanager/v1alpha1/zz_generated.deepcopy.go index 2cd7b9f..61a76c9 100644 --- a/pkg/apis/secretmanager/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/secretmanager/v1alpha1/zz_generated.deepcopy.go @@ -199,11 +199,7 @@ func (in *ExternalSecretList) DeepCopyObject() runtime.Object { func (in *ExternalSecretSpec) DeepCopyInto(out *ExternalSecretSpec) { *out = *in out.StoreRef = in.StoreRef - if in.Template != nil { - in, out := &in.Template, &out.Template - *out = make([]byte, len(*in)) - copy(*out, *in) - } + in.Template.DeepCopyInto(&out.Template) if in.Data != nil { in, out := &in.Data, &out.Data *out = make([]KeyReference, len(*in)) diff --git a/pkg/controller/externalsecret/controller.go b/pkg/controller/externalsecret/controller.go index 042ceef..1a1e89f 100644 --- a/pkg/controller/externalsecret/controller.go +++ b/pkg/controller/externalsecret/controller.go @@ -111,7 +111,7 @@ func (r *ExternalSecretReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err return fmt.Errorf("%s: %w", errGetSecretDataFailed, err) } - if extSecret.Spec.Template != nil { + if extSecret.Spec.Template.Raw != nil { err = r.templateSecret(secret, extSecret.Spec.Template) if err != nil { return fmt.Errorf("%s: %w", errTemplateFailed, err) @@ -202,9 +202,9 @@ func (r *ExternalSecretReconciler) getStore(ctx context.Context, extSecret *smv1 return secretStore, nil } -func (r *ExternalSecretReconciler) templateSecret(secret *corev1.Secret, template []byte) error { +func (r *ExternalSecretReconciler) templateSecret(secret *corev1.Secret, template runtime.RawExtension) error { templatedSecret := &corev1.Secret{} - if err := json.Unmarshal(template, templatedSecret); err != nil { + if err := json.Unmarshal(template.Raw, templatedSecret); err != nil { return fmt.Errorf("error unmarshalling json: %w", err) } diff --git a/pkg/controller/externalsecret/controller_test.go b/pkg/controller/externalsecret/controller_test.go index 9576319..2dfa180 100644 --- a/pkg/controller/externalsecret/controller_test.go +++ b/pkg/controller/externalsecret/controller_test.go @@ -30,6 +30,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" @@ -377,7 +378,9 @@ var _ = Describe("ExternalSecrets Controller", func() { }, }, }, - Template: templateObjectBytes, + Template: runtime.RawExtension{ + Raw: templateObjectBytes, + }, } key := types.NamespacedName{ @@ -463,7 +466,9 @@ var _ = Describe("ExternalSecrets Controller", func() { }, }, }, - Template: templateObjectBytes, + Template: runtime.RawExtension{ + Raw: templateObjectBytes, + }, } key := types.NamespacedName{