Skip to content

Commit

Permalink
Merge pull request #2218 from akalenyu/virt-default-sc-ann-fix
Browse files Browse the repository at this point in the history
Fix wrong mutation of virt sc storage class meta
  • Loading branch information
openshift-ci[bot] authored Oct 17, 2023
2 parents 417bbd1 + 974985a commit 2f69d25
Show file tree
Hide file tree
Showing 2 changed files with 39 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
42 changes: 38 additions & 4 deletions controllers/storagecluster/storageclasses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ 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 +55,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 +103,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 +120,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 +139,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 +188,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 2f69d25

Please sign in to comment.