Skip to content
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

[#226] better naming for generic resource #272

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/brokers/broker-pods/PodsList.container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
K8sResourceCommon,
useK8sWatchResource,
} from '@openshift-console/dynamic-plugin-sdk';
import { K8sResourceKind } from '../../k8s/types';
import { K8sResourceCommonWithData } from '../../k8s/types';
import { useTranslation } from '../../i18n/i18n';
import { PodsList } from './components/PodList';
import {
Expand All @@ -23,7 +23,7 @@ export const PodsContainer: FC = () => {
//states
const { t } = useTranslation();
const { ns: namespace, name } = useParams<{ ns?: string; name?: string }>();
const [brokerPods, setBrokerPods] = useState<K8sResourceKind[]>([]);
const [brokerPods, setBrokerPods] = useState<K8sResourceCommonWithData[]>([]);
const [loading, setLoading] = useState<boolean>(true);
const [pods, loaded, loadError] = useK8sWatchResource<K8sResourceCommon[]>({
groupVersionKind: {
Expand Down
9 changes: 5 additions & 4 deletions src/brokers/view-brokers/BrokersList.container.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState, FC } from 'react';
import { k8sListItems, k8sDelete } from '@openshift-console/dynamic-plugin-sdk';
import { AMQBrokerModel } from '../../k8s/models';
import { K8sResourceKind, BrokerCR } from '../../k8s/types';
import { K8sResourceCommonWithData, BrokerCR } from '../../k8s/types';
import { BrokersList } from './components/BrokersList/BrokersList';
import { PreConfirmDeleteModal } from './components/PreConfirmDeleteModal/PreConfirmDeleteModal';
import { useNavigate, useParams } from 'react-router-dom-v5-compat';
Expand All @@ -11,15 +11,16 @@ export const BrokersContainer: FC = () => {
const { ns: namespace } = useParams<{ ns?: string }>();

//states
const [brokers, setBrokers] = useState<K8sResourceKind[]>();
const [brokers, setBrokers] = useState<K8sResourceCommonWithData[]>();
const [loading, setLoading] = useState<boolean>(true);
const [loadError, setLoadError] = useState<any>();
const [isModalOpen, setIsModalOpen] = useState(false);
const [selectedBroker, setSelectedBroker] = useState<K8sResourceKind>();
const [selectedBroker, setSelectedBroker] =
useState<K8sResourceCommonWithData>();

const fetchK8sListItems = () => {
setLoading(false);
k8sListItems<K8sResourceKind>({
k8sListItems<K8sResourceCommonWithData>({
model: AMQBrokerModel,
queryParams: { ns: namespace },
})
Expand Down
12 changes: 6 additions & 6 deletions src/k8s/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExposeMode } from '../reducers/7.12/reducer';
import { K8sResourceCommon as K8sResource } from '@openshift-console/dynamic-plugin-sdk';
import { K8sResourceCommon } from '@openshift-console/dynamic-plugin-sdk';

export enum K8sResourceConditionStatus {
True = 'True',
Expand Down Expand Up @@ -79,7 +79,7 @@ export type ResourceTemplate = {
};
};

export type BrokerCR = K8sResource & {
export type BrokerCR = K8sResourceCommon & {
spec?: {
ingressDomain?: string;
connectors?: Connector[];
Expand All @@ -103,7 +103,7 @@ export type BrokerCR = K8sResource & {
status?: { [key: string]: any };
};

export type K8sResourceKind = BrokerCR & {
export type K8sResourceCommonWithData = K8sResourceCommon & {
data?: { [key: string]: any };
};

Expand All @@ -115,7 +115,7 @@ export enum BrokerConditionTypes {
TriggerChannelReady = 'TriggerChannelReady',
}

export type IssuerResource = K8sResource & {
export type IssuerResource = K8sResourceCommon & {
kind: 'Issuer';
spec?: {
ca?: {
Expand All @@ -124,7 +124,7 @@ export type IssuerResource = K8sResource & {
};
};

export type SecretResource = K8sResource & {
export type SecretResource = K8sResourceCommon & {
kind: 'Secret';
data?: {
'ca.crt'?: string;
Expand All @@ -133,7 +133,7 @@ export type SecretResource = K8sResource & {
};
};

export type Ingress = K8sResource & {
export type Ingress = K8sResourceCommon & {
spec: {
domain: string;
loadBalancer: {
Expand Down
9 changes: 2 additions & 7 deletions src/reducers/7.12/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { AddBrokerResourceValues as FormState } from './import-types';
import {
K8sResourceKind,
BrokerCR,
Acceptor,
ResourceTemplate,
} from '../../k8s/types';
import { BrokerCR, Acceptor, ResourceTemplate } from '../../k8s/types';
import { createContext } from 'react';
import { SelectOptionObject } from '@patternfly/react-core';
import { ConfigType } from '../../shared-components/FormView/BrokerProperties/ConfigurationPage/ConfigurationPage';
Expand Down Expand Up @@ -81,7 +76,7 @@ export const newArtemisCRState = (namespace: string): FormState => {
};
};

export const convertYamlToForm = (yamlBroker: K8sResourceKind) => {
export const convertYamlToForm = (yamlBroker: BrokerCR) => {
const { metadata } = yamlBroker;

const newFormData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
CertModel,
SecretModel,
} from '../../../../../k8s/models';
import { K8sResourceKind } from '../../../../../k8s/types';
import { K8sResourceCommonWithData } from '../../../../../k8s/types';
import {
k8sCreate,
useK8sWatchResource,
Expand Down Expand Up @@ -129,8 +129,8 @@ const useCreateSecretOptions = ({

type CreateSecretOptionsPropTypes = {
customOptions?: string[];
certManagerSecrets: K8sResourceKind[];
legacySecrets: K8sResourceKind[];
certManagerSecrets: K8sResourceCommonWithData[];
legacySecrets: K8sResourceCommonWithData[];
configType: ConfigType;
configName: string;
isCa: boolean;
Expand All @@ -153,7 +153,9 @@ export const CertSecretSelector: FC<CertSecretSelectorProps> = ({
const { cr } = useContext(BrokerCreationFormState);
const dispatch = useContext(BrokerCreationFormDispatch);

const [secrets, loaded, _loadError] = useK8sWatchResource<K8sResourceKind[]>({
const [secrets, loaded, _loadError] = useK8sWatchResource<
K8sResourceCommonWithData[]
>({
isList: true,
groupVersionKind: secretGroupVersionKind,
namespaced: true,
Expand Down Expand Up @@ -246,7 +248,7 @@ export const CertSecretSelector: FC<CertSecretSelectorProps> = ({

//Cert_annotation_key = "cert-manager.io/issuer-name"
//Bundle_annotation_key = "trust.cert-manager.io/hash"
const isCertSecret = (secret: K8sResourceKind): boolean => {
const isCertSecret = (secret: K8sResourceCommonWithData): boolean => {
if (!secret.metadata || !secret.metadata.annotations) {
return false;
}
Expand All @@ -273,7 +275,7 @@ export const CertSecretSelector: FC<CertSecretSelectorProps> = ({
return false;
};

const isLegacySecret = (secret: K8sResourceKind): boolean => {
const isLegacySecret = (secret: K8sResourceCommonWithData): boolean => {
return (
!(
secret.metadata?.annotations &&
Expand All @@ -287,8 +289,8 @@ export const CertSecretSelector: FC<CertSecretSelectorProps> = ({
};

const parseSecrets = (): {
certManagerSecrets: K8sResourceKind[];
legacySecrets: K8sResourceKind[];
certManagerSecrets: K8sResourceCommonWithData[];
legacySecrets: K8sResourceCommonWithData[];
} => {
const certSecrets = secrets.filter((x) => {
return isCertSecret(x);
Expand Down Expand Up @@ -319,7 +321,9 @@ export const CertSecretSelector: FC<CertSecretSelectorProps> = ({
setIsCertDetailsModalOpen(false);
};

const [certManagerDeployments] = useK8sWatchResource<K8sResourceKind[]>({
const [certManagerDeployments] = useK8sWatchResource<
K8sResourceCommonWithData[]
>({
isList: true,
groupVersionKind: {
group: 'apps',
Expand All @@ -330,7 +334,7 @@ export const CertSecretSelector: FC<CertSecretSelectorProps> = ({
namespace: 'cert-manager',
});

const [certIssuers] = useK8sWatchResource<K8sResourceKind[]>({
const [certIssuers] = useK8sWatchResource<K8sResourceCommonWithData[]>({
isList: true,
groupVersionKind: {
group: 'cert-manager.io',
Expand All @@ -341,7 +345,7 @@ export const CertSecretSelector: FC<CertSecretSelectorProps> = ({
namespace: namespace,
});

const [certs] = useK8sWatchResource<K8sResourceKind[]>({
const [certs] = useK8sWatchResource<K8sResourceCommonWithData[]>({
isList: true,
groupVersionKind: {
group: 'cert-manager.io',
Expand Down Expand Up @@ -452,8 +456,8 @@ export const CertSecretSelector: FC<CertSecretSelectorProps> = ({
});
};

const findSecret = (secName: string): K8sResourceKind => {
let result: K8sResourceKind = null;
const findSecret = (secName: string): K8sResourceCommonWithData => {
let result: K8sResourceCommonWithData = null;
for (let i = 0; i < secrets.length; i++) {
if (secrets[i].metadata.name === secName) {
result = secrets[i];
Expand All @@ -467,7 +471,7 @@ export const CertSecretSelector: FC<CertSecretSelectorProps> = ({
const tlsSecret = findSecret(caGenFromTlsSecret);
if (tlsSecret !== null) {
const caSecName = 'ca-' + caGenFromTlsSecret;
const caSecret: K8sResourceKind = {
const caSecret: K8sResourceCommonWithData = {
apiVersion: 'v1',
kind: 'Secret',
metadata: {
Expand Down
Loading