Skip to content

Commit b59fa70

Browse files
committed
added machine details mutation
1 parent 4381496 commit b59fa70

File tree

10 files changed

+500
-74
lines changed

10 files changed

+500
-74
lines changed

api/v1alpha1/nutanix_node_types.go

Lines changed: 93 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,60 @@
44
package v1alpha1
55

66
import (
7-
capxv1 "github.com/d2iq-labs/capi-runtime-extensions/api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1"
8-
"github.com/d2iq-labs/capi-runtime-extensions/api/variables"
97
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
108
)
119

10+
const (
11+
// NutanixIdentifierUUID is a resource identifier identifying the object by UUID.
12+
NutanixIdentifierUUID NutanixIdentifierType = "uuid"
13+
14+
// NutanixIdentifierName is a resource identifier identifying the object by Name.
15+
NutanixIdentifierName NutanixIdentifierType = "name"
16+
17+
// NutanixBootTypeLegacy is a resource identifier identifying the legacy boot type for virtual machines.
18+
NutanixBootTypeLegacy NutanixBootType = "legacy"
19+
20+
// NutanixBootTypeUEFI is a resource identifier identifying the UEFI boot type for virtual machines.
21+
NutanixBootTypeUEFI NutanixBootType = "uefi"
22+
)
23+
1224
// NutanixIdentifierType is an enumeration of different resource identifier types.
1325
type NutanixIdentifierType string
1426

27+
func (NutanixIdentifierType) VariableSchema() clusterv1.VariableSchema {
28+
return clusterv1.VariableSchema{
29+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
30+
Type: "string",
31+
Description: "NutanixIdentifierType is an enumeration of different resource identifier types",
32+
},
33+
}
34+
}
35+
1536
// NutanixBootType is an enumeration of different boot types.
1637
type NutanixBootType string
1738

39+
func (NutanixBootType) VariableSchema() clusterv1.VariableSchema {
40+
return clusterv1.VariableSchema{
41+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
42+
Type: "string",
43+
Description: "NutanixBootType is an enumeration of different boot types.",
44+
},
45+
}
46+
}
47+
1848
// NutanixGPUIdentifierType is an enumeration of different resource identifier types for GPU entities.
1949
type NutanixGPUIdentifierType string
2050

