Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Add initial test structure. #3

Merged
merged 21 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2ba0a8b
Create initial testing structure and tests.
mpereira Oct 14, 2019
06a01ce
Build docker image.
mpereira Oct 24, 2019
8f3eee7
Format with `goimports -w .`.
mpereira Oct 24, 2019
80382ff
Sync CI tooling to the latest master.
mpereira Oct 24, 2019
dd52e8f
Fix log messages.
mpereira Oct 24, 2019
65b0311
Increase deployment completion timeout.
mpereira Oct 24, 2019
22a669b
Increase deployment completion timeout to 10 minutes.
mpereira Oct 24, 2019
7d97188
Use https://github.com/mesosphere/data-services-kudo/pull/38.
mpereira Oct 28, 2019
8453eb1
Tweak timeouts.
mpereira Oct 28, 2019
1ae8b5f
Use updated https://github.com/mesosphere/data-services-kudo/pull/38.
mpereira Oct 28, 2019
650da87
Get operator name from environment variable.
mpereira Oct 28, 2019
4bc0d1d
Use updated https://github.com/mesosphere/data-services-kudo/pull/38.
mpereira Oct 28, 2019
07a6570
Merge remote-tracking branch 'upstream/master' into initial-test-stru…
mpereira Oct 29, 2019
e0fe6db
Use updated https://github.com/mesosphere/data-services-kudo/pull/38.
mpereira Oct 29, 2019
f04f3b0
Empty commit to trigger CI.
mpereira Oct 29, 2019
37c8928
Script improvements.
mpereira Oct 29, 2019
715cac6
Document command for building Docker images.
mpereira Oct 29, 2019
21b803e
Add usage to uninstall_operator.sh script.
mpereira Oct 29, 2019
7d9f76f
Add tooling to check formatting and format go code.
mpereira Oct 29, 2019
7b3323d
Update README.
mpereira Oct 29, 2019
3166987
Update data-services-kudo module to the latest master.
mpereira Oct 29, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*-junit.xml
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- [Docker daemon running under a non-root
user](https://docs.docker.com/install/linux/linux-postinstall/) (only for
Linux)
- [KUDO](https://github.com/kudobuilder/kudo/releases) (last tested on 0.7.2)
- [KUDO](https://github.com/kudobuilder/kudo/releases) (last tested on 0.7.4)
- Kubernetes cluster (last tested on [Konvoy
v1.1.5](https://github.com/mesosphere/konvoy/releases))

Expand Down Expand Up @@ -96,7 +96,7 @@ kubectl exec "${kudo_cassandra_pod_0}" \
### Uninstalling the KUDO Cassandra operator

```bash
./scripts/uninstall_kudo_cassandra.sh \
./scripts/uninstall_operator.sh \
--instance "${kudo_cassandra_instance_name}" \
--namespace "${kudo_cassandra_instance_namespace}"
```
Expand All @@ -105,7 +105,8 @@ kubectl exec "${kudo_cassandra_pod_0}" \

### Requirements

- [bash 4](https://www.tldp.org/LDP/abs/html/bashver4.html)
- bash 4 ([macOS](https://formulae.brew.sh/formula/bash))
- envsubst ([macOS](https://formulae.brew.sh/formula/gettext))

### Compiling templates

Expand Down
19 changes: 19 additions & 0 deletions images/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# shellcheck disable=SC2039

set -euxo pipefail

readonly SCRIPT_DIRECTORY="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
readonly PROJECT_DIRECTORY="$(readlink -f "${SCRIPT_DIRECTORY}/..")"

# shellcheck source=../metadata.sh
source "${PROJECT_DIRECTORY}/metadata.sh"

docker image build \
-t "${CASSANDRA_DOCKER_IMAGE}" \
-f "${PROJECT_DIRECTORY}/images/Dockerfile" \
"${PROJECT_DIRECTORY}/images"

if [[ "${1:-}" == "push" ]]; then
docker push "${CASSANDRA_DOCKER_IMAGE}"
fi
47 changes: 43 additions & 4 deletions metadata.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,53 @@
#!/usr/bin/env bash

# https://github.com/kudobuilder/kudo/releases/tag/v0.6.0
export KUDO_VERSION="0.7.2"
# This script contains metadata that is either used in other scripts or expanded
# into templates via `tools/compile_templates.sh`.

script_directory="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
project_directory="$(readlink -f "${script_directory}")"

################################################################################
################################# Operator #####################################
################################################################################

# https://github.com/mesosphere/kudo-cassandra-operator

export PROJECT_NAME="kudo-cassandra-operator"
export OPERATOR_NAME="cassandra"

# KUDO still doesn't support snapshots, or compound versions yet. Check out:
# - https://github.com/kudobuilder/kudo/pull/889
# - https://github.com/kudobuilder/kudo/issues/163
export OPERATOR_VERSION="0.1.0"

export OPERATOR_DIRECTORY="${project_directory}/operator"
export VENDOR_DIRECTORY="${project_directory}/shared/vendor"

################################################################################
############################### Dependencies ###################################
################################################################################

# http://www.apache.org/dyn/closer.lua/cassandra/3.11.4
# https://hub.docker.com/_/cassandra
# https://github.com/docker-library/cassandra/blob/master/3.11/Dockerfile
export CASSANDRA_VERSION="3.11.4"

# https://github.com/mesosphere/kudo-cassandra-operator/releases
export KUDO_CASSANDRA_VERSION="0.1.0"
# https://github.com/kudobuilder/kudo/releases/tag/v0.7.4
export KUDO_VERSION="0.7.4"

export KUBERNETES_VERSION="1.15.0"

################################################################################
############################## Docker images ###################################
################################################################################

export CASSANDRA_DOCKER_IMAGE_NAMESPACE="mesosphere"
export CASSANDRA_DOCKER_IMAGE_NAME="${OPERATOR_NAME}"
export CASSANDRA_DOCKER_IMAGE_TAG="${OPERATOR_VERSION}-${CASSANDRA_VERSION}"
export CASSANDRA_DOCKER_IMAGE="${CASSANDRA_DOCKER_IMAGE_NAMESPACE}/${CASSANDRA_DOCKER_IMAGE_NAME}:${CASSANDRA_DOCKER_IMAGE_TAG}"

################################################################################
################################# Testing ######################################
################################################################################

export INTEGRATION_TESTS_DOCKER_IMAGE="golang:1.13.1-stretch"
2 changes: 1 addition & 1 deletion operator/operator.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "cassandra"
version: "0.1.0"
kudoVersion: "0.7.2"
kudoVersion: "0.7.4"
kubernetesVersion: "1.15.0"
appVersion: "3.11.4"
maintainers:
Expand Down
34 changes: 34 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
# shellcheck disable=SC2039

set -euxo pipefail

readonly SCRIPT_DIRECTORY="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
readonly PROJECT_DIRECTORY="$(readlink -f "${SCRIPT_DIRECTORY}")"

# shellcheck source=metadata.sh
source "${PROJECT_DIRECTORY}/metadata.sh"

readonly KUBECONFIG="${KUBECONFIG:-${HOME}/.kube/config}"

readonly CONTAINER_KUBECONFIG="/root/.kube/config"
readonly CONTAINER_PROJECT_DIRECTORY="/${PROJECT_NAME}"
readonly CONTAINER_OPERATOR_DIRECTORY="${CONTAINER_PROJECT_DIRECTORY}/operator"
readonly CONTAINER_VENDOR_DIRECTORY="${CONTAINER_PROJECT_DIRECTORY}/shared/vendor"

# DS_KUDO_VERSION is used by the shared tooling.

docker run \
--rm \
-e "KUBECONFIG=${CONTAINER_KUBECONFIG}" \
-e "KUBECTL_PATH=${CONTAINER_VENDOR_DIRECTORY}/kubectl.sh" \
-e "DS_KUDO_VERSION=v${KUDO_VERSION}" \
-e "OPERATOR_DIRECTORY=${CONTAINER_OPERATOR_DIRECTORY}" \
-e "VENDOR_DIRECTORY=${CONTAINER_VENDOR_DIRECTORY}" \
-v "${KUBECONFIG}:${CONTAINER_KUBECONFIG}:ro" \
-v "${OPERATOR_DIRECTORY}:${CONTAINER_OPERATOR_DIRECTORY}:ro" \
-v "${PROJECT_DIRECTORY}:${CONTAINER_PROJECT_DIRECTORY}" \
-v "${VENDOR_DIRECTORY}:${CONTAINER_VENDOR_DIRECTORY}" \
-w "${CONTAINER_PROJECT_DIRECTORY}" \
"${INTEGRATION_TESTS_DOCKER_IMAGE}" \
bash -c "${CONTAINER_PROJECT_DIRECTORY}/tests/run.sh"
7 changes: 7 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Scripts

Scripts to be used by operators.

## `uninstall_operator.sh`

TODO(mpereira) description.
63 changes: 0 additions & 63 deletions scripts/uninstall_kudo_cassandra.sh

This file was deleted.

70 changes: 70 additions & 0 deletions scripts/uninstall_operator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
# shellcheck disable=SC2039

readonly SCRIPT_DIRECTORY="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
readonly PROJECT_DIRECTORY="$(readlink -f "${SCRIPT_DIRECTORY}/..")"

# shellcheck source=../metadata.sh
source "${PROJECT_DIRECTORY}/metadata.sh"

kubectl="${KUBECTL_PATH:-kubectl}"

operator_name=
operator_version=
operator_instance_name=
operator_instance_namespace=

while [[ ${#} -gt 0 ]]; do
# TODO(mpereira): handle parameters passed in as "parameter=value";
parameter="${1}"

case "${parameter}" in
--operator|-o)
operator_name="${2}"
shift
;;
--version|-v)
operator_version="${2}"
shift
;;
--instance|-i)
operator_instance_name="${2}"
shift
;;
--namespace|-n)
operator_instance_namespace="${2}"
shift
;;
*)
;;
esac

shift
done

operator_name="${operator_name:-${OPERATOR_NAME}}"
operator_version="${operator_version:-${OPERATOR_VERSION}}"

${kubectl} delete instance \
"${operator_instance_name}" \
-n "${operator_instance_namespace}"

${kubectl} delete operatorversion \
"${operator_name}-${operator_version}" \
-n "${operator_instance_namespace}"

${kubectl} delete operator \
"${operator_name}" \
-n "${operator_instance_namespace}"

declare -a PVCS
mapfile -t PVCS < <(
${kubectl} get pvc \
-n "${operator_instance_namespace}" \
-o 'jsonpath={.items[*].metadata.name}' \
| tr ' ' '\n'
)

for pvc in "${PVCS[@]}"; do
${kubectl} delete "pvc/${pvc}" -n "${operator_instance_namespace}"
done
2 changes: 1 addition & 1 deletion shared
2 changes: 1 addition & 1 deletion templates/operator/operator.yaml.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "cassandra"
version: "${KUDO_CASSANDRA_VERSION}"
version: "${OPERATOR_VERSION}"
kudoVersion: "${KUDO_VERSION}"
kubernetesVersion: "${KUBERNETES_VERSION}"
appVersion: "${CASSANDRA_VERSION}"
Expand Down
20 changes: 20 additions & 0 deletions tests/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module github.com/mesosphere/kudo-cassandra-operator/tests

go 1.13

require (
github.com/avast/retry-go v2.4.1+incompatible
github.com/gogo/protobuf v1.3.1 // indirect
github.com/imdario/mergo v0.3.8 // indirect
github.com/kudobuilder/kudo v0.7.4
github.com/mitchellh/go-homedir v1.1.0
github.com/onsi/ginkgo v1.8.0
github.com/onsi/gomega v1.5.0
github.com/sirupsen/logrus v1.4.2
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 // indirect
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b
k8s.io/apiextensions-apiserver v0.0.0-20190409022649-727a075fdec8
k8s.io/apimachinery v0.0.0-20190704094520-6f131bee5e2c
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
)
Loading