From 005a36e88c7341545aa33c034b810a4b8db3c6a4 Mon Sep 17 00:00:00 2001 From: RainbowMango Date: Fri, 11 Aug 2023 17:47:47 +0800 Subject: [PATCH] Extend Cluster API to support multiple zones. Signed-off-by: RainbowMango --- api/openapi-spec/swagger.json | 10 +++++++++- pkg/apis/cluster/types.go | 10 ++++++++++ pkg/apis/cluster/v1alpha1/types.go | 10 ++++++++++ .../cluster/v1alpha1/zz_generated.conversion.go | 2 ++ .../cluster/v1alpha1/zz_generated.deepcopy.go | 5 +++++ pkg/apis/cluster/zz_generated.deepcopy.go | 5 +++++ pkg/generated/openapi/zz_generated.openapi.go | 17 ++++++++++++++++- 7 files changed, 57 insertions(+), 2 deletions(-) diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index 778c6d7eb..1f702865a 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -16357,8 +16357,16 @@ } }, "zone": { - "description": "Zone represents the zone of the member cluster locate in.", + "description": "Zone represents the zone of the member cluster locate in. Deprecated: This filed was never been used by Karmada, and it will not be removed from v1alpha1 for backward compatibility, use Zones instead.", "type": "string" + }, + "zones": { + "description": "Zones 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.", + "type": "array", + "items": { + "type": "string", + "default": "" + } } } }, diff --git a/pkg/apis/cluster/types.go b/pkg/apis/cluster/types.go index b48788e17..99ee72a46 100644 --- a/pkg/apis/cluster/types.go +++ b/pkg/apis/cluster/types.go @@ -117,9 +117,19 @@ type ClusterSpec struct { Region string // Zone represents the zone of the member cluster locate in. + // Deprecated: This filed was never been used by Karmada, and it will not be + // removed from v1alpha1 for backward compatibility, use Zones instead. // +optional Zone string + // Zones 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. + // +optional + Zones []string `json:"zones,omitempty"` + // Taints attached to the member cluster. // Taints on the cluster have the "effect" on // any resource that does not tolerate the Taint. diff --git a/pkg/apis/cluster/v1alpha1/types.go b/pkg/apis/cluster/v1alpha1/types.go index 9d7ab0484..d8bd4e902 100644 --- a/pkg/apis/cluster/v1alpha1/types.go +++ b/pkg/apis/cluster/v1alpha1/types.go @@ -129,9 +129,19 @@ type ClusterSpec struct { Region string `json:"region,omitempty"` // Zone represents the zone of the member cluster locate in. + // Deprecated: This filed was never been used by Karmada, and it will not be + // removed from v1alpha1 for backward compatibility, use Zones instead. // +optional Zone string `json:"zone,omitempty"` + // Zones 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. + // +optional + Zones []string `json:"zones,omitempty"` + // Taints attached to the member cluster. // Taints on the cluster have the "effect" on // any resource that does not tolerate the Taint. diff --git a/pkg/apis/cluster/v1alpha1/zz_generated.conversion.go b/pkg/apis/cluster/v1alpha1/zz_generated.conversion.go index 1bef1cb79..79e7ccfd9 100644 --- a/pkg/apis/cluster/v1alpha1/zz_generated.conversion.go +++ b/pkg/apis/cluster/v1alpha1/zz_generated.conversion.go @@ -331,6 +331,7 @@ func autoConvert_v1alpha1_ClusterSpec_To_cluster_ClusterSpec(in *ClusterSpec, ou out.Provider = in.Provider out.Region = in.Region out.Zone = in.Zone + out.Zones = *(*[]string)(unsafe.Pointer(&in.Zones)) out.Taints = *(*[]v1.Taint)(unsafe.Pointer(&in.Taints)) out.ResourceModels = *(*[]cluster.ResourceModel)(unsafe.Pointer(&in.ResourceModels)) return nil @@ -353,6 +354,7 @@ func autoConvert_cluster_ClusterSpec_To_v1alpha1_ClusterSpec(in *cluster.Cluster out.Provider = in.Provider out.Region = in.Region out.Zone = in.Zone + out.Zones = *(*[]string)(unsafe.Pointer(&in.Zones)) out.Taints = *(*[]v1.Taint)(unsafe.Pointer(&in.Taints)) out.ResourceModels = *(*[]ResourceModel)(unsafe.Pointer(&in.ResourceModels)) return nil diff --git a/pkg/apis/cluster/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/cluster/v1alpha1/zz_generated.deepcopy.go index 05c2cc092..82ad95ac7 100644 --- a/pkg/apis/cluster/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/cluster/v1alpha1/zz_generated.deepcopy.go @@ -170,6 +170,11 @@ func (in *ClusterSpec) DeepCopyInto(out *ClusterSpec) { (*out)[key] = val } } + if in.Zones != nil { + in, out := &in.Zones, &out.Zones + *out = make([]string, len(*in)) + copy(*out, *in) + } if in.Taints != nil { in, out := &in.Taints, &out.Taints *out = make([]v1.Taint, len(*in)) diff --git a/pkg/apis/cluster/zz_generated.deepcopy.go b/pkg/apis/cluster/zz_generated.deepcopy.go index fab6e6558..e2a990efd 100644 --- a/pkg/apis/cluster/zz_generated.deepcopy.go +++ b/pkg/apis/cluster/zz_generated.deepcopy.go @@ -170,6 +170,11 @@ func (in *ClusterSpec) DeepCopyInto(out *ClusterSpec) { (*out)[key] = val } } + if in.Zones != nil { + in, out := &in.Zones, &out.Zones + *out = make([]string, len(*in)) + copy(*out, *in) + } if in.Taints != nil { in, out := &in.Taints, &out.Taints *out = make([]v1.Taint, len(*in)) diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index c947a89c0..53ffbf391 100755 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -1359,11 +1359,26 @@ func schema_pkg_apis_cluster_v1alpha1_ClusterSpec(ref common.ReferenceCallback) }, "zone": { SchemaProps: spec.SchemaProps{ - Description: "Zone represents the zone of the member cluster locate in.", + Description: "Zone represents the zone of the member cluster locate in. Deprecated: This filed was never been used by Karmada, and it will not be removed from v1alpha1 for backward compatibility, use Zones instead.", Type: []string{"string"}, Format: "", }, }, + "zones": { + SchemaProps: spec.SchemaProps{ + Description: "Zones 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.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, "taints": { SchemaProps: spec.SchemaProps{ Description: "Taints attached to the member cluster. Taints on the cluster have the \"effect\" on any resource that does not tolerate the Taint.",