Skip to content

Commit

Permalink
fix: upgrade image improvement
Browse files Browse the repository at this point in the history
New flag.
Proxy image management.

Fixes: siderolabs#8275

Signed-off-by: Matthieu STROHL <mstrohl@dive-in-it.com>
  • Loading branch information
mstrohl committed Feb 8, 2024
1 parent e452513 commit f5800a6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmd/talosctl/cmd/talos/upgrade-k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func init() {
upgradeK8sCmd.Flags().BoolVarP(&upgradeK8sCmdFlags.withDocs, "with-docs", "", true, "patch all machine configs adding the documentation for each field")
upgradeK8sCmd.Flags().BoolVar(&upgradeOptions.DryRun, "dry-run", false, "skip the actual upgrade and show the upgrade plan instead")
upgradeK8sCmd.Flags().BoolVar(&upgradeOptions.PrePullImages, "pre-pull-images", true, "pre-pull images before upgrade")
upgradeK8sCmd.Flags().BoolVar(&upgradeOptions.CustomRegistry, "custom-registry", false, "keep customized registry setting")
upgradeK8sCmd.Flags().BoolVar(&upgradeOptions.UpgradeKubelet, "upgrade-kubelet", true, "upgrade kubelet service")
addCommand(upgradeK8sCmd)
}
Expand Down
17 changes: 12 additions & 5 deletions pkg/cluster/kubernetes/talos_managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,14 @@ func patchKubeProxy(options UpgradeOptions) func(config *v1alpha1config.Config)
config.ClusterConfig.ProxyConfig = &v1alpha1config.ProxyConfig{}
}

config.ClusterConfig.ProxyConfig.ContainerImage = fmt.Sprintf("%s:v%s", constants.KubeProxyImage, options.Path.ToVersion())
imageName := constants.KubeProxyImage

privateRepo := strings.Split(config.ClusterConfig.ProxyConfig.ContainerImage, ":")[0]
if privateRepo != imageName && options.CustomRegistry {
imageName = privateRepo
}

config.ClusterConfig.ProxyConfig.ContainerImage = fmt.Sprintf("%s:v%s", imageName, options.Path.ToVersion())

return nil
}
Expand Down Expand Up @@ -308,7 +315,7 @@ func staticPodImage(logUpdate func(oldImage string), service string, defaultImag
imageName := defaultImage

privateRepo := strings.Split(containerImage, ":")[0]
if privateRepo != defaultImage && !options.PrePullImages {
if privateRepo != defaultImage && !options.PrePullImages && options.CustomRegistry {
imageName = privateRepo
}

Expand Down Expand Up @@ -376,7 +383,7 @@ func upgradeStaticPodPatcher(options UpgradeOptions, service string, configResou
image, err := staticPodImage(logUpdate,
service,
constants.KubernetesAPIServerImage,
strings.Split(config.ClusterConfig.APIServerConfig.ContainerImage, ":")[0],
config.ClusterConfig.APIServerConfig.ContainerImage,
configImage,
options)
if err != nil {
Expand All @@ -392,7 +399,7 @@ func upgradeStaticPodPatcher(options UpgradeOptions, service string, configResou
image, err := staticPodImage(logUpdate,
service,
constants.KubernetesControllerManagerImage,
strings.Split(config.ClusterConfig.ControllerManagerConfig.ContainerImage, ":")[0],
config.ClusterConfig.ControllerManagerConfig.ContainerImage,
configImage,
options)
if err != nil {
Expand All @@ -408,7 +415,7 @@ func upgradeStaticPodPatcher(options UpgradeOptions, service string, configResou
image, err := staticPodImage(logUpdate,
service,
constants.KubernetesSchedulerImage,
strings.Split(config.ClusterConfig.SchedulerConfig.ContainerImage, ":")[0],
config.ClusterConfig.SchedulerConfig.ContainerImage,
configImage,
options)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/cluster/kubernetes/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type UpgradeOptions struct {
ControlPlaneEndpoint string
LogOutput io.Writer
PrePullImages bool
CustomRegistry bool
UpgradeKubelet bool
DryRun bool
EncoderOpt encoder.Option
Expand Down

0 comments on commit f5800a6

Please sign in to comment.