Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Revert "PMM-6884 Use EKS in CI for DBaaS Controller (#145)"
Browse files Browse the repository at this point in the history
This reverts commit 368b7fa.
  • Loading branch information
Jan Prukner committed Feb 24, 2021
1 parent 368b7fa commit 8f5fd22
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 197 deletions.
171 changes: 0 additions & 171 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,177 +178,6 @@ jobs:
pwd
git status
test-on-eks:
name: Test on EKS
timeout-minutes: 20

strategy:
fail-fast: false
matrix:
go-version:
- 1.15.x
build_tags: [""]
os: [ubuntu-latest]
may-fail: [false]
include:
- go-version: tip
build_tags: ""
os: ubuntu-latest
may-fail: true

continue-on-error: ${{ matrix.may-fail }}
runs-on: ${{ matrix.os }}

env:
# no `-mod=readonly` to test PRs made by @dependabot;
# `git diff --exit-code` step below still checks what we need
GOFLAGS: -v -tags='${{ matrix.build_tags }}'

steps:
- name: Set up Go release
if: matrix.go-version != 'tip'
env:
# to avoid error due to `go version` accepting -v flag with an argument since 1.15
GOFLAGS: ""
uses: percona-platform/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Set up Go tip
if: matrix.go-version == 'tip'
env:
# to avoid error due to `go version` accepting -v flag with an argument since 1.15
GOFLAGS: ""
run: |
git clone --depth=1 https://go.googlesource.com/go $HOME/gotip
cd $HOME/gotip/src
./make.bash
echo "GOROOT=$HOME/gotip" >> $GITHUB_ENV
echo "$HOME/gotip/bin" >> $GITHUB_PATH
- name: Set GO_VERSION environment variable
env:
# to avoid error due to `go version` accepting -v flag with an argument since 1.15
GOFLAGS: ""
run: |
go version
echo "GO_VERSION=$(go version)" >> $GITHUB_ENV
- name: Check out code into the Go module directory
uses: percona-platform/checkout@v2

- name: Enable Go modules cache
uses: percona-platform/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ matrix.os }}-go-${{ matrix.go-version }}-modules-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ matrix.os }}-go-${{ matrix.go-version }}-modules-
- name: Enable Go build cache
uses: percona-platform/cache@v2
with:
path: ~/.cache/go-build
key: ${{ matrix.os }}-go-${{ matrix.go-version }}-build-${{ github.ref }}-${{ hashFiles('**') }}
restore-keys: |
${{ matrix.os }}-go-${{ matrix.go-version }}-build-${{ github.ref }}-
${{ matrix.os }}-go-${{ matrix.go-version }}-build-
- name: Download Go modules
run: go mod download

- name: Install tools
run: |
make init
mkdir -p "${DBAAS_TOOLS_PATH}"
echo "${DBAAS_TOOLS_PATH}" >> $GITHUB_PATH
curl -o aws-iam-authenticator https://amazon-eks.s3.us-west-2.amazonaws.com/1.19.6/2021-01-05/bin/linux/amd64/aws-iam-authenticator
chmod +x ./aws-iam-authenticator
mv aws-iam-authenticator "${DBAAS_TOOLS_PATH}"
# dbaas-controller tries to search for kubectl at certain path
cp $(which kubectl) "${DBAAS_TOOLS_PATH}/kubectl-1.16"
env:
DBAAS_TOOLS_PATH: "/opt/dbaas-tools/bin"

- name: Initialize CI environment
run: make ci-init

- name: Generate code
run: make gen

- name: Install binaries
run: make release install

- name: Check that API tests can be built
run: make test-api-build

- name: Setup environment for tests to run
id: setupenv
run: |
export PATH_TO_KUBECONFIG="${HOME}/.kube/config"
mkdir -p "${PATH_TO_KUBECONFIG%/*}"
echo "${BASE64_KUBECONFIG}" > "${PATH_TO_KUBECONFIG}"
export RANDOM_STRING=$(cat /proc/sys/kernel/random/uuid)
export NAMESPACE="dbaas-controller-test-${RANDOM_STRING}"
make eks-setup-test-namespace NAMESPACE="${NAMESPACE}"
env:
BASE64_KUBECONFIG: ${{secrets.BASE64_KUBECONFIG}}

- name: Deploy operators to the test namespace
if: steps.setupenv.outputs.exit_code == 0
run: |
make eks-install-operators
- name: Run tests
if: steps.setupenv.outputs.exit_code == 0
run: |
go clean -testcache
make test-crosscover
- name: Upload coverage results
uses: percona-platform/codecov-action@v1
with:
file: crosscover.out
flags: crosscover
env_vars: GO_VERSION,KUBERNETES_VERSION
fail_ci_if_error: false

- name: Report Kubernetes resources count and state
if: steps.setupenv.outputs.exit_code == 0
run: |
echo "Kubernetes resources counts:"
echo "Namespaces: $(kubectl get ns | tail +2 | wc -l)"
echo "Persistent volumes: $(kubectl get pv | tail +2 | wc -l)"
echo "Pods: $(kubectl get pod | tail +2 | wc -l)"
echo "State of all pods:"
kubectl describe pods
- name: Delete the test namespace
if: steps.setupenv.outputs.exit_code == 0
run: |
make eks-delete-operators
make eks-delete-current-namespace
- name: Check that there are no source code changes
run: |
# Break job if any files were changed during its run (code generation, etc), except go.sum.
# `go mod tidy` could remove old checksums from that file, and that's okay on CI,
# and actually expected for PRs made by @dependabot.
# Checksums of actually used modules are checked by previous `go` subcommands.
pushd tools && go mod tidy && git checkout go.sum
popd && go mod tidy && git checkout go.sum
git diff --exit-code
- name: Run debug commands on failure
if: ${{ failure() }}
run: |
env
go version
go env
pwd
git status
kubectl version
check:
name: Check
timeout-minutes: 5
Expand Down
29 changes: 10 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ PMM_RELEASE_BRANCH ?= $(shell git describe --always --contains --all)
PMM_USER ?= $(shell echo -n 'admin' | base64)
PMM_PASS ?= $(shell echo -n 'admin_password' | base64)
PATH_TO_KUBECONFIG ?= ${HOME}/.kube/config
KUBECTL_ARGS = --kubeconfig ${PATH_TO_KUBECONFIG}
KUBECTL_CMD = "kubectl --kubeconfig ${PATH_TO_KUBECONFIG}"

PMM_LD_FLAGS = -ldflags " \
-X 'github.com/percona/pmm/version.ProjectName=dbaas-controller' \
-X 'github.com/percona/pmm/version.Version=$(COMPONENT_VERSION)' \
Expand Down Expand Up @@ -151,28 +152,18 @@ collect-debugdata: ## Collect debugdata
minikube kubectl -- logs --all-containers --timestamps --selector='name=percona-server-mongodb-operator' > ./debugdata/psmdb-operators.txt
minikube kubectl -- logs --all-containers --timestamps --selector='app.kubernetes.io/name=percona-server-mongodb' > ./debugdata/psmdb-clusters.txt

eks-setup-test-namespace:
kubectl ${KUBECTL_ARGS} create ns "${NAMESPACE}"
kubectl ${KUBECTL_ARGS} config set-context --current --namespace="${NAMESPACE}"

eks-install-operators: ## Install Kubernetes operators in EKS.
# Install the PXC operator
cat ./deploy/pxc-operator.yaml | kubectl ${KUBECTL_ARGS} apply -f -
cat ./deploy/pxc-secrets.yaml | sed "s/pmmserver:.*=/pmmserver: ${PMM_PASS}/g" | kubectl ${KUBECTL_ARGS} apply -f -
cat ./deploy/pxc-operator.yaml | ${KUBECTL_CMD} apply -f -
cat ./deploy/pxc-secrets.yaml | sed "s/pmmserver:.*=/pmmserver: ${PMM_PASS}/g" | ${KUBECTL_CMD} apply -f -
# Install the PSMDB operator
cat ./deploy/psmdb-operator.yaml | kubectl ${KUBECTL_ARGS} apply -f -
cat ./deploy/psmdb-secrets.yaml | sed "s/PMM_SERVER_USER:.*/PMM_SERVER_USER: ${PMM_USER}/g;s/PMM_SERVER_PASSWORD:.*/PMM_SERVER_PASSWORD: ${PMM_PASS}/g;" | kubectl ${KUBECTL_ARGS} apply -f -
kubectl ${KUBECTL_ARGS} wait --timeout=60s --for=condition=Available deployment percona-xtradb-cluster-operator
kubectl ${KUBECTL_ARGS} wait --timeout=60s --for=condition=Available deployment percona-server-mongodb-operator
cat ./deploy/psmdb-operator.yaml | ${KUBECTL_CMD} apply -f -
cat ./deploy/psmdb-secrets.yaml | sed "s/PMM_SERVER_USER:.*$/PMM_SERVER_USER: ${PMM_USER}/g;s/PMM_SERVER_PASSWORD:.*=$/PMM_SERVER_PASSWORD: ${PMM_PASS}/g;" | ${KUBECTL_CMD} apply -f -

eks-delete-operators: ## Delete Kubernetes operators from EKS. Run this before deleting the cluster to not to leave garbage.
# Delete the PXC operator
kubectl ${KUBECTL_ARGS} delete deployment percona-xtradb-cluster-operator
cat ./deploy/pxc-secrets.yaml | sed "s/pmmserver:.*/pmmserver: ${PMM_PASS}/g" | kubectl ${KUBECTL_ARGS} delete -f -
cat ./deploy/pxc-operator.yaml | ${KUBECTL_CMD} delete -f -
cat ./deploy/pxc-secrets.yaml | sed "s/pmmserver:.*=/pmmserver: ${PMM_PASS}/g" | ${KUBECTL_CMD} delete -f -
# Delete the PSMDB operator
kubectl ${KUBECTL_ARGS} delete deployment percona-server-mongodb-operator
cat ./deploy/psmdb-secrets.yaml | sed "s/PMM_SERVER_USER:.*/PMM_SERVER_USER: ${PMM_USER}/g;s/PMM_SERVER_PASSWORD:.*/PMM_SERVER_PASSWORD: ${PMM_PASS}/g;" | kubectl ${KUBECTL_ARGS} delete -f -

eks-delete-current-namespace:
NAMESPACE=$$(kubectl config view --minify --output 'jsonpath={..namespace}'); \
if [ "$$NAMESPACE" != "default" ]; then kubectl delete ns "$$NAMESPACE"; fi
cat ./deploy/psmdb-operator.yaml | ${KUBECTL_CMD} delete -f -
cat ./deploy/psmdb-secrets.yaml | sed "s/PMM_SERVER_USER:.*$/PMM_SERVER_USER: ${PMM_USER}/g;s/PMM_SERVER_PASSWORD:.*=$/PMM_SERVER_PASSWORD: ${PMM_PASS}/g;" | ${KUBECTL_CMD} delete -f -
12 changes: 9 additions & 3 deletions service/k8sclient/internal/kubectl/kubectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ import (
func TestNewKubeCtl(t *testing.T) {
ctx := app.Context()

kubeconfig, err := ioutil.ReadFile(os.Getenv("HOME") + "/.kube/config")
defaultKubectl, err := lookupCorrectKubectlCmd(nil, []string{defaultPmmServerKubectl, defaultDevEnvKubectl})
require.NoError(t, err)

cmd, err := getKubectlCmd(ctx, defaultKubectl, "")
require.NoError(t, err)

validKubeconfig, err := run(ctx, cmd, []string{"config", "view", "-o", "json"}, nil)
require.NoError(t, err)

t.Run("BasicNewKubeCtl", func(t *testing.T) {
kubeCtl, err := NewKubeCtl(ctx, string(kubeconfig))
kubeCtl, err := NewKubeCtl(ctx, string(validKubeconfig))
require.NoError(t, err)
// lookup for kubeconfig path
var kubeconfigFlag string
Expand All @@ -52,7 +58,7 @@ func TestNewKubeCtl(t *testing.T) {
kubeconfigFilePath := strings.Split(kubeconfigFlag, "=")[1]
kubeconfigActual, err := ioutil.ReadFile(kubeconfigFilePath) //nolint:gosec
require.NoError(t, err)
assert.Equal(t, kubeconfig, kubeconfigActual)
assert.Equal(t, validKubeconfig, kubeconfigActual)

err = kubeCtl.Cleanup()
require.NoError(t, err)
Expand Down
9 changes: 5 additions & 4 deletions service/k8sclient/k8sclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package k8sclient
import (
"context"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
"time"
Expand All @@ -30,6 +28,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/percona-platform/dbaas-controller/service/k8sclient/internal/common"
"github.com/percona-platform/dbaas-controller/service/k8sclient/internal/kubectl"
"github.com/percona-platform/dbaas-controller/utils/app"
"github.com/percona-platform/dbaas-controller/utils/logger"
)
Expand All @@ -44,12 +43,14 @@ type pod struct {
func TestK8sClient(t *testing.T) {
ctx := app.Context()

kubeconfig, err := ioutil.ReadFile(os.Getenv("HOME") + "/.kube/config")
kubeCtl, err := kubectl.NewKubeCtl(ctx, "")
require.NoError(t, err)

client, err := New(ctx, string(kubeconfig))
validKubeconfig, err := kubeCtl.Run(ctx, []string{"config", "view", "-o", "json"}, nil)
require.NoError(t, err)

client, err := New(ctx, string(validKubeconfig))
require.NoError(t, err)
t.Cleanup(func() {
err := client.Cleanup()
require.NoError(t, err)
Expand Down

0 comments on commit 8f5fd22

Please sign in to comment.