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

Commit f4bb3d7

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

File tree

6 files changed

+447
-210
lines changed

6 files changed

+447
-210
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{

0 commit comments

Comments
 (0)