Skip to content

🐛 CAPI operator incorrectly finds the manager container if the number of containers is greater than one #796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/controller/component_customizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,14 @@ func customizeDeploymentSpec(dSpec operatorv1.DeploymentSpec, d *appsv1.Deployme
// findManagerContainer finds manager container in the provider deployment.
func findManagerContainer(dSpec *appsv1.DeploymentSpec) *corev1.Container {
for ic := range dSpec.Template.Spec.Containers {
return &dSpec.Template.Spec.Containers[ic]
if dSpec.Template.Spec.Containers[ic].Name == managerContainerName {
return &dSpec.Template.Spec.Containers[ic]
}
}

// This is for backward compatibility before fixing the issue https://github.com/kubernetes-sigs/cluster-api-operator/issues/787
if len(dSpec.Template.Spec.Containers) > 0 {
return &dSpec.Template.Spec.Containers[0]
}

return nil
Expand Down
60 changes: 39 additions & 21 deletions internal/controller/component_customizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,39 @@ func TestCustomizeDeployment(t *testing.T) {
Name: "manager",
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{{
Name: "manager",
Image: "registry.k8s.io/a-manager:1.6.2",
Env: []corev1.EnvVar{
{
Name: "test1",
Value: "value1",
},
Containers: []corev1.Container{
{
Name: "kube-rbac-proxy",
Image: "registry.k8s.io/a-kube-rbac-proxy:v0.13.1",
},
Args: []string{"--webhook-port=2345"},
LivenessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/healthz",
Port: intstr.FromString("healthz"),
{
Name: "manager",
Image: "registry.k8s.io/a-manager:1.6.2",
Env: []corev1.EnvVar{
{
Name: "test1",
Value: "value1",
},
},
},
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/readyz",
Port: intstr.FromString("healthz"),
Args: []string{"--webhook-port=2345"},
LivenessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/healthz",
Port: intstr.FromString("healthz"),
},
},
},
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/readyz",
Port: intstr.FromString("healthz"),
},
},
},
},
}},
},
},
},
},
Expand Down Expand Up @@ -278,6 +284,10 @@ func TestCustomizeDeployment(t *testing.T) {
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "kube-rbac-proxy",
Image: "registry.k8s.io/a-kube-rbac-proxy:v0.13.1",
},
{
Name: "manager",
Image: "quay.io/dev/mydns:v3.4.2",
Expand Down Expand Up @@ -403,6 +413,10 @@ func TestCustomizeDeployment(t *testing.T) {
},
},
Containers: []corev1.Container{
{
Name: "kube-rbac-proxy",
Image: "registry.k8s.io/a-kube-rbac-proxy:v0.13.1",
},
{
Name: "manager",
Image: "quay.io/dev/mydns:v3.4.2",
Expand Down Expand Up @@ -506,6 +520,10 @@ func TestCustomizeDeployment(t *testing.T) {
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "kube-rbac-proxy",
Image: "registry.k8s.io/a-kube-rbac-proxy:v0.13.1",
},
{
Name: "manager",
Image: "registry.k8s.io/a-manager:1.6.2",
Expand Down
Loading