diff --git a/pkg/common/label.go b/pkg/common/label.go index acf4b5cff3e..6c604b8d66f 100644 --- a/pkg/common/label.go +++ b/pkg/common/label.go @@ -29,8 +29,12 @@ const ( LabelAnnotationDataset = LabelAnnotationPrefix + "dataset" // LabelAnnotationDatasetNum indicates the number of the dataset in specific node LabelAnnotationDatasetNum = LabelAnnotationPrefix + "dataset-num" - // LabelAnnotationWrappedBy indicates the resource is wrapped by some dataset - LabelAnnotationWrappedBy = LabelAnnotationPrefix + "wrapped-by" + + // LabelAnnotationManagedByDeprecated is a deprecated label key for LabelAnnotationManagedBy + LabelAnnotationManagedByDeprecated = LabelAnnotationPrefix + "wrapped-by" + + // LabelAnnotationManagedBy indicates a pvc that is managed by Fluid + LabelAnnotationManagedBy = LabelAnnotationPrefix + "managed-by" // fluid adminssion webhook inject flag EnableFluidInjectionFlag = LabelAnnotationPrefix + "enable-injection" @@ -124,3 +128,14 @@ func CheckExpectValue(m map[string]string, key string, targetValue string) bool } return false } + +func GetManagerDatasetFromLabels(labels map[string]string) (datasetName string, exists bool) { + datasetName, exists = labels[LabelAnnotationManagedBy] + if exists { + return + } + + // fallback to check deprecated "fluid.io/wrapped-by" label + datasetName, exists = labels[LabelAnnotationManagedByDeprecated] + return +} diff --git a/pkg/ddc/thin/wrap_pvc.go b/pkg/ddc/thin/wrap_pvc.go index 4c3b168c128..46ecad16d86 100644 --- a/pkg/ddc/thin/wrap_pvc.go +++ b/pkg/ddc/thin/wrap_pvc.go @@ -98,9 +98,9 @@ func (t *ThinEngine) wrapMountedPersistentVolumeClaim() (err error) { return err } - if _, exists := mountedPvc.Labels[common.LabelAnnotationWrappedBy]; !exists { + if _, exists := mountedPvc.Labels[common.LabelAnnotationManagedBy]; !exists { labelsToModify := common.LabelsToModify{} - labelsToModify.Add(common.LabelAnnotationWrappedBy, t.name) + labelsToModify.Add(common.LabelAnnotationManagedBy, t.name) _, err = utils.PatchLabels(t.Client, mountedPvc, labelsToModify) if err != nil { return err @@ -130,9 +130,9 @@ func (t *ThinEngine) unwrapMountedPersistentVolumeClaims() (err error) { return errors.Wrapf(err, "failed to get pvc when unwrapping pvc %s", pvcName) } - if wrappedBy, exists := pvc.Labels[common.LabelAnnotationWrappedBy]; exists && wrappedBy == t.name { + if wrappedBy, exists := pvc.Labels[common.LabelAnnotationManagedBy]; exists && wrappedBy == t.name { labelsToModify := common.LabelsToModify{} - labelsToModify.Delete(common.LabelAnnotationWrappedBy) + labelsToModify.Delete(common.LabelAnnotationManagedBy) if _, err = utils.PatchLabels(t.Client, pvc, labelsToModify); err != nil { return errors.Wrapf(err, "failed to remove label when unwrapping pvc %s", pvc.Name) } diff --git a/pkg/ddc/thin/wrap_pvc_test.go b/pkg/ddc/thin/wrap_pvc_test.go index 37bf8079ffa..b513c88be2f 100644 --- a/pkg/ddc/thin/wrap_pvc_test.go +++ b/pkg/ddc/thin/wrap_pvc_test.go @@ -60,7 +60,7 @@ func TestThinEngine_wrapMountedPersistentVolumeClaim(t *testing.T) { Name: "my-pvc-2", Namespace: "default", Labels: map[string]string{ - common.LabelAnnotationWrappedBy: "dataset2", + common.LabelAnnotationManagedBy: "dataset2", }, }, }, @@ -119,10 +119,10 @@ func TestThinEngine_wrapMountedPersistentVolumeClaim(t *testing.T) { t.Errorf("Got error when checking pvc labels: %v", err) } - if wrappedBy, exists := pvc.Labels[common.LabelAnnotationWrappedBy]; !exists { - t.Errorf("Expect get label \"%s=%s\" on pvc, but not exists", common.LabelAnnotationWrappedBy, engine.name) + if wrappedBy, exists := pvc.Labels[common.LabelAnnotationManagedBy]; !exists { + t.Errorf("Expect get label \"%s=%s\" on pvc, but not exists", common.LabelAnnotationManagedBy, engine.name) } else if wrappedBy != engine.name { - t.Errorf("Expect get label \"%s=%s\" on pvc, but got %s", common.LabelAnnotationWrappedBy, engine.name, wrappedBy) + t.Errorf("Expect get label \"%s=%s\" on pvc, but got %s", common.LabelAnnotationManagedBy, engine.name, wrappedBy) } }) } @@ -137,7 +137,7 @@ func TestThinEngine_unwrapMountedPersistentVolumeClaims(t *testing.T) { Name: "my-pvc-1", Namespace: "default", Labels: map[string]string{ - common.LabelAnnotationWrappedBy: "dataset1", + common.LabelAnnotationManagedBy: "dataset1", }, }, }, @@ -236,8 +236,8 @@ func TestThinEngine_unwrapMountedPersistentVolumeClaims(t *testing.T) { t.Errorf("Got error when checking pvc labels: %v", err) } - if _, exists := pvc.Labels[common.LabelAnnotationWrappedBy]; exists { - t.Errorf("Expect no label \"%s\" on pvc, but it exists. pvc Labels: %v", common.LabelAnnotationWrappedBy, pvc.Labels) + if _, exists := pvc.Labels[common.LabelAnnotationManagedBy]; exists { + t.Errorf("Expect no label \"%s\" on pvc, but it exists. pvc Labels: %v", common.LabelAnnotationManagedBy, pvc.Labels) } }) } diff --git a/pkg/utils/kubeclient/volume.go b/pkg/utils/kubeclient/volume.go index 1ab3f6f405c..1d0bfd3b802 100644 --- a/pkg/utils/kubeclient/volume.go +++ b/pkg/utils/kubeclient/volume.go @@ -364,7 +364,7 @@ func CheckIfPVCIsDataset(pvc *v1.PersistentVolumeClaim) (isDataset bool) { } _, isDataset = pvc.Labels[common.LabelAnnotationStorageCapacityPrefix+namespace+"-"+name] - if _, exists := pvc.Labels[common.LabelAnnotationWrappedBy]; exists { + if _, exists := common.GetManagerDatasetFromLabels(pvc.Labels); exists { isDataset = true } diff --git a/pkg/webhook/scheduler/mutating/utils.go b/pkg/webhook/scheduler/mutating/utils.go index a665f8342fd..6cf65b0fd4f 100644 --- a/pkg/webhook/scheduler/mutating/utils.go +++ b/pkg/webhook/scheduler/mutating/utils.go @@ -25,8 +25,8 @@ func buildRuntimeInfoInternal(client client.Client, namespace = corev1.NamespaceDefault } pvcName := pvc.GetName() - if wrapperName, exists := pvc.Labels[common.LabelAnnotationWrappedBy]; exists { - pvcName = wrapperName + if datasetName, exists := common.GetManagerDatasetFromLabels(pvc.Labels); exists { + pvcName = datasetName } dataset, err := utils.GetDataset(client, pvcName, namespace)