Skip to content

Commit f7f2655

Browse files
Add provision to recipe parameters while enrolling applicaiton
https://issues.redhat.com/browse/DFBUGS-857 Signed-off-by: Timothy Asir Jeyasingh <[email protected]>
1 parent 837f2e0 commit f7f2655

File tree

5 files changed

+73
-4
lines changed

5 files changed

+73
-4
lines changed

locales/en/plugin__odf-console.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@
9898
"Resource label": "Resource label",
9999
"Secure namespaces as per Recipe definition.": "Secure namespaces as per Recipe definition.",
100100
"Recipe": "Recipe",
101+
"Recipe parameters": "Recipe parameters",
102+
"Set of rules and configurations that govern how data is selected, stored, and restored.": "Set of rules and configurations that govern how data is selected, stored, and restored.",
103+
"Add parameter": "Add parameter",
104+
"Value (optional)": "Value (optional)",
101105
"Recipe list": "Recipe list",
102106
"Only recipes of the selected namespaces will appear in the list.": "Only recipes of the selected namespaces will appear in the list.",
103107
"Select a recipe": "Select a recipe",
@@ -147,6 +151,7 @@
147151
"Type:": "Type:",
148152
"Recipe name:": "Recipe name:",
149153
"Recipe namespace:": "Recipe namespace:",
154+
"Recipe Parameters:": "Recipe Parameters:",
150155
"Label expressions:": "Label expressions:",
151156
"PVC label selectors:": "PVC label selectors:",
152157
"Replication": "Replication",
@@ -1304,7 +1309,6 @@
13041309
"Use different criteria for tagging your bucket.": "Use different criteria for tagging your bucket.",
13051310
"No tags are attached to this bucket.": "No tags are attached to this bucket.",
13061311
"Add tag": "Add tag",
1307-
"Value (optional)": "Value (optional)",
13081312
"Enter a valid rule name": "Enter a valid rule name",
13091313
"A rule name is required.": "A rule name is required.",
13101314
"A rule with this name already exists. Type a different name.": "A rule with this name already exists. Type a different name.",

