1
0
mirror of https://github.com/rancher/rke.git synced 2025-08-16 05:53:00 +00:00

replaced ContainerCreateCreatedBody with CreateResponse as per https://github.com/moby/moby/pull/43530/files

add check to remove container-runtime flag from v1.27

ref: https://v1-26.docs.kubernetes.io/docs/reference/command-line-tools-reference/kubelet/
This commit is contained in:
Rayan Das 2023-05-31 13:56:40 +05:30
parent 44fb5d37b7
commit dfa1eeaf12
3 changed files with 15 additions and 12 deletions

View File

@ -11,7 +11,7 @@ RUN apt-get update && \
ENV GOLANG_ARCH_amd64=amd64 GOLANG_ARCH_arm=armv6l GOLANG_ARCH_arm64=arm64 GOLANG_ARCH=GOLANG_ARCH_${ARCH} \ ENV GOLANG_ARCH_amd64=amd64 GOLANG_ARCH_arm=armv6l GOLANG_ARCH_arm64=arm64 GOLANG_ARCH=GOLANG_ARCH_${ARCH} \
GOPATH=/go PATH=/go/bin:/usr/local/go/bin:${PATH} SHELL=/bin/bash GOPATH=/go PATH=/go/bin:/usr/local/go/bin:${PATH} SHELL=/bin/bash
RUN wget -O - https://storage.googleapis.com/golang/go1.19.3.linux-${!GOLANG_ARCH}.tar.gz | tar -xzf - -C /usr/local RUN wget -O - https://storage.googleapis.com/golang/go1.20.4.linux-${!GOLANG_ARCH}.tar.gz | tar -xzf - -C /usr/local
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.52.2 RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.52.2

View File

