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

Commit

Permalink
fix: Add schema defaults for CSI
Browse files Browse the repository at this point in the history
Also add tests for the new schema requirements.
  • Loading branch information
jimmidyson committed Mar 28, 2024
1 parent 5c21017 commit dc7f3bc
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 60 deletions.
52 changes: 29 additions & 23 deletions api/v1alpha1/addon_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/api/variables"
Expand Down Expand Up @@ -36,7 +37,7 @@ type Addons struct {
CPI *CPI `json:"cpi,omitempty"`

// +optional
CSIProviders *CSIProviders `json:"csi,omitempty"`
CSI *CSI `json:"csi,omitempty"`
}

func (Addons) VariableSchema() clusterv1.VariableSchema {
Expand All @@ -48,7 +49,7 @@ func (Addons) VariableSchema() clusterv1.VariableSchema {
"cni": CNI{}.VariableSchema().OpenAPIV3Schema,
"nfd": NFD{}.VariableSchema().OpenAPIV3Schema,
"clusterAutoscaler": ClusterAutoscaler{}.VariableSchema().OpenAPIV3Schema,
"csi": CSIProviders{}.VariableSchema().OpenAPIV3Schema,
"csi": CSI{}.VariableSchema().OpenAPIV3Schema,
"cpi": CPI{}.VariableSchema().OpenAPIV3Schema,
},
},
Expand Down Expand Up @@ -147,7 +148,7 @@ type DefaultStorage struct {
StorageClassConfigName string `json:"storageClassConfigName"`
}

type CSIProviders struct {
type CSI struct {
// +optional
Providers []CSIProvider `json:"providers,omitempty"`
// +optional
Expand Down Expand Up @@ -191,24 +192,34 @@ func (StorageClassConfig) VariableSchema() clusterv1.VariableSchema {
}
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Type: "object",
Required: []string{"name", "parameters", "reclaimPolicy", "volumeBindingMode"},
Properties: map[string]clusterv1.JSONSchemaProps{
"name": {
Type: "string",
Description: "Name of storage class config.",
MinLength: ptr.To(int64(1)),
},
"parameters": {
Type: "object",
Description: "Parameters passed into the storage class object.",
XPreserveUnknownFields: true,
Type: "object",
Description: "Parameters passed into the storage class object.",
AdditionalProperties: &clusterv1.JSONSchemaProps{
Type: "string",
},
Default: variables.MustMarshal(map[string]string{
"csi.storage.k8s.io/fstype": "ext4",
"type": "gp3",
}),
},
"reclaimPolicy": {
Type: "string",
Enum: variables.MustMarshalValuesToEnumJSON(supportedReclaimPolicies...),
Type: "string",
Enum: variables.MustMarshalValuesToEnumJSON(supportedReclaimPolicies...),
Default: variables.MustMarshal(VolumeReclaimDelete),
},
"volumeBindingMode": {
Type: "string",
Enum: variables.MustMarshalValuesToEnumJSON(supportedBindingModes...),
Type: "string",
Enum: variables.MustMarshalValuesToEnumJSON(supportedBindingModes...),
Default: variables.MustMarshal(VolumeBindingImmediate),
},
},
},
Expand All @@ -219,7 +230,8 @@ func (CSIProvider) VariableSchema() clusterv1.VariableSchema {
supportedCSIProviders := []string{CSIProviderAWSEBS, CSIProviderNutanix}
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Type: "object",
Required: []string{"name", "strategy"},
Properties: map[string]clusterv1.JSONSchemaProps{
"name": {
Description: "Name of the CSI Provider",
Expand Down Expand Up @@ -248,11 +260,8 @@ func (CSIProvider) VariableSchema() clusterv1.VariableSchema {
},
},
"storageClassConfig": {
Type: "array",
Items: &clusterv1.JSONSchemaProps{
Type: "object",
Properties: StorageClassConfig{}.VariableSchema().OpenAPIV3Schema.Properties,
},
Type: "array",
Items: ptr.To(StorageClassConfig{}.VariableSchema().OpenAPIV3Schema),
},
},
},
Expand Down Expand Up @@ -281,17 +290,14 @@ func (DefaultStorage) VariableSchema() clusterv1.VariableSchema {
}
}

func (CSIProviders) VariableSchema() clusterv1.VariableSchema {
func (CSI) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"providers": {
Type: "array",
Items: &clusterv1.JSONSchemaProps{
Type: "object",
Properties: CSIProvider{}.VariableSchema().OpenAPIV3Schema.Properties,
},
Type: "array",
Items: ptr.To(CSIProvider{}.VariableSchema().OpenAPIV3Schema),
},
"defaultStorage": DefaultStorage{}.VariableSchema().OpenAPIV3Schema,
},
Expand Down
48 changes: 24 additions & 24 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/handlers/generic/lifecycle/csi/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (c *CSIHandler) AfterControlPlaneInitialized(
)
varMap := variables.ClusterVariablesToVariablesMap(req.Cluster.Spec.Topology.Variables)
resp.SetStatus(runtimehooksv1.ResponseStatusSuccess)
csiProviders, found, err := variables.Get[v1alpha1.CSIProviders](
csiProviders, found, err := variables.Get[v1alpha1.CSI](
varMap,
c.variableName,
c.variablePath...)
Expand Down
Loading

0 comments on commit dc7f3bc

Please sign in to comment.