mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
fix(configmap): create portainer configmap if it doesn't exist [r8s-141] (#113)
This commit is contained in:
parent
e6508140f8
commit
a2da6f1827
3 changed files with 61 additions and 7 deletions
|
@ -19,12 +19,27 @@ export function useUpdateK8sConfigMapMutation(
|
|||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
data,
|
||||
configMap,
|
||||
configMapName,
|
||||
}: {
|
||||
data: ConfigMap;
|
||||
configMap: ConfigMap;
|
||||
configMapName: string;
|
||||
}) => updateConfigMap(environmentId, namespace, configMapName, data),
|
||||
}) => {
|
||||
if (!configMap.metadata?.uid) {
|
||||
return createConfigMap(
|
||||
environmentId,
|
||||
namespace,
|
||||
configMapName,
|
||||
configMap
|
||||
);
|
||||
}
|
||||
return updateConfigMap(
|
||||
environmentId,
|
||||
namespace,
|
||||
configMapName,
|
||||
configMap
|
||||
);
|
||||
},
|
||||
...withInvalidate(queryClient, [
|
||||
configMapQueryKeys.configMaps(environmentId, namespace),
|
||||
]),
|
||||
|
@ -50,3 +65,22 @@ async function updateConfigMap(
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
function createConfigMap(
|
||||
environmentId: EnvironmentId,
|
||||
namespace: string,
|
||||
configMap: string,
|
||||
data: ConfigMap
|
||||
) {
|
||||
try {
|
||||
return axios.post(
|
||||
`/endpoints/${environmentId}/kubernetes/api/v1/namespaces/${namespace}/configmaps`,
|
||||
data
|
||||
);
|
||||
} catch (e) {
|
||||
throw parseKubernetesAxiosError(
|
||||
e,
|
||||
`Unable to create ConfigMap '${configMap}'`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue