Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6150 from andrewballantyne/remaining-hpa
HPA In-Context (Delete | Edit | Topology Sidebar)
- Loading branch information
Showing
27 changed files
with
508 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,84 @@ | ||
import { history, KebabAction } from '@console/internal/components/utils'; | ||
import { K8sKind, K8sResourceCommon } from '@console/internal/module/k8s'; | ||
import { KebabAction } from '@console/internal/components/utils'; | ||
import { | ||
HorizontalPodAutoscalerKind, | ||
K8sKind, | ||
K8sResourceCommon, | ||
referenceForModel, | ||
} from '@console/internal/module/k8s'; | ||
import { HorizontalPodAutoscalerModel } from '@console/internal/models'; | ||
import deleteHPAModal from '@console/dev-console/src/components/hpa/DeleteHPAModal'; | ||
|
||
export const AddHorizontalPodAutoScaler: KebabAction = (kind: K8sKind, obj: K8sResourceCommon) => ({ | ||
type RelatedResources = { | ||
hpas?: HorizontalPodAutoscalerKind[]; | ||
}; | ||
|
||
const hasHPAs = (mapOfResources: RelatedResources) => | ||
Array.isArray(mapOfResources?.hpas) && mapOfResources.hpas.length > 0; | ||
|
||
const hpaRoute = ({ metadata: { name, namespace } }: K8sResourceCommon, kind: K8sKind) => | ||
`/workload-hpa/ns/${namespace}/${referenceForModel(kind)}/${name}`; | ||
|
||
export const AddHorizontalPodAutoScaler: KebabAction = ( | ||
kind: K8sKind, | ||
obj: K8sResourceCommon, | ||
resources: RelatedResources, | ||
) => ({ | ||
label: `Add ${HorizontalPodAutoscalerModel.label}`, | ||
href: hpaRoute(obj, kind), | ||
hidden: hasHPAs(resources), | ||
accessReview: { | ||
group: HorizontalPodAutoscalerModel.apiGroup, | ||
resource: HorizontalPodAutoscalerModel.plural, | ||
namespace: obj.metadata.namespace, | ||
verb: 'create', | ||
}, | ||
}); | ||
|
||
export const EditHorizontalPodAutoScaler: KebabAction = ( | ||
kind: K8sKind, | ||
obj: K8sResourceCommon, | ||
resources: RelatedResources, | ||
) => ({ | ||
label: `Edit ${HorizontalPodAutoscalerModel.label}`, | ||
href: hpaRoute(obj, kind), | ||
hidden: !hasHPAs(resources), | ||
accessReview: { | ||
group: HorizontalPodAutoscalerModel.apiGroup, | ||
resource: HorizontalPodAutoscalerModel.plural, | ||
namespace: obj.metadata.namespace, | ||
verb: 'update', | ||
}, | ||
}); | ||
|
||
export const DeleteHorizontalPodAutoScaler: KebabAction = ( | ||
kind: K8sKind, | ||
obj: K8sResourceCommon, | ||
resources: RelatedResources, | ||
) => ({ | ||
label: `Remove ${HorizontalPodAutoscalerModel.label}`, | ||
callback: () => { | ||
history.push(`/workload-hpa/ns/${obj.metadata.namespace}/${kind.kind}/${obj.metadata.name}`); | ||
deleteHPAModal({ | ||
workload: obj, | ||
hpa: resources?.hpas?.[0], | ||
}); | ||
}, | ||
hidden: !hasHPAs(resources), | ||
accessReview: { | ||
group: HorizontalPodAutoscalerModel.apiGroup, | ||
resource: HorizontalPodAutoscalerModel.plural, | ||
namespace: obj.metadata.namespace, | ||
verb: 'create', | ||
verb: 'delete', | ||
}, | ||
}); | ||
|
||
export const hideActionForHPAs = (action: KebabAction): KebabAction => ( | ||
kind: K8sKind, | ||
obj: K8sResourceCommon, | ||
resources: RelatedResources, | ||
) => { | ||
const actionOptions = action(kind, obj); | ||
return { | ||
...actionOptions, | ||
hidden: hasHPAs(resources) || actionOptions.hidden, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
frontend/packages/dev-console/src/components/hpa/DeleteHPAModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import * as React from 'react'; | ||
import { Form } from '@patternfly/react-core'; | ||
import { ExclamationTriangleIcon } from '@patternfly/react-icons'; | ||
import { global_warning_color_100 as warningColor } from '@patternfly/react-tokens'; | ||
import { | ||
createModalLauncher, | ||
ModalBody, | ||
ModalComponentProps, | ||
ModalSubmitFooter, | ||
ModalTitle, | ||
} from '@console/internal/components/factory/modal'; | ||
import { HorizontalPodAutoscalerModel } from '@console/internal/models'; | ||
import { LoadingInline } from '@console/internal/components/utils'; | ||
import { | ||
HorizontalPodAutoscalerKind, | ||
k8sKill, | ||
K8sResourceCommon, | ||
} from '@console/internal/module/k8s'; | ||
|
||
type DeleteHPAModalProps = ModalComponentProps & { | ||
hpa: HorizontalPodAutoscalerKind; | ||
workload: K8sResourceCommon; | ||
}; | ||
|
||
const DeleteHPAModal: React.FC<DeleteHPAModalProps> = ({ close, hpa, workload }) => { | ||
const [submitError, setSubmitError] = React.useState<string>(null); | ||
const [isSubmitting, setIsSubmitting] = React.useState<boolean>(false); | ||
const hpaName = hpa.metadata.name; | ||
const workloadName = workload.metadata.name; | ||
|
||
const handleSubmit = (e) => { | ||
e.preventDefault(); | ||
setIsSubmitting(true); | ||
k8sKill(HorizontalPodAutoscalerModel, hpa) | ||
.then(() => { | ||
close(); | ||
}) | ||
.catch((error) => { | ||
setSubmitError( | ||
error?.message || | ||
`Unknown error removing ${HorizontalPodAutoscalerModel.label} ${hpaName}.`, | ||
); | ||
}); | ||
}; | ||
|
||
return ( | ||
<Form onSubmit={handleSubmit}> | ||
<div className="modal-content"> | ||
<ModalTitle> | ||
<ExclamationTriangleIcon color={warningColor.value} /> Remove{' '} | ||
{HorizontalPodAutoscalerModel.label}? | ||
</ModalTitle> | ||
<ModalBody> | ||
{hpaName ? ( | ||
<> | ||
<p> | ||
Are you sure you want to remove the {HorizontalPodAutoscalerModel.label}{' '} | ||
<b>{hpaName}</b> from <b>{workloadName}</b>? | ||
</p> | ||
<p> | ||
The resources that are attached to the {HorizontalPodAutoscalerModel.label} will be | ||
deleted. | ||
</p> | ||
</> | ||
) : ( | ||
!submitError && <LoadingInline /> | ||
)} | ||
</ModalBody> | ||
<ModalSubmitFooter | ||
errorMessage={submitError} | ||
inProgress={isSubmitting} | ||
submitText="Remove" | ||
submitDanger | ||
submitDisabled={!!submitError} | ||
cancel={close} | ||
/> | ||
</div> | ||
</Form> | ||
); | ||
}; | ||
|
||
export default createModalLauncher(DeleteHPAModal); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.