Skip to content

Commit

Permalink
refactored and fixed typos
Browse files Browse the repository at this point in the history
  • Loading branch information
sinamna committed Dec 12, 2023
1 parent a43a3f2 commit d211511
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
30 changes: 15 additions & 15 deletions internal/controller/basic_authenticator/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ func (r *BasicAuthenticatorReconciler) removeInjectedContainers(ctx context.Cont
}
}
}

if err := r.Update(ctx, deploy); err != nil {
r.logger.Error(err, "failed to update cleanup deployments")
return subreconciler.RequeueWithError(err)
}
}
return subreconciler.ContinueReconciling()
}
Expand All @@ -84,14 +79,14 @@ func (r *BasicAuthenticatorReconciler) removeCleanupFinalizer(ctx context.Contex
}
if controllerutil.ContainsFinalizer(basicAuthenticator, basicAuthenticatorFinalizer) {
if ok := controllerutil.RemoveFinalizer(basicAuthenticator, basicAuthenticatorFinalizer); !ok {
r.logger.Error(errors.New("finalizer not updated"), "Failed to remove finalizer for Memcached")
r.logger.Error(errors.New("finalizer not updated"), "Failed to remove finalizer for BasicAuthenticator")
return subreconciler.Requeue()
}
}

if err := r.Update(ctx, basicAuthenticator); err != nil {
r.logger.Error(err, "Failed to remove finalizer for Memcached")
return subreconciler.RequeueWithError(err)
}
if err := r.Update(ctx, basicAuthenticator); err != nil {
r.logger.Error(err, "Failed to remove finalizer for BasicAuthenticator")
return subreconciler.RequeueWithError(err)
}
return subreconciler.ContinueReconciling()
}
Expand Down Expand Up @@ -144,9 +139,6 @@ func getTargetSecretName(ctx context.Context, basicAuthenticator *v1alpha1.Basic
return resultSecrets, nil
}
func removeInjectedResources(deployments []*appsv1.Deployment, secrets []string, configmap []string) []*appsv1.Deployment {
targetSecret := secrets[0] // there should always be one secret
targetCm := configmap[0] // there should always be one configmap

for _, deploy := range deployments {
containers := make([]v1.Container, 0)
for _, container := range deploy.Spec.Template.Spec.Containers {
Expand All @@ -157,8 +149,7 @@ func removeInjectedResources(deployments []*appsv1.Deployment, secrets []string,
deploy.Spec.Template.Spec.Containers = containers
volumes := make([]v1.Volume, 0)
for _, vol := range deploy.Spec.Template.Spec.Volumes {

if vol.Name != targetSecret && vol.Name != targetCm {
if !existsInList(secrets, vol.Name) && !existsInList(configmap, vol.Name) {
volumes = append(volumes, vol)
}
}
Expand All @@ -169,3 +160,12 @@ func removeInjectedResources(deployments []*appsv1.Deployment, secrets []string,
}
return deployments
}

func existsInList(strList []string, targetStr string) bool {
for _, val := range strList {
if val == targetStr {
return true
}
}
return false
}
13 changes: 3 additions & 10 deletions internal/controller/basic_authenticator/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,18 +307,11 @@ func (r *BasicAuthenticatorReconciler) createSidecarAuthenticator(ctx context.Co
}
for _, deploy := range deploymentsToUpdate {
if !controllerutil.ContainsFinalizer(deploy, basicAuthenticatorFinalizer) {
if objUpdated := controllerutil.AddFinalizer(deploy, basicAuthenticatorFinalizer); objUpdated {
if err := r.Update(ctx, deploy); err != nil {
r.logger.Error(err, "failed to update injected deployment to add finalizer")
return subreconciler.Requeue()
}

if err = r.Get(ctx, types.NamespacedName{Namespace: deploy.Namespace, Name: deploy.Name}, deploy); err != nil {
r.logger.Error(err, "failed to refetch deploy")
return subreconciler.RequeueWithError(err)
}
if objUpdated := controllerutil.AddFinalizer(deploy, basicAuthenticatorFinalizer); !objUpdated {
return subreconciler.Requeue()
}
}

err := r.Update(ctx, deploy)
if err != nil {
r.logger.Error(err, "failed to update injected deployments")
Expand Down

0 comments on commit d211511

Please sign in to comment.