diff --git a/controllers/reconciler_common.go b/controllers/reconciler_common.go index 9ddd1b879e0f7b0d1216446f12d47f4aa1235520..ab2a65e012f9cb6b482bc556193ae435b918f507 100644 --- a/controllers/reconciler_common.go +++ b/controllers/reconciler_common.go @@ -23,6 +23,7 @@ import ( "fmt" "io" "reflect" + "slices" "time" "github.com/asaskevich/govalidator" @@ -499,17 +500,10 @@ func containerExists(name string, currentobject *appsv1.Deployment) { // containerRemove checks if a container exists on the deployment // if it does exists, removes it -func containerRemove(name string, currentobject *appsv1.Deployment) { - for index, container := range currentobject.Spec.Template.Spec.Containers { - if container.Name == name { - if index == len(currentobject.Spec.Template.Spec.Containers)-1 { - currentobject.Spec.Template.Spec.Containers = currentobject.Spec.Template.Spec.Containers[:index] - } else { - currentobject.Spec.Template.Spec.Containers = append(currentobject.Spec.Template.Spec.Containers[:index], currentobject.Spec.Template.Spec.Containers[index+1]) - } - break - } - } +func containerRemove(name string, d *appsv1.Deployment) { + d.Spec.Template.Spec.Containers = slices.DeleteFunc(d.Spec.Template.Spec.Containers, func(container corev1.Container) bool { + return container.Name == name + }) } // getDeploymentConfiguration precalculates all the configuration that the server deployment needs, including: