Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 020ebdc

Browse files
committed
refactor: reuse existing CAPX types
1 parent 14f7bb4 commit 020ebdc

File tree

6 files changed

+445
-208
lines changed

6 files changed

+445
-208
lines changed

api/v1alpha1/common_types.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
package v1alpha1
55

6+
import clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
7+
68
// ObjectMeta is metadata that all persisted resources must have, which includes all objects
79
// users must create. This is a copy of customizable fields from metav1.ObjectMeta.
810
//
@@ -23,3 +25,24 @@ type ObjectMeta struct {
2325
// +optional
2426
Annotations map[string]string `json:"annotations,omitempty"`
2527
}
28+
29+
type ControlPlaneEndpointSpec clusterv1.APIEndpoint
30+
31+
func (ControlPlaneEndpointSpec) VariableSchema() clusterv1.VariableSchema {
32+
return clusterv1.VariableSchema{
33+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
34+
Description: "Nutanix control-plane endpoint configuration",
35+
Type: "object",
36+
Properties: map[string]clusterv1.JSONSchemaProps{
37+
"host": {
38+
Description: "host ip/fqdn for control plane API Server",
39+
Type: "string",
40+
},
41+
"port": {
42+
Description: "port for control plane API Server",
43+
Type: "integer",
44+
},
45+
},
46+
},
47+
}
48+
}

api/v1alpha1/nutanix_clusterconfig_types.go

Lines changed: 62 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@
44
package v1alpha1
55

66
import (
7+
corev1 "k8s.io/api/core/v1"
78
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
89
)
910

11+
// NutanixSpec defines the desired state of NutanixCluster.
1012
type NutanixSpec struct {
11-
PrismCentralEndpoint *NutanixPrismCentralEndpointSpec `json:"prismCentralEndpoint,omitempty"`
12-
ControlPlaneEndpoint *NutanixControlPlaneEndpointSpec `json:"controlPlaneEndpoint,omitempty"`
13-
FailureDomains []NutanixFailureDomain `json:"failureDomains,omitempty"`
13+
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
14+
// host can be either DNS name or ip address
15+
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
16+
17+
// Nutanix Prism Central endpoint configuration.
18+
PrismCentralEndpoint NutanixPrismCentralEndpointSpec `json:"prismCentralEndpoint"`
19+
20+
// Configures failure domains information for the Nutanix platform.
21+
// When set, the failure domains defined here may be used to spread Machines across
22+
// prism element clusters to improve fault tolerance of the cluster.
23+
FailureDomains []NutanixFailureDomain `json:"failureDomains"`
1424
}
1525

1626
func (NutanixSpec) VariableSchema() clusterv1.VariableSchema {
@@ -19,20 +29,33 @@ func (NutanixSpec) VariableSchema() clusterv1.VariableSchema {
1929
Description: "Nutanix cluster configuration",
2030
Type: "object",
2131
Properties: map[string]clusterv1.JSONSchemaProps{
32+
"controlPlaneEndpoint": ControlPlaneEndpointSpec{}.VariableSchema().OpenAPIV3Schema,
2233
"prismCentralEndpoint": NutanixPrismCentralEndpointSpec{}.VariableSchema().OpenAPIV3Schema,
23-
"controlPlaneEndpoint": NutanixControlPlaneEndpointSpec{}.VariableSchema().OpenAPIV3Schema,
2434
"failureDomains": NutanixFailureDomains{}.VariableSchema().OpenAPIV3Schema,
2535
},
2636
},
2737
}
2838
}
2939

3040
type NutanixPrismCentralEndpointSpec struct {
31-
Host string `json:"host"`
32-
Port int32 `json:"port"`
33-
Insecure bool `json:"insecure"`
34-
AdditionalTrustBundle string `json:"additionalTrustBundle,omitempty"`
35-
CredentialSecret string `json:"credentialSecret"`
41+
// address is the endpoint address (DNS name or IP address) of the Nutanix Prism Central
42+
Address string `json:"address"`
43+
44+
// port is the port number to access the Nutanix Prism Central
45+
Port int32 `json:"port"`
46+
47+
// use insecure connection to Prism Central endpoint
48+
// +optional
49+
Insecure bool `json:"insecure"`
50+
51+
// A reference to the ConfigMap containing a PEM encoded x509 cert for the RootCA that was used to create
52+
// the certificate for a Prism Central that uses certificates that were issued by a non-publicly trusted RootCA.
53+
// The trust bundle is added to the cert pool used to authenticate the TLS connection to the Prism Central.
54+
// +optional
55+
AdditionalTrustBundle *corev1.LocalObjectReference `json:"additionalTrustBundle,omitempty"`
56+
57+
// A reference to the Secret for credential information for the target Prism Central instance
58+
Credentials corev1.LocalObjectReference `json:"credentials"`
3659
}
3760

3861
func (NutanixPrismCentralEndpointSpec) VariableSchema() clusterv1.VariableSchema {
@@ -41,51 +64,47 @@ func (NutanixPrismCentralEndpointSpec) VariableSchema() clusterv1.VariableSchema
4164
Description: "Nutanix Prism Central endpoint configuration",
4265
Type: "object",
4366
Properties: map[string]clusterv1.JSONSchemaProps{
44-
"host": {
45-
Description: "host ip/fqdn for Prism Central Server",
67+
"address": {
68+
Description: "the endpoint address (DNS name or IP address) of the Nutanix Prism Central",
4669
Type: "string",
4770
},
4871
"port": {
49-
Description: "port for Prism Central Server",
72+
Description: "The port number to access the Nutanix Prism Central",
5073
Type: "integer",
5174
},
5275
"insecure": {
53-
Description: "Prism Central Certificate checking",
76+
Description: "Use insecure connection to Prism Central endpoint",
5477
Type: "boolean",
5578
},
5679
"additionalTrustBundle": {
57-
Description: "Name of configMap with certificate trust bundle used for Prism Central connection",
58-
Type: "string",
80+
Description: "A reference to the ConfigMap containing a PEM encoded x509 cert for the RootCA " +
81+
"that was used to create the certificate for a Prism Central that uses certificates " +
82+
"that were issued by a non-publicly trusted RootCA." +
83+
"The trust bundle is added to the cert pool used to authenticate the TLS connection " +
84+
"to the Prism Central.",
85+
Type: "object",
86+
Properties: map[string]clusterv1.JSONSchemaProps{
87+
"name": {
88+
Description: "The name of the ConfigMap",
89+
Type: "string",
90+
},
91+
},
92+
Required: []string{"name"},
5993
},
60-
"credentialSecret": {
61-
Description: "Name of a Credential information secret for the target Prism instance",
62-
Type: "string",
63-
},
64-
},
65-
},
66-
}
67-
}
68-
69-
type NutanixControlPlaneEndpointSpec struct {
70-
Host string `json:"host,omitempty"`
71-
Port int32 `json:"port,omitempty"`
72-
}
73-
74-
func (NutanixControlPlaneEndpointSpec) VariableSchema() clusterv1.VariableSchema {
75-
return clusterv1.VariableSchema{
76-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
77-
Description: "Nutanix control-plane endpoint configuration",
78-
Type: "object",
79-
Properties: map[string]clusterv1.JSONSchemaProps{
80-
"host": {
81-
Description: "host ip/fqdn for control plane API Server",
82-
Type: "string",
83-
},
84-
"port": {
85-
Description: "port for control plane API Server",
86-
Type: "integer",
94+
"credentials": {
95+
Description: "A reference to the Secret for credential information" +
96+
"for the target Prism Central instance",
97+
Type: "object",
98+
Properties: map[string]clusterv1.JSONSchemaProps{
99+
"name": {
100+
Description: "The name of the Secret",
101+
Type: "string",
102+
},
103+
},
104+
Required: []string{"name"},
87105
},
88106
},
107+
Required: []string{"address", "port", "credentials"},
89108
},
90109
}
91110
}
@@ -104,27 +123,7 @@ func (NutanixFailureDomains) VariableSchema() clusterv1.VariableSchema {
104123
}
105124
}
106125

107-
type NutanixFailureDomain struct {
108-
// name defines the unique name of a failure domain.
109-
// Name is required and must be at most 64 characters in length.
110-
// It must consist of only lower case alphanumeric characters and hyphens (-).
111-
// It must start and end with an alphanumeric character.
112-
// This value is arbitrary and is used to identify the failure domain within the platform.
113-
Name string `json:"name"`
114-
115-
// cluster is to identify the cluster (the Prism Element under management of the Prism Central),
116-
// in which the Machine's VM will be created. The cluster identifier (uuid or name) can be obtained
117-
// from the Prism Central console or using the prism_central API.
118-
Cluster NutanixResourceIdentifier `json:"cluster"`
119-
120-
// subnets holds a list of identifiers (one or more) of the cluster's network subnets
121-
// for the Machine's VM to connect to. The subnet identifiers (uuid or name) can be
122-
// obtained from the Prism Central console or using the prism_central API.
123-
Subnets []NutanixResourceIdentifier `json:"subnets"`
124-
125-
// indicates if a failure domain is suited for control plane nodes
126-
ControlPlane bool `json:"controlPlane,omitempty"`
127-
}
126+
type NutanixFailureDomain capxv1.NutanixFailureDomain
128127

