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

fix template type error #84

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 0 additions & 2 deletions pkg/apis/meta/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/apis/secretmanager/v1alpha1/externalsecret_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions pkg/apis/secretmanager/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/controller/externalsecret/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
9 changes: 7 additions & 2 deletions pkg/controller/externalsecret/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -377,7 +378,9 @@ var _ = Describe("ExternalSecrets Controller", func() {
},
},
},
Template: templateObjectBytes,
Template: runtime.RawExtension{
Raw: templateObjectBytes,
},
}

key := types.NamespacedName{
Expand Down Expand Up @@ -463,7 +466,9 @@ var _ = Describe("ExternalSecrets Controller", func() {
},
},
},
Template: templateObjectBytes,
Template: runtime.RawExtension{
Raw: templateObjectBytes,
},
}

key := types.NamespacedName{
Expand Down