Skip to content

Commit

Permalink
Ignore error if credentials secret doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
ccremer committed Jul 12, 2022
1 parent 62eee0d commit 13a55ae
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions operator/cloudscale/deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/vshn/appcat-service-s3/apis/conditions"
"github.com/vshn/appcat-service-s3/operator/steps"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
controllerruntime "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -28,10 +29,9 @@ func (p *DeletionPipeline) Run(ctx context.Context) error {
pipeline.If(isObjectsUserIDKnown, pipeline.NewPipeline().WithNestedSteps("deprovision objects user",
pipeline.NewStepFromFunc("create client", CreateCloudscaleClientFn(APIToken)),
pipeline.NewStepFromFunc("delete objects user", DeleteObjectsUser),
pipeline.NewStepFromFunc("fetch credentials secret", fetchCredentialsSecret),
// Note: We do not need to check if there are Bucket resources still requiring the Secret.
// Cloudscale's API returns an error if there are still buckets existing for that user, which ultimately also ends up as a Failed condition in the ObjectsUser resource.
pipeline.NewStepFromFunc("delete finalizer from secret", steps.RemoveFinalizerFn(UserCredentialSecretKey{}, userFinalizer)),
pipeline.NewStepFromFunc("delete finalizer from secret", deleteFinalizerFromSecret),
pipeline.NewStepFromFunc("emit event", emitDeletionEvent),
)),
pipeline.NewStepFromFunc("remove finalizer", steps.RemoveFinalizerFn(ObjectsUserKey{}, userFinalizer)),
Expand All @@ -41,15 +41,21 @@ func (p *DeletionPipeline) Run(ctx context.Context) error {
return result.Err()
}

func fetchCredentialsSecret(ctx context.Context) error {
func deleteFinalizerFromSecret(ctx context.Context) error {
kube := steps.GetClientFromContext(ctx)
user := steps.GetFromContextOrPanic(ctx, ObjectsUserKey{}).(*cloudscalev1.ObjectsUser)
log := controllerruntime.LoggerFrom(ctx)

secret := &corev1.Secret{}
err := kube.Get(ctx, types.NamespacedName{Name: user.Spec.SecretRef, Namespace: user.Namespace}, secret)
pipeline.StoreInContext(ctx, UserCredentialSecretKey{}, secret)
return logIfNotError(err, log, 1, "Fetched credentials secret", "secretName", user.Spec.SecretRef)
if apierrors.IsNotFound(err) {
return nil // doesn't exist anymore, ignore
}
if err != nil {
return err // some other error
}
err = steps.RemoveFinalizerFn(ObjectsUserKey{}, userFinalizer)(ctx)
return logIfNotError(err, log, 1, "Deleted finalizer from credentials secret", "secretName", user.Spec.SecretRef)
}

func emitDeletionEvent(ctx context.Context) error {
Expand Down

0 comments on commit 13a55ae

Please sign in to comment.