From 58e5fb798c833668b9fa3b0aa8986a3c7ff217d2 Mon Sep 17 00:00:00 2001 From: Adrian Chifor Date: Thu, 22 Mar 2018 17:12:51 +0000 Subject: [PATCH 1/3] Fixed file closing issue. Added directory hash function --- kapitan/resources.py | 6 +++++- kapitan/utils.py | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/kapitan/resources.py b/kapitan/resources.py index 3dc430334..78ad840d8 100644 --- a/kapitan/resources.py +++ b/kapitan/resources.py @@ -125,7 +125,11 @@ def search_imports(cwd, import_str, search_path): logger.debug("cwd:%s import_str:%s basename:%s -> norm:%s", cwd, import_str, basename, normalised_path) - return normalised_path, open(normalised_path).read() + normalised_path_content = "" + with open(normalised_path) as f: + normalised_path_content = f.read() + + return normalised_path, normalised_path_content def inventory(search_path, target, inventory_path="inventory/"): diff --git a/kapitan/utils.py b/kapitan/utils.py index a6fab9f21..e295caf5b 100644 --- a/kapitan/utils.py +++ b/kapitan/utils.py @@ -212,3 +212,29 @@ def deep_get(x, keys): fd.close() for i in output: print('{0!s:{l}} {1!s}'.format(*i, l=maxlenght + 2)) + +def get_directory_hash(directory): + ''' + Compute a sha256 hash for the file contents of a directory + ''' + if not os.path.exists(directory): + logger.error("utils.get_directory_hash failed, %s dir doesn't exist", directory) + return -1 + + try: + hash = sha256() + for root, _, files in os.walk(directory): + for names in files: + file_path = os.path.join(root, names) + try: + with open(file_path, 'r') as f: + hash.update(sha256(f.read().encode("UTF-8")).hexdigest().encode("UTF-8")) + except Exception as e: + logger.error("utils.get_directory_hash failed to open %s: %s", file_path, str(e)) + return -2 + + except Exception as e: + logger.error("utils.get_directory_hash failed: %s", str(e)) + return -2 + + return hash.hexdigest() From 20a5c30389cac9a14263ceabc04abd84f862abb7 Mon Sep 17 00:00:00 2001 From: Adrian Chifor Date: Thu, 22 Mar 2018 17:13:15 +0000 Subject: [PATCH 2/3] Added compilation functional test. Added yaml jinja2 filter test. --- tests/test_compile.py | 41 ++++++++++++ tests/test_jinja2.py | 8 +++ .../minikube-es-2/README.md | 61 +++++++++++++++++ .../minikube-es-2/manifests/es-client.yml | 67 +++++++++++++++++++ .../minikube-es-2/manifests/es-data.yml | 64 ++++++++++++++++++ .../manifests/es-discovery-svc.yml | 16 +++++ .../manifests/es-elasticsearch-svc.yml | 19 ++++++ .../minikube-es-2/manifests/es-master.yml | 64 ++++++++++++++++++ .../minikube-es-2/scripts/apply.sh | 23 +++++++ .../minikube-es-2/scripts/delete.sh | 19 ++++++ .../minikube-es-2/scripts/kubectl.sh | 19 ++++++ .../scripts/minikube/install_minikube.sh | 30 +++++++++ .../scripts/minikube/start_minikube.sh | 19 ++++++ .../minikube-es-2/scripts/setup_cluster.sh | 18 +++++ .../minikube-es-2/scripts/setup_context.sh | 18 +++++ .../minikube-es/README.md | 61 +++++++++++++++++ .../minikube-es/manifests/es-client.yml | 67 +++++++++++++++++++ .../minikube-es/manifests/es-data.yml | 64 ++++++++++++++++++ .../manifests/es-discovery-svc.yml | 16 +++++ .../manifests/es-elasticsearch-svc.yml | 19 ++++++ .../minikube-es/manifests/es-master.yml | 64 ++++++++++++++++++ .../minikube-es/scripts/apply.sh | 23 +++++++ .../minikube-es/scripts/delete.sh | 19 ++++++ .../minikube-es/scripts/kubectl.sh | 19 ++++++ .../scripts/minikube/install_minikube.sh | 30 +++++++++ .../scripts/minikube/start_minikube.sh | 19 ++++++ .../minikube-es/scripts/setup_cluster.sh | 18 +++++ .../minikube-es/scripts/setup_context.sh | 18 +++++ .../minikube-mysql/README.md | 61 +++++++++++++++++ .../minikube-mysql/manifests/mysql_secret.yml | 10 +++ .../manifests/mysql_service_jsonnet.yml | 16 +++++ .../manifests/mysql_service_simple.yml | 16 +++++ .../manifests/mysql_statefulset.yml | 44 ++++++++++++ .../pre-deploy/00_namespace.yml | 7 ++ .../pre-deploy/10_serviceaccount.yml | 7 ++ .../minikube-mysql/scripts/apply.sh | 23 +++++++ .../minikube-mysql/scripts/delete.sh | 19 ++++++ .../minikube-mysql/scripts/kubectl.sh | 19 ++++++ .../scripts/minikube/install_minikube.sh | 30 +++++++++ .../scripts/minikube/start_minikube.sh | 19 ++++++ .../minikube-mysql/scripts/setup_cluster.sh | 18 +++++ .../minikube-mysql/scripts/setup_context.sh | 18 +++++ 42 files changed, 1230 insertions(+) create mode 100644 tests/test_compile.py create mode 100644 tests/test_kubernetes_compiled/minikube-es-2/README.md create mode 100644 tests/test_kubernetes_compiled/minikube-es-2/manifests/es-client.yml create mode 100644 tests/test_kubernetes_compiled/minikube-es-2/manifests/es-data.yml create mode 100644 tests/test_kubernetes_compiled/minikube-es-2/manifests/es-discovery-svc.yml create mode 100644 tests/test_kubernetes_compiled/minikube-es-2/manifests/es-elasticsearch-svc.yml create mode 100644 tests/test_kubernetes_compiled/minikube-es-2/manifests/es-master.yml create mode 100644 tests/test_kubernetes_compiled/minikube-es-2/scripts/apply.sh create mode 100644 tests/test_kubernetes_compiled/minikube-es-2/scripts/delete.sh create mode 100644 tests/test_kubernetes_compiled/minikube-es-2/scripts/kubectl.sh create mode 100644 tests/test_kubernetes_compiled/minikube-es-2/scripts/minikube/install_minikube.sh create mode 100644 tests/test_kubernetes_compiled/minikube-es-2/scripts/minikube/start_minikube.sh create mode 100644 tests/test_kubernetes_compiled/minikube-es-2/scripts/setup_cluster.sh create mode 100644 tests/test_kubernetes_compiled/minikube-es-2/scripts/setup_context.sh create mode 100644 tests/test_kubernetes_compiled/minikube-es/README.md create mode 100644 tests/test_kubernetes_compiled/minikube-es/manifests/es-client.yml create mode 100644 tests/test_kubernetes_compiled/minikube-es/manifests/es-data.yml create mode 100644 tests/test_kubernetes_compiled/minikube-es/manifests/es-discovery-svc.yml create mode 100644 tests/test_kubernetes_compiled/minikube-es/manifests/es-elasticsearch-svc.yml create mode 100644 tests/test_kubernetes_compiled/minikube-es/manifests/es-master.yml create mode 100644 tests/test_kubernetes_compiled/minikube-es/scripts/apply.sh create mode 100644 tests/test_kubernetes_compiled/minikube-es/scripts/delete.sh create mode 100644 tests/test_kubernetes_compiled/minikube-es/scripts/kubectl.sh create mode 100644 tests/test_kubernetes_compiled/minikube-es/scripts/minikube/install_minikube.sh create mode 100644 tests/test_kubernetes_compiled/minikube-es/scripts/minikube/start_minikube.sh create mode 100644 tests/test_kubernetes_compiled/minikube-es/scripts/setup_cluster.sh create mode 100644 tests/test_kubernetes_compiled/minikube-es/scripts/setup_context.sh create mode 100644 tests/test_kubernetes_compiled/minikube-mysql/README.md create mode 100644 tests/test_kubernetes_compiled/minikube-mysql/manifests/mysql_secret.yml create mode 100644 tests/test_kubernetes_compiled/minikube-mysql/manifests/mysql_service_jsonnet.yml create mode 100644 tests/test_kubernetes_compiled/minikube-mysql/manifests/mysql_service_simple.yml create mode 100644 tests/test_kubernetes_compiled/minikube-mysql/manifests/mysql_statefulset.yml create mode 100644 tests/test_kubernetes_compiled/minikube-mysql/pre-deploy/00_namespace.yml create mode 100644 tests/test_kubernetes_compiled/minikube-mysql/pre-deploy/10_serviceaccount.yml create mode 100644 tests/test_kubernetes_compiled/minikube-mysql/scripts/apply.sh create mode 100644 tests/test_kubernetes_compiled/minikube-mysql/scripts/delete.sh create mode 100644 tests/test_kubernetes_compiled/minikube-mysql/scripts/kubectl.sh create mode 100644 tests/test_kubernetes_compiled/minikube-mysql/scripts/minikube/install_minikube.sh create mode 100644 tests/test_kubernetes_compiled/minikube-mysql/scripts/minikube/start_minikube.sh create mode 100644 tests/test_kubernetes_compiled/minikube-mysql/scripts/setup_cluster.sh create mode 100644 tests/test_kubernetes_compiled/minikube-mysql/scripts/setup_context.sh diff --git a/tests/test_compile.py b/tests/test_compile.py new file mode 100644 index 000000000..69ab5fa80 --- /dev/null +++ b/tests/test_compile.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +"compile tests" + +import unittest +import os +import sys +import shutil +from kapitan.cli import main +from kapitan.utils import get_directory_hash + +class CompileTest(unittest.TestCase): + def setUp(self): + os.chdir(os.getcwd() + '/examples/kubernetes/') + + def test_compile(self): + sys.argv[1] = "compile" + main() + compiled_dir_hash = get_directory_hash(os.getcwd() + '/compiled') + test_compiled_dir_hash = get_directory_hash(os.getcwd() + '/../../tests/test_kubernetes_compiled') + self.assertEqual(compiled_dir_hash, test_compiled_dir_hash) + + def tearDown(self): + compile_path = os.getcwd() + '/compiled' + if os.path.exists(compile_path): + shutil.rmtree(compile_path) + os.chdir(os.getcwd() + '/../../') diff --git a/tests/test_jinja2.py b/tests/test_jinja2.py index ee5c680b7..3da868825 100644 --- a/tests/test_jinja2.py +++ b/tests/test_jinja2.py @@ -29,6 +29,14 @@ def test_sha256(self): digest = 'e863c1ac42619a2b429a08775a6acd89ff4c2c6b8dae12e3461a5fa63b2f92f5' self.assertEqual(render_jinja2_file(f.name, context), digest) + def test_yaml(self): + with tempfile.NamedTemporaryFile() as f: + f.write("{{text|yaml}}".encode("UTF-8")) + f.seek(0) + context = {"text":["this", "that"]} + yaml = '- this\n- that\n' + self.assertEqual(render_jinja2_file(f.name, context), yaml) + class Jinja2ContextVars(unittest.TestCase): def test_inventory_context(self): with tempfile.NamedTemporaryFile() as f: diff --git a/tests/test_kubernetes_compiled/minikube-es-2/README.md b/tests/test_kubernetes_compiled/minikube-es-2/README.md new file mode 100644 index 000000000..ef6c5b394 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es-2/README.md @@ -0,0 +1,61 @@ +# Elasticsearch Minikube + +This is a specific version of Elasticsearch to run on a minikube instalation. + +## Prerequisites + +Elasticsearch is a resource hungry application, for this setup we require +that minikube is running with the above options: + +``` +$ minikube start --insecure-registry https://quay.io --memory=4096 --cpus=2 +``` + +_If_ you have created the minikube VM previously, you will most likely need to +delete the vm and recreate it with more memory/cpu. (i.e. +```$ minikube delete```) + +## Setting up + +Assuming you're already running Minikube, setup for this target: + +``` +$ scripts/setup.sh +``` + +This will create a context in your minikube cluster called minikube-es-2. + + +Apply the compiled manifests: + +``` +$ scripts/kubectl.sh apply -f manifests/ +``` + +If the commands above did not error, you should be good to go. + +Let's confirm everything is up: + +``` +$ scripts/kubectl.sh get pods -w +``` + +## Connecting to Elasticsearch + +List the elasticsearch service endpoints running in the cluster: + +``` +$ minikube service -n minikube-es elasticsearch --url +``` + +and curl the health endpoint, i.e.: +```$ curl http://192.168.99.100:32130/_cluster/health?pretty``` + + +## Deleting Elasticsearch + +Deleting is easy (warning, this will remove _everything_): + +``` +$ scripts/kubectl.sh delete -f manifests/ +``` diff --git a/tests/test_kubernetes_compiled/minikube-es-2/manifests/es-client.yml b/tests/test_kubernetes_compiled/minikube-es-2/manifests/es-client.yml new file mode 100644 index 000000000..a2c018f1c --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es-2/manifests/es-client.yml @@ -0,0 +1,67 @@ +apiVersion: apps/v1beta1 +kind: StatefulSet +metadata: + labels: + name: cluster-client + role: client + name: cluster-client + namespace: minikube-es-2 +spec: + replicas: 2 + serviceName: cluster-client + template: + metadata: + labels: + name: cluster-client + role: client + spec: + containers: + - env: + - name: CLUSTER_NAME + value: cluster + - name: ES_JAVA_OPTS + value: -Xms512m -Xmx512m + - name: HTTP_ENABLE + value: 'true' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: NODE_DATA + value: 'false' + - name: NODE_INGEST + value: 'false' + - name: NODE_MASTER + value: 'false' + - name: NODE_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: NUMBER_OF_MASTERS + value: '1' + image: quay.io/pires/docker-elasticsearch-kubernetes:5.5.0 + imagePullPolicy: Always + name: client + ports: + - containerPort: 9200 + name: client + protocol: TCP + - containerPort: 9300 + name: transport + protocol: TCP + securityContext: + capabilities: + add: + - IPC_LOCK + - SYS_RESOURCE + privileged: false + initContainers: + - command: + - sysctl + - -w + - vm.max_map_count=262144 + image: busybox + imagePullPolicy: IfNotPresent + name: sysctl + securityContext: + privileged: true diff --git a/tests/test_kubernetes_compiled/minikube-es-2/manifests/es-data.yml b/tests/test_kubernetes_compiled/minikube-es-2/manifests/es-data.yml new file mode 100644 index 000000000..c144cfbd9 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es-2/manifests/es-data.yml @@ -0,0 +1,64 @@ +apiVersion: apps/v1beta1 +kind: StatefulSet +metadata: + labels: + name: cluster-data + role: data + name: cluster-data + namespace: minikube-es-2 +spec: + replicas: 2 + serviceName: cluster-data + template: + metadata: + labels: + name: cluster-data + role: data + spec: + containers: + - env: + - name: CLUSTER_NAME + value: cluster + - name: ES_JAVA_OPTS + value: -Xms512m -Xmx512m + - name: HTTP_ENABLE + value: 'false' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: NODE_DATA + value: 'true' + - name: NODE_INGEST + value: 'false' + - name: NODE_MASTER + value: 'false' + - name: NODE_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: NUMBER_OF_MASTERS + value: '1' + image: quay.io/pires/docker-elasticsearch-kubernetes:5.5.0 + imagePullPolicy: Always + name: data + ports: + - containerPort: 9300 + name: transport + protocol: TCP + securityContext: + capabilities: + add: + - IPC_LOCK + - SYS_RESOURCE + privileged: false + initContainers: + - command: + - sysctl + - -w + - vm.max_map_count=262144 + image: busybox + imagePullPolicy: IfNotPresent + name: sysctl + securityContext: + privileged: true diff --git a/tests/test_kubernetes_compiled/minikube-es-2/manifests/es-discovery-svc.yml b/tests/test_kubernetes_compiled/minikube-es-2/manifests/es-discovery-svc.yml new file mode 100644 index 000000000..12312bf1b --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es-2/manifests/es-discovery-svc.yml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + name: elasticsearch-discovery + name: elasticsearch-discovery + namespace: minikube-es-2 +spec: + ports: + - name: transport + port: 9300 + targetPort: transport + selector: + name: cluster-master + role: master + type: ClusterIP diff --git a/tests/test_kubernetes_compiled/minikube-es-2/manifests/es-elasticsearch-svc.yml b/tests/test_kubernetes_compiled/minikube-es-2/manifests/es-elasticsearch-svc.yml new file mode 100644 index 000000000..a175abd24 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es-2/manifests/es-elasticsearch-svc.yml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + name: elasticsearch + name: elasticsearch + namespace: minikube-es-2 +spec: + ports: + - name: client + port: 9200 + targetPort: client + - name: transport + port: 9300 + targetPort: transport + selector: + name: cluster-client + role: client + type: NodePort diff --git a/tests/test_kubernetes_compiled/minikube-es-2/manifests/es-master.yml b/tests/test_kubernetes_compiled/minikube-es-2/manifests/es-master.yml new file mode 100644 index 000000000..ead6798ea --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es-2/manifests/es-master.yml @@ -0,0 +1,64 @@ +apiVersion: apps/v1beta1 +kind: StatefulSet +metadata: + labels: + name: cluster-master + role: master + name: cluster-master + namespace: minikube-es-2 +spec: + replicas: 2 + serviceName: cluster-master + template: + metadata: + labels: + name: cluster-master + role: master + spec: + containers: + - env: + - name: CLUSTER_NAME + value: cluster + - name: ES_JAVA_OPTS + value: -Xms512m -Xmx512m + - name: HTTP_ENABLE + value: 'false' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: NODE_DATA + value: 'false' + - name: NODE_INGEST + value: 'false' + - name: NODE_MASTER + value: 'true' + - name: NODE_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: NUMBER_OF_MASTERS + value: '1' + image: quay.io/pires/docker-elasticsearch-kubernetes:5.5.0 + imagePullPolicy: Always + name: master + ports: + - containerPort: 9300 + name: transport + protocol: TCP + securityContext: + capabilities: + add: + - IPC_LOCK + - SYS_RESOURCE + privileged: false + initContainers: + - command: + - sysctl + - -w + - vm.max_map_count=262144 + image: busybox + imagePullPolicy: IfNotPresent + name: sysctl + securityContext: + privileged: true diff --git a/tests/test_kubernetes_compiled/minikube-es-2/scripts/apply.sh b/tests/test_kubernetes_compiled/minikube-es-2/scripts/apply.sh new file mode 100644 index 000000000..d1803c156 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es-2/scripts/apply.sh @@ -0,0 +1,23 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +DIR=$(dirname ${BASH_SOURCE[0]}) + +for SECTION in pre-deploy manifests +do + echo "## run kubectl apply for ${SECTION}" + kapitan secrets --reveal -f ${DIR}/../${SECTION}/ | ${DIR}/kubectl.sh apply -f - | column -t +done \ No newline at end of file diff --git a/tests/test_kubernetes_compiled/minikube-es-2/scripts/delete.sh b/tests/test_kubernetes_compiled/minikube-es-2/scripts/delete.sh new file mode 100644 index 000000000..af7e5faee --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es-2/scripts/delete.sh @@ -0,0 +1,19 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +DIR=$(dirname ${BASH_SOURCE[0]}) + +${DIR}/kubectl.sh delete -f ${DIR}/../manifests diff --git a/tests/test_kubernetes_compiled/minikube-es-2/scripts/kubectl.sh b/tests/test_kubernetes_compiled/minikube-es-2/scripts/kubectl.sh new file mode 100644 index 000000000..3fb7092c5 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es-2/scripts/kubectl.sh @@ -0,0 +1,19 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +KUBECTL="kubectl --context minikube-es-2 --insecure-skip-tls-verify=False " + +${KUBECTL} $@ diff --git a/tests/test_kubernetes_compiled/minikube-es-2/scripts/minikube/install_minikube.sh b/tests/test_kubernetes_compiled/minikube-es-2/scripts/minikube/install_minikube.sh new file mode 100644 index 000000000..9dd54b6e5 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es-2/scripts/minikube/install_minikube.sh @@ -0,0 +1,30 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +case "$(uname -s)" in + Linux*) MINIKUBE_BINARY=minikube-linux-amd64;; + Darwin*) MINIKUBE_BINARY=minikube-darwin-amd64;; + *) exit 1 +esac + +MINIKUBE_VERSION=${MINIKUBE_VERSION:-v0.25.0} +URL=https://storage.googleapis.com/minikube/releases/${MINIKUBE_VERSION}/${MINIKUBE_BINARY} + + +echo Downloading minikube release ${MINIKUBE_VERSION} to /usr/local/bin/minikube +pause +sudo curl --progress-bar -o /usr/local/bin/minikube ${URL} +sudo chmod +x /usr/local/bin/minikube \ No newline at end of file diff --git a/tests/test_kubernetes_compiled/minikube-es-2/scripts/minikube/start_minikube.sh b/tests/test_kubernetes_compiled/minikube-es-2/scripts/minikube/start_minikube.sh new file mode 100644 index 000000000..b1e4c4c98 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es-2/scripts/minikube/start_minikube.sh @@ -0,0 +1,19 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +eval $(minikube docker-env) +minikube start --insecure-registry https://quay.io --memory=4096 --cpus=4 +minikube ssh "sudo ip link set docker0 promisc on" \ No newline at end of file diff --git a/tests/test_kubernetes_compiled/minikube-es-2/scripts/setup_cluster.sh b/tests/test_kubernetes_compiled/minikube-es-2/scripts/setup_cluster.sh new file mode 100644 index 000000000..191ba5c55 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es-2/scripts/setup_cluster.sh @@ -0,0 +1,18 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + + + diff --git a/tests/test_kubernetes_compiled/minikube-es-2/scripts/setup_context.sh b/tests/test_kubernetes_compiled/minikube-es-2/scripts/setup_context.sh new file mode 100644 index 000000000..7b77b0857 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es-2/scripts/setup_context.sh @@ -0,0 +1,18 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +kubectl config set-context minikube-es-2 --cluster minikube --user minikube --namespace minikube-es +kubectl config use-context minikube-es-2 \ No newline at end of file diff --git a/tests/test_kubernetes_compiled/minikube-es/README.md b/tests/test_kubernetes_compiled/minikube-es/README.md new file mode 100644 index 000000000..a6076b3f2 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es/README.md @@ -0,0 +1,61 @@ +# Elasticsearch Minikube + +This is a specific version of Elasticsearch to run on a minikube instalation. + +## Prerequisites + +Elasticsearch is a resource hungry application, for this setup we require +that minikube is running with the above options: + +``` +$ minikube start --insecure-registry https://quay.io --memory=4096 --cpus=2 +``` + +_If_ you have created the minikube VM previously, you will most likely need to +delete the vm and recreate it with more memory/cpu. (i.e. +```$ minikube delete```) + +## Setting up + +Assuming you're already running Minikube, setup for this target: + +``` +$ scripts/setup.sh +``` + +This will create a context in your minikube cluster called minikube-es. + + +Apply the compiled manifests: + +``` +$ scripts/kubectl.sh apply -f manifests/ +``` + +If the commands above did not error, you should be good to go. + +Let's confirm everything is up: + +``` +$ scripts/kubectl.sh get pods -w +``` + +## Connecting to Elasticsearch + +List the elasticsearch service endpoints running in the cluster: + +``` +$ minikube service -n minikube-es elasticsearch --url +``` + +and curl the health endpoint, i.e.: +```$ curl http://192.168.99.100:32130/_cluster/health?pretty``` + + +## Deleting Elasticsearch + +Deleting is easy (warning, this will remove _everything_): + +``` +$ scripts/kubectl.sh delete -f manifests/ +``` diff --git a/tests/test_kubernetes_compiled/minikube-es/manifests/es-client.yml b/tests/test_kubernetes_compiled/minikube-es/manifests/es-client.yml new file mode 100644 index 000000000..1e9562872 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es/manifests/es-client.yml @@ -0,0 +1,67 @@ +apiVersion: apps/v1beta1 +kind: StatefulSet +metadata: + labels: + name: cluster-client + role: client + name: cluster-client + namespace: minikube-es +spec: + replicas: 2 + serviceName: cluster-client + template: + metadata: + labels: + name: cluster-client + role: client + spec: + containers: + - env: + - name: CLUSTER_NAME + value: cluster + - name: ES_JAVA_OPTS + value: -Xms512m -Xmx512m + - name: HTTP_ENABLE + value: 'true' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: NODE_DATA + value: 'false' + - name: NODE_INGEST + value: 'false' + - name: NODE_MASTER + value: 'false' + - name: NODE_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: NUMBER_OF_MASTERS + value: '1' + image: quay.io/pires/docker-elasticsearch-kubernetes:5.5.0 + imagePullPolicy: Always + name: client + ports: + - containerPort: 9200 + name: client + protocol: TCP + - containerPort: 9300 + name: transport + protocol: TCP + securityContext: + capabilities: + add: + - IPC_LOCK + - SYS_RESOURCE + privileged: false + initContainers: + - command: + - sysctl + - -w + - vm.max_map_count=262144 + image: busybox + imagePullPolicy: IfNotPresent + name: sysctl + securityContext: + privileged: true diff --git a/tests/test_kubernetes_compiled/minikube-es/manifests/es-data.yml b/tests/test_kubernetes_compiled/minikube-es/manifests/es-data.yml new file mode 100644 index 000000000..4d973b756 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es/manifests/es-data.yml @@ -0,0 +1,64 @@ +apiVersion: apps/v1beta1 +kind: StatefulSet +metadata: + labels: + name: cluster-data + role: data + name: cluster-data + namespace: minikube-es +spec: + replicas: 2 + serviceName: cluster-data + template: + metadata: + labels: + name: cluster-data + role: data + spec: + containers: + - env: + - name: CLUSTER_NAME + value: cluster + - name: ES_JAVA_OPTS + value: -Xms512m -Xmx512m + - name: HTTP_ENABLE + value: 'false' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: NODE_DATA + value: 'true' + - name: NODE_INGEST + value: 'false' + - name: NODE_MASTER + value: 'false' + - name: NODE_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: NUMBER_OF_MASTERS + value: '1' + image: quay.io/pires/docker-elasticsearch-kubernetes:5.5.0 + imagePullPolicy: Always + name: data + ports: + - containerPort: 9300 + name: transport + protocol: TCP + securityContext: + capabilities: + add: + - IPC_LOCK + - SYS_RESOURCE + privileged: false + initContainers: + - command: + - sysctl + - -w + - vm.max_map_count=262144 + image: busybox + imagePullPolicy: IfNotPresent + name: sysctl + securityContext: + privileged: true diff --git a/tests/test_kubernetes_compiled/minikube-es/manifests/es-discovery-svc.yml b/tests/test_kubernetes_compiled/minikube-es/manifests/es-discovery-svc.yml new file mode 100644 index 000000000..896b08799 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es/manifests/es-discovery-svc.yml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + name: elasticsearch-discovery + name: elasticsearch-discovery + namespace: minikube-es +spec: + ports: + - name: transport + port: 9300 + targetPort: transport + selector: + name: cluster-master + role: master + type: ClusterIP diff --git a/tests/test_kubernetes_compiled/minikube-es/manifests/es-elasticsearch-svc.yml b/tests/test_kubernetes_compiled/minikube-es/manifests/es-elasticsearch-svc.yml new file mode 100644 index 000000000..bf8838eb8 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es/manifests/es-elasticsearch-svc.yml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + name: elasticsearch + name: elasticsearch + namespace: minikube-es +spec: + ports: + - name: client + port: 9200 + targetPort: client + - name: transport + port: 9300 + targetPort: transport + selector: + name: cluster-client + role: client + type: NodePort diff --git a/tests/test_kubernetes_compiled/minikube-es/manifests/es-master.yml b/tests/test_kubernetes_compiled/minikube-es/manifests/es-master.yml new file mode 100644 index 000000000..98dab044e --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es/manifests/es-master.yml @@ -0,0 +1,64 @@ +apiVersion: apps/v1beta1 +kind: StatefulSet +metadata: + labels: + name: cluster-master + role: master + name: cluster-master + namespace: minikube-es +spec: + replicas: 2 + serviceName: cluster-master + template: + metadata: + labels: + name: cluster-master + role: master + spec: + containers: + - env: + - name: CLUSTER_NAME + value: cluster + - name: ES_JAVA_OPTS + value: -Xms512m -Xmx512m + - name: HTTP_ENABLE + value: 'false' + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: NODE_DATA + value: 'false' + - name: NODE_INGEST + value: 'false' + - name: NODE_MASTER + value: 'true' + - name: NODE_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: NUMBER_OF_MASTERS + value: '1' + image: quay.io/pires/docker-elasticsearch-kubernetes:5.5.0 + imagePullPolicy: Always + name: master + ports: + - containerPort: 9300 + name: transport + protocol: TCP + securityContext: + capabilities: + add: + - IPC_LOCK + - SYS_RESOURCE + privileged: false + initContainers: + - command: + - sysctl + - -w + - vm.max_map_count=262144 + image: busybox + imagePullPolicy: IfNotPresent + name: sysctl + securityContext: + privileged: true diff --git a/tests/test_kubernetes_compiled/minikube-es/scripts/apply.sh b/tests/test_kubernetes_compiled/minikube-es/scripts/apply.sh new file mode 100644 index 000000000..d1803c156 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es/scripts/apply.sh @@ -0,0 +1,23 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +DIR=$(dirname ${BASH_SOURCE[0]}) + +for SECTION in pre-deploy manifests +do + echo "## run kubectl apply for ${SECTION}" + kapitan secrets --reveal -f ${DIR}/../${SECTION}/ | ${DIR}/kubectl.sh apply -f - | column -t +done \ No newline at end of file diff --git a/tests/test_kubernetes_compiled/minikube-es/scripts/delete.sh b/tests/test_kubernetes_compiled/minikube-es/scripts/delete.sh new file mode 100644 index 000000000..af7e5faee --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es/scripts/delete.sh @@ -0,0 +1,19 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +DIR=$(dirname ${BASH_SOURCE[0]}) + +${DIR}/kubectl.sh delete -f ${DIR}/../manifests diff --git a/tests/test_kubernetes_compiled/minikube-es/scripts/kubectl.sh b/tests/test_kubernetes_compiled/minikube-es/scripts/kubectl.sh new file mode 100644 index 000000000..7ce9585f0 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es/scripts/kubectl.sh @@ -0,0 +1,19 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +KUBECTL="kubectl --context minikube-es --insecure-skip-tls-verify=False " + +${KUBECTL} $@ diff --git a/tests/test_kubernetes_compiled/minikube-es/scripts/minikube/install_minikube.sh b/tests/test_kubernetes_compiled/minikube-es/scripts/minikube/install_minikube.sh new file mode 100644 index 000000000..9dd54b6e5 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es/scripts/minikube/install_minikube.sh @@ -0,0 +1,30 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +case "$(uname -s)" in + Linux*) MINIKUBE_BINARY=minikube-linux-amd64;; + Darwin*) MINIKUBE_BINARY=minikube-darwin-amd64;; + *) exit 1 +esac + +MINIKUBE_VERSION=${MINIKUBE_VERSION:-v0.25.0} +URL=https://storage.googleapis.com/minikube/releases/${MINIKUBE_VERSION}/${MINIKUBE_BINARY} + + +echo Downloading minikube release ${MINIKUBE_VERSION} to /usr/local/bin/minikube +pause +sudo curl --progress-bar -o /usr/local/bin/minikube ${URL} +sudo chmod +x /usr/local/bin/minikube \ No newline at end of file diff --git a/tests/test_kubernetes_compiled/minikube-es/scripts/minikube/start_minikube.sh b/tests/test_kubernetes_compiled/minikube-es/scripts/minikube/start_minikube.sh new file mode 100644 index 000000000..b1e4c4c98 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es/scripts/minikube/start_minikube.sh @@ -0,0 +1,19 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +eval $(minikube docker-env) +minikube start --insecure-registry https://quay.io --memory=4096 --cpus=4 +minikube ssh "sudo ip link set docker0 promisc on" \ No newline at end of file diff --git a/tests/test_kubernetes_compiled/minikube-es/scripts/setup_cluster.sh b/tests/test_kubernetes_compiled/minikube-es/scripts/setup_cluster.sh new file mode 100644 index 000000000..191ba5c55 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es/scripts/setup_cluster.sh @@ -0,0 +1,18 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + + + diff --git a/tests/test_kubernetes_compiled/minikube-es/scripts/setup_context.sh b/tests/test_kubernetes_compiled/minikube-es/scripts/setup_context.sh new file mode 100644 index 000000000..304dc3412 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-es/scripts/setup_context.sh @@ -0,0 +1,18 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +kubectl config set-context minikube-es --cluster minikube --user minikube --namespace minikube-es +kubectl config use-context minikube-es \ No newline at end of file diff --git a/tests/test_kubernetes_compiled/minikube-mysql/README.md b/tests/test_kubernetes_compiled/minikube-mysql/README.md new file mode 100644 index 000000000..e1576039f --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-mysql/README.md @@ -0,0 +1,61 @@ +# Elasticsearch Minikube + +This is a specific version of Elasticsearch to run on a minikube instalation. + +## Prerequisites + +Elasticsearch is a resource hungry application, for this setup we require +that minikube is running with the above options: + +``` +$ minikube start --insecure-registry https://quay.io --memory=4096 --cpus=2 +``` + +_If_ you have created the minikube VM previously, you will most likely need to +delete the vm and recreate it with more memory/cpu. (i.e. +```$ minikube delete```) + +## Setting up + +Assuming you're already running Minikube, setup for this target: + +``` +$ scripts/setup.sh +``` + +This will create a context in your minikube cluster called minikube-mysql. + + +Apply the compiled manifests: + +``` +$ scripts/kubectl.sh apply -f manifests/ +``` + +If the commands above did not error, you should be good to go. + +Let's confirm everything is up: + +``` +$ scripts/kubectl.sh get pods -w +``` + +## Connecting to Elasticsearch + +List the elasticsearch service endpoints running in the cluster: + +``` +$ minikube service -n minikube-mysql elasticsearch --url +``` + +and curl the health endpoint, i.e.: +```$ curl http://192.168.99.100:32130/_cluster/health?pretty``` + + +## Deleting Elasticsearch + +Deleting is easy (warning, this will remove _everything_): + +``` +$ scripts/kubectl.sh delete -f manifests/ +``` diff --git a/tests/test_kubernetes_compiled/minikube-mysql/manifests/mysql_secret.yml b/tests/test_kubernetes_compiled/minikube-mysql/manifests/mysql_secret.yml new file mode 100644 index 000000000..1d25729c0 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-mysql/manifests/mysql_secret.yml @@ -0,0 +1,10 @@ +apiVersion: v1 +data: + MYSQL_ROOT_PASSWORD: P3tncGc6bXlzcWwvcm9vdC9wYXNzd29yZH0= +kind: Secret +metadata: + labels: + name: example-mysql + name: example-mysql + namespace: minikube-mysql +type: Opaque diff --git a/tests/test_kubernetes_compiled/minikube-mysql/manifests/mysql_service_jsonnet.yml b/tests/test_kubernetes_compiled/minikube-mysql/manifests/mysql_service_jsonnet.yml new file mode 100644 index 000000000..f6ab65e52 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-mysql/manifests/mysql_service_jsonnet.yml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + name: example-mysql-jsonnet + name: example-mysql-jsonnet + namespace: minikube-mysql +spec: + clusterIP: None + ports: + - name: mysql + port: 3306 + targetPort: mysql + selector: + name: example-mysql + type: ClusterIP diff --git a/tests/test_kubernetes_compiled/minikube-mysql/manifests/mysql_service_simple.yml b/tests/test_kubernetes_compiled/minikube-mysql/manifests/mysql_service_simple.yml new file mode 100644 index 000000000..eb6bc2e53 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-mysql/manifests/mysql_service_simple.yml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + name: example-mysql + name: example-mysql + namespace: minikube-mysql +spec: + clusterIP: None + ports: + - name: mysql + port: 3306 + targetPort: mysql + selector: + name: example-mysql + type: ClusterIP diff --git a/tests/test_kubernetes_compiled/minikube-mysql/manifests/mysql_statefulset.yml b/tests/test_kubernetes_compiled/minikube-mysql/manifests/mysql_statefulset.yml new file mode 100644 index 000000000..839a4a3b9 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-mysql/manifests/mysql_statefulset.yml @@ -0,0 +1,44 @@ +apiVersion: apps/v1beta1 +kind: StatefulSet +metadata: + labels: + name: example-mysql + name: example-mysql + namespace: minikube-mysql +spec: + replicas: 1 + serviceName: example-mysql + template: + metadata: + labels: + name: example-mysql + spec: + containers: + - env: + - name: MYSQL_ROOT_PASSWORD + valueFrom: + secretKeyRef: + key: MYSQL_ROOT_PASSWORD + name: example-mysql + image: mysql:latest + imagePullPolicy: Always + name: mysql + ports: + - containerPort: 3306 + name: mysql + volumeClaimTemplates: + - apiVersion: v1 + kind: PersistentVolumeClaim + metadata: + annotations: + volume.beta.kubernetes.io/storage-class: standard + labels: + name: data + name: data + namespace: minikube-mysql + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10G diff --git a/tests/test_kubernetes_compiled/minikube-mysql/pre-deploy/00_namespace.yml b/tests/test_kubernetes_compiled/minikube-mysql/pre-deploy/00_namespace.yml new file mode 100644 index 000000000..9b26b383e --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-mysql/pre-deploy/00_namespace.yml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: Namespace +metadata: + labels: + name: minikube-mysql + name: minikube-mysql + namespace: minikube-mysql diff --git a/tests/test_kubernetes_compiled/minikube-mysql/pre-deploy/10_serviceaccount.yml b/tests/test_kubernetes_compiled/minikube-mysql/pre-deploy/10_serviceaccount.yml new file mode 100644 index 000000000..691d82c14 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-mysql/pre-deploy/10_serviceaccount.yml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + labels: + name: default + name: default + namespace: minikube-mysql diff --git a/tests/test_kubernetes_compiled/minikube-mysql/scripts/apply.sh b/tests/test_kubernetes_compiled/minikube-mysql/scripts/apply.sh new file mode 100644 index 000000000..d1803c156 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-mysql/scripts/apply.sh @@ -0,0 +1,23 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +DIR=$(dirname ${BASH_SOURCE[0]}) + +for SECTION in pre-deploy manifests +do + echo "## run kubectl apply for ${SECTION}" + kapitan secrets --reveal -f ${DIR}/../${SECTION}/ | ${DIR}/kubectl.sh apply -f - | column -t +done \ No newline at end of file diff --git a/tests/test_kubernetes_compiled/minikube-mysql/scripts/delete.sh b/tests/test_kubernetes_compiled/minikube-mysql/scripts/delete.sh new file mode 100644 index 000000000..af7e5faee --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-mysql/scripts/delete.sh @@ -0,0 +1,19 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +DIR=$(dirname ${BASH_SOURCE[0]}) + +${DIR}/kubectl.sh delete -f ${DIR}/../manifests diff --git a/tests/test_kubernetes_compiled/minikube-mysql/scripts/kubectl.sh b/tests/test_kubernetes_compiled/minikube-mysql/scripts/kubectl.sh new file mode 100644 index 000000000..b410d8be8 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-mysql/scripts/kubectl.sh @@ -0,0 +1,19 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +KUBECTL="kubectl --context minikube-mysql --insecure-skip-tls-verify=False " + +${KUBECTL} $@ diff --git a/tests/test_kubernetes_compiled/minikube-mysql/scripts/minikube/install_minikube.sh b/tests/test_kubernetes_compiled/minikube-mysql/scripts/minikube/install_minikube.sh new file mode 100644 index 000000000..9dd54b6e5 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-mysql/scripts/minikube/install_minikube.sh @@ -0,0 +1,30 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +case "$(uname -s)" in + Linux*) MINIKUBE_BINARY=minikube-linux-amd64;; + Darwin*) MINIKUBE_BINARY=minikube-darwin-amd64;; + *) exit 1 +esac + +MINIKUBE_VERSION=${MINIKUBE_VERSION:-v0.25.0} +URL=https://storage.googleapis.com/minikube/releases/${MINIKUBE_VERSION}/${MINIKUBE_BINARY} + + +echo Downloading minikube release ${MINIKUBE_VERSION} to /usr/local/bin/minikube +pause +sudo curl --progress-bar -o /usr/local/bin/minikube ${URL} +sudo chmod +x /usr/local/bin/minikube \ No newline at end of file diff --git a/tests/test_kubernetes_compiled/minikube-mysql/scripts/minikube/start_minikube.sh b/tests/test_kubernetes_compiled/minikube-mysql/scripts/minikube/start_minikube.sh new file mode 100644 index 000000000..b1e4c4c98 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-mysql/scripts/minikube/start_minikube.sh @@ -0,0 +1,19 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +eval $(minikube docker-env) +minikube start --insecure-registry https://quay.io --memory=4096 --cpus=4 +minikube ssh "sudo ip link set docker0 promisc on" \ No newline at end of file diff --git a/tests/test_kubernetes_compiled/minikube-mysql/scripts/setup_cluster.sh b/tests/test_kubernetes_compiled/minikube-mysql/scripts/setup_cluster.sh new file mode 100644 index 000000000..191ba5c55 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-mysql/scripts/setup_cluster.sh @@ -0,0 +1,18 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + + + diff --git a/tests/test_kubernetes_compiled/minikube-mysql/scripts/setup_context.sh b/tests/test_kubernetes_compiled/minikube-mysql/scripts/setup_context.sh new file mode 100644 index 000000000..c0415a970 --- /dev/null +++ b/tests/test_kubernetes_compiled/minikube-mysql/scripts/setup_context.sh @@ -0,0 +1,18 @@ +#!/bin/bash -eu +# +# Copyright 2018 The Kapitan Authors +# +# 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. + +kubectl config set-context minikube-mysql --cluster minikube --user minikube --namespace minikube-mysql +kubectl config use-context minikube-mysql \ No newline at end of file From b1201da8b137e836e864dfb96fc4e415d7022004 Mon Sep 17 00:00:00 2001 From: Adrian Chifor Date: Thu, 22 Mar 2018 17:33:32 +0000 Subject: [PATCH 3/3] Raise exceptions instead of returning --- kapitan/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kapitan/utils.py b/kapitan/utils.py index e295caf5b..146ab51e3 100644 --- a/kapitan/utils.py +++ b/kapitan/utils.py @@ -213,6 +213,7 @@ def deep_get(x, keys): for i in output: print('{0!s:{l}} {1!s}'.format(*i, l=maxlenght + 2)) + def get_directory_hash(directory): ''' Compute a sha256 hash for the file contents of a directory @@ -231,10 +232,10 @@ def get_directory_hash(directory): hash.update(sha256(f.read().encode("UTF-8")).hexdigest().encode("UTF-8")) except Exception as e: logger.error("utils.get_directory_hash failed to open %s: %s", file_path, str(e)) - return -2 + raise except Exception as e: logger.error("utils.get_directory_hash failed: %s", str(e)) - return -2 + raise return hash.hexdigest()