Skip to content

Commit 98b10c5

Browse files
committed
refactor: Use separate types for provider cluster configs
This commit also switches to using controller-gen generated CRDs for the OpenAPI schema for the variable definitions. A lot of this commit is refactoring tests.
1 parent c2dbdce commit 98b10c5

File tree

62 files changed

+1976
-1340
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1976
-1340
lines changed

api/go.mod

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ go 1.21
77

88
toolchain go1.22.2
99

10+
replace github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common => ../common
11+
1012
require (
13+
github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common v0.7.0
1114
github.com/nutanix-cloud-native/prism-go-client v0.3.4
1215
github.com/onsi/gomega v1.32.0
1316
k8s.io/api v0.29.3
@@ -19,31 +22,57 @@ require (
1922
)
2023

2124
require (
25+
github.com/beorn7/perks v1.0.1 // indirect
2226
github.com/blang/semver/v4 v4.0.0 // indirect
27+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
28+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2329
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
30+
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
31+
github.com/fsnotify/fsnotify v1.7.0 // indirect
2432
github.com/go-logr/logr v1.4.1 // indirect
2533
github.com/go-openapi/jsonpointer v0.19.6 // indirect
2634
github.com/go-openapi/jsonreference v0.20.2 // indirect
2735
github.com/go-openapi/swag v0.22.3 // indirect
2836
github.com/gogo/protobuf v1.3.2 // indirect
37+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
2938
github.com/golang/protobuf v1.5.4 // indirect
3039
github.com/google/gnostic-models v0.6.8 // indirect
3140
github.com/google/go-cmp v0.6.0 // indirect
3241
github.com/google/gofuzz v1.2.0 // indirect
42+
github.com/google/uuid v1.3.1 // indirect
43+
github.com/imdario/mergo v0.3.13 // indirect
3344
github.com/josharian/intern v1.0.0 // indirect
3445
github.com/json-iterator/go v1.1.12 // indirect
3546
github.com/mailru/easyjson v0.7.7 // indirect
47+
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
3648
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
3749
github.com/modern-go/reflect2 v1.0.2 // indirect
50+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
3851
github.com/pkg/errors v0.9.1 // indirect
52+
github.com/prometheus/client_golang v1.18.0 // indirect
53+
github.com/prometheus/client_model v0.5.0 // indirect
54+
github.com/prometheus/common v0.45.0 // indirect
55+
github.com/prometheus/procfs v0.12.0 // indirect
56+
github.com/spf13/pflag v1.0.5 // indirect
57+
github.com/valyala/fastjson v1.6.4 // indirect
58+
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
3959
golang.org/x/net v0.24.0 // indirect
60+
golang.org/x/oauth2 v0.14.0 // indirect
61+
golang.org/x/sys v0.19.0 // indirect
62+
golang.org/x/term v0.19.0 // indirect
4063
golang.org/x/text v0.14.0 // indirect
64+
golang.org/x/time v0.3.0 // indirect
65+
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
66+
google.golang.org/appengine v1.6.7 // indirect
4167
google.golang.org/protobuf v1.33.0 // indirect
4268
gopkg.in/inf.v0 v0.9.1 // indirect
4369
gopkg.in/yaml.v2 v2.4.0 // indirect
4470
gopkg.in/yaml.v3 v3.0.1 // indirect
71+
k8s.io/client-go v0.29.3 // indirect
72+
k8s.io/component-base v0.29.3 // indirect
4573
k8s.io/klog/v2 v2.120.1 // indirect
4674
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
4775
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
4876
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
77+
sigs.k8s.io/yaml v1.4.0 // indirect
4978
)

api/go.sum

Lines changed: 62 additions & 6 deletions
Large diffs are not rendered by default.

api/v1alpha1/addon_types.go

Lines changed: 0 additions & 235 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ package v1alpha1
66
import (
77
corev1 "k8s.io/api/core/v1"
88
storagev1 "k8s.io/api/storage/v1"
9-
"k8s.io/utils/ptr"
10-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
11-
12-
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/variables"
139
)
1410

1511
const (
@@ -40,22 +36,6 @@ type Addons struct {
4036
CSIProviders *CSI `json:"csi,omitempty"`
4137
}
4238

43-
func (Addons) VariableSchema() clusterv1.VariableSchema {
44-
return clusterv1.VariableSchema{
45-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
46-
Description: "Cluster configuration",
47-
Type: "object",
48-
Properties: map[string]clusterv1.JSONSchemaProps{
49-
"cni": CNI{}.VariableSchema().OpenAPIV3Schema,
50-
"nfd": NFD{}.VariableSchema().OpenAPIV3Schema,
51-
"clusterAutoscaler": ClusterAutoscaler{}.VariableSchema().OpenAPIV3Schema,
52-
"csi": CSI{}.VariableSchema().OpenAPIV3Schema,
53-
"ccm": CCM{}.VariableSchema().OpenAPIV3Schema,
54-
},
55-
},
56-
}
57-
}
58-
5939
type AddonStrategy string
6040

6141
// CNI required for providing CNI configuration.
@@ -66,83 +46,18 @@ type CNI struct {
6646
Strategy AddonStrategy `json:"strategy,omitempty"`
6747
}
6848

69-
func (CNI) VariableSchema() clusterv1.VariableSchema {
70-
supportedCNIProviders := []string{CNIProviderCalico, CNIProviderCilium}
71-
72-
return clusterv1.VariableSchema{
73-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
74-
Type: "object",
75-
Properties: map[string]clusterv1.JSONSchemaProps{
76-
"provider": {
77-
Description: "CNI provider to deploy",
78-
Type: "string",
79-
Enum: variables.MustMarshalValuesToEnumJSON(supportedCNIProviders...),
80-
},
81-
"strategy": {
82-
Description: "Addon strategy used to deploy the CNI provider to the workload cluster",
83-
Type: "string",
84-
Enum: variables.MustMarshalValuesToEnumJSON(
85-
AddonStrategyClusterResourceSet,
86-
AddonStrategyHelmAddon,
87-
),
88-
},
89-
},
90-
Required: []string{"provider", "strategy"},
91-
},
92-
}
93-
}
94-
9549
// NFD tells us to enable or disable the node feature discovery addon.
9650
type NFD struct {
9751
// +optional
9852
Strategy AddonStrategy `json:"strategy,omitempty"`
9953
}
10054

