Skip to content

Commit

Permalink
Update igm updater example (GoogleCloudPlatform#138)
Browse files Browse the repository at this point in the history
* update project creation sample and set runtimePolicy of get-iam-policy action as UPDATE_ALWAYS

* Update readme for project creation sample

* correct the previouse changes

* update igm-updater sample to use instanceGroupManagers.update that is available in compute beta api

* update project creation sample and set runtimePolicy of get-iam-policy action as UPDATE_ALWAYS

* correct the previouse changes

* update igm-updater sample to use instanceGroupManagers.update that is available in compute beta api

* rebase with dm-repo
  • Loading branch information
likeulb authored and munutzer committed Apr 3, 2018
1 parent 92af9ea commit fc86c3b
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 126 deletions.
29 changes: 17 additions & 12 deletions examples/v2/igm-updater/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,42 @@

This example creates two instance groups in two different zones in the same
region. It creates a level 3 load balancer over the two instance groups. Most
importantly, it uses the Instance Group Updater to perform a rolling update of
your instance groups.
importantly, it uses the Instance Group Manager to perform a rolling update of
your instance groups. For more details, check [Updating Managed Instance
Groups](https://cloud.google.com/compute/docs/instance-groups/updating-managed-instance-groups)

This example consists of:
This example provides both python templates and jinja templates. For python
templates, this example consists of:

* 4 python templates
* ha-service.py - the top level template
* Uses service.py for each zone.
* Uses service.py for each zone
* Uses lb-l3.py to create the load balancer
* service.py
* Creates the instance templates, using instance-template.py
* Creates the instance group
* On update, creates the instance group updater
* On update, update the instance group
* lb-l3.py
* Creates the level 3 load balancer over the two regions
* instance-template.py
* Creates the instance templates.
* Creates the instance templates
* a schema file for the top level python template
* Defines the required inputs and defaults for the optional ones
properties.
* 3 yaml files - used to test the templates with rolling out different linux
distros

To perform a rolling update on an instance group, four resources are needed:
To perform a rolling update on an instance group, below resources are needed:

1. the instance group
1. the previous instance template (for rollbacks if the update fails)
1. the current (ie new) instance template
1. the instance group updater resource
1. the instance group
1. the current (ie new) instance template

The update will take several minutes to run, so be patient.
The update will take several minutes to run, so be patient. Running below
command to monitor the rolling updates of the instances:

```
$ gcloud compute instance-groups managed list-instances <INSTANCE_GROUP_NAME> --zone=<ZONE>
```

The directory also contains three yaml files.
To run the example use them in order.
Expand Down
8 changes: 1 addition & 7 deletions examples/v2/igm-updater/jinja/frontendver2.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016 Google Inc. All rights reserved.
# Copyright 2018 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,16 +27,10 @@ resources:
machineType: f1-micro
zones:
- zone: asia-east1-a
prev:
name: 1a-debian
image: "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-8"
curr:
name: 2b-ubuntu
image: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/family/ubuntu-1404-lts"
- zone: asia-east1-b
prev:
name: 1a-debian
image: "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-8"
curr:
name: 2b-ubuntu
image: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/family/ubuntu-1404-lts"
8 changes: 1 addition & 7 deletions examples/v2/igm-updater/jinja/frontendver3.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016 Google Inc. All rights reserved.
# Copyright 2018 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,16 +27,10 @@ resources:
machineType: f1-micro
zones:
- zone: asia-east1-a
prev:
name: 2b-ubuntu
image: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/family/ubuntu-1404-lts"
curr:
name: 3c-centos
image: "https://www.googleapis.com/compute/v1/projects/centos-cloud/global/images/family/centos-7"
- zone: asia-east1-b
prev:
name: 1a-debian
image: "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-8"
curr:
name: 2b-ubuntu
image: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/family/ubuntu-1404-lts"
7 changes: 2 additions & 5 deletions examples/v2/igm-updater/jinja/ha-service.jinja
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{#
Copyright 2016 Google Inc. All rights reserved.
Copyright 2018 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -26,12 +26,9 @@ resources:
maxSize: {{ properties['maxSize'] }}
machineType: {{ properties['machineType'] }}
zone: {{ zoneName }}
{% if deployZone['prev'] %}
prevVersion: {{ deployZone['prev'] }}
{% endif %}
{% endfor %}
- name: {{ LB_NAME }}
type: lb-l3.jinja
properties:
port: 80
port: 8080
region: {{ REGION }}
15 changes: 2 additions & 13 deletions examples/v2/igm-updater/jinja/ha-service.jinja.schema
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016 Google Inc. All rights reserved.
# Copyright 2018 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -23,8 +23,7 @@ info:
imports:
- path: service.jinja
- path: instance-template.jinja
- path: https://raw.githubusercontent.com/GoogleCloudPlatform/deploymentmanager-samples/master/examples/v2/ha-service/jinja/lb-l3.jinja
name: lb-l3.jinja
- path: lb-l3.jinja


properties:
Expand All @@ -50,16 +49,6 @@ properties:
image:
type: string
description: a fully qualified url to the vm image to use
prev:
type: object
description: a zone object - contains an version name and the image for that version
properties:
name:
type: string
description: an identifier for the version (e.g. 17, 26a, March22)
image:
type: string
description: a fully qualified url to the vm image to use

minSize:
type: integer
Expand Down
13 changes: 11 additions & 2 deletions examples/v2/igm-updater/jinja/instance-template.jinja
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{#
Copyright 2016 Google Inc. All rights reserved.
Copyright 2018 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -25,4 +25,13 @@ resources:
initializeParams:
sourceImage: {{ properties['image'] }}
networkInterfaces:
- network: global/networks/default
- accessConfigs:
- name: external-nat
type: ONE_TO_ONE_NAT
network: global/networks/default
metadata:
items:
- key: startup-script
value: |
#!/bin/bash
sudo python -m SimpleHTTPServer 8080
34 changes: 34 additions & 0 deletions examples/v2/igm-updater/jinja/lb-l3.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{#
Copyright 2016 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#}

{% set HC_NAME = env['name'] + '-hc' %}
{% set TP_NAME = env['name'] + '-tp' %}
{% set FR_NAME = env['name'] + '-fr' %}

resources:
- name: {{ HC_NAME }}
type: compute.v1.httpHealthCheck
properties:
port: {{ properties['port'] }}
requestPath: /
- name: {{ TP_NAME }}
type: compute.v1.targetPool
properties:
region: {{ properties['region'] }}
healthChecks: [$(ref.{{ HC_NAME }}.selfLink)]
- name: {{ FR_NAME }}
type: compute.v1.forwardingRule
properties:
region: {{ properties['region'] }}
portRange: {{ properties['port'] }}
target: $(ref.{{ TP_NAME }}.selfLink)
24 changes: 6 additions & 18 deletions examples/v2/igm-updater/jinja/service.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,18 @@ resources:
zone: {{ ZONE }}
itName: {{ CURR_IT_NAME }}
image: {{ properties['currVersion']['image'] }}
{% if properties['prevVersion'] %}
{% set PREV_IT_NAME = env['name'] + '-it-' + properties['prevVersion']['name'] %}
- name: {{ PREV_IT_NAME }}
type: instance-template.jinja
properties:
machineType: {{ properties['machineType'] }}
zone: {{ ZONE }}
itName: {{ PREV_IT_NAME }}
image: {{ properties['prevVersion']['image'] }}
- name: {{ CURR_IT_NAME }}-igupdater
type: replicapoolupdater.v1beta1.rollingUpdate
properties:
zone: {{ ZONE }}
instanceGroupManager: $(ref.{{ IGM_NAME }}.selfLink)
actionType: RECREATE
instanceTemplate: $(ref.{{ CURR_IT_NAME }}.selfLink)
{% endif %}
- name: {{ IGM_NAME }}
type: compute.v1.instanceGroupManager
type: compute.beta.instanceGroupManager
properties:
baseInstanceName: {{ IGM_NAME }}-instance
instanceTemplate: $(ref.{{ CURR_IT_NAME }}.selfLink)
zone: {{ ZONE }}
targetSize: 1
targetPools:
- $(ref.{{ properties['targetPool'] }}.selfLink)
updatePolicy:
minimalAction: REPLACE
type: PROACTIVE
- name: {{ NAME }}-as
type: compute.v1.autoscaler
properties:
Expand Down
6 changes: 0 additions & 6 deletions examples/v2/igm-updater/python/frontendver2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,10 @@ resources:
machineType: f1-micro
zones:
- zone: asia-east1-a
prev:
name: 1a-debian
image: "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-8"
curr:
name: 2b-ubuntu
image: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/family/ubuntu-1404-lts"
- zone: asia-east1-b
prev:
name: 1a-debian
image: "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-8"
curr:
name: 2b-ubuntu
image: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/family/ubuntu-1404-lts"
6 changes: 0 additions & 6 deletions examples/v2/igm-updater/python/frontendver3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,10 @@ resources:
machineType: f1-micro
zones:
- zone: asia-east1-a
prev:
name: 2b-ubuntu
image: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/family/ubuntu-1404-lts"
curr:
name: 3c-centos
image: "https://www.googleapis.com/compute/v1/projects/centos-cloud/global/images/family/centos-7"
- zone: asia-east1-b
prev:
name: 1a-debian
image: "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-8"
curr:
name: 2b-ubuntu
image: "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/family/ubuntu-1404-lts"
5 changes: 1 addition & 4 deletions examples/v2/igm-updater/python/ha-service.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ def GenerateConfig(context):
'zone': zone_name
}

if 'prev' in deploy_zone:
properties['prevVersion'] = deploy_zone['prev']

service = {
'name': context.env['deployment'] + '-service-' + zone_name,
'type': 'service.py',
Expand All @@ -52,7 +49,7 @@ def GenerateConfig(context):
'name': lb_name,
'type': 'lb-l3.py',
'properties': {
'port': 80,
'port': 8080,
'region': region
}
}
Expand Down
13 changes: 1 addition & 12 deletions examples/v2/igm-updater/python/ha-service.py.schema
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ info:
imports:
- path: service.py
- path: instance-template.py
- path: https://raw.githubusercontent.com/GoogleCloudPlatform/deploymentmanager-samples/master/examples/v2/ha-service/python/lb-l3.py
name: lb-l3.py
- path: lb-l3.py


properties:
Expand All @@ -50,16 +49,6 @@ properties:
image:
type: string
description: a fully qualified url to the vm image to use
prev:
type: object
description: a zone object - contains an version name and the image for that version
properties:
name:
type: string
description: an identifier for the version (e.g. 17, 26a, March22)
image:
type: string
description: a fully qualified url to the vm image to use

minSize:
type: integer
Expand Down
18 changes: 14 additions & 4 deletions examples/v2/igm-updater/python/instance-template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016 Google Inc. All rights reserved.
# Copyright 2018 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,11 +35,21 @@ def GenerateConfig(context):
}
}],
'networkInterfaces': [{
'network': 'global/networks/default'
}]
'accessConfigs': [{
'name': 'external-nat',
'type': 'ONE_TO_ONE_NAT'
}],
'network': 'global/networks/default',
}],
'metadata': {
'items': [{
'key': 'startup-script',
'value': ''.join(['#!/bin/bash\n',
'python -m SimpleHTTPServer 8080'])
}]
}
}
}
}]

return {'resources': resources}

Loading

0 comments on commit fc86c3b

Please sign in to comment.