@ -69,6 +69,7 @@ var (
parsedRangeAtLeast123 = semver.MustParseRange(">= 1.23.0-rancher0") parsedRangeAtLeast123 = semver.MustParseRange(">= 1.23.0-rancher0")
parsedRangeAtLeast124 = semver.MustParseRange(">= 1.24.0-rancher0") parsedRangeAtLeast124 = semver.MustParseRange(">= 1.24.0-rancher0")
parsedRangeAtLeast125 = semver.MustParseRange(">= 1.25.0-rancher0") parsedRangeAtLeast125 = semver.MustParseRange(">= 1.25.0-rancher0")
parsedRangeBelow127 = semver.MustParseRange("< 1.27.0-rancher0")
parsedRange123 = semver.MustParseRange(">=1.23.0-rancher0 <=1.23.99-rancher-0") parsedRange123 = semver.MustParseRange(">=1.23.0-rancher0 <=1.23.99-rancher-0")
parsedRange124 = semver.MustParseRange(">=1.24.0-rancher0 <=1.24.99-rancher-0") parsedRange124 = semver.MustParseRange(">=1.24.0-rancher0 <=1.24.99-rancher-0")
) )
@ -505,12 +506,14 @@ func (c *Cluster) BuildKubeletProcess(host *hosts.Host, serviceOptions v3.Kubern
var Binds []string var Binds []string
if c.IsCRIDockerdEnabled() { if c.IsCRIDockerdEnabled() {
CommandArgs["container-runtime"] = "remote"
CommandArgs["container-runtime-endpoint"] = "/var/run/dockershim.sock"
parsedVersion, err := getClusterVersion(c.Version) parsedVersion, err := getClusterVersion(c.Version)
if err != nil { if err != nil {
logrus.Debugf("Error while parsing cluster version: %s", err) logrus.Debugf("Error while parsing cluster version: %s", err)
} }
if parsedRangeBelow127(parsedVersion) {
CommandArgs["container-runtime"] = "remote" // This flag has been removed from v1.27 https://v1-26.docs.kubernetes.io/docs/reference/command-line-tools-reference/kubelet/
}
CommandArgs["container-runtime-endpoint"] = "/var/run/dockershim.sock"
// cri-dockerd must be enabled if the cluster version is 1.24 and higher // cri-dockerd must be enabled if the cluster version is 1.24 and higher
if parsedRangeAtLeast124(parsedVersion) { if parsedRangeAtLeast124(parsedVersion) {
CommandArgs["container-runtime-endpoint"] = "unix:///var/run/cri-dockerd.sock" CommandArgs["container-runtime-endpoint"] = "unix:///var/run/cri-dockerd.sock"

View File

@ -381,11 +381,11 @@ func RestartContainer(ctx context.Context, dClient *client.Client, hostname, con
return fmt.Errorf("Failed to restart container: docker client is nil for container [%s] on host [%s]", containerName, hostname) return fmt.Errorf("Failed to restart container: docker client is nil for container [%s] on host [%s]", containerName, hostname)
} }
var err error var err error
restartTimeout := RestartTimeout * time.Second restartTimeout := RestartTimeout
// Retry up to RetryCount times to see if image exists // Retry up to RetryCount times to see if image exists
for i := 1; i <= RetryCount; i++ { for i := 1; i <= RetryCount; i++ {
logrus.Infof("Restarting container [%s] on host [%s], try #%d", containerName, hostname, i) logrus.Infof("Restarting container [%s] on host [%s], try #%d", containerName, hostname, i)
err = dClient.ContainerRestart(ctx, containerName, &restartTimeout) err = dClient.ContainerRestart(ctx, containerName, container.StopOptions{Timeout: &restartTimeout})
if err != nil { if err != nil {
logrus.Warningf("Can't restart Docker container [%s] for host [%s]: %v", containerName, hostname, err) logrus.Warningf("Can't restart Docker container [%s] for host [%s]: %v", containerName, hostname, err)
continue continue
@ -400,11 +400,11 @@ func StopContainer(ctx context.Context, dClient *client.Client, hostname string,
} }
var err error var err error
// define the stop timeout // define the stop timeout
stopTimeoutDuration := StopTimeout * time.Second stopTimeout := StopTimeout
// Retry up to RetryCount times to see if image exists // Retry up to RetryCount times to see if image exists
for i := 1; i <= RetryCount; i++ { for i := 1; i <= RetryCount; i++ {
logrus.Infof("Stopping container [%s] on host [%s] with stopTimeoutDuration [%s], try #%d", containerName, hostname, stopTimeoutDuration, i) logrus.Infof("Stopping container [%s] on host [%s] with stopTimeout [%d], try #%d", containerName, hostname, stopTimeout, i)
err = dClient.ContainerStop(ctx, containerName, &stopTimeoutDuration) err = dClient.ContainerStop(ctx, containerName, container.StopOptions{Timeout: &stopTimeout})
if err != nil { if err != nil {
logrus.Warningf("Can't stop Docker container [%s] for host [%s]: %v", containerName, hostname, err) logrus.Warningf("Can't stop Docker container [%s] for host [%s]: %v", containerName, hostname, err)
continue continue
@ -453,11 +453,11 @@ func StartContainer(ctx context.Context, dClient *client.Client, hostname string
return err return err
} }
func CreateContainer(ctx context.Context, dClient *client.Client, hostname string, containerName string, imageCfg *container.Config, hostCfg *container.HostConfig) (container.ContainerCreateCreatedBody, error) { func CreateContainer(ctx context.Context, dClient *client.Client, hostname string, containerName string, imageCfg *container.Config, hostCfg *container.HostConfig) (container.CreateResponse, error) {
if dClient == nil { if dClient == nil {
return container.ContainerCreateCreatedBody{}, fmt.Errorf("Failed to create container: docker client is nil for container [%s] on host [%s]", containerName, hostname) return container.CreateResponse{}, fmt.Errorf("Failed to create container: docker client is nil for container [%s] on host [%s]", containerName, hostname)
} }
var created container.ContainerCreateCreatedBody var created container.CreateResponse
var err error var err error
// Retry up to RetryCount times to see if image exists // Retry up to RetryCount times to see if image exists
for i := 1; i <= RetryCount; i++ { for i := 1; i <= RetryCount; i++ {
@ -468,7 +468,7 @@ func CreateContainer(ctx context.Context, dClient *client.Client, hostname strin
} }
return created, nil return created, nil
} }
return container.ContainerCreateCreatedBody{}, fmt.Errorf("Failed to create Docker container [%s] on host [%s]: %v", containerName, hostname, err) return container.CreateResponse{}, fmt.Errorf("Failed to create Docker container [%s] on host [%s]: %v", containerName, hostname, err)
} }
func InspectContainer(ctx context.Context, dClient *client.Client, hostname string, containerName string) (types.ContainerJSON, error) { func InspectContainer(ctx context.Context, dClient *client.Client, hostname string, containerName string) (types.ContainerJSON, error) {