Skip to content

Commit

Permalink
Merge pull request #11002 from seh/amend-default-choice-for-storage-c…
Browse files Browse the repository at this point in the history
…lass-management

Storage: Amend default choice for StorageClass management to honor a specified OpenStack-related value
  • Loading branch information
k8s-ci-robot authored Mar 9, 2021
2 parents 3b7ca6e + 4406160 commit 59d3fb4
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/kops/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ func Test_Validate_CloudConfiguration(t *testing.T) {
}},
},
{
Description: "os false",
Description: "os true",
Input: kops.CloudConfiguration{
Openstack: &kops.OpenstackConfiguration{
BlockStorage: &kops.OpenstackBlockStorageConfig{
Expand Down
2 changes: 2 additions & 0 deletions pkg/model/components/BUILD.bazel

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

16 changes: 12 additions & 4 deletions pkg/model/components/cloudconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,20 @@ func (b *CloudConfigurationOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec.CloudConfig = c
}

if c.ManageStorageClasses == nil {
c.ManageStorageClasses = fi.Bool(true)
}

// NB: See file openstack.go for establishing default values for the CloudConfig.Openstack
// field.

if c.ManageStorageClasses == nil {
var manage *bool
if c.Openstack != nil && c.Openstack.BlockStorage != nil && c.Openstack.BlockStorage.CreateStorageClass != nil {
// Avoid a spurious conflict with a user-specified configuration for OpenStack by
// adopting that more particular setting generally.
manage = c.Openstack.BlockStorage.CreateStorageClass
} else {
manage = fi.Bool(true)
}
c.ManageStorageClasses = manage
}

return nil
}
125 changes: 125 additions & 0 deletions pkg/model/components/cloudconfiguration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package components

import (
"testing"

kopsapi "k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/upup/pkg/fi"
)

func TestCloudConfigurationOptionsBuilder(t *testing.T) {
ob := &CloudConfigurationOptionsBuilder{
Context: nil,
}
disabled := fi.Bool(false)
enabled := fi.Bool(true)
for _, test := range []struct {
description string
generalManageSCs *bool
openStackManageSCs *bool
expectedGeneralManageSCs *bool
}{
{
"neither",
nil,
nil,
enabled,
},
{
"all false",
disabled,
nil,
disabled,
},
{
"all true",
enabled,
nil,
enabled,
},
{
"os false",
nil,
disabled,
disabled,
},
{
"os true",
nil,
enabled,
enabled,
},
{
"all false, os false",
disabled,
disabled,
disabled,
},
{
"all false, os true",
// Caught as conflict during validation.
disabled,
enabled,
disabled,
},
{
"all true, os false",
// Caught as conflict during validation.
enabled,
disabled,
enabled,
},
{
"all true, os true",
enabled,
enabled,
enabled,
},
} {
t.Run(test.description, func(t *testing.T) {
spec := kopsapi.ClusterSpec{
CloudProvider: string(kopsapi.CloudProviderOpenstack),
CloudConfig: &kopsapi.CloudConfiguration{
Openstack: &kopsapi.OpenstackConfiguration{
BlockStorage: &kopsapi.OpenstackBlockStorageConfig{},
},
},
}
if p := test.generalManageSCs; p != nil {
spec.CloudConfig.ManageStorageClasses = p
}
if p := test.openStackManageSCs; p != nil {
spec.CloudConfig.Openstack.BlockStorage.CreateStorageClass = p
}
if err := ob.BuildOptions(&spec); err != nil {
t.Fatalf("failed to build options: %v", err)
}
if want, got := test.expectedGeneralManageSCs, spec.CloudConfig.ManageStorageClasses; (want == nil) != (got == nil) || (got != nil && *got != *want) {
switch {
case want == nil:
t.Errorf("spec.cloudConfig.manageStorageClasses: want nil, got %t", *got)
case got == nil:
t.Errorf("spec.cloudConfig.manageStorageClasses: want %t, got nil", *want)
default:
t.Errorf("spec.cloudConfig.manageStorageClasses: want %t, got %t", *want, *got)
}
}
})
}
}

0 comments on commit 59d3fb4

Please sign in to comment.