Skip to content

Commit b76f604

Browse files
committed
Decouple InfraEnv Details and Create Page
1 parent e596899 commit b76f604

59 files changed

Lines changed: 2541 additions & 844 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

libs/locales/lib/en/translation.json

Lines changed: 113 additions & 98 deletions
Large diffs are not rendered by default.

libs/ui-lib-tests/cypress/integration/storage/storage-step-disk-holders.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe(`Assisted Installer Storage Step`, () => {
5555

5656
storageForm.diskFormattingAlert.title.should(
5757
'contain.text',
58-
'Warning alert:All bootable disks, except for read-only disks, will be formatted during installation. Make sure to back up any critical data before proceeding.',
58+
'Warning alert:All bootable disks, except for read-only disks, will be formatted during installation. Make sure to back up any sensitive data before proceeding.',
5959
);
6060
});
6161

libs/ui-lib/lib/cim/components/Agent/BMCForm.tsx

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,13 @@ import {
5353
AGENT_BMH_NAME_LABEL_KEY,
5454
BMH_HOSTNAME_ANNOTATION,
5555
INFRAENV_AGENTINSTALL_LABEL_KEY,
56-
} from '../common';
56+
} from '../common/constants';
5757
import { getErrorMessage } from '../../../common/utils';
5858
import { useTranslation } from '../../../common/hooks/use-translation-wrapper';
59+
import { getBareMetalHostCredentialsSecret } from '../modals/utils';
60+
import { k8sCreate, k8sPatch, Patch } from '@openshift-console/dynamic-plugin-sdk';
61+
import { appendPatch } from '../../utils';
62+
import { BMHModel, NMStateModel, SecretModel } from '../../types/models';
5963

6064
type MacMappingFieldProps = { macAddress: string; name: string }[];
6165

@@ -232,8 +236,100 @@ const getInitValues = (
232236
return values;
233237
};
234238

