-
Notifications
You must be signed in to change notification settings - Fork 670
Console 2271: allow for configuring upstream server for air gapped envs #9957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| import * as React from 'react'; | ||
|
|
||
| import { ClusterVersionModel } from '../../models'; | ||
| import { ClusterVersionKind, k8sPatch } from '../../module/k8s'; | ||
| import { | ||
| ModalBody, | ||
| ModalComponentProps, | ||
| ModalSubmitFooter, | ||
| ModalTitle, | ||
| createModalLauncher, | ||
| } from '../factory/modal'; | ||
| import { ExternalLink, HandlePromiseProps, withHandlePromise } from '../utils'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { TFunction } from 'i18next'; | ||
| import { RadioInput } from '../radio'; | ||
| import { CLUSTER_VERSION_DEFAULT_UPSTREAM_SERVER_URL_PLACEHOLDER } from '@console/shared/src/constants'; | ||
| import { TextInput } from '@patternfly/react-core'; | ||
| import { openshiftHelpBase } from '@console/internal/components/utils'; | ||
|
|
||
| export const ConfigureClusterUpstreamModal = withHandlePromise( | ||
| (props: ConfigureClusterUpstreamModalProps) => { | ||
| const { cv, handlePromise, close } = props; | ||
| const currentUpstream = cv?.spec?.upstream; | ||
|
|
||
| const [customSelected, setCustomSelected] = React.useState(!!currentUpstream); | ||
| const [customURL, setCustomURL] = React.useState(currentUpstream); | ||
| const [invalidCustomURL, setInvalidCustomURL] = React.useState(false); | ||
|
|
||
| const submit: React.FormEventHandler<HTMLFormElement> = (e) => { | ||
| e.preventDefault(); | ||
| if (customSelected) { | ||
| if (!customURL) { | ||
| setInvalidCustomURL(true); | ||
| return; | ||
| } else if (customURL === currentUpstream) { | ||
| return handlePromise(Promise.resolve(), close); | ||
spadgett marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } else if (!currentUpstream) { | ||
| return handlePromise(Promise.resolve(), close); | ||
| } | ||
| const value = customSelected ? customURL : null; | ||
| const patch = [{ op: 'add', path: '/spec/upstream', value }]; | ||
| return handlePromise(k8sPatch(ClusterVersionModel, cv, patch), close); | ||
| }; | ||
| const { t } = useTranslation(); | ||
|
|
||
| return ( | ||
| <form onSubmit={submit} name="form" className="modal-content modal-content--no-inner-scroll"> | ||
| <ModalTitle>{t('public~Edit upstream configuration')}</ModalTitle> | ||
| <ModalBody> | ||
| <p> | ||
| {t( | ||
| 'public~Select a configuration to receive updates. Updates can be configured to receive information from Red Hat or a custom update service.', | ||
| )} | ||
| </p> | ||
| <p> | ||
| <ExternalLink | ||
| href={`${openshiftHelpBase}updating/installing-update-service.html`} | ||
| text={t('public~Learn more about OpenShift local update services.')} | ||
| /> | ||
| </p> | ||
| <div className="form-group"> | ||
| <fieldset> | ||
| <label>{t('public~Configuration')}</label> | ||
| <RadioInput | ||
| value="default" | ||
| onChange={() => { | ||
| setCustomSelected(false); | ||
| setInvalidCustomURL(false); | ||
| }} | ||
| checked={!customSelected} | ||
| title={t('public~Default. Receive update information from Red Hat.')} | ||
| > | ||
| <TextInput | ||
| id={'cluster-version-default-upstream-server-url'} | ||
| type="url" | ||
| isReadOnly | ||
| isDisabled | ||
| value={CLUSTER_VERSION_DEFAULT_UPSTREAM_SERVER_URL_PLACEHOLDER} | ||
| /> | ||
| </RadioInput> | ||
| <RadioInput | ||
| value="custom" | ||
| onChange={() => setCustomSelected(true)} | ||
| checked={customSelected} | ||
| title={t('public~Custom update service.')} | ||
| > | ||
| <TextInput | ||
| id={'cluster-version-custom-upstream-server-url'} | ||
| type="url" | ||
| placeholder="https://example.com/api/upgrades_info/v1/graph" | ||
| value={customURL} | ||
| onChange={(text) => { | ||
| setCustomSelected(true); | ||
| setCustomURL(text); | ||
| setInvalidCustomURL(false); | ||
| }} | ||
| validated={invalidCustomURL ? 'error' : 'default'} | ||
| /> | ||
| {invalidCustomURL && ( | ||
| <div className="pf-c-form"> | ||
| <div className="pf-c-form__helper-text pf-m-error"> | ||
| {t('public~Please enter a URL')} | ||
| </div> | ||
| </div> | ||
| )} | ||
| </RadioInput> | ||
| </fieldset> | ||
| </div> | ||
| </ModalBody> | ||
| <ModalSubmitFooter | ||
| errorMessage={props.errorMessage} | ||
| inProgress={props.inProgress} | ||
| submitText={t('public~Save')} | ||
| cancel={props.cancel} | ||
| submitDisabled={invalidCustomURL} | ||
| /> | ||
| </form> | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| export const configureClusterUpstreamModal = createModalLauncher(ConfigureClusterUpstreamModal); | ||
|
|
||
| export type ConfigureClusterUpstreamModalProps = { | ||
| cv: ClusterVersionKind; | ||
| t: TFunction; | ||
| } & ModalComponentProps & | ||
| HandlePromiseProps; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,8 @@ import { | |
| referenceFor, | ||
| Toleration, | ||
| } from '../../module/k8s'; | ||
| import { labelsModal } from '../modals'; | ||
| import { configureClusterUpstreamModal, labelsModal } from '../modals'; | ||
| import { ClusterVersionModel } from '../../models'; | ||
|
|
||
| const editLabelsModal = (e, props) => { | ||
| e.preventDefault(); | ||
|
|
@@ -193,6 +194,43 @@ export const RuntimeClass: React.FC<RuntimeClassProps> = ({ obj, path }) => { | |
| ); | ||
| }; | ||
|
|
||
| export const UpstreamConfigDetailsItem: React.SFC<UpstreamConfigDetailsItemProps> = ({ | ||
| resource, | ||
| }) => { | ||
| const { t } = useTranslation(); | ||
| // TODO this specific RBAC is duplicated across several modals and pages | ||
| const clusterVersionIsEditable = | ||
| useAccessReview({ | ||
| group: ClusterVersionModel.apiGroup, | ||
| resource: ClusterVersionModel.plural, | ||
| verb: 'patch', | ||
| name: resource?.metadata?.name, | ||
| }) && window.SERVER_FLAGS.branding !== 'dedicated'; | ||
| return ( | ||
| <DetailsItem label={t('public~Upstream configuration')} obj={resource} path="spec.upstream"> | ||
| <div> | ||
| <Button | ||
| type="button" | ||
| isInline | ||
| data-test-id="cluster-version-upstream-server-url" | ||
| onClick={(e) => { | ||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
| clusterVersionIsEditable && configureClusterUpstreamModal({ cv: resource }); | ||
| }} | ||
| variant="link" | ||
| isDisabled={!clusterVersionIsEditable} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this still render as a link or does PF render a disabled button with variant="link" as normal text? If not, I think this is OK for now, but something we probably want to change in a follow up.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @spadgett it renders a disabled button with variant="link". The text is grey versus blue: |
||
| > | ||
| {resource?.spec?.upstream || t('public~Default update server')} | ||
| {clusterVersionIsEditable && ( | ||
| <PencilAltIcon className="co-icon-space-l pf-c-button-icon--plain" /> | ||
| )} | ||
| </Button> | ||
| </div> | ||
| </DetailsItem> | ||
| ); | ||
| }; | ||
|
|
||
| export type ResourceSummaryProps = { | ||
| resource: K8sResourceKind; | ||
| showPodSelector?: boolean; | ||
|
|
@@ -211,6 +249,10 @@ export type ResourcePodCountProps = { | |
| resource: K8sResourceKind; | ||
| }; | ||
|
|
||
| export type UpstreamConfigDetailsItemProps = { | ||
| resource: K8sResourceKind; | ||
| }; | ||
|
|
||
| export type RuntimeClassProps = { | ||
| obj: K8sResourceCommon; | ||
| path?: string; | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spadgett for clarification, there are three scenarios (kudos to @wking):
https://example.com/some/custom/thingThis PR will treat 1 as the default case and 2/3 as custom case. The value in this constant is used for display purposes only and will never be sent to the backend.