Skip to content

Commit

Permalink
feat: Update registry configuration page (#20)
Browse files Browse the repository at this point in the history
Jira: EPMDPEDP-12729
Related: #20
Change-Id: Ibca04824cc5c1649a67b2db8c932e505a1f3a6ce
  • Loading branch information
callmevladik committed Oct 20, 2023
1 parent b22e65b commit deb4d9e
Show file tree
Hide file tree
Showing 87 changed files with 3,564 additions and 784 deletions.
3 changes: 3 additions & 0 deletions mocks/headlamp-plugin/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const K8s = {
serviceAccount: {
default: Resource,
},
configMap: {
default: Resource,
},
};

export { ApiProxy, K8s, Utils, Router };
23 changes: 17 additions & 6 deletions src/constants/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,27 +251,38 @@ export const EDP_OPERATOR_GUIDE = {
url: `${EDP_OPERATOR_GUIDE_ROOT_URL}/nexus-sonatype`,
anchors: {
PREREQUISITES: {
url: `${EDP_USER_GUIDE_ROOT_URL}/nexus-sonatype/#prerequisites`,
url: `${EDP_OPERATOR_GUIDE_ROOT_URL}/nexus-sonatype/#prerequisites`,
},
INSTALLATION: {
url: `${EDP_USER_GUIDE_ROOT_URL}/nexus-sonatype/#installation`,
url: `${EDP_OPERATOR_GUIDE_ROOT_URL}/nexus-sonatype/#installation`,
},
CONFIGURATION: {
url: `${EDP_USER_GUIDE_ROOT_URL}/nexus-sonatype/#configuration`,
url: `${EDP_OPERATOR_GUIDE_ROOT_URL}/nexus-sonatype/#configuration`,
},
},
},
SONAR: {
url: `${EDP_OPERATOR_GUIDE_ROOT_URL}/sonarqube`,
anchors: {
PREREQUISITES: {
url: `${EDP_USER_GUIDE_ROOT_URL}/sonarqube/#prerequisites`,
url: `${EDP_OPERATOR_GUIDE_ROOT_URL}/sonarqube/#prerequisites`,
},
INSTALLATION: {
url: `${EDP_USER_GUIDE_ROOT_URL}/sonarqube/#installation`,
url: `${EDP_OPERATOR_GUIDE_ROOT_URL}/sonarqube/#installation`,
},
CONFIGURATION: {
url: `${EDP_USER_GUIDE_ROOT_URL}/sonarqube/#configuration`,
url: `${EDP_OPERATOR_GUIDE_ROOT_URL}/sonarqube/#configuration`,
},
},
},
CONTAINER_REGISTRY_HARBOR: {
url: `${EDP_OPERATOR_GUIDE_ROOT_URL}/container-registry-harbor-integration-tekton-ci/`,
anchors: {
OVERVIEW: {
url: `${EDP_OPERATOR_GUIDE_ROOT_URL}/container-registry-harbor-integration-tekton-ci/#overview`,
},
INTEGRATION_PROCEDURE: {
url: `${EDP_OPERATOR_GUIDE_ROOT_URL}/container-registry-harbor-integration-tekton-ci/#integration-procedure`,
},
},
},
Expand Down
10 changes: 10 additions & 0 deletions src/k8s/ConfigMap/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { KubeObjectConfig } from '../../types/configs/k8s';

export const ConfigMapKubeObjectConfig: KubeObjectConfig = {
kind: 'ConfigMap',
name: {
singularForm: 'configmap',
pluralForm: 'configmaps',
},
version: 'v1',
};
27 changes: 27 additions & 0 deletions src/k8s/ConfigMap/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export const EDP_CONFIG_CONFIG_MAP_NAME = 'edp-config';

export const CONTAINER_REGISTRY_PLATFORM = {
KUBERNETES: 'kubernetes',
OPENSHIFT: 'openshift',
} as const;

export const CONTAINER_REGISTRY_TYPE = {
ECR: 'ecr',
DOCKER_HUB: 'dockerhub',
HARBOR: 'harbor',
OPENSHIFT_REGISTRY: 'openshift',
} as const;

export const CONTAINER_REGISTRY_TYPE_BY_PLATFORM = {
[CONTAINER_REGISTRY_PLATFORM.KUBERNETES]: [
CONTAINER_REGISTRY_TYPE.ECR,
CONTAINER_REGISTRY_TYPE.DOCKER_HUB,
CONTAINER_REGISTRY_TYPE.HARBOR,
],
[CONTAINER_REGISTRY_PLATFORM.OPENSHIFT]: [
CONTAINER_REGISTRY_TYPE.ECR,
CONTAINER_REGISTRY_TYPE.DOCKER_HUB,
CONTAINER_REGISTRY_TYPE.HARBOR,
CONTAINER_REGISTRY_TYPE.OPENSHIFT_REGISTRY,
],
};
47 changes: 47 additions & 0 deletions src/k8s/ConfigMap/hooks/useConfigMapCRUD.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { K8s } from '@kinvolk/headlamp-plugin/lib';
import { KubeObjectInterface } from '@kinvolk/headlamp-plugin/lib/lib/k8s/cluster';
import React from 'react';
import { CRUD_TYPES } from '../../../constants/crudTypes';
import { useResourceCRUDMutation } from '../../../hooks/useResourceCRUDMutation';
import { ConfigMapKubeObjectInterface } from '../types';

interface EditConfigMapProps {
configMapData: ConfigMapKubeObjectInterface;
}

export const useConfigMapCRUD = ({
onSuccess,
onError,
}: {
onSuccess?: () => void;
onError?: () => void;
}) => {
const invokeOnSuccessCallback = React.useCallback(() => onSuccess && onSuccess(), [onSuccess]);
const invokeOnErrorCallback = React.useCallback(() => onError && onError(), [onError]);

const configMapEditMutation = useResourceCRUDMutation<KubeObjectInterface, CRUD_TYPES.EDIT>(
'configMapEditMutation',
K8s.configMap.default,
CRUD_TYPES.EDIT
);

const editConfigMap = React.useCallback(
async ({ configMapData }: EditConfigMapProps) => {
configMapEditMutation.mutate(configMapData, {
onSuccess: () => {
invokeOnSuccessCallback();
},
onError: () => {
invokeOnErrorCallback();
},
});
},
[configMapEditMutation, invokeOnSuccessCallback, invokeOnErrorCallback]
);

const mutations = {
configMapEditMutation,
};

return { editConfigMap, mutations };
};
31 changes: 31 additions & 0 deletions src/k8s/ConfigMap/hooks/useStreamCDPipelineStage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import { EDP_CONFIG_CONFIG_MAP_NAME } from '../constants';
import { ConfigMapKubeObject } from '../index';
import { ConfigMapKubeObjectInterface } from '../types';

interface UseStreamEDPConfigMapProps {
namespace: string;
}

export const useStreamEDPConfigMap = ({ namespace }: UseStreamEDPConfigMapProps) => {
const [EDPConfigMap, setEDPConfigMap] = React.useState<ConfigMapKubeObjectInterface>(null);

React.useEffect(() => {
const cancelStream = ConfigMapKubeObject.streamList({
namespace,
dataHandler: data => {
const EDPConfigMap = data.find(
item => item.metadata.name === EDP_CONFIG_CONFIG_MAP_NAME
);
setEDPConfigMap(EDPConfigMap);
},
errorHandler: error => console.error(error),
});

return () => {
cancelStream();
};
}, [namespace]);

return EDPConfigMap;
};
16 changes: 16 additions & 0 deletions src/k8s/ConfigMap/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { K8s } from '@kinvolk/headlamp-plugin/lib';
import { streamResults } from '../common/streamResults';
import { ConfigMapKubeObjectConfig } from './config';
import { StreamListProps } from './types';

const {
name: { pluralForm },
version,
} = ConfigMapKubeObjectConfig;

export class ConfigMapKubeObject extends K8s.configMap.default {
static streamList({ namespace, dataHandler, errorHandler }: StreamListProps): () => void {
const url = `/api/${version}/namespaces/${namespace}/${pluralForm}`;
return streamResults(url, dataHandler, errorHandler);
}
}
1 change: 1 addition & 0 deletions src/k8s/ConfigMap/requestKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const REQUEST_KEY_QUERY_CONFIG_MAP_LIST = 'REQUEST_KEY_QUERY_CONFIG_MAP_LIST';
9 changes: 9 additions & 0 deletions src/k8s/ConfigMap/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { KubeObjectInterface } from '@kinvolk/headlamp-plugin/lib/lib/k8s/cluster';

export interface ConfigMapKubeObjectInterface extends KubeObjectInterface {}

export interface StreamListProps {
namespace: string;
dataHandler: (data: ConfigMapKubeObjectInterface) => void;
errorHandler: (err: Error) => void;
}
27 changes: 27 additions & 0 deletions src/k8s/ConfigMap/utils/editEDPConfigConfigMap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { set } from 'lodash';
import { FormNameObject } from '../../../types/forms';
import { ConfigMapKubeObjectInterface } from '../types';

export const editEDPConfigConfigMap = (
names: {
[key: string]: FormNameObject;
},
currentConfigMap: ConfigMapKubeObjectInterface,
formValues: {
[key: string]: any;
}
): ConfigMapKubeObjectInterface => {
const base = { ...currentConfigMap };

for (const [propKey, propValue] of Object.entries(formValues)) {
console.log(propKey, propValue, names);
if (names[propKey]?.notUsedInFormData) {
continue;
}

const propPath = names[propKey].path;
set(base, propPath, propValue);
}

return base;
};
5 changes: 5 additions & 0 deletions src/k8s/Secret/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ export const INTEGRATION_SECRET_NAMES = {
SONAR: 'ci-sonarqube',
SSO: 'keycloak',
} as const;

export const REGISTRY_SECRET_NAMES = {
KANIKO_DOCKER_CONFIG: 'kaniko-docker-config',
REGCRED: 'regcred',
} as const;
22 changes: 22 additions & 0 deletions src/k8s/Secret/utils/createRegistrySecretInstance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,25 @@ export const createRegistrySecretInstance = ({
},
};
};

export const createECRSecretInstance = ({ name }: { name: string }): KubeObjectInterface => {
return {
apiVersion: 'v1',
kind: 'Secret',
// @ts-ignore
metadata: {
name,
labels: {
[SECRET_LABEL_SECRET_TYPE]: 'registry',
},
},
type: 'kubernetes.io/dockerconfigjson',
data: {
'.dockerconfigjson': safeEncode(
JSON.stringify({
credsStore: 'ecr-login',
})
),
},
};
};
Loading

0 comments on commit deb4d9e

Please sign in to comment.