21-
type NutanixNodeSpec struct {
51+
func (NutanixGPUIdentifierType) VariableSchema() clusterv1.VariableSchema {
52+
return clusterv1.VariableSchema{
53+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
54+
Type: "string",
55+
Description: "NutanixGPUIdentifierType is an enumeration of different resource identifier types for GPU entities.",
56+
},
57+
}
58+
}
59+
60+
type NutanixMachineDetails struct {
2261
// vcpusPerSocket is the number of vCPUs per socket of the VM
2362
VCPUsPerSocket int32 `json:"vcpusPerSocket"`
2463

@@ -48,10 +87,10 @@ type NutanixNodeSpec struct {
4887
AdditionalCategories []NutanixCategoryIdentifier `json:"additionalCategories,omitempty"`
4988

5089
// Add the machine resources to a Prism Central project
51-
Project *NutanixResourceIdentifier `json:"project,omitempty"`
90+
Project NutanixResourceIdentifier `json:"project,omitempty"`
5291

5392
// Defines the boot type of the virtual machine. Only supports UEFI and Legacy
54-
BootType string `json:"bootType,omitempty"` //TODO use NutanixBootType enum somehow
93+
BootType NutanixBootType `json:"bootType,omitempty"`
5594

5695
// systemDiskSize is size (in Quantity format) of the system disk of the VM
5796
// The minimum systemDiskSize is 20Gi bytes
@@ -61,10 +100,10 @@ type NutanixNodeSpec struct {
61100
GPUs []NutanixGPU `json:"gpus,omitempty"`
62101
}
63102

64-
func (NutanixNodeSpec) VariableSchema() clusterv1.VariableSchema {
103+
func (NutanixMachineDetails) VariableSchema() clusterv1.VariableSchema {
65104
return clusterv1.VariableSchema{
66105
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
67-
Description: "Nutanix Node configuration",
106+
Description: "Nutanix Machine configuration",
68107
Type: "object",
69108
Properties: map[string]clusterv1.JSONSchemaProps{
70109
"vcpusPerSocket": {
@@ -79,41 +118,33 @@ func (NutanixNodeSpec) VariableSchema() clusterv1.VariableSchema {
79118
Description: "memorySize is the memory size (in Quantity format) of the VM eg. 4Gi",
80119
Type: "string",
81120
},
82-
"image": NutanixResourceIdentifier{}.VariableSchema().OpenAPIV3Schema,
83-
"cluster": NutanixResourceIdentifier{}.VariableSchema().OpenAPIV3Schema,
84-
"subnet": NutanixResourceIdentifiers{}.VariableSchema().OpenAPIV3Schema,
85-
"bootType": {
86-
Description: "Defines the boot type of the virtual machine. Only supports UEFI and Legacy",
87-
Type: "string",
88-
},
121+
"image": NutanixResourceIdentifier{}.VariableSchema().OpenAPIV3Schema,
122+
"cluster": NutanixResourceIdentifier{}.VariableSchema().OpenAPIV3Schema,
123+
"subnet": NutanixResourceIdentifiers{}.VariableSchema().OpenAPIV3Schema,
124+
"bootType": NutanixBootType("legacy").VariableSchema().OpenAPIV3Schema,
89125
"systemDiskSize": {
90126
Description: "systemDiskSize is size (in Quantity format) of the system disk of the VM eg. 20Gi",
91127
Type: "string",
92128
},
93-
// "project": {},
129+
"project": NutanixResourceIdentifier{}.VariableSchema().OpenAPIV3Schema,
94130
// "additionalCategories": {},
95131
// "gpus": {},
96132
},
97133
},
98134
}
99135
}
100136

101-
func (NutanixBootType) VariableSchema() clusterv1.VariableSchema {
102-
supportedBootType := []capxv1.NutanixBootType{
103-
capxv1.NutanixBootTypeLegacy,
104-
capxv1.NutanixBootTypeUEFI,
105-
}
137+
type NutanixNodeSpec struct {
138+
MachineDetails *NutanixMachineDetails `json:"machineDetails"`
139+
}
106140

141+
func (NutanixNodeSpec) VariableSchema() clusterv1.VariableSchema {
107142
return clusterv1.VariableSchema{
108143
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
109-
Description: "Nutanix Boot type enum",
110-
Type: "string",
144+
Description: "Nutanix Node configuration",
145+
Type: "object",
111146
Properties: map[string]clusterv1.JSONSchemaProps{
112-
"bootType": {
113-
Description: "Defines the boot type of the virtual machine. Only supports UEFI and Legacy",
114-
Type: "string",
115-
Enum: variables.MustMarshalValuesToEnumJSON(supportedBootType...),
116-
},
147+
"machineDetails": NutanixMachineDetails{}.VariableSchema().OpenAPIV3Schema,
117148
},
118149
},
119150
}
@@ -127,7 +158,7 @@ type NutanixResourceIdentifier struct {
127158
// +optional
128159
UUID *string `json:"uuid,omitempty"`
129160

130-
// name is the resource name in the PC
161+
// name is the resource name in the PC.
131162
// +optional
132163
Name *string `json:"name,omitempty"`
133164
}
@@ -137,7 +168,17 @@ func (NutanixResourceIdentifier) VariableSchema() clusterv1.VariableSchema {
137168
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
138169
Description: "Nutanix Resource Identifier",
139170
Type: "object",
140-
Properties: map[string]clusterv1.JSONSchemaProps{},
171+
Properties: map[string]clusterv1.JSONSchemaProps{
172+
"type": NutanixIdentifierType("name").VariableSchema().OpenAPIV3Schema,
173+
"uuid": {
174+
Type: "string",
175+
Description: "uuid is the UUID of the resource in the PC.",
176+
},
177+
"name": {
178+
Type: "string",
179+
Description: "name is the resource name in the PC.",
180+
},
181+
},
141182
},
142183
}
143184
}
@@ -147,7 +188,7 @@ type NutanixCategoryIdentifier struct {
147188
// +optional
148189
Key string `json:"key,omitempty"`
149190

150-
// value is the category value linked to the category key in PC
191+
// value is the category value linked to the category key in PC.
151192
// +optional
152193
Value string `json:"value,omitempty"`
153194
}
@@ -157,7 +198,16 @@ func (NutanixCategoryIdentifier) VariableSchema() clusterv1.VariableSchema {
157198
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
158199
Description: "Nutanix Category Identifier",
159200
Type: "object",
160-
Properties: map[string]clusterv1.JSONSchemaProps{},
201+
Properties: map[string]clusterv1.JSONSchemaProps{
202+
"key": {
203+
Type: "string",
204+
Description: "key is the Key of category in PC.",
205+
},
206+
"value": {
207+
Type: "string",
208+
Description: "value is the category value linked to the category key in PC",
209+
},
210+
},
161211
},
162212
}
163213
}
@@ -170,7 +220,7 @@ type NutanixGPU struct {
170220
// +optional
171221
DeviceID *int64 `json:"deviceID,omitempty"`
172222

173-
// name is the GPU name
223+
// name is the GPU name.
174224
// +optional
175225
Name *string `json:"name,omitempty"`
176226
}
@@ -180,7 +230,17 @@ func (NutanixGPU) VariableSchema() clusterv1.VariableSchema {
180230
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
181231
Description: "Nutanix GPU type",
182232
Type: "object",
183-
Properties: map[string]clusterv1.JSONSchemaProps{},
233+
Properties: map[string]clusterv1.JSONSchemaProps{
234+
"type": NutanixGPUIdentifierType("name").VariableSchema().OpenAPIV3Schema,
235+
"deviceID": {
236+
Type: "int64",
237+
Description: "deviceID is the id of the GPU entity.",
238+
},
239+
"name": {
240+
Type: "string",
241+
Description: "name is the GPU name.",
242+
},
243+
},
184244
},
185245
}
186246
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 22 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/capi-quick-start/nutanix-final-example.yaml

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,40 @@ spec:
7070
isControlPlane: false
7171
controlPlane:
7272
nutanix:
73+
machineDetails:
74+
bootType: legacy
75+
cluster:
76+
name: PE1
77+
type: name
78+
image:
79+
name: image1
80+
type: name
81+
memorySize: 4Gi
82+
systemDiskSize: 40Gi
83+
vcpuSockets: 2
84+
vcpusPerSocket: 1
85+
subnet:
86+
- name: subnet1
87+
type: name
88+
project: prj1
89+
additionalCategories:
90+
- key1: value1
91+
- key2: value2
92+
gpus:
93+
- type: name
94+
name: gpu1
95+
- type: name
96+
name: gpu2
97+
addons:
98+
cni:
99+
provider: Cilium
100+
strategy: HelmAddon
101+
csi: {}
102+
nfd: {}
103+
- name: workerConfig
104+
value:
105+
nutanix:
106+
machineDetails:
73107
bootType: legacy
74108
cluster:
75109
name: PE1
@@ -93,38 +127,6 @@ spec:
93127
name: gpu1
94128
- type: name
95129
name: gpu2
96-
addons:
97-
cni:
98-
provider: Cilium
99-
strategy: HelmAddon
100-
csi: {}
101-
nfd: {}
102-
- name: workerConfig
103-
value:
104-
nutanix:
105-
bootType: legacy
106-
cluster:
107-
name: PE1
108-
type: name
109-
image:
110-
name: image1
111-
type: name
112-
memorySize: 4Gi
113-
systemDiskSize: 40Gi
114-
vcpuSockets: 2
115-
vcpusPerSocket: 1
116-
subnet:
117-
- name: subnet1
118-
type: name
119-
project: prj1
120-
additionalCategories:
121-
- key1: value1
122-
- key2: value2
123-
gpus:
124-
- type: name
125-
name: gpu1
126-
- type: name
127-
name: gpu2
128130
version: ${KUBERNETES_VERSION}
129131
workers:
130132
machineDeployments:

pkg/handlers/nutanix/mutation/controlplaneendpoint/inject.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (h *nutanixControlPlaneEndpoint) Mutate(
9191
log.WithValues(
9292
"patchedObjectKind", obj.GetObjectKind().GroupVersionKind().String(),
9393
"patchedObjectName", client.ObjectKeyFromObject(obj),
94-
).Info("setting controlPlaneEndpoint in NutanixClusterTemplate spec")
94+
).Info("setting controlPlaneEndpoint in NutanixCluster spec")
9595

9696
obj.Spec.Template.Spec.ControlPlaneEndpoint.Host = controlPlaneEndpointVar.Host
9797
obj.Spec.Template.Spec.ControlPlaneEndpoint.Port = controlPlaneEndpointVar.Port

0 commit comments

Comments
 (0)