239+
export const onCreateBMH = async ({
240+
values,
241+
infraEnv,
242+
nmState,
243+
secret,
244+
bmh,
245+
}: {
246+
values: AddBmcValues;
247+
infraEnv: InfraEnvK8sResource;
248+
nmState?: NMStateK8sResource;
249+
secret?: SecretK8sResource;
250+
bmh?: BareMetalHostK8sResource;
251+
}) => {
252+
let newSecret: SecretK8sResource | undefined = undefined;
253+
if (secret) {
254+
const patches: Patch[] = [];
255+
appendPatch(patches, '/data/username', btoa(values.username), secret.data?.username);
256+
appendPatch(patches, '/data/password', btoa(values.password), secret.data?.password);
257+
if (patches.length) {
258+
await k8sPatch({
259+
model: SecretModel,
260+
resource: secret,
261+
data: patches,
262+
});
263+
}
264+
} else {
265+
const secret = getBareMetalHostCredentialsSecret(values, bmh?.metadata?.namespace || '');
266+
newSecret = await k8sCreate<SecretK8sResource>({
267+
model: SecretModel,
268+
data: secret,
269+
});
270+
}
271+
272+
const formNMState = values.nmState ? getNMState(values, infraEnv) : undefined;
273+
if (nmState) {
274+
const patches: Patch[] = [];
275+
appendPatch(patches, '/spec/config', formNMState?.spec?.config, nmState.spec?.config);
276+
appendPatch(
277+
patches,
278+
'/spec/interfaces',
279+
nmState?.spec?.interfaces || [],
280+
nmState.spec?.interfaces,
281+
);
282+
if (patches.length) {
283+
await k8sPatch({
284+
model: NMStateModel,
285+
resource: nmState,
286+
data: patches,
287+
});
288+
}
289+
} else if (formNMState) {
290+
await k8sCreate({
291+
model: NMStateModel,
292+
data: formNMState,
293+
});
294+
}
295+
296+
if (bmh) {
297+
const patches: Patch[] = [];
298+
appendPatch(
299+
patches,
300+
`/metadata/annotations/${BMH_HOSTNAME_ANNOTATION.replace('/', '~1')}`,
301+
values.hostname,
302+
bmh.metadata?.annotations?.[BMH_HOSTNAME_ANNOTATION],
303+
);
304+
appendPatch(patches, '/spec/bmc/address', values.bmcAddress, bmh.spec?.bmc?.address);
305+
appendPatch(
306+
patches,
307+
'/spec/bmc/disableCertificateVerification',
308+
values.disableCertificateVerification,
309+
bmh.spec?.bmc?.disableCertificateVerification,
310+
);
311+
appendPatch(patches, '/spec/bootMACAddress', values.bootMACAddress, bmh.spec?.bootMACAddress);
312+
appendPatch(patches, '/spec/online', values.online, bmh.spec?.online);
313+
314+
if (newSecret) {
315+
appendPatch(
316+
patches,
317+
'/spec/bmc/credentialsName',
318+
newSecret.metadata?.name,
319+
bmh.spec?.bmc?.credentialsName,
320+
);
321+
}
322+
if (patches.length) {
323+
await k8sPatch({
324+
model: BMHModel,
325+
resource: bmh,
326+
data: patches,
327+
});
328+
}
329+
}
330+
};
331+
235332
const BMCForm: React.FC<BMCFormProps> = ({
236-
onCreateBMH,
237333
onClose,
238334
hasDHCP,
239335
infraEnv,
@@ -249,7 +345,13 @@ const BMCForm: React.FC<BMCFormProps> = ({
249345
try {
250346
setError(undefined);
251347
const nmState = values.nmState ? getNMState(values, infraEnv) : undefined;
252-
await onCreateBMH(values, nmState);
348+
await onCreateBMH({
349+
values,
350+
infraEnv,
351+
nmState,
352+
secret,
353+
bmh,
354+
});
253355
onClose();
254356
} catch (e) {
255357
setError(getErrorMessage(e));

libs/ui-lib/lib/cim/components/Agent/tableUtils.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ export const agentStatusColumn = ({
188188
export const clusterColumn = (
189189
agents: AgentK8sResource[],
190190
agentMachines: AgentMachineK8sResource[],
191-
getClusterDeploymentLink: (cd: { name: string; namespace: string }) => string,
192191
t: TFunction,
193192
): TableRow<Host> => {
194193
return {
@@ -215,10 +214,10 @@ export const clusterColumn = (
215214
if (nodePool) {
216215
const hcNamespace = nodePool.split('/')[0];
217216
const hcName = agent.spec.clusterDeploymentName.name;
218-
cdLink = getClusterDeploymentLink({ name: hcName, namespace: hcNamespace });
217+
cdLink = `/multicloud/infrastructure/clusters/details/${hcNamespace}/${hcName}`;
219218
}
220219
} else {
221-
cdLink = getClusterDeploymentLink(agent.spec.clusterDeploymentName);
220+
cdLink = `/multicloud/infrastructure/clusters/details/${agent.spec.clusterDeploymentName.namespace}/${agent.spec.clusterDeploymentName.name}`;
222221
}
223222
}
224223
return {
@@ -429,7 +428,7 @@ export const useAgentsTable = (
429428
? (host: Host) => {
430429
const agent = agents.find((a) => a.metadata?.uid === host.id);
431430
const bmh = bmhs?.find((a) => a.metadata?.uid === host.id);
432-
return onDeleteHost(agent, bmh);
431+
return onDeleteHost({ agent, bmh });
433432
}
434433
: undefined,
435434
canDelete: (host: Host) => {

libs/ui-lib/lib/cim/components/Agent/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ export type AddBmcValues = {
1717

1818
export type BMCFormProps = {
1919
onClose: VoidFunction;
20-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
21-
onCreateBMH: (values: AddBmcValues, nmState?: NMStateK8sResource) => Promise<any>;
2220
hasDHCP: boolean;
2321
infraEnv: InfraEnvK8sResource;
2422
usedHostnames: string[];

libs/ui-lib/lib/cim/components/ClusterDeployment/ClusterDeploymentHostDiscoveryTable.tsx

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
ChangeHostnameAction,
2525
MassChangeHostnameModal,
2626
TableToolbar,
27+
LoadingState,
2728
} from '../../../common';
2829
import { ClusterDeploymentHostDiscoveryTableProps } from '../ClusterDeployment/types';
2930
import MassApproveAgentModal from '../modals/MassApproveAgentModal';
@@ -34,25 +35,47 @@ import { ExpandComponent } from '../Agent/AgentsSelectionTable';
3435
import { HostsTableDetailContextProvider } from '../../../common/components/hosts/HostsTableDetailContext';
3536
import { agentStatus, bmhStatus } from '../helpers/agentStatus';
3637
import { onAgentChangeHostname } from '../helpers';
38+
import {
39+
AgentClusterInstallK8sResource,
40+
AgentK8sResource,
41+
BareMetalHostK8sResource,
42+
} from '../../types';
43+
import DeleteHostModal from '../modals/DeleteHostModal';
44+
import { useInfraEnvNMStates } from '../../hooks/useInfraEnvNMStates';
45+
import { AgentClusterInstallModel } from '../../types/models';
46+
import { useParams } from 'react-router-dom-v5-compat';
47+
import { useK8sWatchResource } from '../../hooks/useK8sWatchResource';
3748

3849
const ClusterDeploymentHostDiscoveryTable: React.FC<ClusterDeploymentHostDiscoveryTableProps> = ({
3950
agents,
4051
bareMetalHosts,
4152
infraEnv,
42-
onApprove,
43-
onChangeHostname,
44-
onChangeBMHHostname,
4553
onEditRole,
4654
onSetInstallationDiskId,
4755
onEditHost,
4856
onEditBMH,
49-
onDeleteHost,
5057
width,
5158
}) => {
59+
const { name = '', namespace = '' } = useParams<{ name: string; namespace: string }>();
60+
const [deleteHost, setDeleteHost] = React.useState<{
61+
agent?: AgentK8sResource;
62+
bmh?: BareMetalHostK8sResource;
63+
}>();
5264
const [isDiscoveryHintModalOpen, setDiscoveryHintModalOpen] = React.useState(false);
5365
const [isMassChangeHostOpen, setMassChangeHostOpen] = React.useState(false);
5466
const [isMassApproveOpen, setMassApproveOpen] = React.useState(false);
5567
const [selectedHostIDs, setSelectedHostIDs] = React.useState<string[]>([]);
68+
const [nmStates, nmLoaded] = useInfraEnvNMStates(infraEnv);
69+
const [agentClusterInstall, aciLoaded] = useK8sWatchResource<AgentClusterInstallK8sResource>({
70+
groupVersionKind: {
71+
kind: AgentClusterInstallModel.kind,
72+
version: AgentClusterInstallModel.apiVersion,
73+
group: AgentClusterInstallModel.apiGroup,
74+
},
75+
name: name,
76+
namespace: namespace,
77+
isList: false,
78+
});
5679

5780
const { t } = useTranslation();
5881
const agentStatuses = agentStatus(t);
@@ -72,7 +95,7 @@ const ClusterDeploymentHostDiscoveryTable: React.FC<ClusterDeploymentHostDiscove
7295
bmhs: bareMetalHosts,
7396
infraEnv,
7497
},
75-
{ onEditHost, onEditRole, onEditBMH, onDeleteHost, onSetInstallationDiskId },
98+
{ onEditHost, onEditRole, onEditBMH, onDeleteHost: setDeleteHost, onSetInstallationDiskId },
7699
);
77100

78101
const addAll = width && width > 700;
@@ -87,7 +110,6 @@ const ClusterDeploymentHostDiscoveryTable: React.FC<ClusterDeploymentHostDiscove
87110
bareMetalHosts,
88111
bmhStatuses,
89112
onEditHostname: onEditHost,
90-
onApprove,
91113
wizardStepId: 'hosts-discovery',
92114
t,
93115
}),
@@ -107,7 +129,6 @@ const ClusterDeploymentHostDiscoveryTable: React.FC<ClusterDeploymentHostDiscove
107129
agentStatuses,
108130
bmhStatuses,
109131
onEditHost,
110-
onApprove,
111132
],
112133
);
113134

@@ -128,6 +149,10 @@ const ClusterDeploymentHostDiscoveryTable: React.FC<ClusterDeploymentHostDiscove
128149
const paginationProps = usePagination(hosts.length);
129150
const itemIDs = hosts.map((h) => h.id);
130151

152+
if (!nmLoaded || aciLoaded) {
153+
return <LoadingState />;
154+
}
155+
131156
return (
132157
<>
133158
<Stack hasGutter>
@@ -171,12 +196,7 @@ const ClusterDeploymentHostDiscoveryTable: React.FC<ClusterDeploymentHostDiscove
171196
isOpen={isMassChangeHostOpen}
172197
hosts={hosts}
173198
selectedHostIDs={selectedHostIDs}
174-
onChangeHostname={onAgentChangeHostname(
175-
agents,
176-
bareMetalHosts,
177-
onChangeHostname,
178-
onChangeBMHHostname,
179-
)}
199+
onChangeHostname={onAgentChangeHostname(agents, bareMetalHosts)}
180200
onClose={() => setMassChangeHostOpen(false)}
181201
canChangeHostname={canChangeHostname(agents, agentStatuses, bareMetalHosts, t)}
182202
/>
@@ -185,10 +205,17 @@ const ClusterDeploymentHostDiscoveryTable: React.FC<ClusterDeploymentHostDiscove
185205
<MassApproveAgentModal
186206
isOpen={isMassApproveOpen}
187207
agents={selectedAgents}
188-
onApprove={onApprove}
189208
onClose={() => setMassApproveOpen(false)}
190209
/>
191210
)}
211+
{deleteHost && (
212+
<DeleteHostModal
213+
{...deleteHost}
214+
onClose={() => setDeleteHost(undefined)}
215+
nmStates={nmStates}
216+
agentClusterInstall={agentClusterInstall}
217+
/>
218+
)}
192219
</>
193220
);
194221
};

libs/ui-lib/lib/cim/components/ClusterDeployment/ClusterDeploymentHostsDiscovery.tsx

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,8 @@ const ClusterDeploymentHostsDiscovery: React.FC<ClusterDeploymentHostsDiscoveryP
5757
infraEnv,
5858
infraNMStates,
5959
usedHostnames,
60-
onChangeHostname,
6160
onEditRole,
6261
onSetInstallationDiskId,
63-
onSaveBMH,
64-
fetchSecret,
65-
onChangeBMHHostname,
66-
onApproveAgent,
67-
onDeleteHost,
6862
...rest
6963
}) => {
7064
const [isDiscoveryHintModalOpen, setDiscoveryHintModalOpen] = React.useState(false);
@@ -119,36 +113,26 @@ const ClusterDeploymentHostsDiscovery: React.FC<ClusterDeploymentHostsDiscoveryP
119113
onEditRole={onEditRole}
120114
onSetInstallationDiskId={onSetInstallationDiskId}
121115
onEditBMH={setEditBMH}
122-
onChangeHostname={onChangeHostname}
123-
onChangeBMHHostname={onChangeBMHHostname}
124-
onApprove={onApproveAgent}
125116
width={contentRect.bounds?.width}
126-
onDeleteHost={onDeleteHost}
127117
/>
128118
</div>
129119
)}
130120
</Measure>
131-
<EditBMHModal
132-
infraEnv={infraEnv}
133-
bmh={editBMH}
134-
nmStates={infraNMStates}
135-
isOpen={!!editBMH}
136-
onClose={() => setEditBMH(undefined)}
137-
onEdit={onSaveBMH}
138-
fetchSecret={fetchSecret}
139-
usedHostnames={usedHostnames || []}
140-
/>
121+
{editBMH && (
122+
<EditBMHModal
123+
infraEnv={infraEnv}
124+
bmh={editBMH}
125+
nmStates={infraNMStates}
126+
onClose={() => setEditBMH(undefined)}
127+
usedHostnames={usedHostnames || []}
128+
/>
129+
)}
141130
{editAgent && (
142131
<EditAgentModal
143132
onClose={() => setEditAgent(undefined)}
144133
usedHostnames={usedHostnames}
145134
agent={editAgent}
146-
onSave={onAgentChangeHostname(
147-
agents,
148-
bareMetalHosts,
149-
onChangeHostname,
150-
onChangeBMHHostname,
151-
)}
135+
onSave={onAgentChangeHostname(agents, bareMetalHosts)}
152136
/>
153137
)}
154138
</GridItem>

0 commit comments

Comments
 (0)