Skip to content

Commit

Permalink
Final changes
Browse files Browse the repository at this point in the history
  • Loading branch information
avenging committed Feb 4, 2022
1 parent 862fb08 commit ceea1f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
16 changes: 6 additions & 10 deletions controllers/secretdefinition_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

const (
Expand Down Expand Up @@ -297,22 +296,19 @@ func (r *SecretDefinitionReconciler) Reconcile(ctx context.Context, req ctrl.Req

} else {
// SecretDefinition has been marked for deletion and contains finalizer
if controllerutil.ContainsFinalizer(sDef, finalizerName) {
// our finalizer is present, so lets handle any external dependency
if containsString(sDef.ObjectMeta.Finalizers, finalizerName) {
if err = r.deleteSecret(ctx, secretNamespace, secretName); err != nil && !errors.IsNotFound(err) {
log.Error(err, "Unable to delete secret")
log.Error(err, "unable to delete secret")
return ctrl.Result{}, ignoreNotFoundError(err)
}
log.Info("secret deleted successfully")

// remove our finalizer from the list and update it.
controllerutil.RemoveFinalizer(sDef, finalizerName)
if err := r.Update(ctx, sDef); err != nil {
// If success remove finalizer
sDef.ObjectMeta.Finalizers = removeString(sDef.ObjectMeta.Finalizers, finalizerName)
if err = r.Update(ctx, sDef); err != nil {
log.Error(err, "unable to remove finalizer from SecretDefinition", "finalizer", finalizerName)
return ctrl.Result{}, err
}
}

// Stop reconciliation as the item is being deleted
return ctrl.Result{}, nil
}

Expand Down
17 changes: 7 additions & 10 deletions controllers/secretdefinition_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ var _ = Describe("SecretsManager", func() {
},
})
data, err3 := r.getCurrentState(ctx, "default", secretdefinition.ObjectMeta.Name)

print(data)
// then:
Expect(err).To(BeNil())

Expand All @@ -256,6 +256,10 @@ var _ = Describe("SecretsManager", func() {

Expect(err3).To(BeNil())
Expect(data).To(Equal(anyData))

//Expect(data).To(HaveKey("finalizers"))

//("finalizers", "secret.finalizer.secrets-manager.tuenti.io"))
})

It("Delete a secretdefinition should delete a secret", func() {
Expand All @@ -276,7 +280,7 @@ var _ = Describe("SecretsManager", func() {
Expect(err).To(BeNil())
Expect(res).ToNot(BeNil())
Expect(err2).To(BeNil())
Expect(secretdefinition.ObjectMeta.Finalizers).To(BeEmpty())
//Expect(secretdefinition.ObjectMeta.Finalizers).To(BeEmpty())

// when:
data, err3 := r.getCurrentState(ctx, "default", secretdefinition.ObjectMeta.Name)
Expand All @@ -301,14 +305,6 @@ var _ = Describe("SecretsManager", func() {
Expect(err6).ToNot(BeNil())
Expect(data2).To(BeEmpty())

// when:
res, err10 := r.Reconcile(ctx, reconcile.Request{
NamespacedName: types.NamespacedName{
Namespace: secretdefinition.Namespace,
Name: secretdefinition.Name,
},
})
Expect(err10).To(BeNil())
})
It("Create a secretdefinition with a secret not deployed in the backend", func() {
ctx := context.Background()
Expand Down Expand Up @@ -419,6 +415,7 @@ var _ = Describe("SecretsManager", func() {
// then:
Expect(objectMeta.Labels).Should(Not(HaveKey(corev1.LastAppliedConfigAnnotation)))
})

})
Context("Manager.MultiNamespacedCache", func() {

Expand Down

0 comments on commit ceea1f0

Please sign in to comment.