From 2e702ddda3ac9b1232760a6077a1081c12a1bb90 Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Sun, 3 Nov 2019 04:45:23 -0800 Subject: [PATCH] Test installers Signed-off-by: Tamal Saha --- .github/workflows/ci.yml | 40 +++++++++++++++++++ Makefile | 28 +++++++++++++ .../stash-percona-xtradb/.helmignore | 0 .../stash-percona-xtradb/Chart.yaml | 4 +- .../stash-percona-xtradb/templates/NOTES.txt | 0 .../templates/_helpers.tpl | 0 .../percona-xtradb-backup-function.yaml | 0 .../templates/percona-xtradb-backup-task.yaml | 0 .../percona-xtradb-restore-function.yaml | 0 .../percona-xtradb-restore-task.yaml | 0 .../stash-percona-xtradb/values.yaml | 0 hack/build.sh | 6 +-- hack/docker/stash-percona-xtradb/backup.sh | 6 +-- hack/docker/stash-percona-xtradb/restore.sh | 4 +- hack/e2e.sh | 5 ++- hack/fmt.sh | 32 ++++++++++----- hack/kubernetes/kind.yaml | 19 +++++++++ hack/kubernetes/storageclass/standard.yaml | 9 +++++ hack/license/go.txt | 1 - hack/license/makefile.txt | 1 - 20 files changed, 130 insertions(+), 25 deletions(-) rename {chart => charts}/stash-percona-xtradb/.helmignore (100%) rename {chart => charts}/stash-percona-xtradb/Chart.yaml (91%) rename {chart => charts}/stash-percona-xtradb/templates/NOTES.txt (100%) rename {chart => charts}/stash-percona-xtradb/templates/_helpers.tpl (100%) rename {chart => charts}/stash-percona-xtradb/templates/percona-xtradb-backup-function.yaml (100%) rename {chart => charts}/stash-percona-xtradb/templates/percona-xtradb-backup-task.yaml (100%) rename {chart => charts}/stash-percona-xtradb/templates/percona-xtradb-restore-function.yaml (100%) rename {chart => charts}/stash-percona-xtradb/templates/percona-xtradb-restore-task.yaml (100%) rename {chart => charts}/stash-percona-xtradb/values.yaml (100%) create mode 100644 hack/kubernetes/kind.yaml create mode 100644 hack/kubernetes/storageclass/standard.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2bf932272..49c873a6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,3 +40,43 @@ jobs: run: | docker login --username ${USERNAME} --password ${DOCKER_TOKEN} make push + + - name: Create Kubernetes cluster + id: kind + uses: engineerd/setup-kind@v0.1.0 + with: + config: hack/kubernetes/kind.yaml + + - name: Prepare cluster for testing + id: local-path + env: + DOCKER_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + USERNAME: 1gtm + REGISTRY_SECRET: regcred + run: | + export KUBECONFIG="$(kind get kubeconfig-path)" + echo + echo "waiting for nodes to be ready ..." + kubectl wait --for=condition=Ready nodes --all --timeout=5m + kubectl get nodes + echo + echo "installing local-path provisioner ..." + kubectl delete storageclass --all + kubectl apply -f https://github.com/rancher/local-path-provisioner/raw/v0.0.11/deploy/local-path-storage.yaml + kubectl wait --for=condition=Ready pods -n local-path-storage --all --timeout=5m + kubectl apply -f hack/kubernetes/storageclass/standard.yaml + echo + echo "create docker-registry secret" + kubectl create secret docker-registry ${REGISTRY_SECRET} --namespace=kube-system --docker-server=https://index.docker.io/v1/ --docker-username=${USERNAME} --docker-password=${DOCKER_TOKEN} + + - name: Install CRDs + run: | + export KUBECONFIG="$(kind get kubeconfig-path)" + kubectl apply -f https://github.com/stashed/stash/raw/master/api/crds/stash.appscode.com_functions.yaml + kubectl apply -f https://github.com/stashed/stash/raw/master/api/crds/stash.appscode.com_tasks.yaml + kubectl wait --for=condition=NamesAccepted crds --all --timeout=5m + + - name: Test charts + run: | + export KUBECONFIG="$(kind get kubeconfig-path)" + make ct diff --git a/Makefile b/Makefile index 8af7deeeb..91e6fdd28 100644 --- a/Makefile +++ b/Makefile @@ -73,6 +73,7 @@ TAG_DBG := $(VERSION)-dbg_$(OS)_$(ARCH) GO_VERSION ?= 1.12.12 BUILD_IMAGE ?= appscode/golang-dev:$(GO_VERSION)-stretch +CHART_TEST_IMAGE ?= quay.io/helmpack/chart-testing:v2.4.0 OUTBIN = bin/$(OS)_$(ARCH)/$(BIN) ifeq ($(OS),windows) @@ -265,6 +266,33 @@ unit-tests: $(BUILD_DIRS) ./hack/test.sh $(SRC_DIRS) \ " +.PHONY: ct +ct: $(BUILD_DIRS) + @echo $(XYZ) + @docker run \ + -i \ + --rm \ + -v $$(pwd):/src \ + -w /src \ + --net=host \ + -v $(HOME)/.kube:/.kube \ + -v $(HOME)/.minikube:$(HOME)/.minikube \ + -v $(HOME)/.credentials:$(HOME)/.credentials \ + -v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \ + -v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \ + -v $$(pwd)/.go/cache:/.cache \ + --env HTTP_PROXY=$(HTTP_PROXY) \ + --env HTTPS_PROXY=$(HTTPS_PROXY) \ + --env KUBECONFIG=$(subst $(HOME),,$(KUBECONFIG)) \ + $(CHART_TEST_IMAGE) \ + /bin/sh -c " \ + kubectl -n kube-system create sa tiller; \ + kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller; \ + helm init --service-account tiller; \ + kubectl wait --for=condition=Ready pods -n kube-system --all --timeout=5m; \ + ct lint-and-install --all; \ + " + ADDTL_LINTERS := goconst,gofmt,goimports,unparam .PHONY: lint diff --git a/chart/stash-percona-xtradb/.helmignore b/charts/stash-percona-xtradb/.helmignore similarity index 100% rename from chart/stash-percona-xtradb/.helmignore rename to charts/stash-percona-xtradb/.helmignore diff --git a/chart/stash-percona-xtradb/Chart.yaml b/charts/stash-percona-xtradb/Chart.yaml similarity index 91% rename from chart/stash-percona-xtradb/Chart.yaml rename to charts/stash-percona-xtradb/Chart.yaml index fe4b94c2b..f3fd2f910 100644 --- a/chart/stash-percona-xtradb/Chart.yaml +++ b/charts/stash-percona-xtradb/Chart.yaml @@ -1,8 +1,8 @@ apiVersion: v1 description: 'stash-percona-xtradb - PerconaXtraDB database backup and restore plugin for Stash by AppsCode' name: stash-percona-xtradb -version: 5.7 -appVersion: 5.7 +version: "5.7" +appVersion: "5.7" home: https://github.com/stashed/percona-xtradb icon: https://cdn.appscode.com/images/icon/stash.png sources: diff --git a/chart/stash-percona-xtradb/templates/NOTES.txt b/charts/stash-percona-xtradb/templates/NOTES.txt similarity index 100% rename from chart/stash-percona-xtradb/templates/NOTES.txt rename to charts/stash-percona-xtradb/templates/NOTES.txt diff --git a/chart/stash-percona-xtradb/templates/_helpers.tpl b/charts/stash-percona-xtradb/templates/_helpers.tpl similarity index 100% rename from chart/stash-percona-xtradb/templates/_helpers.tpl rename to charts/stash-percona-xtradb/templates/_helpers.tpl diff --git a/chart/stash-percona-xtradb/templates/percona-xtradb-backup-function.yaml b/charts/stash-percona-xtradb/templates/percona-xtradb-backup-function.yaml similarity index 100% rename from chart/stash-percona-xtradb/templates/percona-xtradb-backup-function.yaml rename to charts/stash-percona-xtradb/templates/percona-xtradb-backup-function.yaml diff --git a/chart/stash-percona-xtradb/templates/percona-xtradb-backup-task.yaml b/charts/stash-percona-xtradb/templates/percona-xtradb-backup-task.yaml similarity index 100% rename from chart/stash-percona-xtradb/templates/percona-xtradb-backup-task.yaml rename to charts/stash-percona-xtradb/templates/percona-xtradb-backup-task.yaml diff --git a/chart/stash-percona-xtradb/templates/percona-xtradb-restore-function.yaml b/charts/stash-percona-xtradb/templates/percona-xtradb-restore-function.yaml similarity index 100% rename from chart/stash-percona-xtradb/templates/percona-xtradb-restore-function.yaml rename to charts/stash-percona-xtradb/templates/percona-xtradb-restore-function.yaml diff --git a/chart/stash-percona-xtradb/templates/percona-xtradb-restore-task.yaml b/charts/stash-percona-xtradb/templates/percona-xtradb-restore-task.yaml similarity index 100% rename from chart/stash-percona-xtradb/templates/percona-xtradb-restore-task.yaml rename to charts/stash-percona-xtradb/templates/percona-xtradb-restore-task.yaml diff --git a/chart/stash-percona-xtradb/values.yaml b/charts/stash-percona-xtradb/values.yaml similarity index 100% rename from chart/stash-percona-xtradb/values.yaml rename to charts/stash-percona-xtradb/values.yaml diff --git a/hack/build.sh b/hack/build.sh index 942b174dc..d76311dcc 100755 --- a/hack/build.sh +++ b/hack/build.sh @@ -35,8 +35,8 @@ export GOOS="${OS}" export GO111MODULE=on export GOFLAGS="-mod=vendor" -go install \ - -installsuffix "static" \ +go install \ + -installsuffix "static" \ -ldflags " \ -X main.Version=${VERSION} \ -X main.VersionStrategy=${version_strategy:-} \ @@ -47,5 +47,5 @@ go install \ -X main.GoVersion=$(go version | cut -d " " -f 3) \ -X main.Compiler=$(go env CC) \ -X main.Platform=${OS}/${ARCH} \ - " \ + " \ ./... diff --git a/hack/docker/stash-percona-xtradb/backup.sh b/hack/docker/stash-percona-xtradb/backup.sh index 45c81cd2e..5060d04cc 100755 --- a/hack/docker/stash-percona-xtradb/backup.sh +++ b/hack/docker/stash-percona-xtradb/backup.sh @@ -48,9 +48,9 @@ first=${myips%% *} sst_request_string=$(get_sst_request_string $first $sst_request_opts) # Start backup procedure -echo "" > $log_file +echo "" >$log_file timeout -k 25 20 \ - garbd \ + garbd \ --address="$cluster_addr" \ --group="$cluster_name" \ --sst="$sst_request_string" \ @@ -59,5 +59,5 @@ timeout -k 25 20 \ SOCAT_OPTS=$socat_opts # the first socat run does not give the streams. So, we need to run socat again -socat -u "$SOCAT_OPTS" stdio > /dev/null +socat -u "$SOCAT_OPTS" stdio >/dev/null socat -u "$SOCAT_OPTS" stdio diff --git a/hack/docker/stash-percona-xtradb/restore.sh b/hack/docker/stash-percona-xtradb/restore.sh index 6c9349482..17fd43954 100755 --- a/hack/docker/stash-percona-xtradb/restore.sh +++ b/hack/docker/stash-percona-xtradb/restore.sh @@ -22,5 +22,5 @@ xtrabackup --prepare --target-dir=$datadir # give the ownership (mysql:mysql) needed groupadd -g 1001 mysql useradd -u 1001 -r -g 1001 -s /sbin/nologin \ - -c "Default Application User" mysql -chown -R mysql:mysql $datadir \ No newline at end of file + -c "Default Application User" mysql +chown -R mysql:mysql $datadir diff --git a/hack/e2e.sh b/hack/e2e.sh index 7a8f05da0..00d8a8a74 100755 --- a/hack/e2e.sh +++ b/hack/e2e.sh @@ -16,7 +16,7 @@ set -eou pipefail -export CGO_ENABLED=1 +export CGO_ENABLED=0 export GO111MODULE=on export GOFLAGS="-mod=vendor" @@ -26,4 +26,5 @@ DOCKER_REGISTRY=${DOCKER_REGISTRY:-} echo "Running e2e tests:" cmd="ginkgo -r --v -race --progress --trace --noisyPendings=false ${GINKGO_ARGS} test -- --docker-registry=${DOCKER_REGISTRY} ${TEST_ARGS}" -echo $cmd; $cmd +echo "$cmd" +$cmd diff --git a/hack/fmt.sh b/hack/fmt.sh index 307373fd3..793db8583 100755 --- a/hack/fmt.sh +++ b/hack/fmt.sh @@ -22,17 +22,27 @@ export GOFLAGS="-mod=vendor" TARGETS="$@" -echo "Running reimport.py" -cmd="reimport3.py ${REPO_PKG} ${TARGETS}" -$cmd -echo +if [ -n "$TARGETS" ]; then + echo "Running reimport.py" + cmd="reimport3.py ${REPO_PKG} ${TARGETS}" + $cmd + echo -echo "Running goimports:" -cmd="goimports -w ${TARGETS}" -echo $cmd; $cmd -echo + echo "Running goimports:" + cmd="goimports -w ${TARGETS}" + echo "$cmd" + $cmd + echo + + echo "Running gofmt:" + cmd="gofmt -s -w ${TARGETS}" + echo "$cmd" + $cmd + echo +fi -echo "Running gofmt:" -cmd="gofmt -s -w ${TARGETS}" -echo $cmd; $cmd +echo "Running shfmt:" +cmd="find . -path ./vendor -prune -o -name '*.sh' -exec shfmt -l -w -ci -i 4 {} \;" +echo "$cmd" +eval "$cmd" # xref: https://stackoverflow.com/a/5615748/244009 echo diff --git a/hack/kubernetes/kind.yaml b/hack/kubernetes/kind.yaml new file mode 100644 index 000000000..0f08b3e3b --- /dev/null +++ b/hack/kubernetes/kind.yaml @@ -0,0 +1,19 @@ +kind: Cluster +apiVersion: kind.sigs.k8s.io/v1alpha3 +nodes: +# the control plane node +- role: control-plane + extraMounts: + - containerPath: /opt/local-path-provisioner + hostPath: /mnt + readOnly: false +- role: worker + extraMounts: + - containerPath: /opt/local-path-provisioner + hostPath: /mnt + readOnly: false +- role: worker + extraMounts: + - containerPath: /opt/local-path-provisioner + hostPath: /mnt + readOnly: false diff --git a/hack/kubernetes/storageclass/standard.yaml b/hack/kubernetes/storageclass/standard.yaml new file mode 100644 index 000000000..f3bfd9f80 --- /dev/null +++ b/hack/kubernetes/storageclass/standard.yaml @@ -0,0 +1,9 @@ +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: standard + annotations: + storageclass.beta.kubernetes.io/is-default-class: "true" +provisioner: rancher.io/local-path +volumeBindingMode: WaitForFirstConsumer +reclaimPolicy: Delete diff --git a/hack/license/go.txt b/hack/license/go.txt index 6d8cecd45..d68e18716 100644 --- a/hack/license/go.txt +++ b/hack/license/go.txt @@ -13,4 +13,3 @@ 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/hack/license/makefile.txt b/hack/license/makefile.txt index e5d07beb2..afae7977e 100644 --- a/hack/license/makefile.txt +++ b/hack/license/makefile.txt @@ -12,4 +12,3 @@ # 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. -