Skip to content

Commit

Permalink
fix: copy owner label and annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
mcavoyk committed Sep 12, 2020
1 parent 46a4baa commit b37b27a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/controller/externalsecret/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ func (r *ExternalSecretReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err
return fmt.Errorf("failed to set ExternalSecret controller reference: %w", err)
}

secret.Labels = extSecret.Labels
secret.Annotations = extSecret.Annotations
secret.Data, err = r.getSecret(ctx, storeClient, extSecret)
if err != nil {
return fmt.Errorf("%s: %w", errGetSecretDataFailed, err)
Expand All @@ -108,6 +110,7 @@ func (r *ExternalSecretReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err
return fmt.Errorf("%s: %w", errTemplateFailed, err)
}
}

return nil
})

Expand Down Expand Up @@ -197,15 +200,15 @@ func (r *ExternalSecretReconciler) getStore(ctx context.Context, extSecret *smv1
}
return clusterStore, nil
}
var namespacedStore smv1alpha1.SecretStore
namespacedStore := &smv1alpha1.SecretStore{}
ref := types.NamespacedName{
Namespace: extSecret.Namespace,
Name: extSecret.Spec.StoreRef.Name,
}
if err := r.Reader.Get(ctx, ref, &namespacedStore); err != nil {
if err := r.Reader.Get(ctx, ref, namespacedStore); err != nil {
return nil, fmt.Errorf("SecretStore %q: %w", ref.Name, err)
}
return &namespacedStore, nil
return namespacedStore, nil
}

func (r *ExternalSecretReconciler) templateSecret(secret *corev1.Secret, template []byte) error {
Expand Down
11 changes: 11 additions & 0 deletions pkg/controller/externalsecret/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ var _ = Describe("ExternalSecrets Controller", func() {
ObjectMeta: metav1.ObjectMeta{
Name: key.Name,
Namespace: key.Namespace,
Labels: map[string]string{
"label-key": "label-value",
},
Annotations: map[string]string{
"annotation-key": "annotation-value",
},
},
Spec: spec,
}
Expand Down Expand Up @@ -237,6 +243,11 @@ var _ = Describe("ExternalSecrets Controller", func() {
"The owner kind should be ExternalSecret")
Expect(fetchedSecret.OwnerReferences[0].Name).Should(BeIdenticalTo(toCreate.Name),
"The owner name should be the name of the ExternalSecret")

Expect(fetchedSecret.Labels["label-key"]).Should(BeIdenticalTo(toCreate.Labels["label-key"]),
"The secret should have labels of the ExternalSecret")
Expect(fetchedSecret.Annotations["annotation-key"]).Should(BeIdenticalTo(toCreate.Annotations["annotation-key"]),
"The secret should have annotations of the ExternalSecret")
})

It("An ExternalSecret with dataFrom specified should generate secret", func() {
Expand Down

0 comments on commit b37b27a

Please sign in to comment.