question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid template metadata labels generated

See original GitHub issue

Description 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:open
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
markuslcommented, Feb 23, 2022

@Chriscbr can you reopen the ticket or do I have to file a new one?

Thanks, Markus

0reactions
Chriscbrcommented, Nov 24, 2022

@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. 🙏

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found