Skip to content

Commit

Permalink
Fix wrong mutation of virt sc storage class meta
Browse files Browse the repository at this point in the history
We weren't performing the changes on the pointer,
and thus name/annotations are not applied.

Signed-off-by: Alex Kalenyuk <[email protected]>
  • Loading branch information
akalenyu committed Oct 17, 2023
1 parent 417bbd1 commit 8d30aeb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion controllers/storagecluster/storageclasses.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func newCephBlockPoolStorageClassConfiguration(initData *ocsv1.StorageCluster) S
// newCephBlockPoolVirtualizationStorageClassConfiguration generates configuration options for a Ceph Block Pool StorageClass for virtualization environment.
func newCephBlockPoolVirtualizationStorageClassConfiguration(initData *ocsv1.StorageCluster) StorageClassConfiguration {
virtualizationStorageClassConfig := newCephBlockPoolStorageClassConfiguration(initData)
meta := virtualizationStorageClassConfig.storageClass.ObjectMeta
meta := &virtualizationStorageClassConfig.storageClass.ObjectMeta
meta.Name = generateNameForCephBlockPoolVirtualizationSC(initData)
meta.Annotations["description"] = "Provides RWO and RWX Block volumes suitable for Virtual Machine disks"
meta.Annotations["storageclass.kubevirt.io/is-default-virt-class"] = "true"
Expand Down
43 changes: 39 additions & 4 deletions controllers/storagecluster/storageclasses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
api "github.com/red-hat-storage/ocs-operator/v4/api/v1"
"github.com/stretchr/testify/assert"
storagev1 "k8s.io/api/storage/v1"
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
Expand Down Expand Up @@ -53,6 +56,32 @@ var (
},
},
}
createVirtualMachineCRD = func() *extv1.CustomResourceDefinition {
pluralName := "virtualmachines"
return &extv1.CustomResourceDefinition{
TypeMeta: metav1.TypeMeta{
Kind: "CustomResourceDefinition",
APIVersion: extv1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: pluralName + "." + "kubevirt.io",
},
Spec: extv1.CustomResourceDefinitionSpec{
Group: "kubevirt.io",
Scope: extv1.NamespaceScoped,
Names: extv1.CustomResourceDefinitionNames{
Plural: pluralName,
Kind: "VirtualMachine",
},
Versions: []extv1.CustomResourceDefinitionVersion{
{
Name: "v1",
Served: true,
},
},
},
}
}
)

func TestDefaultStorageClasses(t *testing.T) {
Expand All @@ -75,6 +104,7 @@ func testStorageClasses(t *testing.T, pvEncryption bool, customSpec *api.Storage
for _, eachPlatform := range allPlatforms {
cp := &Platform{platform: eachPlatform}
runtimeObjs := []client.Object{}
runtimeObjs = append(runtimeObjs, createVirtualMachineCRD())
if pvEncryption {
runtimeObjs = append(runtimeObjs, createDummyKMSConfigMap(dummyKmsProvider, dummyKmsAddress, ""))
}
Expand All @@ -91,13 +121,15 @@ func assertStorageClasses(t *testing.T, reconciler StorageClusterReconciler, cr
scNameRbd := generateNameForCephBlockPoolSC(cr)
scNameEncryptedRbd := generateNameForEncryptedCephBlockPoolSC(cr)
scNameRgw := generateNameForCephRgwSC(cr)
scNameVirt := generateNameForCephBlockPoolVirtualizationSC(cr)

actual := map[string]*storagev1.StorageClass{
scNameCephfs: {},
scNameNfs: {},
scNameRbd: {},
scNameEncryptedRbd: {},
scNameRgw: {},
scNameVirt: {},
}
expected, err := reconciler.newStorageClassConfigurations(cr)
assert.NoError(t, err)
Expand All @@ -108,16 +140,16 @@ func assertStorageClasses(t *testing.T, reconciler StorageClusterReconciler, cr
assert.NoError(t, skipErr)
if skip {
if pvEncryption {
assert.Equal(t, len(expected), 4)
assert.Equal(t, len(expected), 5)
} else {
assert.Equal(t, len(expected), 3)
assert.Equal(t, len(expected), 4)
}
} else {
if pvEncryption {
assert.Equal(t, len(expected), 5)
assert.Equal(t, len(expected), 6)
} else {
// if not a cloud platform, RGW StorageClass should be created/updated
assert.Equal(t, len(expected), 4)
assert.Equal(t, len(expected), 5)
}
}

Expand Down Expand Up @@ -157,6 +189,9 @@ func assertStorageClasses(t *testing.T, reconciler StorageClusterReconciler, cr
assert.Equal(t, actualSc.Parameters["encrypted"], "true")
assert.NotEmpty(t, actualSc.Parameters["encryptionKMSID"])
}
if scName == scNameVirt {
assert.Equal(t, actualSc.ObjectMeta.Annotations["storageclass.kubevirt.io/is-default-virt-class"], "true")
}
}
}
}

0 comments on commit 8d30aeb

Please sign in to comment.