Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support specify global image registry for enable addons #3345

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/karmadactl/addons/descheduler/descheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var enableDescheduler = func(opts *addoninit.CommandAddonsEnableOption) error {
karmadaDeschedulerDeploymentBytes, err := addonutils.ParseTemplate(karmadaDeschedulerDeployment, DeploymentReplace{
Namespace: opts.Namespace,
Replicas: &opts.KarmadaDeschedulerReplicas,
Image: opts.KarmadaDeschedulerImage,
Image: addoninit.KarmadaDeschedulerImage(opts),
})
if err != nil {
return fmt.Errorf("error when parsing karmada descheduler deployment template :%v", err)
Expand Down
15 changes: 4 additions & 11 deletions pkg/karmadactl/addons/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import (
"fmt"

"github.com/spf13/cobra"
"k8s.io/klog/v2"
"k8s.io/kubectl/pkg/util/templates"

addoninit "github.com/karmada-io/karmada/pkg/karmadactl/addons/init"
"github.com/karmada-io/karmada/pkg/karmadactl/cmdinit/options"
globaloptions "github.com/karmada-io/karmada/pkg/karmadactl/options"
"github.com/karmada-io/karmada/pkg/version"
)

var (
Expand Down Expand Up @@ -65,21 +63,16 @@ func NewCmdAddonsEnable(parentCommand string) *cobra.Command {
},
}

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
}

flags := cmd.Flags()
opts.GlobalCommandOptions.AddFlags(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.")
flags.IntVar(&opts.WaitComponentReadyTimeout, "pod-timeout", options.WaitComponentReadyTimeout, "Wait pod ready timeout.")
flags.IntVar(&opts.WaitAPIServiceReadyTimeout, "apiservice-timeout", 30, "Wait apiservice ready timeout.")
flags.StringVar(&opts.KarmadaSearchImage, "karmada-search-image", fmt.Sprintf("docker.io/karmada/karmada-search:%s", releaseVer.PatchRelease()), "karmada search image")
flags.StringVar(&opts.KarmadaSearchImage, "karmada-search-image", addoninit.DefaultKarmadaSearchImage, "karmada search image")
flags.Int32Var(&opts.KarmadaSearchReplicas, "karmada-search-replicas", 1, "Karmada search replica set")
flags.StringVar(&opts.KarmadaDeschedulerImage, "karmada-descheduler-image", fmt.Sprintf("docker.io/karmada/karmada-descheduler:%s", releaseVer.PatchRelease()), "karmada descheduler image")
flags.StringVar(&opts.KarmadaDeschedulerImage, "karmada-descheduler-image", addoninit.DefaultKarmadaDeschedulerImage, "karmada descheduler image")
flags.Int32Var(&opts.KarmadaDeschedulerReplicas, "karmada-descheduler-replicas", 1, "Karmada descheduler replica set")
flags.StringVar(&opts.KarmadaSchedulerEstimatorImage, "karmada-scheduler-estimator-image", fmt.Sprintf("docker.io/karmada/karmada-scheduler-estimator:%s", releaseVer.PatchRelease()), "karmada scheduler-estimator image")
flags.StringVar(&opts.KarmadaSchedulerEstimatorImage, "karmada-scheduler-estimator-image", addoninit.DefaultKarmadaSchedulerEstimatorImage, "karmada scheduler-estimator image")
flags.Int32Var(&opts.KarmadaEstimatorReplicas, "karmada-estimator-replicas", 1, "Karmada scheduler estimator replica set")
flags.StringVar(&opts.MemberKubeConfig, "member-kubeconfig", "", "Member cluster's kubeconfig which to deploy scheduler estimator")
flags.StringVar(&opts.MemberContext, "member-context", "", "Member cluster's context which to deploy scheduler estimator")
Expand Down
2 changes: 1 addition & 1 deletion pkg/karmadactl/addons/estimator/estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ var enableEstimator = func(opts *addoninit.CommandAddonsEnableOption) error {
karmadaEstimatorDeploymentBytes, err := addonutils.ParseTemplate(karmadaEstimatorDeployment, DeploymentReplace{
Namespace: opts.Namespace,
Replicas: &opts.KarmadaEstimatorReplicas,
Image: opts.KarmadaSchedulerEstimatorImage,
Image: addoninit.KarmadaSchedulerEstimatorImage(opts),
MemberClusterName: opts.Cluster,
})
if err != nil {
Expand Down
51 changes: 51 additions & 0 deletions pkg/karmadactl/addons/init/enable_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

cmdinit "github.com/karmada-io/karmada/pkg/karmadactl/cmdinit/kubernetes"
"github.com/karmada-io/karmada/pkg/karmadactl/util/apiclient"
"github.com/karmada-io/karmada/pkg/version"
)

// CommandAddonsEnableOption options for addons list.
Expand All @@ -32,6 +33,8 @@ type CommandAddonsEnableOption struct {

KarmadaKubeClientSet *kubernetes.Clientset

ImageRegistry string

WaitComponentReadyTimeout int

WaitAPIServiceReadyTimeout int
Expand All @@ -43,6 +46,54 @@ type CommandAddonsEnableOption struct {
HostClusterDomain string
}

var (
// DefaultKarmadaDeschedulerImage Karmada descheduler image
DefaultKarmadaDeschedulerImage string
// DefaultKarmadaSchedulerEstimatorImage Karmada scheduler-estimator image
DefaultKarmadaSchedulerEstimatorImage string
// DefaultKarmadaSearchImage Karmada search estimator image
DefaultKarmadaSearchImage string

karmadaRelease string
)

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
}
karmadaRelease = releaseVer.PatchRelease()

DefaultKarmadaDeschedulerImage = fmt.Sprintf("docker.io/karmada/karmada-descheduler:%s", releaseVer.PatchRelease())
DefaultKarmadaSchedulerEstimatorImage = fmt.Sprintf("docker.io/karmada/karmada-scheduler-estimator:%s", releaseVer.PatchRelease())
DefaultKarmadaSearchImage = fmt.Sprintf("docker.io/karmada/karmada-search:%s", releaseVer.PatchRelease())
}

// KarmadaDeschedulerImage get karmada descheduler image
func KarmadaDeschedulerImage(o *CommandAddonsEnableOption) string {
if o.ImageRegistry != "" && o.KarmadaDeschedulerImage == DefaultKarmadaDeschedulerImage {
return o.ImageRegistry + "/karmada-descheduler:" + karmadaRelease
}
return o.KarmadaDeschedulerImage
}

// KarmadaSchedulerEstimatorImage get karmada scheduler-estimator image
func KarmadaSchedulerEstimatorImage(o *CommandAddonsEnableOption) string {
my-git9 marked this conversation as resolved.
Show resolved Hide resolved
if o.ImageRegistry != "" && o.KarmadaSchedulerEstimatorImage == DefaultKarmadaSchedulerEstimatorImage {
return o.ImageRegistry + "/karmada-scheduler-estimator:" + karmadaRelease
}
return o.KarmadaSchedulerEstimatorImage
}

// KarmadaSearchImage get karmada search image
func KarmadaSearchImage(o *CommandAddonsEnableOption) string {
my-git9 marked this conversation as resolved.
Show resolved Hide resolved
if o.ImageRegistry != "" && o.KarmadaSearchImage == DefaultKarmadaSearchImage {
return o.ImageRegistry + "/karmada-search:" + karmadaRelease
}
return o.KarmadaSearchImage
}

// Complete the conditions required to be able to run enable.
func (o *CommandAddonsEnableOption) Complete() error {
err := o.GlobalCommandOptions.Complete()
Expand Down
2 changes: 1 addition & 1 deletion pkg/karmadactl/addons/search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func installComponentsOnHostCluster(opts *addoninit.CommandAddonsEnableOption) e
Namespace: opts.Namespace,
Replicas: &opts.KarmadaSearchReplicas,
ETCDSevers: etcdServers,
Image: opts.KarmadaSearchImage,
Image: addoninit.KarmadaSearchImage(opts),
})
if err != nil {
return fmt.Errorf("error when parsing karmada search deployment template :%v", err)
Expand Down