From f0182ed5743b0efab02bc1dd463c2824958c503f Mon Sep 17 00:00:00 2001 From: Alex Rakowski <20504869+agrski@users.noreply.github.com> Date: Thu, 4 Nov 2021 20:09:47 +0000 Subject: [PATCH] Parameterise resource cache location (#39) * Replace hard-coded resource cache location with variable * Update task names to reflect lack of hard-coding * Formatting * Add cache location var in all roles creating local resources --- roles/efk_opendistro_stack/defaults/main.yaml | 2 ++ roles/efk_opendistro_stack/tasks/get_resources.yaml | 2 +- .../tasks/install_elasticsearch.yaml | 2 +- roles/istio/defaults/main.yaml | 2 ++ roles/istio/tasks/main.yaml | 12 ++++++------ roles/iter8/defaults/main.yaml | 2 ++ roles/iter8/tasks/main.yaml | 7 ++++--- roles/kind/defaults/main.yaml | 2 ++ roles/kind/tasks/create_cluster.yaml | 4 ++-- roles/kind/tasks/download_kind.yaml | 10 +++++----- roles/postgres_operator/defaults/main.yaml | 2 ++ roles/postgres_operator/tasks/get_resources.yaml | 2 +- .../tasks/install_postgres_operator.yaml | 2 +- roles/seldon_core/defaults/main.yaml | 2 ++ roles/seldon_core/tasks/main.yaml | 5 +++-- 15 files changed, 36 insertions(+), 22 deletions(-) diff --git a/roles/efk_opendistro_stack/defaults/main.yaml b/roles/efk_opendistro_stack/defaults/main.yaml index 6020e00..8b234b2 100644 --- a/roles/efk_opendistro_stack/defaults/main.yaml +++ b/roles/efk_opendistro_stack/defaults/main.yaml @@ -1,4 +1,6 @@ --- +seldon_cache_directory: "{{ ansible_env.HOME }}/.cache/seldon" + seldon_system_namespace: seldon-system elastic_opendistro_namespace: seldon-logs diff --git a/roles/efk_opendistro_stack/tasks/get_resources.yaml b/roles/efk_opendistro_stack/tasks/get_resources.yaml index 64453d4..e552bea 100644 --- a/roles/efk_opendistro_stack/tasks/get_resources.yaml +++ b/roles/efk_opendistro_stack/tasks/get_resources.yaml @@ -3,5 +3,5 @@ ansible.builtin.git: version: "{{ elastic_opendistro_version }}" repo: "{{ elastic_opendistro_repo }}" - dest: "{{ inventory_dir }}/.resources/opendistro-build" + dest: "{{ seldon_cache_directory }}/opendistro-build" force: yes diff --git a/roles/efk_opendistro_stack/tasks/install_elasticsearch.yaml b/roles/efk_opendistro_stack/tasks/install_elasticsearch.yaml index efadd6f..0a6e098 100644 --- a/roles/efk_opendistro_stack/tasks/install_elasticsearch.yaml +++ b/roles/efk_opendistro_stack/tasks/install_elasticsearch.yaml @@ -3,7 +3,7 @@ kubernetes.core.helm: name: elasticsearch release_namespace: "{{ elastic_opendistro_namespace }}" - chart_ref: "{{ inventory_dir }}/.resources/opendistro-build/helm/opendistro-es" + chart_ref: "{{ seldon_cache_directory }}/opendistro-build/helm/opendistro-es" values: "{{ elastic_opendistro_values }}" - name: Wait for Elasticsearch deployments diff --git a/roles/istio/defaults/main.yaml b/roles/istio/defaults/main.yaml index 17524b4..0a28c17 100644 --- a/roles/istio/defaults/main.yaml +++ b/roles/istio/defaults/main.yaml @@ -1,4 +1,6 @@ --- +seldon_cache_directory: "{{ ansible_env.HOME }}/.cache/seldon" + istio_version: 1.10.3 istio_verify_install: true istio_create_seldon_gateway: true diff --git a/roles/istio/tasks/main.yaml b/roles/istio/tasks/main.yaml index 06532a7..612af74 100644 --- a/roles/istio/tasks/main.yaml +++ b/roles/istio/tasks/main.yaml @@ -1,13 +1,13 @@ --- - name: Check if Istio {{ istio_version }} already downloaded. stat: - path: "{{ inventory_dir }}/.resources/istio-{{ istio_version }}" + path: "{{ seldon_cache_directory }}/istio-{{ istio_version }}" register: istio_directory -- name: "Create .resources directory if does not exist: {{ inventory_dir }}/.resources/" +- name: "Create resources directory if does not exist: {{ seldon_cache_directory }}/" ansible.builtin.file: - path: "{{ inventory_dir }}/.resources/" + path: "{{ seldon_cache_directory }}/" state: directory mode: '0755' @@ -15,7 +15,7 @@ - name: Download Istio {{ istio_version }} shell: "curl -L https://istio.io/downloadIstio | ISTIO_VERSION={{ istio_version }} sh -" args: - chdir: "{{ inventory_dir }}/.resources" + chdir: "{{ seldon_cache_directory }}" warn: false when: istio_directory.stat.exists == false @@ -23,13 +23,13 @@ - name: Install Istio {{ istio_version }} shell: "./bin/istioctl install --set profile=default -y" args: - chdir: "{{ inventory_dir }}/.resources/istio-{{ istio_version }}" + chdir: "{{ seldon_cache_directory }}/istio-{{ istio_version }}" - name: Verify Install Istio {{ istio_version }} shell: "./bin/istioctl verify-install" args: - chdir: "{{ inventory_dir }}/.resources/istio-{{ istio_version }}" + chdir: "{{ seldon_cache_directory }}/istio-{{ istio_version }}" when: istio_verify_install | bool diff --git a/roles/iter8/defaults/main.yaml b/roles/iter8/defaults/main.yaml index 6385f56..e101c96 100644 --- a/roles/iter8/defaults/main.yaml +++ b/roles/iter8/defaults/main.yaml @@ -1,4 +1,6 @@ --- +seldon_cache_directory: "{{ ansible_env.HOME }}/.cache/seldon" + iter8_namespace: iter8-system iter8_version: master diff --git a/roles/iter8/tasks/main.yaml b/roles/iter8/tasks/main.yaml index 5436ba8..995cdce 100644 --- a/roles/iter8/tasks/main.yaml +++ b/roles/iter8/tasks/main.yaml @@ -3,16 +3,17 @@ ansible.builtin.git: version: "{{ iter8_version }}" repo: "{{ iter8_repo }}" - dest: "{{ inventory_dir }}/.resources/iter8" + dest: "{{ seldon_cache_directory }}/iter8" force: yes when: iter8_source_dir is undefined - name: Set Iter8 Directory - set_fact: iter8_source_dir="{{ inventory_dir }}/.resources/iter8" + set_fact: + iter8_source_dir: "{{ seldon_cache_directory }}/iter8" when: iter8_source_dir is undefined - name: Install Iter8 - ansible.builtin.shell: "kustomize build {{ inventory_dir }}/.resources/iter8/install/core | kubectl apply -n {{ iter8_namespace }} -f -" + ansible.builtin.shell: "kustomize build {{ seldon_cache_directory }}/iter8/install/core | kubectl apply -n {{ iter8_namespace }} -f -" - name: Wait for Iter8 deployments kubernetes.core.k8s_info: diff --git a/roles/kind/defaults/main.yaml b/roles/kind/defaults/main.yaml index af0bb54..cef0e9d 100644 --- a/roles/kind/defaults/main.yaml +++ b/roles/kind/defaults/main.yaml @@ -1,4 +1,6 @@ --- +seldon_cache_directory: "{{ ansible_env.HOME }}/.cache/seldon" + kind_cluster_name: ansible kind_image_version: kindest/node:v1.20.7@sha256:cbeaf907fc78ac97ce7b625e4bf0de16e3ea725daf6b04f930bd14c67c671ff9 diff --git a/roles/kind/tasks/create_cluster.yaml b/roles/kind/tasks/create_cluster.yaml index 35095a3..9f998d2 100644 --- a/roles/kind/tasks/create_cluster.yaml +++ b/roles/kind/tasks/create_cluster.yaml @@ -7,7 +7,7 @@ - name: "Start KinD Cluster: '{{ kind_cluster_name }}'" command: argv: - - "{{ inventory_dir }}/.resources/kind-{{ kind_version }}" + - "{{ seldon_cache_directory }}/kind-{{ kind_version }}" - create - cluster - --name={{ kind_cluster_name }} @@ -24,7 +24,7 @@ - name: "Export kubeconfig for KinD Cluster: '{{ kind_cluster_name }}'" command: argv: - - "{{ inventory_dir }}/.resources/kind-{{ kind_version }}" + - "{{ seldon_cache_directory }}/kind-{{ kind_version }}" - export - kubeconfig - --name={{ kind_cluster_name }} diff --git a/roles/kind/tasks/download_kind.yaml b/roles/kind/tasks/download_kind.yaml index 0dc6791..4ffd96e 100644 --- a/roles/kind/tasks/download_kind.yaml +++ b/roles/kind/tasks/download_kind.yaml @@ -1,24 +1,24 @@ --- - name: Check if Kind {{ kind_version }} already downloaded stat: - path: "{{ inventory_dir }}/.resources/kind-{{ kind_version }}" + path: "{{ seldon_cache_directory }}/kind-{{ kind_version }}" register: kind_binary -- name: "Create .resources directory if does not exist: {{ inventory_dir }}/.resources/" +- name: "Create resources directory if does not exist: {{ seldon_cache_directory }}/" ansible.builtin.file: - path: "{{ inventory_dir }}/.resources/" + path: "{{ seldon_cache_directory }}/" state: directory mode: '0755' - name: Download Kind {{ kind_version }} binary shell: "curl -Lo kind-{{ kind_version }} {{ kind_url }}" args: - chdir: "{{ inventory_dir }}/.resources" + chdir: "{{ seldon_cache_directory }}" warn: false when: kind_binary.stat.exists == false - name: Make Kind {{ kind_version }} binary executable ansible.builtin.file: - path: "{{ inventory_dir }}/.resources/kind-{{ kind_version }}" + path: "{{ seldon_cache_directory }}/kind-{{ kind_version }}" state: file mode: '0755' diff --git a/roles/postgres_operator/defaults/main.yaml b/roles/postgres_operator/defaults/main.yaml index dc1febc..56c7253 100644 --- a/roles/postgres_operator/defaults/main.yaml +++ b/roles/postgres_operator/defaults/main.yaml @@ -1,4 +1,6 @@ --- +seldon_cache_directory: "{{ ansible_env.HOME }}/.cache/seldon" + postgres_operator_namespace: postgres postgres_operator_repo: https://github.com/zalando/postgres-operator.git diff --git a/roles/postgres_operator/tasks/get_resources.yaml b/roles/postgres_operator/tasks/get_resources.yaml index 7d01dfd..0a25036 100644 --- a/roles/postgres_operator/tasks/get_resources.yaml +++ b/roles/postgres_operator/tasks/get_resources.yaml @@ -3,5 +3,5 @@ ansible.builtin.git: version: "{{ postgres_operator_version }}" repo: "{{ postgres_operator_repo }}" - dest: "{{ inventory_dir }}/.resources/postgres-operator" + dest: "{{ seldon_cache_directory }}/postgres-operator" force: yes diff --git a/roles/postgres_operator/tasks/install_postgres_operator.yaml b/roles/postgres_operator/tasks/install_postgres_operator.yaml index 6f05dac..f8b2241 100644 --- a/roles/postgres_operator/tasks/install_postgres_operator.yaml +++ b/roles/postgres_operator/tasks/install_postgres_operator.yaml @@ -3,6 +3,6 @@ kubernetes.core.helm: name: postgres-operator release_namespace: "{{ postgres_operator_namespace }}" - chart_ref: "{{ inventory_dir }}/.resources/postgres-operator/charts/postgres-operator" + chart_ref: "{{ seldon_cache_directory }}/postgres-operator/charts/postgres-operator" values: "{{ postgres_operator_values }}" values_files: "{{ postgres_operator_values_files }}" diff --git a/roles/seldon_core/defaults/main.yaml b/roles/seldon_core/defaults/main.yaml index 7bfe626..e504fbc 100644 --- a/roles/seldon_core/defaults/main.yaml +++ b/roles/seldon_core/defaults/main.yaml @@ -1,4 +1,6 @@ --- +seldon_cache_directory: "{{ ansible_env.HOME }}/.cache/seldon" + seldon_system_namespace: seldon-system seldon_core_version: master diff --git a/roles/seldon_core/tasks/main.yaml b/roles/seldon_core/tasks/main.yaml index 9c64e41..f987708 100644 --- a/roles/seldon_core/tasks/main.yaml +++ b/roles/seldon_core/tasks/main.yaml @@ -6,12 +6,13 @@ ansible.builtin.git: version: "{{ seldon_core_version }}" repo: "{{ seldon_core_repo }}" - dest: "{{ inventory_dir }}/.resources/seldon-core" + dest: "{{ seldon_cache_directory }}/seldon-core" force: yes when: seldon_core_source_dir is undefined - name: Set Seldon Core Directory - set_fact: seldon_core_source_dir="{{ inventory_dir }}/.resources/seldon-core" + set_fact: + seldon_core_source_dir: "{{ seldon_cache_directory }}/seldon-core" when: seldon_core_source_dir is undefined - name: Deploy Seldon Core