diff --git a/.github/kind-config.yaml b/.github/kind-config.yaml new file mode 100644 index 0000000..2f9b0f4 --- /dev/null +++ b/.github/kind-config.yaml @@ -0,0 +1,8 @@ +kind: Cluster +apiVersion: kind.sigs.k8s.io/v1alpha3 +nodes: + # the control plane node config + - role: control-plane + # the 2 workers + - role: worker + - role: worker \ No newline at end of file diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml index 3056439..c79bbc8 100644 --- a/.github/workflows/go.yaml +++ b/.github/workflows/go.yaml @@ -2,6 +2,10 @@ name: Go on: [push] +env: + CHANGE_MINIKUBE_NONE_USER: true + INSTALL_K8S_TOOLS: 1 + IMG: kiwigrid/secret-replicator jobs: build: @@ -9,22 +13,44 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go 1.13 + - name: Set up Go 1.12 uses: actions/setup-go@v1 with: - go-version: 1.13 + go-version: 1.12 id: go - name: Check out code into the Go module directory uses: actions/checkout@v2 - name: Get dependencies - run: | - go get -v -t -d ./... - if [ -f Gopkg.toml ]; then - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - dep ensure - fi + run: go get -v -t -d ./... - name: Build - run: go build -v . + run: make + + - name: Build Docker + run: make docker-build + + install-chart: + name: install-chart + runs-on: ubuntu-latest + needs: + - build + strategy: + matrix: + k8s: + # assume no breaking changes between the version + - v1.12.10 + - v1.17.2 + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Create kind ${{ matrix.k8s }} cluster + uses: engineerd/setup-kind@v0.3.0 + with: + config: .github/kind-config.yaml + image: kindest/node:${{ matrix.k8s }} + - name: Run tests + env: + TEST_EXTERNAL_KUBE: true + run: make test \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f41875e..3d86a52 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,8 +11,9 @@ RUN go mod download # Copy the go source COPY main.go main.go -COPY api/ api/ +# COPY api/ api/ COPY controllers/ controllers/ +COPY service/ service/ # Build RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go diff --git a/Makefile b/Makefile index 27ed807..ad7b7d7 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ generate: controller-gen $(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths="./..." # Build the docker image -docker-build: test +docker-build: docker build . -t ${IMG} # Push the docker image diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 0392035..c68c593 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -16,11 +16,13 @@ limitations under the License. package controllers import ( + "os" "path/filepath" "testing" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" @@ -50,8 +52,19 @@ var _ = BeforeSuite(func(done Done) { logf.SetLogger(zap.LoggerTo(GinkgoWriter, true)) By("bootstrapping test environment") - testEnv = &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")}, + + if os.Getenv("TEST_EXTERNAL_KUBE") != "" { + existing := true + config, _ := clientcmd.BuildConfigFromFlags("", os.Getenv("KUBECONFIG")) + testEnv = &envtest.Environment{ + CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")}, + UseExistingCluster: &existing, + Config: config, + } + } else { + testEnv = &envtest.Environment{ + CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")}, + } } var err error diff --git a/tools/github/k8s-tools.sh b/tools/github/k8s-tools.sh new file mode 100755 index 0000000..cee9e73 --- /dev/null +++ b/tools/github/k8s-tools.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +# +# Copyright 2017-2018 IBM Corporation +# +# 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. +# + +set -e + +if [ -z "${INSTALL_K8S_TOOLS}" ]; then + exit 0 +fi + +if [ -z ${KUBECTL_VERSION+x} ]; then + KUBECTL_VERSION=v1.10.0 +fi + +if [ -z ${KB_VERSION+x} ]; then + KB_VERSION=1.0.5 +fi + +if [ -z ${KUSTOMIZE_VERSION+x} ]; then + KUSTOMIZE_VERSION=1.0.10 +fi + +echo "installing kubectl" +curl -LO https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl +chmod +x ./kubectl +sudo mv ./kubectl /usr/local/bin/ + +echo "installing kubebuilder" +curl -SL "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${KB_VERSION}/kubebuilder_${KB_VERSION}_linux_amd64.tar.gz" | tar xz +sudo mv kubebuilder_${KB_VERSION}_linux_amd64 /usr/local/kubebuilder +export KUBEBUILDER_ASSETS=/usr/local/kubebuilder/bin +sudo ln -s ${KUBEBUILDER_ASSETS}/kubebuilder /usr/local/bin/kubebuilder +kubebuilder version + +echo "installing kustomize" +curl -OL "https://github.com/kubernetes-sigs/kustomize/releases/download/v${KUSTOMIZE_VERSION}/kustomize_${KUSTOMIZE_VERSION}_linux_amd64" +sudo chmod +x kustomize_${KUSTOMIZE_VERSION}_linux_amd64 +sudo mv kustomize_${KUSTOMIZE_VERSION}_linux_amd64 /usr/local/bin/kustomize +kustomize version \ No newline at end of file diff --git a/tools/github/minikube-install.sh b/tools/github/minikube-install.sh new file mode 100755 index 0000000..e428230 --- /dev/null +++ b/tools/github/minikube-install.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +# +# Copyright 2017-2018 IBM Corporation +# +# 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. +# + +set -e + +if [ -z "${INSTALL_MINIKUBE}" ]; then + exit 0 +fi + +MINIKUBE_VERSION=${MINIKUBE_VERSION:-v0.30.0} +BOOTSTRAPPER=${BOOTSTRAPPER:-kubeadm} +KUBE_VERSION=${KUBE_VERSION:-v1.11.0} + +export MINIKUBE_WANTUPDATENOTIFICATION=false +export MINIKUBE_WANTREPORTERRORPROMPT=false +export CHANGE_MINIKUBE_NONE_USER=true +export MINIKUBE_HOME=$HOME + +echo "installing nsenter" +if ! which nsenter; then + curl -L https://github.com/minrk/git-crypt-bin/releases/download/trusty/nsenter > nsenter + chmod +x nsenter + sudo mv nsenter /usr/local/bin/ +fi + +# this is needed for kube > 1.11 +echo "installing crictl" +curl -OL https://github.com/kubernetes-sigs/cri-tools/releases/download/${KUBE_VERSION}/crictl-${KUBE_VERSION}-linux-amd64.tar.gz +sudo tar zxvf crictl-${KUBE_VERSION}-linux-amd64.tar.gz -C /usr/local/bin +rm -f crictl-${KUBE_VERSION}-linux-amd64.tar.gz + +echo "installing minikube" +curl -Lo minikube https://storage.googleapis.com/minikube/releases/${MINIKUBE_VERSION}/minikube-linux-amd64 +chmod +x minikube +sudo mv minikube /usr/local/bin/ + +echo "starting minikube" +export KUBECONFIG=$HOME/.kube/config +sudo -E minikube start --vm-driver=none --bootstrapper=${BOOTSTRAPPER} --extra-config apiserver.authorization-mode=RBAC --kubernetes-version ${KUBE_VERSION} +echo "update context" +minikube update-context + +echo "waiting minikube to be ready" +JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; + +until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; +do + sleep 1; +done \ No newline at end of file diff --git a/tools/github/start-kubeadm-dind.sh b/tools/github/start-kubeadm-dind.sh new file mode 100755 index 0000000..5c9ed27 --- /dev/null +++ b/tools/github/start-kubeadm-dind.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements; and to You under the Apache License, Version 2.0. + +set -x + +if [ -z "${INSTALL_DIND}" ]; then + exit 0 +fi + +# Install kubernetes-dind-cluster and boot it +wget https://cdn.rawgit.com/kubernetes-sigs/kubeadm-dind-cluster/master/fixed/dind-cluster-v$TRAVIS_KUBE_VERSION.sh -O $HOME/dind-cluster.sh && chmod +x $HOME/dind-cluster.sh && USE_HAIRPIN=true $HOME/dind-cluster.sh up