Skip to content

Commit 379b3a2

Browse files
committed
Move PvcApplyStorageProfileLabel constant to API package
- Add LabelApplyStorageProfile to containerized-data-importer-api package for external consumer access - Update CDI code to use cdiv1.LabelApplyStorageProfile - Keep deprecated common.PvcApplyStorageProfileLabel alias for backwards compatibility This enables external projects (e.g., KubeVirt) to import the constant from the API package instead of duplicating it. Signed-off-by: Noam Assouline <[email protected]>
1 parent 4c3dc65 commit 379b3a2

File tree

11 files changed

+19
-19
lines changed

11 files changed

+19
-19
lines changed

pkg/apiserver/webhooks/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ go_test(
6262
embed = [":go_default_library"],
6363
deps = [
6464
"//pkg/client/clientset/versioned/fake:go_default_library",
65-
"//pkg/common:go_default_library",
6665
"//pkg/controller/common:go_default_library",
6766
"//staging/src/kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1:go_default_library",
6867
"//vendor/github.com/appscode/jsonpatch:go_default_library",

pkg/apiserver/webhooks/pvc-mutate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
"sigs.k8s.io/controller-runtime/pkg/client"
3131

32-
"kubevirt.io/containerized-data-importer/pkg/common"
32+
cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
3333
dvc "kubevirt.io/containerized-data-importer/pkg/controller/datavolume"
3434
)
3535

@@ -52,7 +52,7 @@ func (wh *pvcMutatingWebhook) Admit(ar admissionv1.AdmissionReview) *admissionv1
5252
}
5353

5454
// Note the webhook LabelSelector should not pass us such pvcs
55-
if pvc.Labels[common.PvcApplyStorageProfileLabel] != "true" {
55+
if pvc.Labels[cdiv1.LabelApplyStorageProfile] != "true" {
5656
klog.Warningf("Got PVC %s/%s which was not labeled for rendering", pvc.Namespace, pvc.Name)
5757
return allowedAdmissionResponse()
5858
}

pkg/apiserver/webhooks/pvc-mutate_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141
"sigs.k8s.io/controller-runtime/pkg/client/fake"
4242

4343
cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
44-
"kubevirt.io/containerized-data-importer/pkg/common"
4544
)
4645

