From 8ea93d83e9fbe24e0fdd8f91fa6342065a1c09d9 Mon Sep 17 00:00:00 2001 From: Evan Baker Date: Wed, 26 May 2021 17:32:28 -0500 Subject: [PATCH] feat: add more status fields to the nodenetworkconfig: status, allocated IPs, subnets Signed-off-by: Evan Baker --- Makefile | 2 +- .../api/v1alpha/nodenetworkconfig.go | 19 +++++++++++ .../acn.azure.com_nodenetworkconfigs.yaml | 31 ++++++++++++++++++ nodenetworkconfig/manifests/embed.go | 31 ++++++++++++++++++ nodenetworkconfig/manifests/embed_test.go | 32 +++++++++++++++++++ 5 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 nodenetworkconfig/manifests/embed.go create mode 100644 nodenetworkconfig/manifests/embed_test.go diff --git a/Makefile b/Makefile index 6a96023f24..12ae78964e 100644 --- a/Makefile +++ b/Makefile @@ -503,4 +503,4 @@ $(GO_JUNIT_REPORT): $(TOOLS_DIR)/go.mod go-junit-report: $(GO_JUNIT_REPORT) ## Build go-junit-report -tools: gocov gocov-xml go-junit-report ## Build bins for built tools +tools: gocov gocov-xml go-junit-report ## Build bins for build tools diff --git a/nodenetworkconfig/api/v1alpha/nodenetworkconfig.go b/nodenetworkconfig/api/v1alpha/nodenetworkconfig.go index 1035db6d3d..a1df4a8cd4 100644 --- a/nodenetworkconfig/api/v1alpha/nodenetworkconfig.go +++ b/nodenetworkconfig/api/v1alpha/nodenetworkconfig.go @@ -28,6 +28,13 @@ import ( // +kubebuilder:resource:scope=Namespaced // +kubebuilder:resource:shortName=nnc // +kubebuilder:subresource:status +// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.status` +// +kubebuilder:printcolumn:name="Requested IPs",type=string,JSONPath=`.spec.requestedIPCount` +// +kubebuilder:printcolumn:name="Assigned IPs",type=string,JSONPath=`.status.assignedIPCount` +// +kubebuilder:printcolumn:name="Subnet",type=string,JSONPath=`.status.networkContainers[*].subnetName` +// +kubebuilder:printcolumn:name="Subnet CIDR",type=string,JSONPath=`.status.networkContainers[*].subnetAddressSpace` +// +kubebuilder:printcolumn:name="NC ID",type=string,JSONPath=`.status.networkContainers[*].id` +// +kubebuilder:printcolumn:name="NC Version",type=string,JSONPath=`.status.networkContainers[*].version` type NodeNetworkConfig struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` @@ -53,7 +60,9 @@ type NodeNetworkConfigSpec struct { // NodeNetworkConfigStatus defines the observed state of NetworkConfig type NodeNetworkConfigStatus struct { + AssignedIPCount int `json:"assignedIPCount,omitempty"` Scaler Scaler `json:"scaler,omitempty"` + Status Status `json:"status,omitempty"` NetworkContainers []NetworkContainer `json:"networkContainers,omitempty"` } @@ -65,6 +74,16 @@ type Scaler struct { MaxIPCount int64 `json:"maxIPCount,omitempty"` } +// Status indicates the NNC reconcile status +// +kubebuilder:validation:Enum=Updating;Update;Error +type Status string + +const ( + Updating Status = "Updating" + Updated Status = "Updated" + Error Status = "Error" +) + // NetworkContainer defines the structure of a Network Container as found in NetworkConfigStatus type NetworkContainer struct { ID string `json:"id,omitempty"` diff --git a/nodenetworkconfig/manifests/acn.azure.com_nodenetworkconfigs.yaml b/nodenetworkconfig/manifests/acn.azure.com_nodenetworkconfigs.yaml index 53cf6ecbae..fced62589c 100644 --- a/nodenetworkconfig/manifests/acn.azure.com_nodenetworkconfigs.yaml +++ b/nodenetworkconfig/manifests/acn.azure.com_nodenetworkconfigs.yaml @@ -8,6 +8,28 @@ metadata: creationTimestamp: null name: nodenetworkconfigs.acn.azure.com spec: + additionalPrinterColumns: + - JSONPath: .status.status + name: Status + type: string + - JSONPath: .spec.requestedIPCount + name: Requested IPs + type: string + - JSONPath: .status.assignedIPCount + name: Assigned IPs + type: string + - JSONPath: .status.networkContainers[*].subnetName + name: Subnet + type: string + - JSONPath: .status.networkContainers[*].subnetAddressSpace + name: Subnet CIDR + type: string + - JSONPath: .status.networkContainers[*].id + name: NC ID + type: string + - JSONPath: .status.networkContainers[*].version + name: NC Version + type: string group: acn.azure.com names: kind: NodeNetworkConfig @@ -49,6 +71,8 @@ spec: status: description: NodeNetworkConfigStatus defines the observed state of NetworkConfig properties: + assignedIPCount: + type: integer networkContainers: items: description: NetworkContainer defines the structure of a Network Container @@ -96,6 +120,13 @@ spec: format: int64 type: integer type: object + status: + description: Status indicates the NNC reconcile status + enum: + - Updating + - Update + - Error + type: string type: object type: object version: v1alpha diff --git a/nodenetworkconfig/manifests/embed.go b/nodenetworkconfig/manifests/embed.go new file mode 100644 index 0000000000..f6cbb67ca6 --- /dev/null +++ b/nodenetworkconfig/manifests/embed.go @@ -0,0 +1,31 @@ +/* +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package manifests + +import ( + _ "embed" + + v1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + "sigs.k8s.io/yaml" +) + +// NodeNetworkConfigsYAML embeds the CRD YAML for downstream consumers. +//go:embed acn.azure.com_nodenetworkconfigs.yaml +var NodeNetworkConfigsYAML []byte + +// GetNodeNetworkConfigsDefinition parses the raw []byte NodeNetworkConfigs in +// to a CustomResourceDefinition and returns it or an unmarshalling error. +func GetNodeNetworkConfigs() (*v1beta1.CustomResourceDefinition, error) { + nodeNetworkConfigs := &v1beta1.CustomResourceDefinition{} + return nodeNetworkConfigs, yaml.Unmarshal(NodeNetworkConfigsYAML, &nodeNetworkConfigs) +} diff --git a/nodenetworkconfig/manifests/embed_test.go b/nodenetworkconfig/manifests/embed_test.go new file mode 100644 index 0000000000..6dba265eb6 --- /dev/null +++ b/nodenetworkconfig/manifests/embed_test.go @@ -0,0 +1,32 @@ +/* +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package manifests + +import ( + "os" + "reflect" + "testing" +) + +const filename = "acn.azure.com_nodenetworkconfigs.yaml" + +func TestEmbed(t *testing.T) { + b, err := os.ReadFile(filename) + if err != nil { + t.Error(err) + } + + if !reflect.DeepEqual(NodeNetworkConfigsYAML, b) { + t.Errorf("embedded file did not match file on disk") + } +}