diff --git a/packages/mco/components/modals/app-manage-policies/utils/k8s-utils.ts b/packages/mco/components/modals/app-manage-policies/utils/k8s-utils.ts index 93756b60b..e8c62653d 100644 --- a/packages/mco/components/modals/app-manage-policies/utils/k8s-utils.ts +++ b/packages/mco/components/modals/app-manage-policies/utils/k8s-utils.ts @@ -10,8 +10,7 @@ import { PROTECTED_APP_ANNOTATION_WO_SLASH, } from '@odf/mco/constants'; import { DRPlacementControlKind } from '@odf/mco/types'; -import { matchClusters } from '@odf/mco/utils'; -import { objectify } from '@odf/shared/modals/EditLabelModal'; +import { convertLabelToExpression, matchClusters } from '@odf/mco/utils'; import { getAPIVersion, getAnnotations, @@ -59,7 +58,7 @@ export const getDRPCKindObj = ( }, preferredCluster: matchClusters(drClusterNames, decisionClusters), pvcSelector: { - matchLabels: objectify(pvcSelectors), + matchExpressions: convertLabelToExpression(pvcSelectors), }, }, }); diff --git a/packages/mco/components/modals/app-manage-policies/utils/parser-utils.ts b/packages/mco/components/modals/app-manage-policies/utils/parser-utils.ts index 269c8e217..e1e69b215 100644 --- a/packages/mco/components/modals/app-manage-policies/utils/parser-utils.ts +++ b/packages/mco/components/modals/app-manage-policies/utils/parser-utils.ts @@ -6,12 +6,14 @@ import { DRPolicyKind, } from '@odf/mco/types'; import { + convertExpressionToLabel, getReplicationType, isDRPolicyValidated, matchClusters, } from '@odf/mco/utils'; import { getLatestDate } from '@odf/shared/details-page/datetime'; import { arrayify } from '@odf/shared/modals/EditLabelModal'; +import { Selector } from '@openshift-console/dynamic-plugin-sdk'; import * as _ from 'lodash-es'; import { ApplicationType, @@ -20,6 +22,11 @@ import { PlacementType, } from './types'; +const getPVCSelector = (pvcSelector: Selector): string[] => { + const { matchLabels, matchExpressions } = pvcSelector; + return convertExpressionToLabel(matchExpressions) || arrayify(matchLabels); +}; + const getDRPolicyInfo = (drPolicy: DRPolicyKind, assignedOn?: string) => !_.isEmpty(drPolicy) ? { @@ -72,7 +79,7 @@ export const generateDRPlacementControlInfo = ( metadata: drpc.metadata, drPolicyRef: drpc.spec.drPolicyRef, placementInfo: plsInfo, - pvcSelector: arrayify(drpc?.spec.pvcSelector.matchLabels) || [], + pvcSelector: getPVCSelector(drpc.spec.pvcSelector), lastGroupSyncTime: drpc?.status?.lastGroupSyncTime, }, ] diff --git a/packages/mco/utils/common.ts b/packages/mco/utils/common.ts index 88b81bb23..da7f2b49e 100644 --- a/packages/mco/utils/common.ts +++ b/packages/mco/utils/common.ts @@ -8,6 +8,8 @@ import { groupVersionFor, referenceFor } from '@odf/shared/utils'; import { ObjectReference, K8sResourceCommon, + MatchExpression, + Operator, } from '@openshift-console/dynamic-plugin-sdk'; export const getGVKFromK8Resource = (resource: K8sResourceCommon) => { @@ -30,3 +32,33 @@ export const getMajorVersion = (version: string): string => { ? version.split('.')[0] + '.' + version.split('.')[1] + '.0' : ''; }; + +export const convertLabelToExpression = ( + labels: string[] +): MatchExpression[] => { + // appName: busybox-1, appName: busybox-2 will be converted to {key: appName, operator: Equals, values: [busybox-1, busybox-2]} + const labelExpressions = labels.reduce((acc, label) => { + const [key, value = ''] = label.split('='); + if (key in acc) { + acc[key].values.push(value); + } else { + acc[key] = { + key, + operator: Operator.In, + values: [value], + }; + } + return acc; + }, {} as { [key in string]: MatchExpression }); + return Object.values(labelExpressions); +}; + +export const convertExpressionToLabel = ( + labelExpressions: MatchExpression[] +): string[] => + // {key: appName, operator: Equals, values: [busybox-1, busybox-2]} will be converted to appName: busybox-1, appName: busybox-2 + labelExpressions?.reduce((acc, labelExpression) => { + const { key, values } = labelExpression; + acc.push(...values.map((value) => `${key}=${value}`)); + return acc; + }, []);