Referencing output of a template

3/1/2018

I have a Deployment Manager script as follows: cluster.py creates a kubernetes cluster and when the script was run only for the k8 cluster creation, it was successful -- so it means the cluster.py had no issues in creation of a k8 cluster

cluster.py also exposes ouputs: A small snippet of the cluster.py is as follows:

outputs.append({
            'name': 'v1endpoint' ,
            'value': type_name + type_suffix })

return {'resources': resources, 'outputs': outputs}

If I try to access the exposed output inside dmnginxservice resource below as $(ref.dmcluster.v1endpoint) I get an error as resource not found

imports:
- path: cluster.py 
- path: nodeport.py

resources:
- name: dmcluster
  type: cluster.py
  properties:
   zone: us-central1-a

- name: dmnginxservice
  type: nodeport.py
  properties:
   cluster: $(ref.dmcluster.v1endpoint)
   image: gcr.io/pr1/nginx:latest
   port: 342
   nodeport: 32123



ERROR: (gcloud.deployment-manager.deployments.create) Error in Operation [operation-1519960432614-566655da89a70-a2f917ad-69eab05a]: errors:
- code: CONDITION_NOT_MET
  message: Referenced resource yaml%dmcluster could not be found. At resource
    gke-cluster-dmnginxservice.
-- Varunkumar Manohar
google-cloud-platform
google-deployment-manager
google-kubernetes-engine
python
yaml

1 Answer

3/2/2018

I tried to reproduce a similar implementation and I have been able to deploy it with no issues making use of your very same sintax for the output.

I deployed 2 VM and a new network. I will post you my code, maybe you find some interesting hints concerning the outputs.

  • The first VM pass as output the name for the second VM and use a reference from the network
  • The second VM takes the name from the properties that have been populated from the output of the first VM
  • the network thanks to the references is the first one to be created.

Keep in mind that:

This can get tricky because the order of creation for resources is important; you cannot add virtual machine instances to a network that does not exist, or attach non-existent persistent disks. Furthermore, by default, Deployment Manager creates all resources in parallel, so there is no guarantee that dependent resources are created in the correct order.

I will skip that is the same. If you provide your code I could try to help you to debug it, but from the error code it seems that the DM is not aware that the first element has been created, but from the info provided is not clear why.

Moreover if I were you I would give a shot to explicitly set that dmnginxservice depends on dmcluster making use of the metadata. In this way you can double check if it is actually waiting the first resource.

UPDATE

I have been able to reproduce the bug with a simpler configuration basically depending on how I reference the variables, the behaviour is different and for some reason the property get expanded to $(ref.yaml%vm-1.paolo), it seems that the combination of project and cluster references causes troubles.

#'name': context.properties["debug"],WORKING
#'name': context.env["project"],WORKING
 'name': context.properties["debug"]+context.env["project"],#NOT WORKING

You can check the configuration here, If you need it.

-- GalloCedrone
Source: StackOverflow