Skip to content

Commit

Permalink
fix: karmada-operator install default version karmada
Browse files Browse the repository at this point in the history
Signed-off-by: chaosi-zju <chaosi@zju.edu.cn>
  • Loading branch information
chaosi-zju committed Oct 21, 2023
1 parent 920f5bf commit 56ce05c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
4 changes: 4 additions & 0 deletions operator/cmd/operator/app/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down
7 changes: 1 addition & 6 deletions operator/config/samples/karmada.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
26 changes: 20 additions & 6 deletions operator/pkg/apis/operator/v1alpha1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions operator/pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions operator/pkg/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit 56ce05c

Please sign in to comment.