Skip to content

Commit

Permalink
kcp: patch ImageRepository in ClusterConfiguration if it is not set f…
Browse files Browse the repository at this point in the history
…or v1.25
  • Loading branch information
chrischdi committed Jul 19, 2022
1 parent ef7172a commit a959caf
Show file tree
Hide file tree
Showing 20 changed files with 316 additions and 187 deletions.
4 changes: 2 additions & 2 deletions bootstrap/kubeadm/api/v1alpha4/kubeadm_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ type ClusterConfiguration struct {
CertificatesDir string `json:"certificatesDir,omitempty"`

// ImageRepository sets the container registry to pull images from.
// If empty, `k8s.gcr.io` will be used by default; in case of kubernetes version is a CI build (kubernetes version starts with `ci/` or `ci-cross/`)
// `gcr.io/k8s-staging-ci-images` will be used as a default for control plane components and for kube-proxy, while `k8s.gcr.io`
// If empty, `registry.k8s.io` will be used by default; in case of kubernetes version is a CI build (kubernetes version starts with `ci/` or `ci-cross/`)
// `gcr.io/k8s-staging-ci-images` will be used as a default for control plane components and for kube-proxy, while `registry.k8s.io`
// will be used for all the other images.
// +optional
ImageRepository string `json:"imageRepository,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/kubeadm/api/v1beta1/kubeadm_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ type ClusterConfiguration struct {
CertificatesDir string `json:"certificatesDir,omitempty"`

// ImageRepository sets the container registry to pull images from.
// If empty, `k8s.gcr.io` will be used by default; in case of kubernetes version is a CI build (kubernetes version starts with `ci/` or `ci-cross/`)
// `gcr.io/k8s-staging-ci-images` will be used as a default for control plane components and for kube-proxy, while `k8s.gcr.io`
// If empty, `registry.k8s.io` will be used by default; in case of kubernetes version is a CI build (kubernetes version starts with `ci/` or `ci-cross/`)
// `gcr.io/k8s-staging-ci-images` will be used as a default for control plane components and for kube-proxy, while `registry.k8s.io`
// will be used for all the other images.
// +optional
ImageRepository string `json:"imageRepository,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1256,12 +1256,12 @@ spec:
type: object
imageRepository:
description: ImageRepository sets the container registry to pull
images from. If empty, `k8s.gcr.io` will be used by default;
images from. If empty, `registry.k8s.io` will be used by default;
in case of kubernetes version is a CI build (kubernetes version
starts with `ci/` or `ci-cross/`) `gcr.io/k8s-staging-ci-images`
will be used as a default for control plane components and for
kube-proxy, while `k8s.gcr.io` will be used for all the other
images.
kube-proxy, while `registry.k8s.io` will be used for all the
other images.
type: string
kind:
description: 'Kind is a string value representing the REST resource
Expand Down Expand Up @@ -2244,12 +2244,12 @@ spec:
type: object
imageRepository:
description: ImageRepository sets the container registry to pull
images from. If empty, `k8s.gcr.io` will be used by default;
images from. If empty, `registry.k8s.io` will be used by default;
in case of kubernetes version is a CI build (kubernetes version
starts with `ci/` or `ci-cross/`) `gcr.io/k8s-staging-ci-images`
will be used as a default for control plane components and for
kube-proxy, while `k8s.gcr.io` will be used for all the other
images.
kube-proxy, while `registry.k8s.io` will be used for all the
other images.
type: string
kind:
description: 'Kind is a string value representing the REST resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1265,12 +1265,13 @@ spec:
type: object
imageRepository:
description: ImageRepository sets the container registry
to pull images from. If empty, `k8s.gcr.io` will be
used by default; in case of kubernetes version is a
CI build (kubernetes version starts with `ci/` or `ci-cross/`)
`gcr.io/k8s-staging-ci-images` will be used as a default
for control plane components and for kube-proxy, while
`k8s.gcr.io` will be used for all the other images.
to pull images from. If empty, `registry.k8s.io` will
be used by default; in case of kubernetes version is
a CI build (kubernetes version starts with `ci/` or
`ci-cross/`) `gcr.io/k8s-staging-ci-images` will be
used as a default for control plane components and for
kube-proxy, while `registry.k8s.io` will be used for
all the other images.
type: string
kind:
description: 'Kind is a string value representing the
Expand Down Expand Up @@ -2246,12 +2247,13 @@ spec:
type: object
imageRepository:
description: ImageRepository sets the container registry
to pull images from. If empty, `k8s.gcr.io` will be
used by default; in case of kubernetes version is a
CI build (kubernetes version starts with `ci/` or `ci-cross/`)
`gcr.io/k8s-staging-ci-images` will be used as a default
for control plane components and for kube-proxy, while
`k8s.gcr.io` will be used for all the other images.
to pull images from. If empty, `registry.k8s.io` will
be used by default; in case of kubernetes version is
a CI build (kubernetes version starts with `ci/` or
`ci-cross/`) `gcr.io/k8s-staging-ci-images` will be
used as a default for control plane components and for
kube-proxy, while `registry.k8s.io` will be used for
all the other images.
type: string
kind:
description: 'Kind is a string value representing the
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/kubeadm/types/upstreamv1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ type ClusterConfiguration struct {
CertificatesDir string `json:"certificatesDir,omitempty"`

// ImageRepository sets the container registry to pull images from.
// If empty, `k8s.gcr.io` will be used by default; in case of kubernetes version is a CI build (kubernetes version starts with `ci/` or `ci-cross/`)
// `gcr.io/k8s-staging-ci-images` will be used as a default for control plane components and for kube-proxy, while `k8s.gcr.io`
// If empty, `registry.k8s.io` will be used by default; in case of kubernetes version is a CI build (kubernetes version starts with `ci/`)
// `gcr.io/k8s-staging-ci-images` will be used as a default for control plane components and for kube-proxy, while `registry.k8s.io`
// will be used for all the other images.
// +optional
ImageRepository string `json:"imageRepository,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/kubeadm/types/upstreamv1beta3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ type ClusterConfiguration struct {
CertificatesDir string `json:"certificatesDir,omitempty"`

// ImageRepository sets the container registry to pull images from.
// If empty, `k8s.gcr.io` will be used by default; in case of kubernetes version is a CI build (kubernetes version starts with `ci/` or `ci-cross/`)
// `gcr.io/k8s-staging-ci-images` will be used as a default for control plane components and for kube-proxy, while `k8s.gcr.io`
// If empty, `registry.k8s.io` will be used by default; in case of kubernetes version is a CI build (kubernetes version starts with `ci/` or `ci-cross/`)
// `gcr.io/k8s-staging-ci-images` will be used as a default for control plane components and for kube-proxy, while `registry.k8s.io`
// will be used for all the other images.
// +optional
ImageRepository string `json:"imageRepository,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1482,12 +1482,12 @@ spec:
type: object
imageRepository:
description: ImageRepository sets the container registry to
pull images from. If empty, `k8s.gcr.io` will be used by
default; in case of kubernetes version is a CI build (kubernetes
version starts with `ci/` or `ci-cross/`) `gcr.io/k8s-staging-ci-images`
pull images from. If empty, `registry.k8s.io` will be used
by default; in case of kubernetes version is a CI build
(kubernetes version starts with `ci/` or `ci-cross/`) `gcr.io/k8s-staging-ci-images`
will be used as a default for control plane components and
for kube-proxy, while `k8s.gcr.io` will be used for all
the other images.
for kube-proxy, while `registry.k8s.io` will be used for
all the other images.
type: string
kind:
description: 'Kind is a string value representing the REST
Expand Down Expand Up @@ -2702,12 +2702,12 @@ spec:
type: object
imageRepository:
description: ImageRepository sets the container registry to
pull images from. If empty, `k8s.gcr.io` will be used by
default; in case of kubernetes version is a CI build (kubernetes
version starts with `ci/` or `ci-cross/`) `gcr.io/k8s-staging-ci-images`
pull images from. If empty, `registry.k8s.io` will be used
by default; in case of kubernetes version is a CI build
(kubernetes version starts with `ci/` or `ci-cross/`) `gcr.io/k8s-staging-ci-images`
will be used as a default for control plane components and
for kube-proxy, while `k8s.gcr.io` will be used for all
the other images.
for kube-proxy, while `registry.k8s.io` will be used for
all the other images.
type: string
kind:
description: 'Kind is a string value representing the REST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,13 @@ spec:
type: object
imageRepository:
description: ImageRepository sets the container registry
to pull images from. If empty, `k8s.gcr.io` will
be used by default; in case of kubernetes version
to pull images from. If empty, `registry.k8s.io`
will be used by default; in case of kubernetes version
is a CI build (kubernetes version starts with `ci/`
or `ci-cross/`) `gcr.io/k8s-staging-ci-images` will
be used as a default for control plane components
and for kube-proxy, while `k8s.gcr.io` will be used
for all the other images.
and for kube-proxy, while `registry.k8s.io` will
be used for all the other images.
type: string
kind:
description: 'Kind is a string value representing
Expand Down Expand Up @@ -1467,13 +1467,13 @@ spec:
type: object
imageRepository:
description: ImageRepository sets the container registry
to pull images from. If empty, `k8s.gcr.io` will
be used by default; in case of kubernetes version
to pull images from. If empty, `registry.k8s.io`
will be used by default; in case of kubernetes version
is a CI build (kubernetes version starts with `ci/`
or `ci-cross/`) `gcr.io/k8s-staging-ci-images` will
be used as a default for control plane components
and for kube-proxy, while `k8s.gcr.io` will be used
for all the other images.
and for kube-proxy, while `registry.k8s.io` will
be used for all the other images.
type: string
kind:
description: 'Kind is a string value representing
Expand Down
14 changes: 7 additions & 7 deletions controlplane/kubeadm/internal/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,20 +382,20 @@ func (r *KubeadmControlPlaneReconciler) reconcile(ctx context.Context, cluster *
return ctrl.Result{}, errors.Wrap(err, "failed to set role and role binding for kubeadm")
}

// Update kube-proxy daemonset.
if err := workloadCluster.UpdateKubeProxyImageInfo(ctx, kcp); err != nil {
log.Error(err, "failed to update kube-proxy daemonset")
return ctrl.Result{}, err
}

// Update CoreDNS deployment.
// We intentionally only parse major/minor/patch so that the subsequent code
// also already applies to beta versions of new releases.
parsedVersion, err := version.ParseMajorMinorPatchTolerant(kcp.Spec.Version)
if err != nil {
return ctrl.Result{}, errors.Wrapf(err, "failed to parse kubernetes version %q", kcp.Spec.Version)
}

// Update kube-proxy daemonset.
if err := workloadCluster.UpdateKubeProxyImageInfo(ctx, kcp, parsedVersion); err != nil {
log.Error(err, "failed to update kube-proxy daemonset")
return ctrl.Result{}, err
}

// Update CoreDNS deployment.
if err := workloadCluster.UpdateCoreDNS(ctx, kcp, parsedVersion); err != nil {
return ctrl.Result{}, errors.Wrap(err, "failed to update CoreDNS deployment")
}
Expand Down
11 changes: 10 additions & 1 deletion controlplane/kubeadm/internal/controllers/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sigs.k8s.io/cluster-api/controlplane/kubeadm/internal"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/collections"
"sigs.k8s.io/cluster-api/util/version"
)

func (r *KubeadmControlPlaneReconciler) upgradeControlPlane(
Expand Down Expand Up @@ -75,7 +76,15 @@ func (r *KubeadmControlPlaneReconciler) upgradeControlPlane(
}

if kcp.Spec.KubeadmConfigSpec.ClusterConfiguration != nil {
imageRepository := kcp.Spec.KubeadmConfigSpec.ClusterConfiguration.ImageRepository
// We intentionally only parse major/minor/patch so that the subsequent code
// also already applies to beta versions of new releases.
parsedVersionTolerant, err := version.ParseMajorMinorPatchTolerant(kcp.Spec.Version)
if err != nil {
return ctrl.Result{}, errors.Wrapf(err, "failed to parse kubernetes version %q", kcp.Spec.Version)
}
// Get the imageRepository or the correct value if nothing is set and a migration is necessary.
imageRepository := internal.ImageRepositoryFromClusterConfig(kcp.Spec.KubeadmConfigSpec.ClusterConfiguration, parsedVersionTolerant)

if err := workloadCluster.UpdateImageRepositoryInKubeadmConfigMap(ctx, imageRepository, parsedVersion); err != nil {
return ctrl.Result{}, errors.Wrap(err, "failed to update the image repository in the kubeadm config map")
}
Expand Down

0 comments on commit a959caf

Please sign in to comment.