Skip to content

Commit 16b3645

Browse files
authored
feat: add more status fields to the nodenetworkconfig: status, allocated IPs, subnets (#889)
Signed-off-by: Evan Baker <[email protected]>
1 parent de466f5 commit 16b3645

File tree

5 files changed

+114
-1
lines changed

5 files changed

+114
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,4 +505,4 @@ $(GO_JUNIT_REPORT): $(TOOLS_DIR)/go.mod
505505

506506
go-junit-report: $(GO_JUNIT_REPORT) ## Build go-junit-report
507507

508-
tools: gocov gocov-xml go-junit-report ## Build bins for built tools
508+
tools: gocov gocov-xml go-junit-report ## Build bins for build tools

nodenetworkconfig/api/v1alpha/nodenetworkconfig.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ import (
2828
// +kubebuilder:resource:scope=Namespaced
2929
// +kubebuilder:resource:shortName=nnc
3030
// +kubebuilder:subresource:status
31+
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.status`
32+
// +kubebuilder:printcolumn:name="Requested IPs",type=string,JSONPath=`.spec.requestedIPCount`
33+
// +kubebuilder:printcolumn:name="Assigned IPs",type=string,JSONPath=`.status.assignedIPCount`
34+
// +kubebuilder:printcolumn:name="Subnet",type=string,JSONPath=`.status.networkContainers[*].subnetName`
35+
// +kubebuilder:printcolumn:name="Subnet CIDR",type=string,JSONPath=`.status.networkContainers[*].subnetAddressSpace`
36+
// +kubebuilder:printcolumn:name="NC ID",type=string,JSONPath=`.status.networkContainers[*].id`
37+
// +kubebuilder:printcolumn:name="NC Version",type=string,JSONPath=`.status.networkContainers[*].version`
3138
type NodeNetworkConfig struct {
3239
metav1.TypeMeta `json:",inline"`
3340
metav1.ObjectMeta `json:"metadata,omitempty"`
@@ -53,7 +60,9 @@ type NodeNetworkConfigSpec struct {
5360

5461
// NodeNetworkConfigStatus defines the observed state of NetworkConfig
5562
type NodeNetworkConfigStatus struct {
63+
AssignedIPCount int `json:"assignedIPCount,omitempty"`
5664
Scaler Scaler `json:"scaler,omitempty"`
65+
Status Status `json:"status,omitempty"`
5766
NetworkContainers []NetworkContainer `json:"networkContainers,omitempty"`
5867
}
5968

@@ -65,6 +74,16 @@ type Scaler struct {
6574
MaxIPCount int64 `json:"maxIPCount,omitempty"`
6675
}
6776

77+
// Status indicates the NNC reconcile status
78+
// +kubebuilder:validation:Enum=Updating;Update;Error
79+
type Status string
80+
81+
const (
82+
Updating Status = "Updating"
83+
Updated Status = "Updated"
84+
Error Status = "Error"
85+
)
86+
6887
// NetworkContainer defines the structure of a Network Container as found in NetworkConfigStatus
6988
type NetworkContainer struct {
7089
ID string `json:"id,omitempty"`

nodenetworkconfig/manifests/acn.azure.com_nodenetworkconfigs.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@ metadata:
88
creationTimestamp: null
99
name: nodenetworkconfigs.acn.azure.com
1010
spec:
11+
additionalPrinterColumns:
12+
- JSONPath: .status.status
13+
name: Status
14+
type: string
15+
- JSONPath: .spec.requestedIPCount
16+
name: Requested IPs
17+
type: string
18+
- JSONPath: .status.assignedIPCount
19+
name: Assigned IPs
20+
type: string
21+
- JSONPath: .status.networkContainers[*].subnetName
22+
name: Subnet
23+
type: string
24+
- JSONPath: .status.networkContainers[*].subnetAddressSpace
25+
name: Subnet CIDR
26+
type: string
27+
- JSONPath: .status.networkContainers[*].id
28+
name: NC ID
29+
type: string
30+
- JSONPath: .status.networkContainers[*].version
31+
name: NC Version
32+
type: string
1133
group: acn.azure.com
1234
names:
1335
kind: NodeNetworkConfig
@@ -49,6 +71,8 @@ spec:
4971
status:
5072
description: NodeNetworkConfigStatus defines the observed state of NetworkConfig
5173
properties:
74+
assignedIPCount:
75+
type: integer
5276
networkContainers:
5377
items:
5478
description: NetworkContainer defines the structure of a Network Container
@@ -96,6 +120,13 @@ spec:
96120
format: int64
97121
type: integer
98122
type: object
123+
status:
124+
description: Status indicates the NNC reconcile status
125+
enum:
126+
- Updating
127+
- Update
128+
- Error
129+
type: string
99130
type: object
100131
type: object
101132
version: v1alpha
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Licensed under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License.
4+
You may obtain a copy of the License at
5+
http://www.apache.org/licenses/LICENSE-2.0
6+
Unless required by applicable law or agreed to in writing, software
7+
distributed under the License is distributed on an "AS IS" BASIS,
8+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
See the License for the specific language governing permissions and
10+
limitations under the License.
11+
*/
12+
13+
package manifests
14+
15+
import (
16+
_ "embed"
17+
18+
v1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
19+
"sigs.k8s.io/yaml"
20+
)
21+
22+
// NodeNetworkConfigsYAML embeds the CRD YAML for downstream consumers.
23+
//go:embed acn.azure.com_nodenetworkconfigs.yaml
24+
var NodeNetworkConfigsYAML []byte
25+
26+
// GetNodeNetworkConfigsDefinition parses the raw []byte NodeNetworkConfigs in
27+
// to a CustomResourceDefinition and returns it or an unmarshalling error.
28+
func GetNodeNetworkConfigs() (*v1beta1.CustomResourceDefinition, error) {
29+
nodeNetworkConfigs := &v1beta1.CustomResourceDefinition{}
30+
return nodeNetworkConfigs, yaml.Unmarshal(NodeNetworkConfigsYAML, &nodeNetworkConfigs)
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Licensed under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License.
4+
You may obtain a copy of the License at
5+
http://www.apache.org/licenses/LICENSE-2.0
6+
Unless required by applicable law or agreed to in writing, software
7+
distributed under the License is distributed on an "AS IS" BASIS,
8+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
See the License for the specific language governing permissions and
10+
limitations under the License.
11+
*/
12+
13+
package manifests
14+
15+
import (
16+
"os"
17+
"reflect"
18+
"testing"
19+
)
20+
21+
const filename = "acn.azure.com_nodenetworkconfigs.yaml"
22+
23+
func TestEmbed(t *testing.T) {
24+
b, err := os.ReadFile(filename)
25+
if err != nil {
26+
t.Error(err)
27+
}
28+
29+
if !reflect.DeepEqual(NodeNetworkConfigsYAML, b) {
30+
t.Errorf("embedded file did not match file on disk")
31+
}
32+
}

0 commit comments

Comments
 (0)