GoogleCloudPlatform / GoogleCloudPlatform/deploymentmanager-samples

Question about ref

Open
#291 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Jinja
Stars
951
Forks
700
PR merge metrics
No merged PRs in 30d

Description

Hi,

I'm trying to create a k8s cluster and a k8s secret for the cluster name. The code I have is the following:

` secret.yaml`
```yaml
imports:
- path: create-k8s-secret.py

resources:
- name: mycluster
type: container.v1.cluster
properties:
zone: us-east1-b
cluster:
name: mycluster
description: "a k8s cluster"
initialClusterVersion: 1.9.7-gke.6
monitoringService: none
loggingService: none
nodePools:
- name: default-pool
initialNodeCount: 1
config:
machineType: n1-standard-1
preemptible: true
oauthScopes:
- https://www.googleapis.com/auth/compute
- https://www.googleapis.com/auth/devstorage.read_only
management:
autoUpgrade: false
autoRepair: true
autoscaling:
enabled: true
minNodeCount: 1
maxNodeCount: 2

- name: k8s-type
type: deploymentmanager.v2beta.typeProvider
properties:
options:
validationOptions:
schemaValidation: IGNORE_WITH_WARNINGS
inputMappings:
- fieldName: name
location: PATH
methodMatch: ^(GET|DELETE|PUT)$
value: $.ifNull($.resource.properties.metadata.name, $.resource.name)
- fieldName: metadata.name
location: BODY
methodMatch: ^(PUT|POST)$
value: $.ifNull($.resource.properties.metadata.name, $.resource.name)
- fieldName: Authorization
location: HEADER
value: >
$.concat("Bearer ", $.googleOauth2AccessToken())
descriptorUrl: https://$(ref.mycluster.endpoint)/swaggerapi/api/v1

- name: mysecret
type: create-k8s-secret.py
properties:
name: mysecret
data:
CLUSTER_NAME: $(ref.mycluster.name) # <------ This line does not refer to the name correctly
```

`create-k8s-secret.py`
```python
import base64

def GenerateConfig(context):
"""Generates configuration."""
secret = {
'name': context.env['name'],
'type': context.env['project'] + '/' + 'k8s-type:/api/v1/namespaces/{namespace}/secrets',
'properties': {
'apiVersion': 'v1',
'kind': 'Secret',
'namespace': 'default',
'metadata': {
'name': context.properties['name']
},
'data': dict(map(lambda item: (item[0], base64.b64encode(item[1])), context.properties['data'].iteritems()))
},
"metadata": {
"dependsOn": [
"k8s-type",
]
}
}
return {'resources': [secret] }
```

The reference `$(ref.mycluster.name)` in the `mysecret` resource doesn't work correctly because when I inspect the k8s secret content, the base64-decoded string for `CLUSTER_NAME` is set to `$(ref.yaml%mycluster.name)`. I expect it to be `mycluster`. Is that a bug or my misunderstanding for the usage of `ref`?

How to reproduce?

- `gcloud deployment-manager deployments create --config=secret.yaml test`
- `gcloud container clusters get-credentials mycluster`
- `kubectl get secret mysecret -o yaml | grep CLUSTER_NAME | awk '{print $2}' | base64 -D`

You will see that the base64-decoded value for `CLUSTER_NAME` is `$(ref.yaml%mycluster.name)`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.