cdk8s-team / cdk8s

Define Kubernetes native apps and abstractions using object-oriented programming

Home Page:https://cdk8s.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setting namespace for Helm construct

erikschul opened this issue · comments

Description of the bug:

When importing a Helm chart, the namespace is not set/forced on objects.

Reproduction Steps:

** Chart **

import { Chart, ChartProps, Helm } from "cdk8s"
import { Construct } from "constructs"

export class CoreDNSChart extends Chart {
	constructor(scope: Construct, id: string, props: ChartProps = {}) {
		super(scope, id, props)

		new Helm(this, "helm", {
			chart: "coredns/coredns",
			releaseName: "coredns",
			namespace: "kube-system",
			values: {
				fullnameOverride: "coredns",
				serviceAccount: {
					create: true
				},
				service: {
					clusterIP: "10.96.0.10"
				},
				replicaCount: 2
			},
			helmFlags: ["--namespace", "kube-system"]
		})
	}
}

produces YAML missing metadata.namespace:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/instance: coredns
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: coredns
    app.kubernetes.io/version: 1.11.1
    helm.sh/chart: coredns-1.26.0
    k8s-app: coredns
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: CoreDNS
  name: coredns
spec:
  ...

Hack solution
This can be solved by setting the namespace on the chart. But it may be relevant to specify a different namespace on objects.
Maybe one hack-solution is to create a new Chart, set namespace, then use it as a scope for the Helm object.

Error Log:

Environment:

  • Framework Version: 2.56.0
  • OS:

Other:


This is 🐛 Bug Report

Related: #675

Closing because I conclude that this is a parameter passed to helm, i.e. the problem is with helm or the underlying template not using the value properly.

The cdk8s solution is to wrap it in a chart.