packages/mco/components/discovered-application-wizard/utils/k8s-utils.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ export const getDRPCKindObj = (props: {
3131
k8sResourceReplicationInterval: string;
3232
recipeName?: string;
3333
recipeNamespace?: string;
34+
recipeParameters?: Record<string, string[]>;
3435
k8sResourceLabelExpressions?: MatchExpression[];
3536
pvcLabelExpressions?: MatchExpression[];
3637
placementName: string;
37-
recipeParameters?: Record<string, string[]>;
3838
labels?: ObjectMetadata['labels'];
3939
}): DRPlacementControlKind => ({
4040
apiVersion: getAPIVersionForModel(DRPlacementControlModel),
@@ -106,7 +106,7 @@ export const createPromise = (
106106
const { namespace, configuration, replication } = state;
107107
const { clusterName, namespaces, name } = namespace;
108108
const { protectionMethod, recipe, resourceLabels } = configuration;
109-
const { recipeName, recipeNamespace } = recipe;
109+
const { recipeName, recipeNamespace, recipeParameters } = recipe;
110110
const { k8sResourceLabelExpressions, pvcLabelExpressions } = resourceLabels;
111111
const { drPolicy, k8sResourceReplicationInterval } = replication;
112112
const namespaceList = namespaces.map(getName);
@@ -122,6 +122,14 @@ export const createPromise = (
122122
})
123123
);
124124

125+
const normalizedRecipeParameters: Record<string, string[]> =
126+
Object.fromEntries(
127+
Object.entries(recipeParameters || {}).map(([key, value]) => [
128+
key,
129+
[value],
130+
])
131+
);
132+
125133
promises.push(
126134
k8sCreate({
127135
model: DRPlacementControlModel,
@@ -132,6 +140,7 @@ export const createPromise = (
132140
protectionMethod,
133141
recipeName,
134142
recipeNamespace,
143+
recipeParameters: normalizedRecipeParameters,
135144
k8sResourceLabelExpressions,
136145
pvcLabelExpressions,
137146
drPolicyName: getName(drPolicy),

packages/mco/components/discovered-application-wizard/utils/reducer.ts

+20
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export enum EnrollDiscoveredApplicationStateType {
1616
SET_NAMESPACES = 'NAMESPACE/SET_NAMESPACES',
1717
SET_PROTECTION_METHOD = 'CONFIGURATION/SET_PROTECTION_METHOD',
1818
SET_RECIPE_NAME_NAMESPACE = 'CONFIGURATION/RECIPE/SET_RECIPE_NAME_NAMESPACE',
19+
SET_RECIPE_PARAMETERS = 'SET_RECIPE_PARAMETERS',
1920
SET_K8S_RESOURCE_LABEL_EXPRESSIONS = 'CONFIGURATION/RESOURCE_LABEL/SET_K8S_RESOURCE_LABEL_EXPRESSIONS',
2021
SET_PVC_LABEL_EXPRESSIONS = 'CONFIGURATION/RESOURCE_LABEL/SET_PVC_LABEL_EXPRESSIONS',
2122
SET_POLICY = 'REPLICATION/SET_POLICY',
@@ -40,6 +41,7 @@ export type EnrollDiscoveredApplicationState = {
4041
recipeName: string;
4142
// recipe CR namespace
4243
recipeNamespace: string;
44+
recipeParameters: Record<string, string>;
4345
};
4446
resourceLabels: {
4547
k8sResourceLabelExpressions: MatchExpression[];
@@ -70,6 +72,7 @@ export const initialState: EnrollDiscoveredApplicationState = {
7072
recipe: {
7173
recipeName: '',
7274
recipeNamespace: '',
75+
recipeParameters: {},
7376
},
7477
resourceLabels: {
7578
k8sResourceLabelExpressions: [],
@@ -112,6 +115,10 @@ export type EnrollDiscoveredApplicationAction =
112115
type: EnrollDiscoveredApplicationStateType.SET_POLICY;
113116
payload: DRPolicyKind;
114117
}
118+
| {
119+
type: EnrollDiscoveredApplicationStateType.SET_RECIPE_PARAMETERS;
120+
payload: Record<string, string>;
121+
}
115122
| {
116123
type: EnrollDiscoveredApplicationStateType.SET_K8S_RESOURCE_REPLICATION_INTERVAL;
117124
payload: string;
@@ -159,6 +166,18 @@ export const reducer: EnrollReducer = (state, action) => {
159166
},
160167
};
161168
}
169+
case EnrollDiscoveredApplicationStateType.SET_RECIPE_PARAMETERS: {
170+
return {
171+
...state,
172+
configuration: {
173+
...state.configuration,
174+
recipe: {
175+
...state.configuration.recipe,
176+
recipeParameters: action.payload,
177+
},
178+
},
179+
};
180+
}
162181
case EnrollDiscoveredApplicationStateType.SET_RECIPE_NAME_NAMESPACE: {
163182
const [recipeName, recipeNamespace] = action.payload.split(
164183
NAME_NAMESPACE_SPLIT_CHAR
@@ -168,6 +187,7 @@ export const reducer: EnrollReducer = (state, action) => {
168187
configuration: {
169188
...state.configuration,
170189
recipe: {
190+
...state.configuration.recipe,
171191
recipeName,
172192
recipeNamespace,
173193
},

packages/mco/components/discovered-application-wizard/wizard-steps/configuration-step/recipe-selection.tsx

+25
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
EnrollDiscoveredApplicationStateType,
2222
} from '../../utils/reducer';
2323
import './configuration-step.scss';
24+
import { RecipeParameters } from './recipe-parameters';
2425

2526
const getRecipeOptions = (
2627
searchResultItem: SearchResultItemType[]
@@ -51,6 +52,9 @@ export const RecipeSelection: React.FC<RecipeSelectionProps> = ({
5152
dispatch,
5253
}) => {
5354
const { t } = useCustomTranslation();
55+
const [recipeParams, setRecipeParams] = React.useState<[string, string][]>([
56+
['', ''],
57+
]);
5458

5559
const searchQuery = React.useMemo(
5660
() => queryRecipesFromCluster(clusterName, namespaces.map(getName)),
@@ -81,6 +85,20 @@ export const RecipeSelection: React.FC<RecipeSelectionProps> = ({
8185
payload: nameNamespace,
8286
});
8387

88+
const updateRecipeParams = ({
89+
nameValuePairs,
90+
}: {
91+
nameValuePairs: [string, string][];
92+
}) => {
93+
// Filter valid key-value pairs and update global state
94+
setRecipeParams(nameValuePairs);
95+
const validPairs = nameValuePairs.filter(([key]) => key.trim());
96+
dispatch({
97+
type: EnrollDiscoveredApplicationStateType.SET_RECIPE_PARAMETERS,
98+
payload: Object.fromEntries(validPairs.map(([k, v]) => [k.trim(), v])),
99+
});
100+
};
101+
84102
return (
85103
<>
86104
{/* todo(bipuladh): Add form validation again */}
@@ -117,6 +135,13 @@ export const RecipeSelection: React.FC<RecipeSelectionProps> = ({
117135
) : (
118136
<StatusBox loaded={searchLoaded} loadError={searchError} />
119137
)}
138+
139+
{recipeNameNamespace && (
140+
<RecipeParameters
141+
recipeParams={recipeParams}
142+
updateRecipeParams={updateRecipeParams}
143+
/>
144+
)}
120145
</>
121146
);
122147
};

packages/mco/components/discovered-application-wizard/wizard-steps/review-step/review-step.tsx

+12-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from '@odf/shared/review-and-create-step';
1313
import { getName } from '@odf/shared/selectors';
1414
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook';
15+
import * as _ from 'lodash-es';
1516
import {
1617
EnrollDiscoveredApplicationState,
1718
ProtectionMethodType,
@@ -23,7 +24,7 @@ export const Review: React.FC<ReviewProps> = ({ state }) => {
2324
const { namespace, configuration, replication } = state;
2425
const { clusterName, namespaces, name } = namespace;
2526
const { protectionMethod, recipe, resourceLabels } = configuration;
26-
const { recipeName, recipeNamespace } = recipe;
27+
const { recipeName, recipeNamespace, recipeParameters } = recipe;
2728
const { k8sResourceLabelExpressions, pvcLabelExpressions } = resourceLabels;
2829
const { drPolicy, k8sResourceReplicationInterval } = replication;
2930

@@ -37,6 +38,11 @@ export const Review: React.FC<ReviewProps> = ({ state }) => {
3738
drPolicy.spec.schedulingInterval === '0m'
3839
? REPLICATION_DISPLAY_TEXT(t).sync
3940
: REPLICATION_DISPLAY_TEXT(t).async;
41+
const formatRecipeParameters = (params: Record<string, string>): string => {
42+
return Object.entries(params)
43+
.map(([key, value]) => `${key}: ${value}`)
44+
.join(', ');
45+
};
4046
const [unitVal, interval] = parseSyncInterval(k8sResourceReplicationInterval);
4147

4248
return (
@@ -62,6 +68,11 @@ export const Review: React.FC<ReviewProps> = ({ state }) => {
6268
<ReviewAndCreationItem label={t('Recipe namespace:')}>
6369
{recipeNamespace}
6470
</ReviewAndCreationItem>
71+
{!_.isEmpty(recipeParameters) && (
72+
<ReviewAndCreationItem label={t('Recipe Parameters:')}>
73+
{formatRecipeParameters(recipeParameters)}
74+
</ReviewAndCreationItem>
75+
)}
6576
</>
6677
)}
6778
{protectionMethod === ProtectionMethodType.RESOURCE_LABEL && (

0 commit comments

Comments
 (0)