# Copyright 2021 Google LLC
# 
# 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.

- name: Set context
  set_fact:
    context: "gke_{{ project_id }}_{{ region }}_{{ cluster }}"

- name: Create sample namespace
  shell: 
    cmd: |
      cat << EOF | kubectl apply --context {{ context }} -f  -
      apiVersion: v1
      kind: Namespace
      metadata:
        name: sample
      EOF

- name: Label the sample namespace for istio sidecar injection
  shell: >
    kubectl label namespace sample \
    istio-injection- istio.io/rev=asm-managed \
    --context {{ context }} \
    --overwrite

- name: Create helloworld service
  shell: >
    kubectl apply
    -f samples/helloworld/helloworld.yaml \
    -l service=helloworld \
    -n sample \
    --context {{ context }}
  args:
    chdir: ~/istio-{{ istio_version }}  

- name: Create helloworld deployment
  shell: >
    kubectl apply
    -f samples/helloworld/helloworld.yaml \
    -l version=v{{ index + 1 }} \
    -n sample \
    --context {{ context }}
  args:
    chdir: ~/istio-{{ istio_version }}  

- name: Create sleep service and deployment
  shell: >
    kubectl apply \
    -f samples/sleep/sleep.yaml \
    -n sample \
    --context {{ context }}
  args:
    chdir: ~/istio-{{ istio_version }}        