From d0ef3343ae28f3a364e4537626ee5fedb3e216b3 Mon Sep 17 00:00:00 2001 From: whitewindmills Date: Thu, 24 Aug 2023 18:47:24 +0800 Subject: [PATCH] deprecate cluster-zone flag and introduce cluster-zones flag Signed-off-by: whitewindmills --- cmd/agent/app/agent.go | 4 ++-- pkg/karmadactl/join/join.go | 22 +++++++++++++++++++++- pkg/util/cluster.go | 6 ++++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/cmd/agent/app/agent.go b/cmd/agent/app/agent.go index 8bb5a25c5..37ade10f0 100644 --- a/cmd/agent/app/agent.go +++ b/cmd/agent/app/agent.go @@ -405,8 +405,8 @@ func generateClusterInControllerPlane(opts util.ClusterRegisterOption) (*cluster cluster.Spec.Provider = opts.ClusterProvider } - if opts.ClusterZone != "" { - cluster.Spec.Zone = opts.ClusterZone + if len(opts.ClusterZones) > 0 { + cluster.Spec.Zones = opts.ClusterZones } if opts.ClusterRegion != "" { diff --git a/pkg/karmadactl/join/join.go b/pkg/karmadactl/join/join.go index 8cc2b8adf..8174c6dec 100644 --- a/pkg/karmadactl/join/join.go +++ b/pkg/karmadactl/join/join.go @@ -85,8 +85,16 @@ type CommandJoinOption struct { ClusterRegion string // ClusterZone represents the zone of the cluster locate in. + // Deprecated: Use ClusterZones instead. ClusterZone string + // ClusterZones represents the failure zones(also called availability zones) of the + // member cluster. The zones are presented as a slice to support the case + // that cluster runs across multiple failure zones. + // Refer https://kubernetes.io/docs/setup/best-practices/multiple-zones/ for + // more details about running Kubernetes in multiple zones. + ClusterZones []string + // DryRun tells if run the command in dry-run mode, without making any server requests. DryRun bool } @@ -116,6 +124,10 @@ func (j *CommandJoinOption) Validate(args []string) error { if j.ClusterNamespace == util.NamespaceKarmadaSystem { klog.Warningf("karmada-system is always reserved for Karmada control plane. We do not recommend using karmada-system to store secrets of member clusters. It may cause mistaken cleanup of resources.") } + + if j.ClusterZone != "" && len(j.ClusterZones) > 0 { + return fmt.Errorf("--cluster-zone and --cluster-zones can not co-exist") + } return nil } @@ -128,7 +140,10 @@ func (j *CommandJoinOption) AddFlags(flags *pflag.FlagSet) { "Path of the cluster's kubeconfig.") flags.StringVar(&j.ClusterProvider, "cluster-provider", "", "Provider of the joining cluster. The Karmada scheduler can use this information to spread workloads across providers for higher availability.") flags.StringVar(&j.ClusterRegion, "cluster-region", "", "The region of the joining cluster. The Karmada scheduler can use this information to spread workloads across regions for higher availability.") - flags.StringVar(&j.ClusterZone, "cluster-zone", "", "The zone of the joining cluster") + flags.StringVar(&j.ClusterZone, "cluster-zone", "", "The zone of the joining cluster.") + // nolint: errcheck + flags.MarkDeprecated("cluster-zone", "This flag is deprecated and will be removed in future releases. Use --cluster-zones instead.") + flags.StringSliceVar(&j.ClusterZones, "cluster-zones", nil, "The zones of the joining cluster. The Karmada scheduler can use this information to spread workloads across zones for higher availability.") flags.BoolVar(&j.DryRun, "dry-run", false, "Run the command in dry-run mode, without making any server requests.") } @@ -168,6 +183,7 @@ func (j *CommandJoinOption) RunJoinCluster(controlPlaneRestConfig, clusterConfig ClusterProvider: j.ClusterProvider, ClusterRegion: j.ClusterRegion, ClusterZone: j.ClusterZone, + ClusterZones: j.ClusterZones, DryRun: j.DryRun, ControlPlaneConfig: controlPlaneRestConfig, ClusterConfig: clusterConfig, @@ -231,6 +247,10 @@ func generateClusterInControllerPlane(opts util.ClusterRegisterOption) (*cluster clusterObj.Spec.Zone = opts.ClusterZone } + if len(opts.ClusterZones) > 0 { + clusterObj.Spec.Zones = opts.ClusterZones + } + if opts.ClusterRegion != "" { clusterObj.Spec.Region = opts.ClusterRegion } diff --git a/pkg/util/cluster.go b/pkg/util/cluster.go index 046343852..c4c9bba9f 100644 --- a/pkg/util/cluster.go +++ b/pkg/util/cluster.go @@ -40,8 +40,10 @@ type ClusterRegisterOption struct { ProxyServerAddress string ClusterProvider string ClusterRegion string - ClusterZone string - DryRun bool + // Deprecated: Use ClusterZones instead. + ClusterZone string + ClusterZones []string + DryRun bool ControlPlaneConfig *rest.Config ClusterConfig *rest.Config