Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/v1.5] Refactor validation for csiConfig #2447

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ issues:
text: "cyclomatic complexity 36 of func `openstackValidationFunc` is high"

- path: pkg/apis/kubeone
text: "cyclomatic complexity 31 of func `ValidateCloudProviderSpec` is high"
text: "cyclomatic complexity 32 of func `ValidateCloudProviderSpec` is high"
4 changes: 4 additions & 0 deletions pkg/apis/kubeone/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,8 @@ func checkClusterFeatures(c kubeoneapi.KubeOneCluster, logger logrus.FieldLogger
if c.ContainerRuntime.Docker != nil {
logger.Warnf("Support for docker will be removed with Kubernetes 1.24 release. It is recommended to switch to containerd as container runtime using `kubeone migrate to-containerd`")
}

if c.CloudProvider.Vsphere != nil && !c.CloudProvider.External && len(c.CloudProvider.CSIConfig) > 0 {
logger.Warnf(".cloudProvider.csiConfig is provided, but is ignored when used with the in-tree cloud provider")
}
}
12 changes: 5 additions & 7 deletions pkg/apis/kubeone/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ func ValidateCloudProviderSpec(p kubeoneapi.CloudProviderSpec, fldPath *field.Pa
if len(p.CloudConfig) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("cloudConfig"), ".cloudProvider.cloudConfig is required for vSphere provider"))
}
if p.External && len(p.CSIConfig) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("csiConfig"), ".cloudProvider.csiConfig is required for vSphere provider"))
}
providerFound = true
}
if p.None != nil {
Expand All @@ -257,13 +260,8 @@ func ValidateCloudProviderSpec(p kubeoneapi.CloudProviderSpec, fldPath *field.Pa
allErrs = append(allErrs, field.Invalid(fldPath, "", "provider must be specified"))
}

if len(p.CSIConfig) > 0 {
if p.Vsphere == nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child("csiConfig"), "", ".cloudProvider.csiConfig is currently supported only for vsphere clusters"))
}
if !p.External {
allErrs = append(allErrs, field.Invalid(fldPath.Child("csiConfig"), "", ".cloudProvider.csiConfig is supported only for clusters using external cloud provider (.cloudProvider.external)"))
}
if p.Vsphere == nil && len(p.CSIConfig) > 0 {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("csiConfig"), ".cloudProvider.csiConfig is currently supported only for vsphere clusters"))
}

return allErrs
Expand Down
13 changes: 11 additions & 2 deletions pkg/apis/kubeone/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,13 +667,22 @@ func TestValidateCloudProviderSpec(t *testing.T) {
expectedError: true,
},
{
name: "vSphere provider config without csiConfig",
name: "vSphere provider config without csiConfig (external disabled)",
providerConfig: kubeoneapi.CloudProviderSpec{
Vsphere: &kubeoneapi.VsphereSpec{},
CloudConfig: "test",
},
expectedError: false,
},
{
name: "vSphere provider config without csiConfig (external enabled)",
providerConfig: kubeoneapi.CloudProviderSpec{
Vsphere: &kubeoneapi.VsphereSpec{},
External: true,
CloudConfig: "test",
},
expectedError: true,
},
{
name: "vSphere provider config with csiConfig",
providerConfig: kubeoneapi.CloudProviderSpec{
Expand All @@ -692,7 +701,7 @@ func TestValidateCloudProviderSpec(t *testing.T) {
CloudConfig: "test",
CSIConfig: "test",
},
expectedError: true,
expectedError: false,
},
{
name: "OpenStack provider config without csiConfig",
Expand Down