Handle CRI config of NetworkPlugin and PauseImage

These have been removed from the kubelet, and are supposed to be
handled by the CRI config. Remove the earlier Docker-only hacks.
pull/14703/head
Anders F Björklund 2022-08-02 13:37:48 +02:00
parent 91cf318412
commit 2624a19c72
4 changed files with 24 additions and 22 deletions

View File

@ -90,9 +90,12 @@ func extraKubeletOpts(mc config.ClusterConfig, nc config.Node, r cruntime.Manage
extraOpts["hostname-override"] = nodeName
}
pauseImage := images.Pause(version, k8s.ImageRepository)
if _, ok := extraOpts["pod-infra-container-image"]; !ok && k8s.ImageRepository != "" && pauseImage != "" && k8s.ContainerRuntime != remoteContainerRuntime {
extraOpts["pod-infra-container-image"] = pauseImage
// Handled by CRI in 1.24+, and not by kubelet
if version.LT(semver.MustParse("1.24.0-alpha.2")) {
pauseImage := images.Pause(version, k8s.ImageRepository)
if _, ok := extraOpts["pod-infra-container-image"]; !ok && k8s.ImageRepository != "" && pauseImage != "" && k8s.ContainerRuntime != remoteContainerRuntime {
extraOpts["pod-infra-container-image"] = pauseImage
}
}
// parses a map of the feature gates for kubelet

View File

@ -147,6 +147,8 @@ type Config struct {
Socket string
// Runner is the CommandRunner object to execute commands with
Runner CommandRunner
// NetworkPlugin name of networking plugin ("cni")
NetworkPlugin string
// ImageRepository image repository to download image from
ImageRepository string
// KubernetesVersion Kubernetes version
@ -219,6 +221,7 @@ func New(c Config) (Manager, error) {
return &Docker{
Socket: sp,
Runner: c.Runner,
NetworkPlugin: c.NetworkPlugin,
ImageRepository: c.ImageRepository,
KubernetesVersion: c.KubernetesVersion,
Init: sm,
@ -336,14 +339,3 @@ func CheckKernelCompatibility(cr CommandRunner, major, minor int) error {
}
return nil
}
func ConfigureNetworkPlugin(r Manager, cr CommandRunner, networkPlugin string) error {
// Only supported for Docker with cri-dockerd
if r.Name() != "Docker" {
if networkPlugin != "cni" {
return fmt.Errorf("unknown network plugin: %s", networkPlugin)
}
return nil
}
return dockerConfigureNetworkPlugin(cr, networkPlugin)
}

View File

@ -69,6 +69,7 @@ func (e *ErrISOFeature) Error() string {
type Docker struct {
Socket string
Runner CommandRunner
NetworkPlugin string
ImageRepository string
KubernetesVersion semver.Version
Init sysinit.Manager
@ -140,6 +141,9 @@ func (r *Docker) Enable(disOthers bool, cgroupDriver string, inUserNamespace boo
if err := populateCRIConfig(r.Runner, r.SocketPath()); err != nil {
return err
}
if err := generateCRIDockerdConfig(r.Runner, r.ImageRepository, r.KubernetesVersion, r.NetworkPlugin); err != nil {
return err
}
if err := r.Init.Unmask("docker.service"); err != nil {
return err
@ -170,6 +174,9 @@ func (r *Docker) Enable(disOthers bool, cgroupDriver string, inUserNamespace boo
if err := r.Init.Restart(r.CRIService); err != nil {
return err
}
if err := r.Init.Restart("cri-docker"); err != nil {
return err
}
}
return nil
@ -696,7 +703,9 @@ func getCriDockerdPath(cr CommandRunner) string {
return strings.TrimSuffix(rr.Stdout.String(), "\n")
}
func dockerConfigureNetworkPlugin(cr CommandRunner, networkPlugin string) error {
func generateCRIDockerdConfig(cr CommandRunner, imageRepository string, kv semver.Version, networkPlugin string) error {
pauseImage := images.Pause(kv, imageRepository)
// $ cri-dockerd --version
// cri-dockerd 0.2.6 (d8accf7)
// $ cri-dockerd --help | grep -i cni
@ -711,10 +720,12 @@ func dockerConfigureNetworkPlugin(cr CommandRunner, networkPlugin string) error
}
opts := struct {
ExecPath string
PauseImage string
NetworkPlugin string
ExtraArguments string
}{
ExecPath: getCriDockerdPath(cr),
PauseImage: pauseImage,
NetworkPlugin: networkPlugin,
ExtraArguments: args,
}
@ -722,7 +733,7 @@ func dockerConfigureNetworkPlugin(cr CommandRunner, networkPlugin string) error
const CRIDockerServiceConfFile = "/etc/systemd/system/cri-docker.service.d/10-cni.conf"
var CRIDockerServiceConfTemplate = template.Must(template.New("criDockerServiceConfTemplate").Parse(`[Service]
ExecStart=
ExecStart={{.ExecPath}} --container-runtime-endpoint fd:// --network-plugin={{.NetworkPlugin}}{{.ExtraArguments}}`))
ExecStart={{.ExecPath}} --container-runtime-endpoint fd:// --pod-infra-container-image={{.PauseImage}} --network-plugin={{.NetworkPlugin}}{{.ExtraArguments}}`))
b := bytes.Buffer{}
if err := CRIDockerServiceConfTemplate.Execute(&b, opts); err != nil {

View File

@ -385,6 +385,7 @@ func configureRuntimes(runner cruntime.CommandRunner, cc config.ClusterConfig, k
Type: cc.KubernetesConfig.ContainerRuntime,
Socket: cc.KubernetesConfig.CRISocket,
Runner: runner,
NetworkPlugin: cc.KubernetesConfig.NetworkPlugin,
ImageRepository: cc.KubernetesConfig.ImageRepository,
KubernetesVersion: kv,
InsecureRegistry: cc.InsecureRegistry,
@ -404,12 +405,7 @@ func configureRuntimes(runner cruntime.CommandRunner, cc config.ClusterConfig, k
// make sure container runtime is restarted afterwards for these changes to take effect
disableLoopback := co.Type == constants.CRIO
if err := cni.ConfigureLoopbackCNI(runner, disableLoopback); err != nil {
klog.Warningf("unable to name loopback interface in dockerConfigureNetworkPlugin: %v", err)
}
if kv.GTE(semver.MustParse("1.24.0-alpha.2")) {
if err := cruntime.ConfigureNetworkPlugin(cr, runner, cc.KubernetesConfig.NetworkPlugin); err != nil {
exit.Error(reason.RuntimeEnable, "Failed to configure network plugin", err)
}
klog.Warningf("unable to name loopback interface in configureRuntimes: %v", err)
}
// ensure all default CNI(s) are properly configured on each and every node (re)start
// make sure container runtime is restarted afterwards for these changes to take effect