mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-26 14:49:26 +08:00
Vidya reddy/prettier code (#203)
This commit is contained in:
@@ -1,71 +1,73 @@
|
||||
import {
|
||||
InputObjectKindNotDefinedError,
|
||||
isServiceEntity,
|
||||
KubernetesWorkload,
|
||||
NullInputObjectError,
|
||||
} from "../types/kubernetesTypes";
|
||||
InputObjectKindNotDefinedError,
|
||||
isServiceEntity,
|
||||
KubernetesWorkload,
|
||||
NullInputObjectError
|
||||
} from '../types/kubernetesTypes'
|
||||
|
||||
export function updateSpecLabels(
|
||||
inputObject: any,
|
||||
newLabels: Map<string, string>,
|
||||
override: boolean
|
||||
inputObject: any,
|
||||
newLabels: Map<string, string>,
|
||||
override: boolean
|
||||
) {
|
||||
if (!inputObject) throw NullInputObjectError;
|
||||
if (!inputObject) throw NullInputObjectError
|
||||
|
||||
if (!inputObject.kind) throw InputObjectKindNotDefinedError;
|
||||
if (!inputObject.kind) throw InputObjectKindNotDefinedError
|
||||
|
||||
if (!newLabels) return;
|
||||
if (!newLabels) return
|
||||
|
||||
let existingLabels = getSpecLabels(inputObject);
|
||||
if (override) {
|
||||
existingLabels = newLabels;
|
||||
} else {
|
||||
existingLabels = existingLabels || new Map<string, string>();
|
||||
Object.keys(newLabels).forEach(
|
||||
(key) => (existingLabels[key] = newLabels[key])
|
||||
);
|
||||
}
|
||||
let existingLabels = getSpecLabels(inputObject)
|
||||
if (override) {
|
||||
existingLabels = newLabels
|
||||
} else {
|
||||
existingLabels = existingLabels || new Map<string, string>()
|
||||
Object.keys(newLabels).forEach(
|
||||
(key) => (existingLabels[key] = newLabels[key])
|
||||
)
|
||||
}
|
||||
|
||||
setSpecLabels(inputObject, existingLabels);
|
||||
setSpecLabels(inputObject, existingLabels)
|
||||
}
|
||||
|
||||
function getSpecLabels(inputObject: any) {
|
||||
if (!inputObject) return null;
|
||||
if (!inputObject) return null
|
||||
|
||||
if (inputObject.kind.toLowerCase() === KubernetesWorkload.POD.toLowerCase())
|
||||
return inputObject.metadata.labels;
|
||||
if (inputObject.kind.toLowerCase() === KubernetesWorkload.POD.toLowerCase())
|
||||
return inputObject.metadata.labels
|
||||
|
||||
if (inputObject?.spec?.template?.metadata)
|
||||
return inputObject.spec.template.metadata.labels;
|
||||
if (inputObject?.spec?.template?.metadata)
|
||||
return inputObject.spec.template.metadata.labels
|
||||
|
||||
return null;
|
||||
return null
|
||||
}
|
||||
|
||||
function setSpecLabels(inputObject: any, newLabels: any) {
|
||||
if (!inputObject || !newLabels) return null;
|
||||
if (!inputObject || !newLabels) return null
|
||||
|
||||
if (inputObject.kind.toLowerCase() === KubernetesWorkload.POD.toLowerCase()) {
|
||||
inputObject.metadata.labels = newLabels;
|
||||
return;
|
||||
}
|
||||
if (
|
||||
inputObject.kind.toLowerCase() === KubernetesWorkload.POD.toLowerCase()
|
||||
) {
|
||||
inputObject.metadata.labels = newLabels
|
||||
return
|
||||
}
|
||||
|
||||
if (inputObject?.spec?.template?.metatada) {
|
||||
inputObject.spec.template.metatada.labels = newLabels;
|
||||
return;
|
||||
}
|
||||
if (inputObject?.spec?.template?.metatada) {
|
||||
inputObject.spec.template.metatada.labels = newLabels
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
export function getSpecSelectorLabels(inputObject: any) {
|
||||
if (inputObject?.spec?.selector) {
|
||||
if (isServiceEntity(inputObject.kind)) return inputObject.spec.selector;
|
||||
else return inputObject.spec.selector.matchLabels;
|
||||
}
|
||||
if (inputObject?.spec?.selector) {
|
||||
if (isServiceEntity(inputObject.kind)) return inputObject.spec.selector
|
||||
else return inputObject.spec.selector.matchLabels
|
||||
}
|
||||
}
|
||||
|
||||
export function setSpecSelectorLabels(inputObject: any, newLabels: any) {
|
||||
if (inputObject?.spec?.selector) {
|
||||
if (isServiceEntity(inputObject.kind))
|
||||
inputObject.spec.selector = newLabels;
|
||||
else inputObject.spec.selector.matchLabels = newLabels;
|
||||
}
|
||||
if (inputObject?.spec?.selector) {
|
||||
if (isServiceEntity(inputObject.kind))
|
||||
inputObject.spec.selector = newLabels
|
||||
else inputObject.spec.selector.matchLabels = newLabels
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user