129128
func (NutanixFailureDomain) VariableSchema() clusterv1.VariableSchema {
130129
return clusterv1.VariableSchema{

api/v1alpha1/nutanix_node_types.go

Lines changed: 33 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,11 @@ package v1alpha1
55

66
import (
77
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
8-
)
9-
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"
168

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"
9+
capxv1 "github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1"
2210
)
2311

24-
// NutanixIdentifierType is an enumeration of different resource identifier types.
25-
type NutanixIdentifierType string
26-
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-
36-
// NutanixBootType is an enumeration of different boot types.
37-
type NutanixBootType string
38-
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-
48-
// NutanixGPUIdentifierType is an enumeration of different resource identifier types for GPU entities.
49-
type NutanixGPUIdentifierType string
50-
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 {
12+
type NutanixNodeSpec struct {
6113
// vcpusPerSocket is the number of vCPUs per socket of the VM
6214
VCPUsPerSocket int32 `json:"vcpusPerSocket"`
6315

@@ -100,10 +52,10 @@ type NutanixMachineDetails struct {
10052
GPUs []NutanixGPU `json:"gpus,omitempty"`
10153
}
10254

103-
func (NutanixMachineDetails) VariableSchema() clusterv1.VariableSchema {
55+
func (NutanixNodeSpec) VariableSchema() clusterv1.VariableSchema {
10456
return clusterv1.VariableSchema{
10557
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
106-
Description: "Nutanix Machine configuration",
58+
Description: "Nutanix Node configuration",
10759
Type: "object",
10860
Properties: map[string]clusterv1.JSONSchemaProps{
10961
"vcpusPerSocket": {
@@ -134,35 +86,44 @@ func (NutanixMachineDetails) VariableSchema() clusterv1.VariableSchema {
13486
}
13587
}
13688

137-
type NutanixNodeSpec struct {
138-
MachineDetails *NutanixMachineDetails `json:"machineDetails"`
139-
}
89+
// NutanixIdentifierType is an enumeration of different resource identifier types.
90+
type NutanixIdentifierType capxv1.NutanixIdentifierType
14091

141-
func (NutanixNodeSpec) VariableSchema() clusterv1.VariableSchema {
92+
func (NutanixIdentifierType) VariableSchema() clusterv1.VariableSchema {
14293
return clusterv1.VariableSchema{
14394
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
144-
Description: "Nutanix Node configuration",
145-
Type: "object",
146-
Properties: map[string]clusterv1.JSONSchemaProps{
147-
"machineDetails": NutanixMachineDetails{}.VariableSchema().OpenAPIV3Schema,
148-
},
95+
Type: "string",
96+
Description: "NutanixIdentifierType is an enumeration of different resource identifier types",
14997
},
15098
}
15199
}
152100

153-
type NutanixResourceIdentifier struct {
154-
// Type is the identifier type to use for this resource.
155-
Type NutanixIdentifierType `json:"type"`
101+
// NutanixBootType is an enumeration of different boot types.
102+
type NutanixBootType capxv1.NutanixBootType
156103

157-
// uuid is the UUID of the resource in the PC.
158-
// +optional
159-
UUID *string `json:"uuid,omitempty"`
104+
func (NutanixBootType) VariableSchema() clusterv1.VariableSchema {
105+
return clusterv1.VariableSchema{
106+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
107+
Type: "string",
108+
Description: "NutanixBootType is an enumeration of different boot types.",
109+
},
110+
}
111+
}
112+
113+
// NutanixGPUIdentifierType is an enumeration of different resource identifier types for GPU entities.
114+
type NutanixGPUIdentifierType capxv1.NutanixGPUIdentifierType
160115

161-
// name is the resource name in the PC.
162-
// +optional
163-
Name *string `json:"name,omitempty"`
116+
func (NutanixGPUIdentifierType) VariableSchema() clusterv1.VariableSchema {
117+
return clusterv1.VariableSchema{
118+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
119+
Type: "string",
120+
Description: "NutanixGPUIdentifierType is an enumeration of different resource identifier types for GPU entities.",
121+
},
122+
}
164123
}
165124

125+
type NutanixResourceIdentifier capxv1.NutanixResourceIdentifier
126+
166127
func (NutanixResourceIdentifier) VariableSchema() clusterv1.VariableSchema {
167128
return clusterv1.VariableSchema{
168129
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
@@ -183,15 +144,7 @@ func (NutanixResourceIdentifier) VariableSchema() clusterv1.VariableSchema {
183144
}
184145
}
185146

186-
type NutanixCategoryIdentifier struct {
187-
// key is the Key of category in PC.
188-
// +optional
189-
Key string `json:"key,omitempty"`
190-
191-
// value is the category value linked to the category key in PC.
192-
// +optional
193-
Value string `json:"value,omitempty"`
194-
}
147+
type NutanixCategoryIdentifier capxv1.NutanixCategoryIdentifier
195148

196149
func (NutanixCategoryIdentifier) VariableSchema() clusterv1.VariableSchema {
197150
return clusterv1.VariableSchema{
@@ -226,18 +179,7 @@ func (NutanixCategoryIdentifiers) VariableSchema() clusterv1.VariableSchema {
226179
}
227180
}
228181

229-
type NutanixGPU struct {
230-
// Type is the identifier type to use for this resource.
231-
Type NutanixGPUIdentifierType `json:"type"`
232-
233-
// deviceID is the id of the GPU entity.
234-
// +optional
235-
DeviceID *int64 `json:"deviceID,omitempty"`
236-
237-
// name is the GPU name.
238-
// +optional
239-
Name *string `json:"name,omitempty"`
240-
}
182+
type NutanixGPU capxv1.NutanixGPU
241183

242184
func (NutanixGPU) VariableSchema() clusterv1.VariableSchema {
243185
return clusterv1.VariableSchema{

0 commit comments

Comments
 (0)