101-
func (NFD) VariableSchema() clusterv1.VariableSchema {
102-
return clusterv1.VariableSchema{
103-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
104-
Type: "object",
105-
Properties: map[string]clusterv1.JSONSchemaProps{
106-
"strategy": {
107-
Description: "Addon strategy used to deploy Node Feature Discovery (NFD) to the workload cluster",
108-
Type: "string",
109-
Enum: variables.MustMarshalValuesToEnumJSON(
110-
AddonStrategyClusterResourceSet,
111-
AddonStrategyHelmAddon,
112-
),
113-
},
114-
},
115-
Required: []string{"strategy"},
116-
},
117-
}
118-
}
119-
12055
// ClusterAutoscaler tells us to enable or disable the cluster-autoscaler addon.
12156
type ClusterAutoscaler struct {
12257
// +optional
12358
Strategy AddonStrategy `json:"strategy,omitempty"`
12459
}
12560

126-
func (ClusterAutoscaler) VariableSchema() clusterv1.VariableSchema {
127-
return clusterv1.VariableSchema{
128-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
129-
Type: "object",
130-
Properties: map[string]clusterv1.JSONSchemaProps{
131-
"strategy": {
132-
Description: "Addon strategy used to deploy cluster-autoscaler to the management cluster," +
133-
"targeting the workload cluster.",
134-
Type: "string",
135-
Enum: variables.MustMarshalValuesToEnumJSON(
136-
AddonStrategyClusterResourceSet,
137-
AddonStrategyHelmAddon,
138-
),
139-
},
140-
},
141-
Required: []string{"strategy"},
142-
},
143-
}
144-
}
145-
14661
type DefaultStorage struct {
14762
ProviderName string `json:"providerName"`
14863
StorageClassConfigName string `json:"storageClassConfigName"`
@@ -183,159 +98,9 @@ type StorageClassConfig struct {
18398
AllowExpansion bool `json:"allowExpansion,omitempty"`
18499
}
185100

186-
func (StorageClassConfig) VariableSchema() clusterv1.VariableSchema {
187-
supportedReclaimPolicies := []string{
188-
string(VolumeReclaimRecycle),
189-
string(VolumeReclaimDelete),
190-
string(VolumeReclaimRetain),
191-
}
192-
supportedBindingModes := []string{
193-
string(VolumeBindingImmediate),
194-
string(VolumeBindingWaitForFirstConsumer),
195-
}
196-
return clusterv1.VariableSchema{
197-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
198-
Type: "object",
199-
Required: []string{"name"},
200-
Properties: map[string]clusterv1.JSONSchemaProps{
201-
"name": {
202-
Type: "string",
203-
Description: "Name of storage class config.",
204-
},
205-
"parameters": {
206-
Type: "object",
207-
Description: "Parameters passed into the storage class object.",
208-
AdditionalProperties: &clusterv1.JSONSchemaProps{
209-
Type: "string",
210-
},
211-
},
212-
"reclaimPolicy": {
213-
Type: "string",
214-
Enum: variables.MustMarshalValuesToEnumJSON(supportedReclaimPolicies...),
215-
Default: variables.MustMarshal(VolumeReclaimDelete),
216-
},
217-
"volumeBindingMode": {
218-
Type: "string",
219-
Enum: variables.MustMarshalValuesToEnumJSON(supportedBindingModes...),
220-
Default: variables.MustMarshal(VolumeBindingWaitForFirstConsumer),
221-
},
222-
"allowExpansion": {
223-
Type: "boolean",
224-
Default: variables.MustMarshal(false),
225-
Description: "If the storage class should allow volume expanding",
226-
},
227-
},
228-
},
229-
}
230-
}
231-
232-
func (CSIProvider) VariableSchema() clusterv1.VariableSchema {
233-
supportedCSIProviders := []string{CSIProviderAWSEBS, CSIProviderNutanix}
234-
return clusterv1.VariableSchema{
235-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
236-
Type: "object",
237-
Required: []string{"name", "strategy"},
238-
Properties: map[string]clusterv1.JSONSchemaProps{
239-
"name": {
240-
Description: "Name of the CSI Provider",
241-
Type: "string",
242-
Enum: variables.MustMarshalValuesToEnumJSON(
243-
supportedCSIProviders...),
244-
},
245-
"strategy": {
246-
Description: "Addon strategy used to deploy the CSI provider to the workload cluster",
247-
Type: "string",
248-
Enum: variables.MustMarshalValuesToEnumJSON(
249-
AddonStrategyClusterResourceSet,
250-
AddonStrategyHelmAddon,
251-
),
252-
},
253-
"credentials": {
254-
Type: "object",
255-
Description: "The reference to any secret used by the CSI Provider.",
256-
Properties: map[string]clusterv1.JSONSchemaProps{
257-
"name": {
258-
Type: "string",
259-
},
260-
},
261-
},
262-
"storageClassConfig": {
263-
Type: "array",
264-
Items: ptr.To(StorageClassConfig{}.VariableSchema().OpenAPIV3Schema),
265-
},
266-
},
267-
},
268-
}
269-
}
270-
271-
func (DefaultStorage) VariableSchema() clusterv1.VariableSchema {
272-
supportedCSIProviders := []string{CSIProviderAWSEBS, CSIProviderNutanix}
273-
return clusterv1.VariableSchema{
274-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
275-
Type: "object",
276-
Description: "A tuple of provider name and storage class ",
277-
Required: []string{"providerName", "storageClassConfigName"},
278-
Properties: map[string]clusterv1.JSONSchemaProps{
279-
"providerName": {
280-
Type: "string",
281-
Description: "Name of the CSI Provider for the default storage class",
282-
Enum: variables.MustMarshalValuesToEnumJSON(
283-
supportedCSIProviders...,
284-
),
285-
},
286-
"storageClassConfigName": {
287-
Type: "string",
288-
Description: "Name of storage class config in any of the provider objects",
289-
},
290-
},
291-
},
292-
}
293-
}
294-
295-
func (CSI) VariableSchema() clusterv1.VariableSchema {
296-
return clusterv1.VariableSchema{
297-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
298-
Type: "object",
299-
Properties: map[string]clusterv1.JSONSchemaProps{
300-
"providers": {
301-
Type: "array",
302-
Items: ptr.To(CSIProvider{}.VariableSchema().OpenAPIV3Schema),
303-
},
304-
"defaultStorage": DefaultStorage{}.VariableSchema().OpenAPIV3Schema,
305-
},
306-
},
307-
}
308-
}
309-
310101
// CCM tells us to enable or disable the cloud provider interface.
311102
type CCM struct {
312103
// A reference to the Secret for credential information for the target Prism Central instance
313104
// +optional
314105
Credentials *corev1.LocalObjectReference `json:"credentials,omitempty"`
315106
}
316-
317-
func (CCM) VariableSchema() clusterv1.VariableSchema {
318-
// TODO Validate credentials is set.
319-
// This CCM is shared across all providers.
320-
// Some of these providers may require credentials to be set, but we don't want to require it for all providers.
321-
// The Nutanix CCM handler will fail in at runtime if credentials are not set.
322-
return clusterv1.VariableSchema{
323-
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
324-
Type: "object",
325-
Properties: map[string]clusterv1.JSONSchemaProps{
326-
"credentials": {
327-
Description: "A reference to the Secret for credential information" +
328-
"for the target Prism Central instance",
329-
Type: "object",
330-
Properties: map[string]clusterv1.JSONSchemaProps{
331-
"name": {
332-
Description: "The name of the Secret",
333-
Type: "string",
334-
},
335-
},
336-
Required: []string{"name"},
337-
},
338-
},
339-
},
340-
}
341-
}

0 commit comments

Comments
 (0)