From f957d0f57f9155778b65d31e5ea4ae9ef179cb1b Mon Sep 17 00:00:00 2001 From: Arnaud Tincelin Date: Wed, 4 Aug 2021 15:38:08 +0200 Subject: [PATCH] Updated pipeline --- .github/workflows/ci-pipeline.yaml | 106 ++++++++++++++++++++++++++ .github/workflows/ci-pipeline.yml | 56 -------------- azurepipeline/start.sh | 80 ------------------- azurepipeline/stop.sh | 44 ----------- tests/aksperiscopeintegration_test.go | 78 ------------------- tests/helper_test.go | 52 ------------- 6 files changed, 106 insertions(+), 310 deletions(-) create mode 100644 .github/workflows/ci-pipeline.yaml delete mode 100644 .github/workflows/ci-pipeline.yml delete mode 100644 azurepipeline/start.sh delete mode 100644 azurepipeline/stop.sh delete mode 100644 tests/aksperiscopeintegration_test.go delete mode 100644 tests/helper_test.go diff --git a/.github/workflows/ci-pipeline.yaml b/.github/workflows/ci-pipeline.yaml new file mode 100644 index 00000000..aee237c9 --- /dev/null +++ b/.github/workflows/ci-pipeline.yaml @@ -0,0 +1,106 @@ +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +env: + GO_VERSION: '1.15' + KIND_VERSION: v0.11.1 + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + - name: Linter + uses: golangci/golangci-lint-action@v2 + with: + version: latest + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + - name: Download modules + run: go mod download + - name: Build project + run: go build ./cmd/aks-periscope + tests: + runs-on: ubuntu-latest + # services: + # registry: + # image: registry:2 + # ports: + # - 5000:5000 + steps: + - uses: actions/checkout@v2 + - uses: azure/setup-kubectl@v1 + - name: Install Packages + run: | + curl -Lo ./kind https://kind.sigs.k8s.io/dl/${{ env.KIND_VERSION }}/kind-linux-amd64 + chmod +x ./kind + + curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash + - name: Start kind + run: | + docker run -d --restart=always -p "127.0.0.1:5000:5000" --name "registry" registry:2 + + # 3 nodes (two workers) cluster with the local registry enabled in containerd (https://kind.sigs.k8s.io/docs/user/local-registry/) + cat < (default INTEGRATION_TEST_CLUSTER) -# --kind-version (default v0.7.0) -# --kubectl-version (default v1.18.0) -# --helm-version (default v3.2.0) -########################################################################### - -# All Supported Arguments -ARGUMENT_LIST=( - "kind-cluster-name" - "kind-version" - "kubectl-version" - "helm-version" -) - -# Read Arguments -opts=$(getopt \ - --longoptions "$(printf "%s:," "${ARGUMENT_LIST[@]}")" \ - --name "$(basename "$0")" \ - --options "" \ - -- "$@" -) - -# Assign Values from Arguments -eval set --$opts -while [[ $# -gt 0 ]]; do - case "$1" in - --kind-cluster-name) - CLUSTER_NAME=$2 - shift 2 - ;; - --kind-version) - KIND_VERSION=$2 - shift 2 - ;; - --kubectl-version) - KUBECTL_VERSION=$2 - shift 2 - ;; - --helm-version) - HELM_VERSION=$2 - shift 2 - ;; - *) - break - ;; - esac -done - -# Assign Deafults -CLUSTER_NAME=${CLUSTER_NAME:-"INTEGRATION_TEST_CLUSTER"} -KIND_VERSION=${KIND_VERSION:-v0.7.0} -KUBECTL_VERSION=${KUBECTL_VERSION:-v1.18.0} -HELM_VERSION=${HELM_VERSION:-v3.2.0} - -echo $(date -u) "[INFO] Downloading Kubectl ..." -curl -LO https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl -chmod +x ./kubectl - -echo $(date -u) "[INFO] Downloading KIND ..." -curl -Lo ./kind https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-$(uname)-amd64 -chmod +x ./kind - -echo $(date -u) "[INFO] Downloading helm ..." -wget https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz -tar -zxvf helm-${HELM_VERSION}-linux-amd64.tar.gz - -echo $(date -u) "[INFO] Creating a KIND cluster ${CLUSTER_NAME} ..." -./kind create cluster --name ${CLUSTER_NAME} - -echo $(date -u) "[INFO] Sleeping for 60s to make sure KIND cluster is ready to accept request ..." -sleep 60s \ No newline at end of file diff --git a/azurepipeline/stop.sh b/azurepipeline/stop.sh deleted file mode 100644 index 0b2eb86c..00000000 --- a/azurepipeline/stop.sh +++ /dev/null @@ -1,44 +0,0 @@ -#/bin/bash -set +x -set +e -set -o pipefail -set -u - -########################################################################### -# Usage: bash -f ./stop.sh -# Supported Options - -# --kind-cluster-name= (default INTEGRATION_TEST_CLUSTER) -########################################################################### - -# All Supported Arguments -ARGUMENT_LIST=( - "kind-cluster-name" -) - -# Read Arguments -opts=$(getopt \ - --longoptions "$(printf "%s:," "${ARGUMENT_LIST[@]}")" \ - --name "$(basename "$0")" \ - --options "" \ - -- "$@" -) - -# Assign Values from Arguments -eval set --$opts -while [[ $# -gt 0 ]]; do - case "$1" in - --kind-cluster-name) - CLUSTER_NAME=$2 - shift 2 - ;; - *) - break - ;; - esac -done - -# Assign Deafults -CLUSTER_NAME=${CLUSTER_NAME:-"INTEGRATION_TEST_CLUSTER"} - -echo $(date -u) "[INFO] Deleting a KIND cluster ${CLUSTER_NAME}" -./kind delete cluster --name ${CLUSTER_NAME} \ No newline at end of file diff --git a/tests/aksperiscopeintegration_test.go b/tests/aksperiscopeintegration_test.go deleted file mode 100644 index 18bf84b7..00000000 --- a/tests/aksperiscopeintegration_test.go +++ /dev/null @@ -1,78 +0,0 @@ -package main - -import ( - "fmt" - "strings" - "testing" - - "github.com/Azure/aks-periscope/pkg/utils" - . "github.com/onsi/gomega" -) - -func TestEndToEndIntegrationSuccessCase(t *testing.T) { - runperiscopedeploycommand(t, false) - g := NewGomegaWithT(t) - - g.Eventually(func() bool { - return checkifpodsrunning(t) - }, "60s", "2s").Should(BeTrue()) - - /* - More integration test expansiont Ideas: - Further work: ToExpand: - * Another good integration test could be the lcoation the logs get collected before zipping and prior to storage call. - * /var/logs/aks-periscope/* - is the location I think. - * funct : zipAndExport has more details. - */ - -} - -func TestEndToEndIntegrationUnsuccessFulCase(t *testing.T) { - runperiscopedeploycommand(t, true) -} - -func runperiscopedeploycommand(t *testing.T, validate bool) { - // This flag switch on and off for storage account validation. - validateflag := fmt.Sprintf("--validate=%v", validate) - g := NewGomegaWithT(t) - - output, err := utils.RunCommandOnContainer("kubectl", "apply", "-f", "../deployment/aks-periscope.yaml", validateflag) - - if err != nil && validate { - g.Expect(err).Should(HaveOccurred()) - t.Logf("unsuccessful output: %v\n", err) - } - - if output != "" && !validate { - g.Expect(err).ToNot(HaveOccurred()) - t.Logf("successful output: %v\n", output) - } -} - -func checkifpodsrunning(t *testing.T) bool { - g := NewGomegaWithT(t) - - output, err := utils.RunCommandOnContainer("kubectl", "get", "pods", "-n", "aks-periscope") - firstpod := strings.Split(output, "\n") - - firstpodname := strings.Fields(firstpod[1])[0] - firstpodstate := strings.Fields(firstpod[1])[2] - - t.Logf(" Outcome is %v ===> %v", firstpodname, firstpodstate) - - if err != nil { - g.Expect(err).ToNot(HaveOccurred()) - t.Logf("unsuccessful error: %v\n", err) - } - - if output != "" { - g.Expect(err).ToNot(HaveOccurred()) - t.Logf("successful output: %v\n", output) - } - - if firstpodstate == "Running" { - return true - } - - return false -} diff --git a/tests/helper_test.go b/tests/helper_test.go deleted file mode 100644 index 91521b20..00000000 --- a/tests/helper_test.go +++ /dev/null @@ -1,52 +0,0 @@ -package main - -import ( - "errors" - "log" - "testing" - - "github.com/Azure/aks-periscope/pkg/utils" - . "github.com/onsi/gomega" -) - -func TestGetHostNameSuccessCase(t *testing.T) { - g := NewGomegaWithT(t) - - // Save current function and restore at the end: - old := utils.GetHostNameFunc - defer func() { utils.GetHostNameFunc = old }() - - utils.GetHostNameFunc = &utils.HostName{ - HostName: "aks-agentpool-20752274-vmss000000", - Err: nil, - } - - // setup expectations - // call the code we are testing - hostname, _ := utils.GetHostName() - - // assert that the expectations were met - g.Expect(hostname).To(BeElementOf("aks-agentpool-20752274-vmss000000")) -} - -func TestGetHostNameFailureCase(t *testing.T) { - g := NewGomegaWithT(t) - - // Save current function and restore at the end: - old := utils.GetHostNameFunc - defer func() { utils.GetHostNameFunc = old }() - - utils.GetHostNameFunc = &utils.HostName{ - HostName: "", - Err: errors.New("an error"), - } - - // setup expectations - // call the code we are testing - _, err := utils.GetHostName() - log.Printf("Error is %s", err) - // assert that the expectations were met - g.Expect(err).Should(HaveOccurred()) - g.Expect(err).To(BeElementOf(errors.New("Fail to get host name: an error"))) - -}