Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
use debian instead of ubuntu as base image
Browse files Browse the repository at this point in the history
Signed-off-by: Paco Xu <[email protected]>
  • Loading branch information
pacoxu committed Jun 17, 2022
1 parent ab38447 commit 94d41af
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 44 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager
# Refer to https://github.com/GoogleContainerTools/distroless for more details
# distroless cannot run `kubeadm upgrade apply` smoothly
# FROM gcr.m.daocloud.io/distroless/static:nonroot
FROM docker.m.daocloud.io/ubuntu
RUN apt-get update -q -y && apt-get install -q -y curl && apt clean all

# ubuntu based operation image is about 158MiB 72.8MiB.
# FROM docker.m.daocloud.io/ubuntu

FROM k8s-gcr.m.daocloud.io/debian-base:v1.0.0
RUN apt-get update -q -y && apt-get install -q -y curl && apt clean all
WORKDIR /
COPY --from=builder /workspace/manager .
# USER nonroot:nonroot
Expand Down
2 changes: 1 addition & 1 deletion commands/upgrade_kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func runUpgradeKubeadm(spec *operatorv1.UpgradeKubeadmCommandSpec, log logr.Logg
return err
}

cmd := newCmd("/usr/bin/cp", "-f", "/usr/bin/kubeadm-"+spec.KubernetesVersion, "/usr/bin/kubeadm")
cmd := newCmd("cp", "-f", "/usr/bin/kubeadm-"+spec.KubernetesVersion, "/usr/bin/kubeadm")
start, err := cmd.RunAndCapture()
if err != nil {
return errors.WithStack(errors.WithMessage(err, strings.Join(start, "\n")))
Expand Down
4 changes: 2 additions & 2 deletions commands/upgrade_kubectlkubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func runUpgradeKubectlAndKubelet(spec *operatorv1.UpgradeKubeletAndKubeactlComma
// upgrade can skip kubectl upgrade
log.Info("kubectl upgrade is not significant, so skip")
}
cmd := newCmd("/usr/bin/cp", "-f", "/usr/bin/kubectl-"+spec.KubernetesVersion, "/usr/bin/kubectl")
cmd := newCmd("cp", "-f", "/usr/bin/kubectl-"+spec.KubernetesVersion, "/usr/bin/kubectl")
start, err := cmd.RunAndCapture()
if err != nil {
return errors.WithStack(errors.WithMessage(err, strings.Join(start, "\n")))
Expand All @@ -65,7 +65,7 @@ func runUpgradeKubectlAndKubelet(spec *operatorv1.UpgradeKubeletAndKubeactlComma
}

// see https://github.com/pacoxu/kubelet-reloader/ to add a daemon or service on nodes to replace kubelet and restart kubelet.
cmd = newCmd("/usr/bin/cp", "-f", "/usr/bin/kubelet-"+spec.KubernetesVersion, "/usr/bin/kubelet-new")
cmd = newCmd("cp", "-f", "/usr/bin/kubelet-"+spec.KubernetesVersion, "/usr/bin/kubelet-new")
start, err = cmd.RunAndCapture()
if err != nil {
return errors.WithStack(errors.WithMessage(err, strings.Join(start, "\n")))
Expand Down
9 changes: 3 additions & 6 deletions config/crd/bases/operator.kubeadm.x-k8s.io_operations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,8 @@ spec:
- kubernetesVersion
type: object
kubeadmUpgradeNode:
description: TODO download the specified
version bin and replace it in the node
KubeadmUpgradeNodeCommandSpec provides...
description: KubeadmUpgradeNodeCommandSpec
provides...
properties:
dryRun:
description: for dry run mode
Expand Down Expand Up @@ -322,9 +321,7 @@ spec:
type: boolean
type: object
upgradeKubeletAndKubeactl:
description: TODO download the specified
version bin and replace it in the node
UpgradeKubeletAndKubeactlCommandSpec
description: UpgradeKubeletAndKubeactlCommandSpec
provides...
properties:
kubernetesVersion:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,7 @@ spec:
- kubernetesVersion
type: object
kubeadmUpgradeNode:
description: TODO download the specified version bin
and replace it in the node KubeadmUpgradeNodeCommandSpec
provides...
description: KubeadmUpgradeNodeCommandSpec provides...
properties:
dryRun:
description: for dry run mode
Expand Down Expand Up @@ -269,9 +267,7 @@ spec:
type: boolean
type: object
upgradeKubeletAndKubeactl:
description: TODO download the specified version bin
and replace it in the node UpgradeKubeletAndKubeactlCommandSpec
provides...
description: UpgradeKubeletAndKubeactlCommandSpec provides...
properties:
kubernetesVersion:
description: KubernetesVersion specifies the target
Expand Down
6 changes: 2 additions & 4 deletions config/crd/bases/operator.kubeadm.x-k8s.io_runtimetasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ spec:
- kubernetesVersion
type: object
kubeadmUpgradeNode:
description: TODO download the specified version bin and replace
it in the node KubeadmUpgradeNodeCommandSpec provides...
description: KubeadmUpgradeNodeCommandSpec provides...
properties:
dryRun:
description: for dry run mode
Expand Down Expand Up @@ -146,8 +145,7 @@ spec:
type: boolean
type: object
upgradeKubeletAndKubeactl:
description: TODO download the specified version bin and replace
it in the node UpgradeKubeletAndKubeactlCommandSpec provides...
description: UpgradeKubeletAndKubeactlCommandSpec provides...
properties:
kubernetesVersion:
description: KubernetesVersion specifies the target kubernetes
Expand Down
14 changes: 0 additions & 14 deletions controllers/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,6 @@ func createDaemonSet(c client.Client, operation *operatorv1.Operation, namespace
Name: "crictl",
MountPath: "/usr/local/bin/crictl",
},
// cp is used by kubeadm upgrade apply to run command like `cp`
{
Name: "cp",
MountPath: "/usr/bin/cp",
},
{
Name: "etc-kubernetes",
MountPath: "/etc/kubernetes",
Expand Down Expand Up @@ -287,15 +282,6 @@ func createDaemonSet(c client.Client, operation *operatorv1.Operation, namespace
},
},
},
{
Name: "cp",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: "/usr/bin/cp",
Type: hostPathTypePtr(corev1.HostPathFile),
},
},
},
{
Name: "run",
VolumeSource: corev1.VolumeSource{
Expand Down
2 changes: 1 addition & 1 deletion operations/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TaskGroupList(operation *operatorv1.Operation, c client.Client) (*operatorv
}

if operation.Spec.Upgrade != nil {
return planUpgrade(operation, operation.Spec.Upgrade, c), nil
return planUpgrade(operation, operation.Spec.Upgrade, c)
}

if operation.Spec.CustomOperation != nil {
Expand Down
16 changes: 8 additions & 8 deletions operations/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ func setupUpgrade() map[string]string {
return map[string]string{}
}

func planUpgrade(operation *operatorv1.Operation, spec *operatorv1.UpgradeOperationSpec, c client.Client) *operatorv1.RuntimeTaskGroupList {
func planUpgrade(operation *operatorv1.Operation, spec *operatorv1.UpgradeOperationSpec, c client.Client) (*operatorv1.RuntimeTaskGroupList, error) {
log := ctrl.Log.WithName("operations").WithName("Upgrade").WithValues("task", operation.Name)
var items []operatorv1.RuntimeTaskGroup

serverVersion, err := getServerVersion()
if err != nil {
log.Error(err, "get server version failed")
return nil
return nil, errors.Wrap(err, "Failed to get server version")
}
isServerSupported, isServerCrossVersion, isServerCanSkip := upgradeCheck(serverVersion, spec.KubernetesVersion)
if !isServerSupported {
log.Info("Upgrade is not supported", "serverVersion", serverVersion, "kubernetesVersion", spec.KubernetesVersion)
// TODO current not supported operation will succeed immeditely.
return nil
return nil, errors.Wrap(err, "Upgrade is not supported")
}
log.Info("Upgrade is supported", "serverVersion", serverVersion, "kubernetesVersion", spec.KubernetesVersion)
nodes, err := listNodesBySelector(c, getAllSelector())
if err != nil {
log.Error(err, "list node failed")
return nil
log.Error(err, "list nodes failed")
return nil, errors.Wrap(err, "Failed to list nodes")
}
var isClientSupported, isClientCrossVersion, isClientCanSkip bool = true, false, true
var clientServerMatch bool = true
Expand All @@ -72,15 +72,15 @@ func planUpgrade(operation *operatorv1.Operation, spec *operatorv1.UpgradeOperat
}
if !isClientSupported {
log.Info("Upgrade is not supported", "clientVersion", spec.KubernetesVersion)
return nil
return nil, errors.Wrap(err, "Upgrade is not supported for some nodes' kubelet version")
}
log.Info("show all client version check results", "isClientSupported", isClientSupported, "isClientCrossVersion", isClientCrossVersion, "isClientCanSkip", isClientCanSkip, "clientServerMatch", clientServerMatch)
log.Info("show all server version check results", "isServerSupported", isServerSupported, "isServerCrossVersion", isServerCrossVersion, "isServerCanSkip", isServerCanSkip)
if isClientCanSkip && isServerCanSkip {
// skip upgrade directly
return &operatorv1.RuntimeTaskGroupList{
Items: items,
}
}, nil
} else if isClientCrossVersion || isServerCrossVersion {
// support upgrade to v1.n-1~v1.n of current kubernetes server version.
// If the current kubernetes server version is v1.n-2 which is below the target version, we need to generate a further upgrade plan
Expand All @@ -105,7 +105,7 @@ func planUpgrade(operation *operatorv1.Operation, spec *operatorv1.UpgradeOperat

return &operatorv1.RuntimeTaskGroupList{
Items: items,
}
}, nil
}

// the version may not be operation.Spec.Upgrade.KubernetesVersion for cross upgrade
Expand Down

0 comments on commit 94d41af

Please sign in to comment.