From 63f2f6b1a61edac23037682b86e3574c14dcf67f Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Thu, 27 Jul 2023 14:55:38 +0545 Subject: [PATCH] chore: separate search fixtures --- .github/workflows/test.yml | 1 + fixtures/datasources/_post_setup.sh | 9 - fixtures/datasources/_setup.yaml | 177 ------------------ fixtures/datasources/kustomization.yaml | 4 - fixtures/search/_post_setup.sh | 11 ++ fixtures/search/_setup.yaml | 176 +++++++++++++++++ .../elasticsearch_fail.yaml | 0 .../elasticsearch_pass.yaml | 0 fixtures/search/kustomization.yaml | 8 + .../opensearch_fail.yaml | 0 .../opensearch_pass.yaml | 0 11 files changed, 196 insertions(+), 190 deletions(-) create mode 100644 fixtures/search/_post_setup.sh create mode 100644 fixtures/search/_setup.yaml rename fixtures/{datasources => search}/elasticsearch_fail.yaml (100%) rename fixtures/{datasources => search}/elasticsearch_pass.yaml (100%) create mode 100644 fixtures/search/kustomization.yaml rename fixtures/{datasources => search}/opensearch_fail.yaml (100%) rename fixtures/{datasources => search}/opensearch_pass.yaml (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a1835594c..661b3a5c8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,6 +18,7 @@ jobs: - minimal --skip-all - k8s - datasources + - search - git # - restic runs-on: ubuntu-latest diff --git a/fixtures/datasources/_post_setup.sh b/fixtures/datasources/_post_setup.sh index 6731e724b..05a7907cf 100644 --- a/fixtures/datasources/_post_setup.sh +++ b/fixtures/datasources/_post_setup.sh @@ -1,11 +1,2 @@ #!/bin/bash -echo "Running kubectl wait for elasticsearch" -kubectl -n default wait --for=condition=ready pod -l app=elasticsearch --timeout=5m - -echo "Fetching elastic search health"; -curl -s "http://elasticsearch.default.svc.cluster.local:9200/_cluster/health" -H 'Content-Type: application/json'; -curl -s "http://elasticsearch.default.svc.cluster.local:9200/_cluster/allocation/explain" -H 'Content-Type: application/json'; - -echo "Fetching populate-db logs from elasticsearch pod"; -kubectl logs -n default -l app=elasticsearch -c populate-db \ No newline at end of file diff --git a/fixtures/datasources/_setup.yaml b/fixtures/datasources/_setup.yaml index 64a5d3540..f0ac97d82 100644 --- a/fixtures/datasources/_setup.yaml +++ b/fixtures/datasources/_setup.yaml @@ -580,183 +580,6 @@ metadata: namespace: default --- apiVersion: v1 -kind: Secret -metadata: - name: search - namespace: default -stringData: - OPENSEARCH_USERNAME: admin - OPENSEARCH_PASSWORD: secret - ELASTIC_SEARCH_USERNAME: admin - ELASTIC_SEARCH_PASSWORD: secret ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - labels: - app: elasticsearch - name: elasticsearch - namespace: default -spec: - replicas: 1 - selector: - matchLabels: - app: elasticsearch - template: - metadata: - labels: - app: elasticsearch - spec: - containers: - - name: elasticsearch - image: docker.elastic.co/elasticsearch/elasticsearch:8.1.3 - env: - - name: ES_JAVA_OPTS - value: "-Xms256m -Xmx256m" - - name: network.bind_host - value: 0.0.0.0 - - name: network.host - value: 0.0.0.0 - - name: discovery.type - value: single-node - - name: xpack.security.enabled - value: "false" - imagePullPolicy: IfNotPresent - ports: - - containerPort: 9200 - name: http - protocol: TCP - - containerPort: 9300 - name: transport - protocol: TCP - readinessProbe: - httpGet: - path: / - port: 9200 - initialDelaySeconds: 10 - - name: populate-db - image: ellerbrock/alpine-bash-curl-ssl - command: ["/bin/sh", "-c"] - readinessProbe: - exec: - command: - - ls - - /tmp/done - args: - # We install wait-for-it and wait for elasticsearch to be ready and then - # populate it with dummy data - - > - echo "Starting Elasticsearch"; - curl -s https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -o wait-for-it.sh; - chmod +x wait-for-it.sh; ./wait-for-it.sh localhost:9200 --timeout=0; - printf "\nWaiting for cluster status to be green\n"; - curl -s -X GET "localhost:9200/_cluster/health?wait_for_status=green&wait_for_active_shards=all&timeout=2m" -H 'Content-Type: application/json'; - printf "\nCreating new index\n"; - curl -s -X PUT localhost:9200/index; - printf "\nReducing replicas to 0\n"; - curl -s -X PUT "localhost:9200/index/_settings" -H 'Content-Type: application/json' -d '{"index" : {"number_of_replicas" : 0}}'; - print "\nGetting Health data\n"; - curl -s "localhost:9200/_cluster/health" -H 'Content-Type: application/json'; - curl -s "localhost:9200/_cluster/allocation/explain" -H 'Content-Type: application/json'; - printf "\nInserting dummy data\n"; - curl -s -X POST localhost:9200/index/_doc -d '{"system": {"role": "api"}}' -H 'Content-Type: application/json'; - printf "\nCreating /tmp/done\n"; - touch /tmp/done; - sleep 365d; ---- -apiVersion: v1 -kind: Service -metadata: - name: elasticsearch - namespace: default -spec: - ports: - - name: elasticsearch - port: 9200 - targetPort: 9200 - protocol: TCP - selector: - app: elasticsearch ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - labels: - app: opensearch - name: opensearch - namespace: default -spec: - replicas: 1 - selector: - matchLabels: - app: opensearch - template: - metadata: - labels: - app: opensearch - spec: - containers: - - name: opensearch - image: opensearchproject/opensearch:2.7.0 - env: - - name: ES_JAVA_OPTS - value: "-Xms256m -Xmx256m" - - name: network.bind_host - value: 0.0.0.0 - - name: network.host - value: 0.0.0.0 - - name: discovery.type - value: single-node - - name: DISABLE_SECURITY_PLUGIN - value: "true" - imagePullPolicy: IfNotPresent - ports: - - containerPort: 9200 - name: http - protocol: TCP - - containerPort: 9300 - name: transport - protocol: TCP - readinessProbe: - httpGet: - path: / - port: 9200 - initialDelaySeconds: 10 - - name: populate-db - image: debian:bookworm - command: ["/bin/sh", "-c"] - readinessProbe: - exec: - command: - - ls - - /tmp/done - args: - # We install wait-for-it and wait for elasticsearch to be ready and then - # populate it with dummy data - - > - apt update && apt install -y curl; - curl https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -o wait-for-it.sh; - chmod +x wait-for-it.sh; ./wait-for-it.sh localhost:9200 --timeout=0; - curl -X PUT localhost:9200/index; - curl -X POST localhost:9200/index/_doc -d '{"system": {"role": "api", "version": "v1.0"}}' -H 'Content-Type: application/json'; - touch /tmp/done; - sleep infinity ---- -apiVersion: v1 -kind: Service -metadata: - name: opensearch - namespace: default -spec: - ports: - - name: opensearch - port: 9200 - targetPort: 9200 - protocol: TCP - selector: - app: opensearch ---- -apiVersion: v1 kind: Namespace metadata: name: ldap diff --git a/fixtures/datasources/kustomization.yaml b/fixtures/datasources/kustomization.yaml index 3e0928eda..670f5438d 100644 --- a/fixtures/datasources/kustomization.yaml +++ b/fixtures/datasources/kustomization.yaml @@ -14,8 +14,4 @@ resources: - prometheus.yaml - redis_fail.yaml - redis_pass.yaml - - elasticsearch_fail.yaml - - elasticsearch_pass.yaml - - opensearch_fail.yaml - - opensearch_pass.yaml - alertmanager_fail.yaml diff --git a/fixtures/search/_post_setup.sh b/fixtures/search/_post_setup.sh new file mode 100644 index 000000000..6731e724b --- /dev/null +++ b/fixtures/search/_post_setup.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +echo "Running kubectl wait for elasticsearch" +kubectl -n default wait --for=condition=ready pod -l app=elasticsearch --timeout=5m + +echo "Fetching elastic search health"; +curl -s "http://elasticsearch.default.svc.cluster.local:9200/_cluster/health" -H 'Content-Type: application/json'; +curl -s "http://elasticsearch.default.svc.cluster.local:9200/_cluster/allocation/explain" -H 'Content-Type: application/json'; + +echo "Fetching populate-db logs from elasticsearch pod"; +kubectl logs -n default -l app=elasticsearch -c populate-db \ No newline at end of file diff --git a/fixtures/search/_setup.yaml b/fixtures/search/_setup.yaml new file mode 100644 index 000000000..a8fe1225c --- /dev/null +++ b/fixtures/search/_setup.yaml @@ -0,0 +1,176 @@ +apiVersion: v1 +kind: Secret +metadata: + name: search + namespace: default +stringData: + OPENSEARCH_USERNAME: admin + OPENSEARCH_PASSWORD: secret + ELASTIC_SEARCH_USERNAME: admin + ELASTIC_SEARCH_PASSWORD: secret +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: elasticsearch + name: elasticsearch + namespace: default +spec: + replicas: 1 + selector: + matchLabels: + app: elasticsearch + template: + metadata: + labels: + app: elasticsearch + spec: + containers: + - name: elasticsearch + image: docker.elastic.co/elasticsearch/elasticsearch:8.1.3 + env: + - name: ES_JAVA_OPTS + value: "-Xms256m -Xmx256m" + - name: network.bind_host + value: 0.0.0.0 + - name: network.host + value: 0.0.0.0 + - name: discovery.type + value: single-node + - name: xpack.security.enabled + value: "false" + imagePullPolicy: IfNotPresent + ports: + - containerPort: 9200 + name: http + protocol: TCP + - containerPort: 9300 + name: transport + protocol: TCP + readinessProbe: + httpGet: + path: / + port: 9200 + initialDelaySeconds: 10 + - name: populate-db + image: ellerbrock/alpine-bash-curl-ssl + command: ["/bin/sh", "-c"] + readinessProbe: + exec: + command: + - ls + - /tmp/done + args: + # We install wait-for-it and wait for elasticsearch to be ready and then + # populate it with dummy data + - > + echo "Starting Elasticsearch"; + curl -s https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -o wait-for-it.sh; + chmod +x wait-for-it.sh; ./wait-for-it.sh localhost:9200 --timeout=0; + printf "\nWaiting for cluster status to be green\n"; + curl -s -X GET "localhost:9200/_cluster/health?wait_for_status=green&wait_for_active_shards=all&timeout=2m" -H 'Content-Type: application/json'; + printf "\nCreating new index\n"; + curl -s -X PUT localhost:9200/index; + printf "\nReducing replicas to 0\n"; + curl -s -X PUT "localhost:9200/index/_settings" -H 'Content-Type: application/json' -d '{"index" : {"number_of_replicas" : 0}}'; + print "\nGetting Health data\n"; + curl -s "localhost:9200/_cluster/health" -H 'Content-Type: application/json'; + curl -s "localhost:9200/_cluster/allocation/explain" -H 'Content-Type: application/json'; + printf "\nInserting dummy data\n"; + curl -s -X POST localhost:9200/index/_doc -d '{"system": {"role": "api"}}' -H 'Content-Type: application/json'; + printf "\nCreating /tmp/done\n"; + touch /tmp/done; + sleep 365d; +--- +apiVersion: v1 +kind: Service +metadata: + name: elasticsearch + namespace: default +spec: + ports: + - name: elasticsearch + port: 9200 + targetPort: 9200 + protocol: TCP + selector: + app: elasticsearch +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: opensearch + name: opensearch + namespace: default +spec: + replicas: 1 + selector: + matchLabels: + app: opensearch + template: + metadata: + labels: + app: opensearch + spec: + containers: + - name: opensearch + image: opensearchproject/opensearch:2.7.0 + env: + - name: ES_JAVA_OPTS + value: "-Xms256m -Xmx256m" + - name: network.bind_host + value: 0.0.0.0 + - name: network.host + value: 0.0.0.0 + - name: discovery.type + value: single-node + - name: DISABLE_SECURITY_PLUGIN + value: "true" + imagePullPolicy: IfNotPresent + ports: + - containerPort: 9200 + name: http + protocol: TCP + - containerPort: 9300 + name: transport + protocol: TCP + readinessProbe: + httpGet: + path: / + port: 9200 + initialDelaySeconds: 10 + - name: populate-db + image: debian:bookworm + command: ["/bin/sh", "-c"] + readinessProbe: + exec: + command: + - ls + - /tmp/done + args: + # We install wait-for-it and wait for elasticsearch to be ready and then + # populate it with dummy data + - > + apt update && apt install -y curl; + curl https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -o wait-for-it.sh; + chmod +x wait-for-it.sh; ./wait-for-it.sh localhost:9200 --timeout=0; + curl -X PUT localhost:9200/index; + curl -X POST localhost:9200/index/_doc -d '{"system": {"role": "api", "version": "v1.0"}}' -H 'Content-Type: application/json'; + touch /tmp/done; + sleep infinity +--- +apiVersion: v1 +kind: Service +metadata: + name: opensearch + namespace: default +spec: + ports: + - name: opensearch + port: 9200 + targetPort: 9200 + protocol: TCP + selector: + app: opensearch \ No newline at end of file diff --git a/fixtures/datasources/elasticsearch_fail.yaml b/fixtures/search/elasticsearch_fail.yaml similarity index 100% rename from fixtures/datasources/elasticsearch_fail.yaml rename to fixtures/search/elasticsearch_fail.yaml diff --git a/fixtures/datasources/elasticsearch_pass.yaml b/fixtures/search/elasticsearch_pass.yaml similarity index 100% rename from fixtures/datasources/elasticsearch_pass.yaml rename to fixtures/search/elasticsearch_pass.yaml diff --git a/fixtures/search/kustomization.yaml b/fixtures/search/kustomization.yaml new file mode 100644 index 000000000..657f19b35 --- /dev/null +++ b/fixtures/search/kustomization.yaml @@ -0,0 +1,8 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - _setup.yaml + - elasticsearch_fail.yaml + - elasticsearch_pass.yaml + - opensearch_fail.yaml + - opensearch_pass.yaml diff --git a/fixtures/datasources/opensearch_fail.yaml b/fixtures/search/opensearch_fail.yaml similarity index 100% rename from fixtures/datasources/opensearch_fail.yaml rename to fixtures/search/opensearch_fail.yaml diff --git a/fixtures/datasources/opensearch_pass.yaml b/fixtures/search/opensearch_pass.yaml similarity index 100% rename from fixtures/datasources/opensearch_pass.yaml rename to fixtures/search/opensearch_pass.yaml