diff --git a/pkg/karmadactl/cmdinit/cmdinit.go b/pkg/karmadactl/cmdinit/cmdinit.go index 62f4d090925d..e6d83431b693 100644 --- a/pkg/karmadactl/cmdinit/cmdinit.go +++ b/pkg/karmadactl/cmdinit/cmdinit.go @@ -21,6 +21,7 @@ import ( "strings" "github.com/spf13/cobra" + corev1 "k8s.io/api/core/v1" "k8s.io/klog/v2" "k8s.io/kubectl/pkg/util/templates" @@ -114,6 +115,7 @@ func NewCmdInit(parentCommand string) *cobra.Command { } flags := cmd.Flags() flags.StringVarP(&opts.ImageRegistry, "private-image-registry", "", "", "Private image registry where pull images from. If set, all required images will be downloaded from it, it would be useful in offline installation scenarios. In addition, you still can use --kube-image-registry to specify the registry for Kubernetes's images.") + flags.StringVarP(&opts.ImagePullPolicy, "image-pull-policy", "", string(corev1.PullIfNotPresent), "The image pull policy for all Karmada components container. One of Always, Never, IfNotPresent. Defaults to IfNotPresent.") flags.StringSliceVar(&opts.PullSecrets, "image-pull-secrets", nil, "Image pull secrets are used to pull images from the private registry, could be secret list separated by comma (e.g '--image-pull-secrets PullSecret1,PullSecret2', the secrets should be pre-settled in the namespace declared by '--namespace')") // kube image registry flags.StringVarP(&opts.KubeImageMirrorCountry, "kube-image-mirror-country", "", "", "Country code of the kube image registry to be used. For Chinese mainland users, set it to cn") diff --git a/pkg/karmadactl/cmdinit/kubernetes/deploy.go b/pkg/karmadactl/cmdinit/kubernetes/deploy.go index 2890fb411381..d5ac6ab365d4 100644 --- a/pkg/karmadactl/cmdinit/kubernetes/deploy.go +++ b/pkg/karmadactl/cmdinit/kubernetes/deploy.go @@ -124,6 +124,7 @@ func init() { // CommandInitOption holds all flags options for init. type CommandInitOption struct { ImageRegistry string + ImagePullPolicy string KubeImageRegistry string KubeImageMirrorCountry string KubeImageTag string @@ -218,8 +219,6 @@ func (i *CommandInitOption) isExternalEtcdProvided() bool { } // Validate Check that there are enough flags to run the command. -// -//nolint:gocyclo func (i *CommandInitOption) Validate(parentCommand string) error { if i.KarmadaAPIServerAdvertiseAddress != "" { if netutils.ParseIPSloppy(i.KarmadaAPIServerAdvertiseAddress) == nil { @@ -227,6 +226,13 @@ func (i *CommandInitOption) Validate(parentCommand string) error { } } + switch i.ImagePullPolicy { + case string(corev1.PullAlways), string(corev1.PullIfNotPresent), string(corev1.PullNever): + // continue + default: + return fmt.Errorf("invalid image pull policy: %s", i.ImagePullPolicy) + } + if i.isExternalEtcdProvided() { return i.validateExternalEtcd(parentCommand) } diff --git a/pkg/karmadactl/cmdinit/kubernetes/deployments.go b/pkg/karmadactl/cmdinit/kubernetes/deployments.go index da7c8b912e8c..ec4a0d06e64c 100644 --- a/pkg/karmadactl/cmdinit/kubernetes/deployments.go +++ b/pkg/karmadactl/cmdinit/kubernetes/deployments.go @@ -444,8 +444,9 @@ func (i *CommandInitOption) makeKarmadaSchedulerDeployment() *appsv1.Deployment }, Containers: []corev1.Container{ { - Name: schedulerDeploymentNameAndServiceAccountName, - Image: i.karmadaSchedulerImage(), + Name: schedulerDeploymentNameAndServiceAccountName, + Image: i.karmadaSchedulerImage(), + ImagePullPolicy: corev1.PullPolicy(i.ImagePullPolicy), Command: []string{ "/bin/karmada-scheduler", "--kubeconfig=/etc/kubeconfig", @@ -559,8 +560,9 @@ func (i *CommandInitOption) makeKarmadaControllerManagerDeployment() *appsv1.Dep }, Containers: []corev1.Container{ { - Name: controllerManagerDeploymentAndServiceName, - Image: i.karmadaControllerManagerImage(), + Name: controllerManagerDeploymentAndServiceName, + Image: i.karmadaControllerManagerImage(), + ImagePullPolicy: corev1.PullPolicy(i.ImagePullPolicy), Command: []string{ "/bin/karmada-controller-manager", "--kubeconfig=/etc/kubeconfig", @@ -677,8 +679,9 @@ func (i *CommandInitOption) makeKarmadaWebhookDeployment() *appsv1.Deployment { AutomountServiceAccountToken: pointer.Bool(false), Containers: []corev1.Container{ { - Name: webhookDeploymentAndServiceAccountAndServiceName, - Image: i.karmadaWebhookImage(), + Name: webhookDeploymentAndServiceAccountAndServiceName, + Image: i.karmadaWebhookImage(), + ImagePullPolicy: corev1.PullPolicy(i.ImagePullPolicy), Command: []string{ "/bin/karmada-webhook", "--kubeconfig=/etc/kubeconfig", @@ -847,9 +850,10 @@ func (i *CommandInitOption) makeKarmadaAggregatedAPIServerDeployment() *appsv1.D AutomountServiceAccountToken: pointer.Bool(false), Containers: []corev1.Container{ { - Name: karmadaAggregatedAPIServerDeploymentAndServiceName, - Image: i.karmadaAggregatedAPIServerImage(), - Command: command, + Name: karmadaAggregatedAPIServerDeploymentAndServiceName, + Image: i.karmadaAggregatedAPIServerImage(), + ImagePullPolicy: corev1.PullPolicy(i.ImagePullPolicy), + Command: command, VolumeMounts: []corev1.VolumeMount{ { Name: KubeConfigSecretAndMountName,