diff --git a/operator/cmd/operator/app/operator.go b/operator/cmd/operator/app/operator.go index f3749b8b1269..1ca8c6708fbd 100644 --- a/operator/cmd/operator/app/operator.go +++ b/operator/cmd/operator/app/operator.go @@ -25,6 +25,8 @@ import ( "github.com/karmada-io/karmada/operator/pkg/scheme" "github.com/karmada-io/karmada/pkg/sharedcli" "github.com/karmada-io/karmada/pkg/sharedcli/klogflag" + "github.com/karmada-io/karmada/pkg/version" + "github.com/karmada-io/karmada/pkg/version/sharedcommand" ) // NewOperatorCommand creates a *cobra.Command object with default parameters @@ -67,6 +69,7 @@ func NewOperatorCommand(ctx context.Context) *cobra.Command { logsFlagSet := fss.FlagSet("logs") klogflag.Add(logsFlagSet) + cmd.AddCommand(sharedcommand.NewCmdVersion("karmada-operator")) cmd.Flags().AddFlagSet(genericFlagSet) cmd.Flags().AddFlagSet(logsFlagSet) @@ -77,6 +80,7 @@ func NewOperatorCommand(ctx context.Context) *cobra.Command { // Run runs the karmada-operator. This should never exit. func Run(ctx context.Context, o *options.Options) error { + klog.Infof("karmada-operator version: %s", version.Get()) klog.InfoS("Golang settings", "GOGC", os.Getenv("GOGC"), "GOMAXPROCS", os.Getenv("GOMAXPROCS"), "GOTRACEBACK", os.Getenv("GOTRACEBACK")) manager, err := createControllerManager(ctx, o) diff --git a/operator/config/samples/karmada.yaml b/operator/config/samples/karmada.yaml index cf2452e46ca5..235d41eef19c 100644 --- a/operator/config/samples/karmada.yaml +++ b/operator/config/samples/karmada.yaml @@ -15,8 +15,7 @@ spec: # type: DirectoryOrCreate # path: /var/lib/karmada/etcd/karmada-demo volumeClaim: - metadata: - name: etcd-data + name: etcd-data spec: accessModes: - ReadWriteOnce @@ -31,19 +30,15 @@ spec: serviceSubnet: 10.96.0.0/12 karmadaAggregatedAPIServer: imageRepository: docker.io/karmada/karmada-aggregated-apiserver - imageTag: v1.7.0 replicas: 1 karmadaControllerManager: imageRepository: docker.io/karmada/karmada-controller-manager - imageTag: v1.7.0 replicas: 1 karmadaScheduler: imageRepository: docker.io/karmada/karmada-scheduler - imageTag: v1.7.0 replicas: 1 karmadaWebhook: imageRepository: docker.io/karmada/karmada-webhook - imageTag: v1.7.0 replicas: 1 kubeControllerManager: imageRepository: registry.k8s.io/kube-controller-manager diff --git a/operator/pkg/apis/operator/v1alpha1/defaults.go b/operator/pkg/apis/operator/v1alpha1/defaults.go index de8ff85430ee..25328d2ad3a3 100644 --- a/operator/pkg/apis/operator/v1alpha1/defaults.go +++ b/operator/pkg/apis/operator/v1alpha1/defaults.go @@ -5,12 +5,16 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/klog/v2" "k8s.io/utils/pointer" "github.com/karmada-io/karmada/operator/pkg/constants" + "github.com/karmada-io/karmada/pkg/version" ) var ( + // DefaultKarmadaImageVersion defines the default of the karmada components image tag + DefaultKarmadaImageVersion string etcdImageRepository = fmt.Sprintf("%s/%s", constants.KubeDefaultRepository, constants.Etcd) karmadaAPIServiceImageRepository = fmt.Sprintf("%s/%s", constants.KubeDefaultRepository, constants.KubeAPIServer) karmadaAggregatedAPIServerImageRepository = fmt.Sprintf("%s/%s", constants.KarmadaDefaultRepository, constants.KarmadaAggregatedAPIServer) @@ -22,6 +26,16 @@ var ( KarmadaMetricsAdapterImageRepository = fmt.Sprintf("%s/%s", constants.KarmadaDefaultRepository, constants.KarmadaMetricsAdapter) ) +func init() { + releaseVer, err := version.ParseGitVersion(version.Get().GitVersion) + if err != nil { + klog.Infof("No default release version found. build version: %s", version.Get().String()) + releaseVer = &version.ReleaseVersion{} // initialize to avoid panic + } + DefaultKarmadaImageVersion = releaseVer.ReleaseVersion() + klog.Infof("default Karmada Image Version: %s", DefaultKarmadaImageVersion) +} + func addDefaultingFuncs(scheme *runtime.Scheme) error { return RegisterDefaults(scheme) } @@ -138,7 +152,7 @@ func setDefaultsKarmadaAggregatedAPIServer(obj *KarmadaComponents) { aggregated.Image.ImageRepository = karmadaAggregatedAPIServerImageRepository } if len(aggregated.Image.ImageTag) == 0 { - aggregated.Image.ImageTag = constants.KarmadaDefaultVersion + aggregated.Image.ImageTag = DefaultKarmadaImageVersion } if aggregated.Replicas == nil { aggregated.Replicas = pointer.Int32(1) @@ -172,7 +186,7 @@ func setDefaultsKarmadaControllerManager(obj *KarmadaComponents) { karmadaControllerManager.Image.ImageRepository = karmadaControllerManagerImageRepository } if len(karmadaControllerManager.Image.ImageTag) == 0 { - karmadaControllerManager.Image.ImageTag = constants.KarmadaDefaultVersion + karmadaControllerManager.Image.ImageTag = DefaultKarmadaImageVersion } if karmadaControllerManager.Replicas == nil { karmadaControllerManager.Replicas = pointer.Int32(1) @@ -189,7 +203,7 @@ func setDefaultsKarmadaScheduler(obj *KarmadaComponents) { scheduler.Image.ImageRepository = karmadaSchedulerImageRepository } if len(scheduler.Image.ImageTag) == 0 { - scheduler.Image.ImageTag = constants.KarmadaDefaultVersion + scheduler.Image.ImageTag = DefaultKarmadaImageVersion } if scheduler.Replicas == nil { scheduler.Replicas = pointer.Int32(1) @@ -206,7 +220,7 @@ func setDefaultsKarmadaWebhook(obj *KarmadaComponents) { webhook.Image.ImageRepository = karmadaWebhookImageRepository } if len(webhook.Image.ImageTag) == 0 { - webhook.Image.ImageTag = constants.KarmadaDefaultVersion + webhook.Image.ImageTag = DefaultKarmadaImageVersion } if webhook.Replicas == nil { webhook.Replicas = pointer.Int32(1) @@ -223,7 +237,7 @@ func setDefaultsKarmadaDescheduler(obj *KarmadaComponents) { descheduler.Image.ImageRepository = karmadaDeschedulerImageRepository } if len(descheduler.Image.ImageTag) == 0 { - descheduler.Image.ImageTag = constants.KarmadaDefaultVersion + descheduler.Image.ImageTag = DefaultKarmadaImageVersion } if descheduler.Replicas == nil { descheduler.Replicas = pointer.Int32(1) @@ -240,7 +254,7 @@ func setDefaultsKarmadaMetricsAdapter(obj *KarmadaComponents) { metricsAdapter.Image.ImageRepository = KarmadaMetricsAdapterImageRepository } if len(metricsAdapter.Image.ImageTag) == 0 { - metricsAdapter.Image.ImageTag = constants.KarmadaDefaultVersion + metricsAdapter.Image.ImageTag = DefaultKarmadaImageVersion } if metricsAdapter.Replicas == nil { diff --git a/operator/pkg/constants/constants.go b/operator/pkg/constants/constants.go index d31d9b31e042..c03454e1c7e3 100644 --- a/operator/pkg/constants/constants.go +++ b/operator/pkg/constants/constants.go @@ -14,8 +14,6 @@ const ( KarmadaDefaultRepository = "docker.io/karmada" // EtcdDefaultVersion defines the default of the karmada etcd image tag EtcdDefaultVersion = "3.5.9-0" - // KarmadaDefaultVersion defines the default of the karmada components image tag - KarmadaDefaultVersion = "v1.7.0" // KubeDefaultVersion defines the default of the karmada apiserver and kubeControllerManager image tag KubeDefaultVersion = "v1.25.4" // KarmadaDefaultServiceSubnet defines the default of the subnet used by k8s services. diff --git a/operator/pkg/init.go b/operator/pkg/init.go index 979ba5cbc573..b1d05858b4f7 100644 --- a/operator/pkg/init.go +++ b/operator/pkg/init.go @@ -230,8 +230,8 @@ func defaultJobInitOptions() *InitOptions { operatorscheme.Scheme.Default(karmada) return &InitOptions{ - CrdRemoteURL: fmt.Sprintf(defaultCrdURL, constants.KarmadaDefaultVersion), - KarmadaVersion: constants.KarmadaDefaultVersion, + CrdRemoteURL: fmt.Sprintf(defaultCrdURL, operatorv1alpha1.DefaultKarmadaImageVersion), + KarmadaVersion: operatorv1alpha1.DefaultKarmadaImageVersion, KarmadaDataDir: constants.KarmadaDataDir, Karmada: karmada, }