Skip to content

Commit

Permalink
remove nginx from upgrader pod (#7438)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavmpandey08 authored Jan 31, 2024
1 parent e92754c commit dea47a0
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 65 deletions.
9 changes: 7 additions & 2 deletions controllers/nodeupgrade_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func updateComponentsConditions(pod *corev1.Pod, nodeUpgrade *anywherev1.NodeUpg

completed := true
for _, container := range containersMap {
status, err := getInitContainerStatus(pod, container.name)
status, err := getContainerStatus(pod, container.name)
if err != nil {
conditions.MarkFalse(nodeUpgrade, container.condition, "Container status not available yet", clusterv1.ConditionSeverityWarning, "")
completed = false
Expand Down Expand Up @@ -341,12 +341,17 @@ func updateComponentsConditions(pod *corev1.Pod, nodeUpgrade *anywherev1.NodeUpg
nodeUpgrade.Status.Completed = completed
}

func getInitContainerStatus(pod *corev1.Pod, containerName string) (*corev1.ContainerStatus, error) {
func getContainerStatus(pod *corev1.Pod, containerName string) (*corev1.ContainerStatus, error) {
for _, status := range pod.Status.InitContainerStatuses {
if status.Name == containerName {
return &status, nil
}
}
for _, status := range pod.Status.ContainerStatuses {
if status.Name == containerName {
return &status, nil
}
}
return nil, fmt.Errorf("status not found for container %s in pod %s", containerName, pod.Name)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@ metadata:
namespace: eksa-system
spec:
containers:
- image: nginx
name: done
- args:
- --target
- "1"
- --mount
- --uts
- --ipc
- --net
- /foo/eksa-upgrades/scripts/upgrade.sh
- print_status_and_cleanup
command:
- nsenter
image: public.ecr.aws/eks-anywhere/node-upgrader:latest
name: post-upgrade-status
resources: {}
securityContext:
privileged: true
hostPID: true
initContainers:
- args:
Expand Down Expand Up @@ -89,23 +102,8 @@ spec:
resources: {}
securityContext:
privileged: true
- args:
- --target
- "1"
- --mount
- --uts
- --ipc
- --net
- /foo/eksa-upgrades/scripts/upgrade.sh
- print_status_and_cleanup
command:
- nsenter
image: public.ecr.aws/eks-anywhere/node-upgrader:latest
name: post-upgrade-status
resources: {}
securityContext:
privileged: true
nodeName: my-node
restartPolicy: Never
volumes:
- hostPath:
path: /foo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@ metadata:
namespace: eksa-system
spec:
containers:
- image: nginx
name: done
- args:
- --target
- "1"
- --mount
- --uts
- --ipc
- --net
- /foo/eksa-upgrades/scripts/upgrade.sh
- print_status_and_cleanup
command:
- nsenter
image: public.ecr.aws/eks-anywhere/node-upgrader:latest
name: post-upgrade-status
resources: {}
securityContext:
privileged: true
hostPID: true
initContainers:
- args:
Expand Down Expand Up @@ -87,23 +100,8 @@ spec:
resources: {}
securityContext:
privileged: true
- args:
- --target
- "1"
- --mount
- --uts
- --ipc
- --net
- /foo/eksa-upgrades/scripts/upgrade.sh
- print_status_and_cleanup
command:
- nsenter
image: public.ecr.aws/eks-anywhere/node-upgrader:latest
name: post-upgrade-status
resources: {}
securityContext:
privileged: true
nodeName: my-node
restartPolicy: Never
volumes:
- hostPath:
path: /foo
Expand Down
34 changes: 16 additions & 18 deletions pkg/nodeupgrader/testdata/expected_worker_upgrader_pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@ metadata:
namespace: eksa-system
spec:
containers:
- image: nginx
name: done
- args:
- --target
- "1"
- --mount
- --uts
- --ipc
- --net
- /foo/eksa-upgrades/scripts/upgrade.sh
- print_status_and_cleanup
command:
- nsenter
image: public.ecr.aws/eks-anywhere/node-upgrader:latest
name: post-upgrade-status
resources: {}
securityContext:
privileged: true
hostPID: true
initContainers:
- args:
Expand Down Expand Up @@ -87,23 +100,8 @@ spec:
resources: {}
securityContext:
privileged: true
- args:
- --target
- "1"
- --mount
- --uts
- --ipc
- --net
- /foo/eksa-upgrades/scripts/upgrade.sh
- print_status_and_cleanup
command:
- nsenter
image: public.ecr.aws/eks-anywhere/node-upgrader:latest
name: post-upgrade-status
resources: {}
securityContext:
privileged: true
nodeName: my-node
restartPolicy: Never
volumes:
- hostPath:
path: /foo
Expand Down
11 changes: 2 additions & 9 deletions pkg/nodeupgrader/upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,10 @@ func upgraderPod(nodeName, image string) *corev1.Pod {
},
},
},
// TODO(in-place): currently, the pod requires atleast one container.
// For the time being, I have added an nginx container but
// this should be replaced with something that makes more
// sense in in-place context.
Containers: []corev1.Container{
{
Name: "done",
Image: "nginx",
},
nsenterContainer(image, PostUpgradeContainerName, upgradeScript, "print_status_and_cleanup"),
},
RestartPolicy: corev1.RestartPolicyNever,
},
}
}
Expand All @@ -103,7 +97,6 @@ func containersForUpgrade(image, nodeName string, kubeadmUpgradeCommand ...strin
nsenterContainer(image, CNIPluginsUpgraderContainerName, upgradeScript, "cni_plugins"),
nsenterContainer(image, KubeadmUpgraderContainerName, append([]string{upgradeScript}, kubeadmUpgradeCommand...)...),
nsenterContainer(image, KubeletUpgradeContainerName, upgradeScript, "kubelet_and_kubectl"),
nsenterContainer(image, PostUpgradeContainerName, upgradeScript, "print_status_and_cleanup"),
}
}

Expand Down

0 comments on commit dea47a0

Please sign in to comment.