diff --git a/src/brokers/add-broker/AddBroker.container.tsx b/src/brokers/add-broker/AddBroker.container.tsx index 1e11d906..7ff95622 100644 --- a/src/brokers/add-broker/AddBroker.container.tsx +++ b/src/brokers/add-broker/AddBroker.container.tsx @@ -13,6 +13,7 @@ import { } from '../../reducers/7.12/reducer'; import { AddBrokerResourceValues } from '../../reducers/7.12/import-types'; import { useNavigate, useParams } from 'react-router-dom-v5-compat'; +import { UseGetIngressDomain } from '../../k8s/customHooks'; export interface AddBrokerProps { initialValues: AddBrokerResourceValues; @@ -54,6 +55,16 @@ export const AddBrokerPage: FC = () => { setPrevNamespace(namespace); } + const { clusterDomain, isLoading } = UseGetIngressDomain(); + const [isDomainSet, setIsDomainSet] = useState(false); + if (!isLoading && !isDomainSet) { + dispatch({ + operation: ArtemisReducerOperations.setIngressDomain, + payload: clusterDomain, + }); + setIsDomainSet(true); + } + return ( diff --git a/src/brokers/update-broker/UpdateBroker.container.tsx b/src/brokers/update-broker/UpdateBroker.container.tsx index 78c8090d..e86a4c07 100644 --- a/src/brokers/update-broker/UpdateBroker.container.tsx +++ b/src/brokers/update-broker/UpdateBroker.container.tsx @@ -5,6 +5,7 @@ import { AddBroker } from '../add-broker/AddBroker.component'; import { Loading } from '../../shared-components/Loading/Loading'; import { AMQBrokerModel } from '../../k8s/models'; import { BrokerCR } from '../../k8s/types'; +import { UseGetIngressDomain } from '../../k8s/customHooks'; import { ArtemisReducerOperations, BrokerCreationFormDispatch, @@ -20,7 +21,7 @@ export const UpdateBrokerPage: FC = () => { //states const [notification, setNotification] = useState(defaultNotification); - const [loading, setLoading] = useState(false); + const [loadingBrokerCR, setLoading] = useState(false); const crState = getArtemisCRState(name, namespace); @@ -69,7 +70,18 @@ export const UpdateBrokerPage: FC = () => { if (name) k8sGetBroker(); }, [name]); - if (loading && !notification.title) return ; + const { clusterDomain, isLoading: isLoadingClusterDomain } = + UseGetIngressDomain(); + const [isDomainSet, setIsDomainSet] = useState(false); + if (!loadingBrokerCR && !isLoadingClusterDomain && !isDomainSet) { + dispatch({ + operation: ArtemisReducerOperations.setIngressDomain, + payload: clusterDomain, + }); + setIsDomainSet(true); + } + + if (loadingBrokerCR && !notification.title) return ; if (!brokerModel.cr.spec?.deploymentPlan) { return ; diff --git a/src/k8s/customHooks.ts b/src/k8s/customHooks.ts new file mode 100644 index 00000000..4c85a7df --- /dev/null +++ b/src/k8s/customHooks.ts @@ -0,0 +1,36 @@ +import { useState } from 'react'; +import { Ingress } from './types'; +import { k8sGet } from '@openshift-console/dynamic-plugin-sdk'; +import { IngressDomainModel } from './models'; + +export const UseGetIngressDomain = (): { + clusterDomain: string; + isLoading: boolean; + error: string; +} => { + const [domain, setDomain] = useState(''); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(''); + + const k8sGetBroker = () => { + setLoading(true); + k8sGet({ model: IngressDomainModel, name: 'cluster' }) + .then((ing: Ingress) => { + setDomain(ing.spec.domain); + }) + .catch((e) => { + setError(e.message); + }) + .finally(() => { + setLoading(false); + }); + }; + + const [isFirstMount, setIsFirstMount] = useState(true); + if (isFirstMount) { + k8sGetBroker(); + setIsFirstMount(false); + } + + return { clusterDomain: domain, isLoading: loading, error: error }; +}; diff --git a/src/k8s/models.ts b/src/k8s/models.ts index 7f83c92d..dddef4a0 100644 --- a/src/k8s/models.ts +++ b/src/k8s/models.ts @@ -68,3 +68,14 @@ export const SecretModel: K8sModel = { namespaced: false, crd: true, }; + +export const IngressDomainModel: K8sModel = { + apiGroup: 'config.openshift.io', + apiVersion: 'v1', + kind: 'Ingress', + label: 'ingress', + plural: 'ingresses', + labelPlural: 'ingresses', + abbr: 'I', + namespaced: false, +}; diff --git a/src/k8s/types.ts b/src/k8s/types.ts index a9cb7143..7b989e35 100644 --- a/src/k8s/types.ts +++ b/src/k8s/types.ts @@ -132,3 +132,14 @@ export type SecretResource = K8sResource & { 'tls.key'?: string; }; }; + +export type Ingress = K8sResource & { + spec: { + domain: string; + loadBalancer: { + platform: { + type: string; + }; + }; + }; +}; diff --git a/src/reducers/7.12/reducer.test.ts b/src/reducers/7.12/reducer.test.ts index 54d47a92..937f3954 100644 --- a/src/reducers/7.12/reducer.test.ts +++ b/src/reducers/7.12/reducer.test.ts @@ -616,7 +616,11 @@ describe('test the creation broker reducer', () => { const stateWith1Acceptor = artemisCrReducer(initialState, { operation: ArtemisReducerOperations.addAcceptor, }); - const stateWithPEM = artemisCrReducer(stateWith1Acceptor, { + const stateWithIngressDomain = artemisCrReducer(stateWith1Acceptor, { + operation: ArtemisReducerOperations.setIngressDomain, + payload: 'apps-crc.testing', + }); + const stateWithPEM = artemisCrReducer(stateWithIngressDomain, { operation: ArtemisReducerOperations.activatePEMGenerationForAcceptor, payload: { acceptor: 'acceptors0', diff --git a/src/reducers/7.12/reducer.ts b/src/reducers/7.12/reducer.ts index 9729e2fd..30107379 100644 --- a/src/reducers/7.12/reducer.ts +++ b/src/reducers/7.12/reducer.ts @@ -62,7 +62,7 @@ export const newArtemisCRState = (namespace: string): FormState => { spec: { adminUser: 'admin', adminPassword: 'admin', - ingressDomain: 'apps-crc.testing', + ingressDomain: '', console: { expose: true, }, diff --git a/src/shared-components/FormView/FormView.tsx b/src/shared-components/FormView/FormView.tsx index aa5ccea1..0cf98fcf 100644 --- a/src/shared-components/FormView/FormView.tsx +++ b/src/shared-components/FormView/FormView.tsx @@ -183,20 +183,6 @@ export const FormView: FC = ({ plusBtnAriaLabel="plus" /> - - - dispatch({ - operation: ArtemisReducerOperations.setIngressDomain, - payload: v, - }) - } - /> -