mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
kubeadm: mutate ClusterConfiguration.imageRepository to "registry.k8s.io"
If the user runs "kubeadm upgrade apply", kubeadm can download a configuration from the cluster. If the configuration contains the legacy default imageRepository of "k8s.gcr.io", mutate it to the new default of "registry.k8s.io" and update the configuration in the config map. During "upgrade node/diff" download the configuration, mutate the image repository locally, but do not mutate the in-cluster value. That is done only on "apply". This ensures that users are migrated from the old default registry domain.
This commit is contained in:
parent
451e1fa8bc
commit
1c46686f09
@ -41,6 +41,7 @@ import (
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/features"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/phases/upgrade"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/phases/uploadconfig"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/preflight"
|
||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/util/apiclient"
|
||||
@ -72,6 +73,15 @@ func loadConfig(cfgPath string, client clientset.Interface, skipComponentConfigs
|
||||
// This is probably 90% of the time. So we handle it first.
|
||||
if cfgPath == "" {
|
||||
cfg, err := configutil.FetchInitConfigurationFromCluster(client, printer, logPrefix, false, skipComponentConfigs)
|
||||
// In case we fetch a configuration from the cluster, mutate the ImageRepository field
|
||||
// to be 'registry.k8s.io', if it was 'k8s.gcr.io'.
|
||||
// TODO: Remove this in 1.26
|
||||
// https://github.com/kubernetes/kubeadm/issues/2671
|
||||
if err == nil {
|
||||
if err := uploadconfig.MutateImageRepository(cfg, client); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
}
|
||||
return cfg, false, err
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ import (
|
||||
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/phases/controlplane"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/phases/uploadconfig"
|
||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
||||
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
||||
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
||||
@ -119,6 +120,14 @@ func runDiff(flags *diffFlags, args []string) error {
|
||||
return errors.Wrapf(err, "couldn't create a Kubernetes client from file %q", flags.kubeConfigPath)
|
||||
}
|
||||
cfg, err = configutil.FetchInitConfigurationFromCluster(client, nil, "upgrade/diff", false, false)
|
||||
// In case we fetch a configuration from the cluster, mutate the ImageRepository field
|
||||
// to be 'registry.k8s.io', if it was 'k8s.gcr.io'. Don't mutate the in-cluster value by passing
|
||||
// nil as the client field; this is done only on "apply".
|
||||
// TODO: Remove this in 1.26
|
||||
// https://github.com/kubernetes/kubeadm/issues/2671
|
||||
if err == nil {
|
||||
_ = uploadconfig.MutateImageRepository(cfg, nil)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -32,6 +32,7 @@ import (
|
||||
phases "k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/upgrade/node"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/phases/uploadconfig"
|
||||
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
||||
)
|
||||
|
||||
@ -143,6 +144,12 @@ func newNodeData(cmd *cobra.Command, args []string, options *nodeOptions) (*node
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unable to fetch the kubeadm-config ConfigMap")
|
||||
}
|
||||
// In case we fetch a configuration from the cluster, mutate the ImageRepository field
|
||||
// to be 'registry.k8s.io', if it was 'k8s.gcr.io'. Don't mutate the in-cluster value by passing
|
||||
// nil as the client field; this is done only on "apply".
|
||||
// TODO: Remove this in 1.26
|
||||
// https://github.com/kubernetes/kubeadm/issues/2671
|
||||
_ = uploadconfig.MutateImageRepository(cfg, nil)
|
||||
|
||||
ignorePreflightErrorsSet, err := validation.ValidateIgnorePreflightErrors(options.ignorePreflightErrors, cfg.NodeRegistration.IgnorePreflightErrors)
|
||||
if err != nil {
|
||||
|
@ -19,10 +19,12 @@ package uploadconfig
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
rbac "k8s.io/api/rbac/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
@ -115,3 +117,25 @@ func UploadConfiguration(cfg *kubeadmapi.InitConfiguration, client clientset.Int
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// MutateImageRepository mutates the imageRepository field in the ClusterConfiguration
|
||||
// to 'registry.k8s.io' in case it was the legacy default 'k8s.gcr.io'
|
||||
// TODO: Remove this in 1.26
|
||||
// https://github.com/kubernetes/kubeadm/issues/2671
|
||||
func MutateImageRepository(cfg *kubeadmapi.InitConfiguration, client clientset.Interface) error {
|
||||
if cfg.ImageRepository != "k8s.gcr.io" {
|
||||
return nil
|
||||
}
|
||||
cfg.ImageRepository = "registry.k8s.io"
|
||||
// If the client is nil assume that we don't want to mutate the in-cluster config
|
||||
if client == nil {
|
||||
return nil
|
||||
}
|
||||
klog.V(1).Info("updating the ClusterConfiguration.ImageRepository field in the kube-system/kubeadm-config " +
|
||||
"ConfigMap to be 'registry.k8s.io' instead of the legacy default of 'k8s.gcr.io'")
|
||||
if err := UploadConfiguration(cfg, client); err != nil {
|
||||
return errors.Wrap(err, "could not mutate the ClusterConfiguration.ImageRepository field in "+
|
||||
"the kube-system/kubeadm-config ConfigMap")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user