keep labels on edit ingress, configmaps and secrets (#11050)

pull/11077/head
Prabhat Khera 2024-02-05 16:30:36 +13:00 committed by GitHub
parent 9ad78753bc
commit a2195caa10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 21 additions and 2 deletions

View File

@ -241,7 +241,10 @@ func (kcl *KubeClient) DeleteIngresses(reqs models.K8sIngressDeleteRequests) err
// UpdateIngress updates an existing ingress in a given namespace in a k8s endpoint.
func (kcl *KubeClient) UpdateIngress(namespace string, info models.K8sIngressInfo) error {
ingressClient := kcl.cli.NetworkingV1().Ingresses(namespace)
var ingress netv1.Ingress
ingress, err := ingressClient.Get(context.Background(), info.Name, metav1.GetOptions{})
if err != nil {
return err
}
ingress.Name = info.Name
ingress.Namespace = info.Namespace
@ -299,6 +302,6 @@ func (kcl *KubeClient) UpdateIngress(namespace string, info models.K8sIngressInf
}
}
_, err := ingressClient.Update(context.Background(), &ingress, metav1.UpdateOptions{})
_, err = ingressClient.Update(context.Background(), ingress, metav1.UpdateOptions{})
return err
}

View File

@ -38,6 +38,7 @@ class KubernetesConfigMapConverter {
res.ConfigurationOwner = data.metadata.labels ? data.metadata.labels[KubernetesPortainerConfigurationOwnerLabel] : '';
res.CreationDate = data.metadata.creationTimestamp;
res.Yaml = yaml ? yaml.data : '';
res.Labels = data.metadata.labels;
res.Data = _.concat(
_.map(data.data, (value, key) => {
@ -98,6 +99,7 @@ class KubernetesConfigMapConverter {
res.metadata.uid = data.Id;
res.metadata.name = data.Name;
res.metadata.namespace = data.Namespace;
res.metadata.labels = data.Labels || {};
res.metadata.labels[KubernetesPortainerConfigurationOwnerLabel] = data.ConfigurationOwner;
_.forEach(data.Data, (entry) => {
if (entry.IsBinary) {

View File

@ -21,6 +21,7 @@ class KubernetesConfigurationConverter {
if (secret.Annotations) {
res.ServiceAccountName = secret.Annotations['kubernetes.io/service-account.name'];
}
res.Labels = secret.Labels;
return res;
}
@ -37,6 +38,7 @@ class KubernetesConfigurationConverter {
});
res.data = res.Data;
res.ConfigurationOwner = configMap.ConfigurationOwner;
res.Labels = configMap.Labels;
return res;
}
}

View File

@ -39,6 +39,7 @@ class KubernetesSecretConverter {
res.metadata.name = secret.Name;
res.metadata.namespace = secret.Namespace;
res.type = secret.Type;
res.metadata.labels = secret.Labels || {};
res.metadata.labels[KubernetesPortainerConfigurationOwnerLabel] = secret.ConfigurationOwner;
let annotation = '';
@ -67,6 +68,7 @@ class KubernetesSecretConverter {
res.Name = payload.metadata.name;
res.Namespace = payload.metadata.namespace;
res.Type = payload.type;
res.Labels = payload.metadata.labels || {};
res.ConfigurationOwner = payload.metadata.labels ? payload.metadata.labels[KubernetesPortainerConfigurationOwnerLabel] : '';
res.CreationDate = payload.metadata.creationTimestamp;
res.Annotations = payload.metadata.annotations;

View File

@ -21,6 +21,7 @@ const _KubernetesConfigMap = Object.freeze({
Yaml: '',
ConfigurationOwner: '',
Data: [],
Labels: {},
});
export class KubernetesConfigMap {

View File

@ -14,6 +14,7 @@ const _KubernetesConfigurationFormValues = Object.freeze({
IsSimple: true,
ServiceAccountName: '',
Type: KubernetesSecretTypeOptions.OPAQUE.value,
Labels: {},
});
export class KubernetesConfigurationFormValues {

View File

@ -12,6 +12,7 @@ const _KubernetesApplicationSecret = Object.freeze({
Data: [],
SecretType: '',
Annotations: [],
Labels: {},
});
export class KubernetesApplicationSecret {

View File

@ -82,10 +82,12 @@ class KubernetesConfigurationService {
if (formValues.Kind === KubernetesConfigurationKinds.CONFIGMAP) {
const configMap = KubernetesConfigMapConverter.configurationFormValuesToConfigMap(formValues);
configMap.ConfigurationOwner = configuration.ConfigurationOwner;
configMap.Labels = configuration.Labels;
await this.KubernetesConfigMapService.update(configMap);
} else {
const secret = KubernetesSecretConverter.configurationFormValuesToSecret(formValues);
secret.ConfigurationOwner = configuration.ConfigurationOwner;
secret.Labels = configuration.Labels;
await this.KubernetesSecretService.update(secret);
}
}

View File

@ -159,6 +159,7 @@ class KubernetesConfigMapController {
this.formValues.Type = this.configuration.Type;
this.formValues.Kind = this.configuration.Kind;
this.oldDataYaml = this.formValues.DataYaml;
this.formValues.Labels = this.configuration.Labels;
return this.configuration;
} catch (err) {

View File

@ -155,6 +155,7 @@ class KubernetesSecretController {
this.formValues.Type = this.configuration.Type;
this.formValues.Kind = this.configuration.Kind;
this.oldDataYaml = this.formValues.DataYaml;
this.formValues.Labels = this.configuration.Labels;
return this.configuration;
} catch (err) {

View File

@ -828,6 +828,7 @@ export function CreateIngressView() {
Paths: preparePaths(rule.IngressName, rule.Hosts),
TLS: prepareTLS(rule.Hosts),
Annotations: prepareAnnotations(rule.Annotations || []),
Labels: rule.Labels,
};
if (isEdit) {

View File

@ -28,6 +28,7 @@ export interface Rule {
Hosts: Host[];
Annotations?: Annotation[];
IngressType?: string;
Labels?: Record<string, string>;
}
export interface ServicePorts {

View File

@ -104,6 +104,7 @@ export function prepareRuleFromIngress(
Hosts: prepareRuleHostsFromIngress(ing) || [],
Annotations: ing.Annotations ? getAnnotationsForEdit(ing.Annotations) : [],
IngressType: ing.Type,
Labels: ing.Labels,
};
}