-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update registry configuration page (#20)
Jira: EPMDPEDP-12729 Related: #20 Change-Id: Ibca04824cc5c1649a67b2db8c932e505a1f3a6ce
- Loading branch information
1 parent
b22e65b
commit deb4d9e
Showing
87 changed files
with
3,564 additions
and
784 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
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
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', | ||
}; |
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,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, | ||
], | ||
}; |
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,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 }; | ||
}; |
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,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; | ||
}; |
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,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); | ||
} | ||
} |
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 @@ | ||
export const REQUEST_KEY_QUERY_CONFIG_MAP_LIST = 'REQUEST_KEY_QUERY_CONFIG_MAP_LIST'; |
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,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; | ||
} |
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,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; | ||
}; |
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.