kubernetes-cd-plugin icon indicating copy to clipboard operation
kubernetes-cd-plugin copied to clipboard

Expecting to have "Kubernetes Namespace for Secret" support system variable

Open grantsunny opened this issue 5 years ago • 3 comments

We currently have pipeline create and deploy services in namespaces according the branch-name and we found there is a small gap prevent us to make things perfect.

That is, when I run the whole stuff in default namespace I am able to leverage $KUBERNETES_SECRET_NAME but when I am using system variable as the name of namespaces dynamically and deploy things inside the namespace, I found I just cannot use system variable in the field "Kubernetes Namespace for Secret" field.

apiVersion: v1
kind: Namespace
metadata:
  name: ${KUBERNETES_NS}
  labels:
    name: ${KUBERNETES_NS}

And I put ${KUBERNETES_NS} in the configuration field "Kubernetes Namespace for Secret" but it seems this configuration does not honor the system parameters configuration.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: sample-k8s-deployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: sample-k8s-app
    spec:
      containers:
      - name: sample-k8s-app-container
        image: <username or registry URL>/<image_name>:<tag(maybe $BUILD_NUMBER)>
        ports:
        - containerPort: 8080
      imagePullSecrets:
      - name: $KUBERNETES_SECRET_NAME

Will appreciate if anyone could have a look and provide a suggestion on this. Thank you!

grantsunny avatar Jun 03 '19 12:06 grantsunny

I have the same problem.

max464 avatar Oct 25 '19 14:10 max464

In my opinion, the problem with the variables is even bigger. We habe a Jenkins job with a choice parameter for selecting the customer. In my GIT repository, i have YAML files per customer (each one in a subdirectory with the customer name), so I want so put ${CUSTOMER}/kubernetes.yaml to the field where the config file is specified. But unfortunately, the plugin does not support variables in this field. So please add support for variables in all plugin fields, so the plugin finally becomes usable.

gutschet avatar Sep 14 '20 13:09 gutschet

Today i had the same problem. After some research i found issue #53.

If you have a variable that you want to use inside the config, you should define it as env.VARIABLE_OF_CHOICHE = "value". Then you can use $VARIABLE_OF_CHOICHE in the kubernetes config.

@gutschet I think in your situation you could do this. You dont have to define it as an environment variable because that is for using it inside the file. For using variables inside strings make sure you use double qoutes. kubernetesDeploy(configs: "${CUSTOMER}/fj-producties.yaml", kubeconfigId: "your-kubeconfig")

ricklambrechts avatar Oct 14 '20 22:10 ricklambrechts