Container deployment using .jinja template file

11/20/2018

I am trying to deploy containers within a .jinja file, I am aware this can be done using a .yaml file but desire my deployment to be done from a single .yaml file calling multiple .jinja files.

This is what I currently have in my .jinja file for container deployment:

resources:
- name: test-cluster
  type: container.v1.cluster
  properties:
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.7.9
            ports:
            - containerPort: 80

and I currently receive the error:

ERROR: (gcloud.deployment-manager.deployments.create) Error in Operation [operation-1542747397856-57b1edea09b01-d7bff680-2f96dfe0]: errors:
- code: CONDITION_NOT_MET
  location: /deployments/deployment-test/resources/test-cluster->$.properties->$.cluster.name
  message: |-
    InputMapping for field [cluster.name] for method [create] could not be set from input, mapping was: [$.ifNull($.resource.properties.cluster.name, $.resource.name)
-- user10190803
containers
google-cloud-platform
google-kubernetes-engine
jinja2
yaml

1 Answer

11/23/2018

This github repo is an example of what you're trying to accomplish as a whole. Note in the file cluster.jinja, under properties, there is a list called "cluster" that specifies properties of the cluster itself like the node count etc. copy/pasted below. In the file you've presented, you are specifying the container.v1.cluster type but you are not specifying what's implied by that type (what's necessary to create the cluster). The error is indicating the program is looking for "cluster: name: {{ CLUSTER_NAME }}" but it is not present.You will need something similar to below for the container.v1.cluster type.

resources:
- name: {{ CLUSTER_NAME }}
type: container.v1.cluster
properties:
    zone: {{ properties['zone'] }}
    cluster:
      name: {{ CLUSTER_NAME }}
      initialNodeCount: {{ properties['initialNodeCount'] }}
      nodeConfig:...

There is another file in that github repo called deployment.jinja that contains syntax for deploying pods. You should try to replicate something similar to that file for specifying the pods

-- xavierc
Source: StackOverflow