Invalid template metadata labels generated
See original GitHub issueDescription of the bug:
Consider the following cdk8s code:
import { Construct } from 'constructs';
import * as kplus from 'cdk8s-plus-22';
import { Chart, ChartProps } from 'cdk8s';
export const PodLabels = {
'custom-label-1': 'value1',
'custom-label-2': 'value2',
'custom-label-3': 'value3',
};
export class TestChart extends Chart {
constructor(scope: Construct, id: string, props: ChartProps = { }) {
super(scope, id, props);
const deployment1 = new kplus.Deployment(this, 'deployment1', {
metadata: {
name: `${id}-deployment1`,
namespace: 'testns',
},
podMetadata: {
labels: PodLabels,
}
});
deployment1.addContainer({
image: 'paulbouwer/hello-kubernetes',
port: 8080
});
const deployment2 = new kplus.Deployment(this, 'deployment2', {
metadata: {
name: `${id}-deployment2`,
namespace: 'testns',
},
podMetadata: {
labels: PodLabels,
}
});
deployment2.addContainer({
image: 'paulbouwer/hello-kubernetes',
port: 8080
});
}
}
The following template is generated where there’s invalid label cdk8s.deployment: testchart-deployment2-c87e348b
under the deployment 1.
apiVersion: apps/v1
kind: Deployment
metadata:
name: testchart-deployment1
namespace: testns
spec:
replicas: 1
selector:
matchLabels:
cdk8s.deployment: testchart-deployment1-c87d5b0d
template:
metadata:
labels:
cdk8s.deployment: testchart-deployment2-c87e348b
custom-label-1: value1
custom-label-2: value2
custom-label-3: value3
spec:
containers:
- env: []
image: paulbouwer/hello-kubernetes
imagePullPolicy: Always
name: main
ports:
- containerPort: 8080
volumeMounts: []
volumes: []
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: testchart-deployment2
namespace: testns
spec:
replicas: 1
selector:
matchLabels:
cdk8s.deployment: testchart-deployment2-c87e348b
template:
metadata:
labels:
cdk8s.deployment: testchart-deployment2-c87e348b
custom-label-1: value1
custom-label-2: value2
custom-label-3: value3
spec:
containers:
- env: []
image: paulbouwer/hello-kubernetes
imagePullPolicy: Always
name: main
ports:
- containerPort: 8080
volumeMounts: []
volumes: []
Reproduction Steps:
Error Log:
Environment:
- Framework Version: “cdk8s”: “^1.2.11”, “cdk8s-plus-22”: “^1.0.0-beta.62”,
- OS: macOS
Other:
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
spec.template.metadata.labels: Invalid value - Stack Overflow
The Deployment "moverick-mule-pre" is invalid: spec.selector: Required value; spec.template.metadata.labels: Invalid value: map[string]string{..
Read more >The Deployment myweb-rs is invalid spec template metadata ...
Hi Guys, I am trying to create deployment resource in minikube cluster. But it is showing me the ... match template `labels` How...
Read more >controller provisioning fails due to an invalid spec.selector
Message: StatefulSet.apps "controller-test" is invalid: [spec.selector: Required value, spec.template.metadata.labels: Invalid value: ...
Read more >Unwanted (and invalid) metadata.label when creating wftmpl ...
Summary When creating templates via argo template create a label is added to the workflowtemplate which is not in the yaml file.
Read more >Kubernetes Error Codes: Selector Does Not Match Template ...
This label isn't present in the pod metadata in the deployment's `template`, so the definition is invalid. In this case, the difference is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Chriscbr can you reopen the ticket or do I have to file a new one?
Thanks, Markus
@markusl I’m not actively working on cdk8s at the moment, so I don’t think I can help. @iliapolo might be able to answer, otherwise I’d try asking on the cdk.dev slack. 🙏