mirror of https://github.com/portainer/portainer
keep labels on edit ingress, configmaps and secrets (#11050)
parent
9ad78753bc
commit
a2195caa10
|
@ -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.
|
// UpdateIngress updates an existing ingress in a given namespace in a k8s endpoint.
|
||||||
func (kcl *KubeClient) UpdateIngress(namespace string, info models.K8sIngressInfo) error {
|
func (kcl *KubeClient) UpdateIngress(namespace string, info models.K8sIngressInfo) error {
|
||||||
ingressClient := kcl.cli.NetworkingV1().Ingresses(namespace)
|
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.Name = info.Name
|
||||||
ingress.Namespace = info.Namespace
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ class KubernetesConfigMapConverter {
|
||||||
res.ConfigurationOwner = data.metadata.labels ? data.metadata.labels[KubernetesPortainerConfigurationOwnerLabel] : '';
|
res.ConfigurationOwner = data.metadata.labels ? data.metadata.labels[KubernetesPortainerConfigurationOwnerLabel] : '';
|
||||||
res.CreationDate = data.metadata.creationTimestamp;
|
res.CreationDate = data.metadata.creationTimestamp;
|
||||||
res.Yaml = yaml ? yaml.data : '';
|
res.Yaml = yaml ? yaml.data : '';
|
||||||
|
res.Labels = data.metadata.labels;
|
||||||
|
|
||||||
res.Data = _.concat(
|
res.Data = _.concat(
|
||||||
_.map(data.data, (value, key) => {
|
_.map(data.data, (value, key) => {
|
||||||
|
@ -98,6 +99,7 @@ class KubernetesConfigMapConverter {
|
||||||
res.metadata.uid = data.Id;
|
res.metadata.uid = data.Id;
|
||||||
res.metadata.name = data.Name;
|
res.metadata.name = data.Name;
|
||||||
res.metadata.namespace = data.Namespace;
|
res.metadata.namespace = data.Namespace;
|
||||||
|
res.metadata.labels = data.Labels || {};
|
||||||
res.metadata.labels[KubernetesPortainerConfigurationOwnerLabel] = data.ConfigurationOwner;
|
res.metadata.labels[KubernetesPortainerConfigurationOwnerLabel] = data.ConfigurationOwner;
|
||||||
_.forEach(data.Data, (entry) => {
|
_.forEach(data.Data, (entry) => {
|
||||||
if (entry.IsBinary) {
|
if (entry.IsBinary) {
|
||||||
|
|
|
@ -21,6 +21,7 @@ class KubernetesConfigurationConverter {
|
||||||
if (secret.Annotations) {
|
if (secret.Annotations) {
|
||||||
res.ServiceAccountName = secret.Annotations['kubernetes.io/service-account.name'];
|
res.ServiceAccountName = secret.Annotations['kubernetes.io/service-account.name'];
|
||||||
}
|
}
|
||||||
|
res.Labels = secret.Labels;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +38,7 @@ class KubernetesConfigurationConverter {
|
||||||
});
|
});
|
||||||
res.data = res.Data;
|
res.data = res.Data;
|
||||||
res.ConfigurationOwner = configMap.ConfigurationOwner;
|
res.ConfigurationOwner = configMap.ConfigurationOwner;
|
||||||
|
res.Labels = configMap.Labels;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ class KubernetesSecretConverter {
|
||||||
res.metadata.name = secret.Name;
|
res.metadata.name = secret.Name;
|
||||||
res.metadata.namespace = secret.Namespace;
|
res.metadata.namespace = secret.Namespace;
|
||||||
res.type = secret.Type;
|
res.type = secret.Type;
|
||||||
|
res.metadata.labels = secret.Labels || {};
|
||||||
res.metadata.labels[KubernetesPortainerConfigurationOwnerLabel] = secret.ConfigurationOwner;
|
res.metadata.labels[KubernetesPortainerConfigurationOwnerLabel] = secret.ConfigurationOwner;
|
||||||
|
|
||||||
let annotation = '';
|
let annotation = '';
|
||||||
|
@ -67,6 +68,7 @@ class KubernetesSecretConverter {
|
||||||
res.Name = payload.metadata.name;
|
res.Name = payload.metadata.name;
|
||||||
res.Namespace = payload.metadata.namespace;
|
res.Namespace = payload.metadata.namespace;
|
||||||
res.Type = payload.type;
|
res.Type = payload.type;
|
||||||
|
res.Labels = payload.metadata.labels || {};
|
||||||
res.ConfigurationOwner = payload.metadata.labels ? payload.metadata.labels[KubernetesPortainerConfigurationOwnerLabel] : '';
|
res.ConfigurationOwner = payload.metadata.labels ? payload.metadata.labels[KubernetesPortainerConfigurationOwnerLabel] : '';
|
||||||
res.CreationDate = payload.metadata.creationTimestamp;
|
res.CreationDate = payload.metadata.creationTimestamp;
|
||||||
res.Annotations = payload.metadata.annotations;
|
res.Annotations = payload.metadata.annotations;
|
||||||
|
|
|
@ -21,6 +21,7 @@ const _KubernetesConfigMap = Object.freeze({
|
||||||
Yaml: '',
|
Yaml: '',
|
||||||
ConfigurationOwner: '',
|
ConfigurationOwner: '',
|
||||||
Data: [],
|
Data: [],
|
||||||
|
Labels: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
export class KubernetesConfigMap {
|
export class KubernetesConfigMap {
|
||||||
|
|
|
@ -14,6 +14,7 @@ const _KubernetesConfigurationFormValues = Object.freeze({
|
||||||
IsSimple: true,
|
IsSimple: true,
|
||||||
ServiceAccountName: '',
|
ServiceAccountName: '',
|
||||||
Type: KubernetesSecretTypeOptions.OPAQUE.value,
|
Type: KubernetesSecretTypeOptions.OPAQUE.value,
|
||||||
|
Labels: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
export class KubernetesConfigurationFormValues {
|
export class KubernetesConfigurationFormValues {
|
||||||
|
|
|
@ -12,6 +12,7 @@ const _KubernetesApplicationSecret = Object.freeze({
|
||||||
Data: [],
|
Data: [],
|
||||||
SecretType: '',
|
SecretType: '',
|
||||||
Annotations: [],
|
Annotations: [],
|
||||||
|
Labels: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
export class KubernetesApplicationSecret {
|
export class KubernetesApplicationSecret {
|
||||||
|
|
|
@ -82,10 +82,12 @@ class KubernetesConfigurationService {
|
||||||
if (formValues.Kind === KubernetesConfigurationKinds.CONFIGMAP) {
|
if (formValues.Kind === KubernetesConfigurationKinds.CONFIGMAP) {
|
||||||
const configMap = KubernetesConfigMapConverter.configurationFormValuesToConfigMap(formValues);
|
const configMap = KubernetesConfigMapConverter.configurationFormValuesToConfigMap(formValues);
|
||||||
configMap.ConfigurationOwner = configuration.ConfigurationOwner;
|
configMap.ConfigurationOwner = configuration.ConfigurationOwner;
|
||||||
|
configMap.Labels = configuration.Labels;
|
||||||
await this.KubernetesConfigMapService.update(configMap);
|
await this.KubernetesConfigMapService.update(configMap);
|
||||||
} else {
|
} else {
|
||||||
const secret = KubernetesSecretConverter.configurationFormValuesToSecret(formValues);
|
const secret = KubernetesSecretConverter.configurationFormValuesToSecret(formValues);
|
||||||
secret.ConfigurationOwner = configuration.ConfigurationOwner;
|
secret.ConfigurationOwner = configuration.ConfigurationOwner;
|
||||||
|
secret.Labels = configuration.Labels;
|
||||||
await this.KubernetesSecretService.update(secret);
|
await this.KubernetesSecretService.update(secret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,6 +159,7 @@ class KubernetesConfigMapController {
|
||||||
this.formValues.Type = this.configuration.Type;
|
this.formValues.Type = this.configuration.Type;
|
||||||
this.formValues.Kind = this.configuration.Kind;
|
this.formValues.Kind = this.configuration.Kind;
|
||||||
this.oldDataYaml = this.formValues.DataYaml;
|
this.oldDataYaml = this.formValues.DataYaml;
|
||||||
|
this.formValues.Labels = this.configuration.Labels;
|
||||||
|
|
||||||
return this.configuration;
|
return this.configuration;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -155,6 +155,7 @@ class KubernetesSecretController {
|
||||||
this.formValues.Type = this.configuration.Type;
|
this.formValues.Type = this.configuration.Type;
|
||||||
this.formValues.Kind = this.configuration.Kind;
|
this.formValues.Kind = this.configuration.Kind;
|
||||||
this.oldDataYaml = this.formValues.DataYaml;
|
this.oldDataYaml = this.formValues.DataYaml;
|
||||||
|
this.formValues.Labels = this.configuration.Labels;
|
||||||
|
|
||||||
return this.configuration;
|
return this.configuration;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -828,6 +828,7 @@ export function CreateIngressView() {
|
||||||
Paths: preparePaths(rule.IngressName, rule.Hosts),
|
Paths: preparePaths(rule.IngressName, rule.Hosts),
|
||||||
TLS: prepareTLS(rule.Hosts),
|
TLS: prepareTLS(rule.Hosts),
|
||||||
Annotations: prepareAnnotations(rule.Annotations || []),
|
Annotations: prepareAnnotations(rule.Annotations || []),
|
||||||
|
Labels: rule.Labels,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isEdit) {
|
if (isEdit) {
|
||||||
|
|
|
@ -28,6 +28,7 @@ export interface Rule {
|
||||||
Hosts: Host[];
|
Hosts: Host[];
|
||||||
Annotations?: Annotation[];
|
Annotations?: Annotation[];
|
||||||
IngressType?: string;
|
IngressType?: string;
|
||||||
|
Labels?: Record<string, string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ServicePorts {
|
export interface ServicePorts {
|
||||||
|
|
|
@ -104,6 +104,7 @@ export function prepareRuleFromIngress(
|
||||||
Hosts: prepareRuleHostsFromIngress(ing) || [],
|
Hosts: prepareRuleHostsFromIngress(ing) || [],
|
||||||
Annotations: ing.Annotations ? getAnnotationsForEdit(ing.Annotations) : [],
|
Annotations: ing.Annotations ? getAnnotationsForEdit(ing.Annotations) : [],
|
||||||
IngressType: ing.Type,
|
IngressType: ing.Type,
|
||||||
|
Labels: ing.Labels,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue