From a0832c4dffee79d161eb2b64ad37d2f2ac59b445 Mon Sep 17 00:00:00 2001 From: Andrei Alexandru Date: Tue, 5 Dec 2023 17:57:48 +0200 Subject: [PATCH] Add AvailabilityZones field (#92) * Add AvailabilityZones field * Update db test * Update swagger --------- Co-authored-by: aalexand --- .../registry.ethos.adobe.com_clusters.yaml | 12 +++++ local/client/dummy-crd.yaml | 7 +++ local/database/dummy-data.yaml | 7 +++ pkg/api/registry/v1/cluster_types.go | 8 ++++ pkg/api/registry/v1/zz_generated.deepcopy.go | 20 ++++++++ pkg/apiserver/docs/docs.go | 18 ++++++++ pkg/apiserver/docs/swagger.json | 18 ++++++++ pkg/apiserver/docs/swagger.yaml | 12 +++++ pkg/database/database_test.go | 46 ++++++++++++++++++- pkg/database/testdata/clusters.yaml | 7 +++ 10 files changed, 153 insertions(+), 2 deletions(-) diff --git a/config/crd/bases/registry.ethos.adobe.com_clusters.yaml b/config/crd/bases/registry.ethos.adobe.com_clusters.yaml index 0b85a01b..d22fdbf1 100644 --- a/config/crd/bases/registry.ethos.adobe.com_clusters.yaml +++ b/config/crd/bases/registry.ethos.adobe.com_clusters.yaml @@ -74,6 +74,18 @@ spec: - certificateAuthorityData - endpoint type: object + availabilityZones: + description: AvailabilityZones cluster availability zones + items: + properties: + id: + type: string + name: + type: string + required: + - name + type: object + type: array businessUnit: description: The BU that owns the cluster type: string diff --git a/local/client/dummy-crd.yaml b/local/client/dummy-crd.yaml index 46b8b24e..5a83aec7 100644 --- a/local/client/dummy-crd.yaml +++ b/local/client/dummy-crd.yaml @@ -65,6 +65,13 @@ spec: taints: - workload=memory-optimized:NoSchedule accountId: "11111-2222-3333-4444-555555555" + availabilityZones: + - name: us-east-1a + id: use1-az1 + - name: us-east-1b + id: use1-az2 + - name: us-east-1c + id: use1-az3 virtualNetworks: - id: "/subscriptions/11111-2222-3333-4444-555555555/resourceGroups/cluster01_local_network/providers/Microsoft.Network/virtualNetworks/cluster01_local_useast1-vnet/subnets/cluster01_local_useast1_master_network_10_0_0_0_24" cidrs: diff --git a/local/database/dummy-data.yaml b/local/database/dummy-data.yaml index 1184c6b1..40eb4650 100644 --- a/local/database/dummy-data.yaml +++ b/local/database/dummy-data.yaml @@ -266,6 +266,13 @@ clusterCapacity: 30 clusterProvisioning: 30 lastUpdated: "2023-03-22T11:55:41Z" + availabilityZones: + - name: us-east-1a + id: use1-az1 + - name: us-east-1b + id: use1-az2 + - name: us-east-1c + id: use1-az3 status: Active phase: Running tags: diff --git a/pkg/api/registry/v1/cluster_types.go b/pkg/api/registry/v1/cluster_types.go index a4c467f9..243620b0 100644 --- a/pkg/api/registry/v1/cluster_types.go +++ b/pkg/api/registry/v1/cluster_types.go @@ -119,6 +119,9 @@ type ClusterSpec struct { // ServiceMetadata service specific metadata ServiceMetadata ServiceMetadata `json:"services,omitempty"` + + // AvailabilityZones cluster availability zones + AvailabilityZones []AvailabilityZone `json:"availabilityZones,omitempty"` } // Offering the cluster is meant for @@ -255,6 +258,11 @@ type ServiceMetadataItem map[string]ServiceMetadataMap type ServiceMetadataMap map[string]string +type AvailabilityZone struct { + Name string `json:"name"` + ID string `json:"id,omitempty"` +} + // ClusterStatus defines the observed state of Cluster type ClusterStatus struct { // Send/Receive Errors diff --git a/pkg/api/registry/v1/zz_generated.deepcopy.go b/pkg/api/registry/v1/zz_generated.deepcopy.go index ed867961..a4c8951a 100644 --- a/pkg/api/registry/v1/zz_generated.deepcopy.go +++ b/pkg/api/registry/v1/zz_generated.deepcopy.go @@ -60,6 +60,21 @@ func (in *AllowedOnboardingTeam) DeepCopy() *AllowedOnboardingTeam { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AvailabilityZone) DeepCopyInto(out *AvailabilityZone) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AvailabilityZone. +func (in *AvailabilityZone) DeepCopy() *AvailabilityZone { + if in == nil { + return nil + } + out := new(AvailabilityZone) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Capacity) DeepCopyInto(out *Capacity) { *out = *in @@ -214,6 +229,11 @@ func (in *ClusterSpec) DeepCopyInto(out *ClusterSpec) { (*out)[key] = outVal } } + if in.AvailabilityZones != nil { + in, out := &in.AvailabilityZones, &out.AvailabilityZones + *out = make([]AvailabilityZone, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterSpec. diff --git a/pkg/apiserver/docs/docs.go b/pkg/apiserver/docs/docs.go index 970b073d..4f03cd26 100644 --- a/pkg/apiserver/docs/docs.go +++ b/pkg/apiserver/docs/docs.go @@ -468,6 +468,17 @@ const docTemplate = `{ } } }, + "github_com_adobe_cluster-registry_pkg_api_registry_v1.AvailabilityZone": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, "github_com_adobe_cluster-registry_pkg_api_registry_v1.Capacity": { "type": "object", "properties": { @@ -504,6 +515,13 @@ const docTemplate = `{ } ] }, + "availabilityZones": { + "description": "AvailabilityZones cluster availability zones", + "type": "array", + "items": { + "$ref": "#/definitions/github_com_adobe_cluster-registry_pkg_api_registry_v1.AvailabilityZone" + } + }, "businessUnit": { "description": "The BU that owns the cluster\n+kubebuilder:validation:Required", "type": "string" diff --git a/pkg/apiserver/docs/swagger.json b/pkg/apiserver/docs/swagger.json index b0030db7..46fc7eaf 100644 --- a/pkg/apiserver/docs/swagger.json +++ b/pkg/apiserver/docs/swagger.json @@ -466,6 +466,17 @@ } } }, + "github_com_adobe_cluster-registry_pkg_api_registry_v1.AvailabilityZone": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, "github_com_adobe_cluster-registry_pkg_api_registry_v1.Capacity": { "type": "object", "properties": { @@ -502,6 +513,13 @@ } ] }, + "availabilityZones": { + "description": "AvailabilityZones cluster availability zones", + "type": "array", + "items": { + "$ref": "#/definitions/github_com_adobe_cluster-registry_pkg_api_registry_v1.AvailabilityZone" + } + }, "businessUnit": { "description": "The BU that owns the cluster\n+kubebuilder:validation:Required", "type": "string" diff --git a/pkg/apiserver/docs/swagger.yaml b/pkg/apiserver/docs/swagger.yaml index 0cce893f..f752e5c3 100644 --- a/pkg/apiserver/docs/swagger.yaml +++ b/pkg/apiserver/docs/swagger.yaml @@ -29,6 +29,13 @@ definitions: +kubebuilder:validation:Required type: string type: object + github_com_adobe_cluster-registry_pkg_api_registry_v1.AvailabilityZone: + properties: + id: + type: string + name: + type: string + type: object github_com_adobe_cluster-registry_pkg_api_registry_v1.Capacity: properties: clusterCapacity: @@ -57,6 +64,11 @@ definitions: description: |- Information about K8s API endpoint and CA cert +kubebuilder:validation:Required + availabilityZones: + description: AvailabilityZones cluster availability zones + items: + $ref: '#/definitions/github_com_adobe_cluster-registry_pkg_api_registry_v1.AvailabilityZone' + type: array businessUnit: description: |- The BU that owns the cluster diff --git a/pkg/database/database_test.go b/pkg/database/database_test.go index 7bdf2615..7d6ebc89 100644 --- a/pkg/database/database_test.go +++ b/pkg/database/database_test.go @@ -626,8 +626,22 @@ var _ = Describe("Database Suite", func() { Phase: "Running", Type: "Dedicated", Capabilities: []string{"gpu-compute"}, - LastUpdated: "2020-03-20T07:55:46.132Z", - Tags: map[string]string{"onboarding": "on", "scaling": "on"}, + AvailabilityZones: []registryv1.AvailabilityZone{ + { + Name: "us-east-1a", + ID: "use1-az1", + }, + { + Name: "us-east-1b", + ID: "use1-az2", + }, + { + Name: "us-east-1c", + ID: "use1-az3", + }, + }, + LastUpdated: "2020-03-20T07:55:46.132Z", + Tags: map[string]string{"onboarding": "on", "scaling": "on"}, }, }, }, @@ -1106,6 +1120,20 @@ var _ = Describe("Database Suite", func() { Capabilities: []string{"gpu-compute"}, LastUpdated: "2020-03-20T07:55:46.132Z", Tags: map[string]string{"onboarding": "on", "scaling": "on"}, + AvailabilityZones: []registryv1.AvailabilityZone{ + { + Name: "us-east-1a", + ID: "use1-az1", + }, + { + Name: "us-east-1b", + ID: "use1-az2", + }, + { + Name: "us-east-1c", + ID: "use1-az3", + }, + }, }, }, }, @@ -1427,6 +1455,20 @@ var _ = Describe("Database Suite", func() { Capabilities: []string{"gpu-compute"}, LastUpdated: "2020-03-20T07:55:46.132Z", Tags: map[string]string{"onboarding": "on", "scaling": "on"}, + AvailabilityZones: []registryv1.AvailabilityZone{ + { + Name: "us-east-1a", + ID: "use1-az1", + }, + { + Name: "us-east-1b", + ID: "use1-az2", + }, + { + Name: "us-east-1c", + ID: "use1-az3", + }, + }, }, }, }, diff --git a/pkg/database/testdata/clusters.yaml b/pkg/database/testdata/clusters.yaml index 7193130d..bc29eb96 100644 --- a/pkg/database/testdata/clusters.yaml +++ b/pkg/database/testdata/clusters.yaml @@ -228,3 +228,10 @@ tags: onboarding: "on" scaling: "on" + availabilityZones: + - name: us-east-1a + id: use1-az1 + - name: us-east-1b + id: use1-az2 + - name: us-east-1c + id: use1-az3