4746
var _ = Describe("Mutating PVC Webhook", func() {
@@ -158,7 +157,7 @@ func newPvc() *corev1.PersistentVolumeClaim {
158157
pvc := &corev1.PersistentVolumeClaim{
159158
ObjectMeta: metav1.ObjectMeta{
160159
Name: "testPvc",
161-
Labels: map[string]string{common.PvcApplyStorageProfileLabel: "true"},
160+
Labels: map[string]string{cdiv1.LabelApplyStorageProfile: "true"},
162161
},
163162
Spec: corev1.PersistentVolumeClaimSpec{
164163
Resources: corev1.VolumeResourceRequirements{

pkg/common/common.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ const (
6565
// DataImportCronCleanupLabel tells whether to delete the resource when its DataImportCron is deleted
6666
DataImportCronCleanupLabel = DataImportCronLabel + ".cleanup"
6767

68-
// PvcApplyStorageProfileLabel tells whether the PVC should be rendered by the mutating webhook based on StorageProfiles
69-
PvcApplyStorageProfileLabel = CDIComponentLabel + "/applyStorageProfile"
70-
7168
// ImporterVolumePath provides a constant for the directory where the PV is mounted.
7269
ImporterVolumePath = "/data"
7370
// DiskImageName provides a constant for our importer/datastream_ginkgo_test and to build ImporterWritePath

pkg/controller/datavolume/controller-base.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,13 +1155,13 @@ func (r *ReconcilerBase) newPersistentVolumeClaim(dataVolume *cdiv1.DataVolume,
11551155
annotations[cc.AnnPreallocationRequested] = strconv.FormatBool(cc.GetPreallocation(context.TODO(), r.client, dataVolume.Spec.Preallocation))
11561156
annotations[cc.AnnCreatedForDataVolume] = string(dataVolume.UID)
11571157

1158-
if dataVolume.Spec.Storage != nil && labels[common.PvcApplyStorageProfileLabel] == "true" {
1158+
if dataVolume.Spec.Storage != nil && labels[cdiv1.LabelApplyStorageProfile] == "true" {
11591159
isWebhookPvcRenderingEnabled, err := featuregates.IsWebhookPvcRenderingEnabled(r.client)
11601160
if err != nil {
11611161
return nil, err
11621162
}
11631163
if isWebhookPvcRenderingEnabled {
1164-
labels[common.PvcApplyStorageProfileLabel] = "true"
1164+
labels[cdiv1.LabelApplyStorageProfile] = "true"
11651165
if targetPvcSpec.VolumeMode == nil {
11661166
targetPvcSpec.VolumeMode = ptr.To[corev1.PersistentVolumeMode](cdiv1.PersistentVolumeFromStorageProfile)
11671167
}

pkg/controller/datavolume/util.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141
"sigs.k8s.io/controller-runtime/pkg/reconcile"
4242

4343
cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
44-
"kubevirt.io/containerized-data-importer/pkg/common"
4544
cc "kubevirt.io/containerized-data-importer/pkg/controller/common"
4645
"kubevirt.io/containerized-data-importer/pkg/controller/populators"
4746
featuregates "kubevirt.io/containerized-data-importer/pkg/feature-gates"
@@ -100,7 +99,7 @@ func pvcFromStorage(client client.Client, recorder record.EventRecorder, log log
10099
return nil, err
101100
}
102101

103-
shouldRender := !isWebhookRenderingEnabled || dv.Labels[common.PvcApplyStorageProfileLabel] != "true"
102+
shouldRender := !isWebhookRenderingEnabled || dv.Labels[cdiv1.LabelApplyStorageProfile] != "true"
104103

105104
if pvc == nil {
106105
pvcSpec = copyStorageAsPvc(dv.Spec.Storage)

pkg/operator/controller/callbacks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ func initPvcMutatingWebhook(whc *admissionregistrationv1.MutatingWebhookConfigur
537537
},
538538
ObjectSelector: &metav1.LabelSelector{
539539
MatchLabels: map[string]string{
540-
common.PvcApplyStorageProfileLabel: "true",
540+
cdiv1.LabelApplyStorageProfile: "true",
541541
},
542542
},
543543
ReinvocationPolicy: &reinvocationNever,

staging/src/kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
corev1 "k8s.io/api/core/v1"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222
sdkapi "kubevirt.io/controller-lifecycle-operator-sdk/api"
23+
24+
"kubevirt.io/containerized-data-importer-api/pkg/apis/core"
2325
)
2426

2527
// DataVolume is an abstraction on top of PersistentVolumeClaims to allow easy population of those PersistentVolumeClaims with relation to VirtualMachines
@@ -108,6 +110,11 @@ type StorageSpec struct {
108110
// PersistentVolumeFromStorageProfile means the volume mode will be auto selected by CDI according to a matching StorageProfile
109111
const PersistentVolumeFromStorageProfile corev1.PersistentVolumeMode = "FromStorageProfile"
110112

113+
// LabelApplyStorageProfile is a PVC label that tells the CDI mutating webhook to modify the PVC
114+
// according to the storage profile. When set to "true", the webhook will process the PVC based on
115+
// its associated StorageProfile (e.g., setting volume mode, access modes, etc.).
116+
const LabelApplyStorageProfile = core.GroupName + "/applyStorageProfile"
117+
111118
// DataVolumeCheckpoint defines a stage in a warm migration.
112119
type DataVolumeCheckpoint struct {
113120
// Previous is the identifier of the snapshot from the previous checkpoint.

tests/clone-populator_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"sigs.k8s.io/controller-runtime/pkg/client"
2121

2222
cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
23-
"kubevirt.io/containerized-data-importer/pkg/common"
2423
"kubevirt.io/containerized-data-importer/pkg/controller/clone"
2524
cc "kubevirt.io/containerized-data-importer/pkg/controller/common"
2625
"kubevirt.io/containerized-data-importer/tests/framework"
@@ -189,7 +188,7 @@ var _ = Describe("Clone Populator tests", func() {
189188
}
190189
pvc := generateTargetPVCWithStrategy(size, vm, strategy, scName)
191190
pvc.Spec.AccessModes = nil
192-
cc.AddLabel(pvc, common.PvcApplyStorageProfileLabel, "true")
191+
cc.AddLabel(pvc, cdiv1.LabelApplyStorageProfile, "true")
193192
err := f.CrClient.Create(context.Background(), pvc)
194193
Expect(err).ToNot(HaveOccurred())
195194
f.ForceSchedulingIfWaitForFirstConsumerPopulationPVC(pvc)

tests/datavolume_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,7 +2067,7 @@ var _ = Describe("[vendor:[email protected]][level:component]DataVolume tests",
20672067
},
20682068
}
20692069
dataVolume := createLabeledDataVolumeForImport(f, spec,
2070-
map[string]string{common.PvcApplyStorageProfileLabel: webhookRenderingLabel})
2070+
map[string]string{cdiv1.LabelApplyStorageProfile: webhookRenderingLabel})
20712071

20722072
By("verifying event occurred")
20732073
Eventually(func() bool {
@@ -2113,7 +2113,7 @@ var _ = Describe("[vendor:[email protected]][level:component]DataVolume tests",
21132113
},
21142114
}
21152115
dataVolume := createLabeledDataVolumeForImport(f, spec,
2116-
map[string]string{common.PvcApplyStorageProfileLabel: webhookRenderingLabel})
2116+
map[string]string{cdiv1.LabelApplyStorageProfile: webhookRenderingLabel})
21172117

21182118
By("verifying pvc not created")
21192119
_, err := utils.FindPVC(f.K8sClient, dataVolume.Namespace, dataVolume.Name)
@@ -2548,7 +2548,7 @@ var _ = Describe("[vendor:[email protected]][level:component]DataVolume tests",
25482548
By(fmt.Sprintf("creating new datavolume %s with StorageClassName %s", dataVolumeName, scName))
25492549
dataVolume := utils.NewDataVolumeWithHTTPImportAndStorageSpec(
25502550
dataVolumeName, "100Mi", fmt.Sprintf(utils.TinyCoreQcow2URL, f.CdiInstallNs))
2551-
dataVolume.Labels = map[string]string{common.PvcApplyStorageProfileLabel: webhookRenderingLabel}
2551+
dataVolume.Labels = map[string]string{cdiv1.LabelApplyStorageProfile: webhookRenderingLabel}
25522552
dataVolume.Spec.Storage.StorageClassName = ptr.To[string](scName)
25532553
dataVolume.Spec.Storage.AccessModes = nil
25542554

0 commit comments

Comments
 (0)