diff --git a/.github/workflows/pr-cli.yml b/.github/workflows/pr-cli.yml new file mode 100644 index 00000000..864c693d --- /dev/null +++ b/.github/workflows/pr-cli.yml @@ -0,0 +1,39 @@ +name: PR check - CLI Installation test +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + cli-test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + + steps: + - name: checkout + uses: actions/checkout@v4 + with: + fetch-tags: true + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: ./go.mod + - name: Install kind + uses: helm/kind-action@v1.10.0 + with: + install_only: true + - name: Run build + run: make build + - name: Build docker images + run: make docker-build + - name: Run installation test using CLI + run: ./tests/cli/basic_test.sh + - name: upload e2e k8s test logs + uses: actions/upload-artifact@v4 + if: failure() + with: + name: tests-cli + path: /tmp/clusterlink-cli diff --git a/.golangci.yaml b/.golangci.yaml index bb1bd4d7..5fbf3f0d 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -24,7 +24,7 @@ linters: - bodyclose - contextcheck - durationcheck - - errcheck + - errcheck - errname - errorlint - exportloopref @@ -122,7 +122,8 @@ linters-settings: output: # prefer the simplest output: `line-number` without saving to file - format: line-number + formats: + - format: line-number print-issued-lines: false print-linter-name: true # allow multiple reports per line diff --git a/pkg/controlplane/control/manager.go b/pkg/controlplane/control/manager.go index fabe0bc6..3d59e8d3 100644 --- a/pkg/controlplane/control/manager.go +++ b/pkg/controlplane/control/manager.go @@ -889,7 +889,6 @@ func generateJWKSecret() ([]byte, error) { Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(rsaKey), }) - if err != nil { return nil, fmt.Errorf("cannot encode JWK key: %w", err) } diff --git a/tests/cli/basic_test.sh b/tests/cli/basic_test.sh new file mode 100755 index 00000000..ce2e3f20 --- /dev/null +++ b/tests/cli/basic_test.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +# Copyright (c) The ClusterLink Authors. +# 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 -ex + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +TEST_DIR=$(mktemp -d) +CLI=$SCRIPT_DIR/../../bin/clusterlink + +function clean_up { + kind delete cluster --name peer1 + + cd - +} + +function clean_up_with_logs { + # export logs + kind export logs /tmp/clusterlink-cli --name peer1 + + clean_up +} + +function test_k8s { + # create fabric with a single peer (peer1) + $CLI create fabric + $CLI create peer-cert --name peer1 + + # create kind cluster + kind create cluster --name peer1 + + # load images to cluster + kind load docker-image cl-controlplane --name peer1 + kind load docker-image cl-dataplane --name peer1 + kind load docker-image cl-operator --name peer1 + + # configure kubectl + kubectl config use-context kind-peer1 + + # wait for service account to be created + timeout 30 sh -c 'until kubectl -n default get serviceaccount default -o name; do sleep 0.1; done > /dev/null 2>&1' + + # create clusterlink objects + $CLI deploy peer --name peer1 --container-registry=docker.io/library --ingress=NodePort --ingress-port=30443 + + # wait for cl-controlplane and cl-dataplane to be created + if ! timeout 30 sh -c 'until kubectl rollout status deployment cl-controlplane -n clusterlink-system; do sleep 0.1; done > /dev/null 2>&1'; then + echo "Error: Timeout occurred while waiting for cl-controlplane deployment" + exit 1 + fi + + if ! timeout 30 sh -c 'until kubectl rollout status deployment cl-dataplane -n clusterlink-system; do sleep 0.1; done > /dev/null 2>&1'; then + echo "Error: Timeout occurred while waiting for cl-dataplane deployment" + exit 1 + fi + + # Delete clusterlink objects + $CLI delete peer --name peer1 + +} + +cd $TEST_DIR +clean_up + +trap clean_up_with_logs INT TERM EXIT + +cd $TEST_DIR +test_k8s + +echo OK