Skip to content
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

handle pod-infra-container-image on older versions #1596

Merged
merged 3 commits into from
Feb 1, 2024
Merged
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
36 changes: 36 additions & 0 deletions nodeadm/internal/kubelet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,38 @@ func (ksc *kubeletConfig) withDefaultReservedResources() {
ksc.KubeReservedCgroup = ptr.String("/runtime")
}

// withPodInfraContainerImage determines whether to add the
// '--pod-infra-container-image' flag, which is used to ensure the sandbox image
// is not garbage collected.
//
// TODO: revisit once the minimum supportted version catches up or the container
// runtime is moved to containerd 2.0
func (ksc *kubeletConfig) withPodInfraContainerImage(cfg *api.NodeConfig, kubeletVersion string, flags map[string]string) error {
// the flag is a noop on 1.29+, since the behavior was changed to use the
// CRI image pinning behavior and no longer considers the flag value.
Copy link
Member

@Issacwww Issacwww Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, we also need to add #1605 and #1601 into al2023 to help with 1.29 right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, it looks like we will need the crictl for sure in some equivalent fashion. Am i missing any go libraries to pull the image through the CRI versus crictl?

Copy link
Member Author

@ndbaker1 ndbaker1 Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i could use the same upstream resources to pull this to remove the cri-tools install,
it would look something like:

import (
	v1 "k8s.io/cri-api/pkg/apis/runtime/v1"
	"k8s.io/kubernetes/pkg/kubelet/cri/remote"
)

imageManager, err := remote.NewRemoteImageService("unix:///run/containerd/containerd.sock", 2*time.Second, nil)
imageSpec := v1.ImageSpec{Image: sandboxImage}
authConfig := v1.AuthConfig{Username: "AWS", Password: ecrUserToken}
imageRef, err := imageManager.PullImage(context.TODO(), &imageSpec, &authConfig, nil)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chatted offline, I think it's a good idea for nodeadm to bake in this functionality but we need to find the right CRI client library to use (pulling in kubelet internals should be a last resort)

// see: https://github.com/kubernetes/kubernetes/pull/118544
if semver.Compare(kubeletVersion, "v1.29.0") < 0 {
awsDomain, err := util.GetAwsDomain(context.TODO(), imds.New(imds.Options{}))
if err != nil {
return err
}
ecrUri, err := util.GetEcrUri(util.GetEcrUriRequest{
Region: cfg.Status.Instance.Region,
Domain: awsDomain,
AllowFips: true,
})
if err != nil {
return err
}
pauseContainerImage, err := util.GetPauseContainer(ecrUri)
if err != nil {
return err
}
flags["pod-infra-container-image"] = pauseContainerImage
}
return nil
}

func (k *kubelet) GenerateKubeletConfig(cfg *api.NodeConfig) (*kubeletConfig, error) {
// Get the kubelet/kubernetes version to help conditionally enable features
kubeletVersion, err := GetKubeletVersion()
Expand All @@ -249,6 +281,7 @@ func (k *kubelet) GenerateKubeletConfig(cfg *api.NodeConfig) (*kubeletConfig, er
zap.L().Info("Detected kubelet version", zap.String("version", kubeletVersion))

kubeletConfig := defaultKubeletSubConfig()

if err := kubeletConfig.withFallbackClusterDns(&cfg.Spec.Cluster); err != nil {
return nil, err
}
Expand All @@ -258,6 +291,9 @@ func (k *kubelet) GenerateKubeletConfig(cfg *api.NodeConfig) (*kubeletConfig, er
if err := kubeletConfig.withNodeIp(cfg, k.flags); err != nil {
return nil, err
}
if err := kubeletConfig.withPodInfraContainerImage(cfg, kubeletVersion, k.flags); err != nil {
return nil, err
}

kubeletConfig.withVersionToggles(kubeletVersion, k.flags)
kubeletConfig.withCloudProvider(cfg, k.flags)
Expand Down
9 changes: 9 additions & 0 deletions nodeadm/test/e2e/cases/pod-infra-container/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
apiVersion: node.eks.aws/v1alpha1
kind: NodeConfig
spec:
cluster:
name: my-cluster
apiServerEndpoint: https://example.com
certificateAuthority: Y2VydGlmaWNhdGVBdXRob3JpdHk=
cidr: 10.100.0.0/16
18 changes: 18 additions & 0 deletions nodeadm/test/e2e/cases/pod-infra-container/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

source /helpers.sh

mock::imds
wait::dbus-ready

mock::kubelet 1.28.0
nodeadm init --skip run --config-source file://config.yaml
assert::file-contains /etc/eks/kubelet/environment '--pod-infra-container-image=602401143452.dkr.ecr.us-west-2.amazonaws.com/eks/pause:3.5'

mock::kubelet 1.29.0
nodeadm init --skip run --config-source file://config.yaml
assert::file-not-contains /etc/eks/kubelet/environment 'pod-infra-container-image'
Loading