Skip to content

Commit

Permalink
refactor: streamline installation workflow by consolidating cluster r…
Browse files Browse the repository at this point in the history
…egistration steps and improving log handling

Signed-off-by: Sky Singh <[email protected]>
  • Loading branch information
SkySingh04 committed Feb 6, 2025
1 parent bf1a595 commit fd74a37
Showing 1 changed file with 33 additions and 102 deletions.
135 changes: 33 additions & 102 deletions .github/workflows/installation-cli.yaml
Original file line number Diff line number Diff line change
@@ -1,116 +1,45 @@
name: CLI
on:
# Run this workflow every time a new commit pushed to upstream/fork repository.
# Run workflow on fork repository will help contributors find and resolve issues before sending a PR.
push:
# Exclude branches created by Dependabot to avoid triggering current workflow
# for PRs initiated by Dependabot.
branches-ignore:
- 'dependabot/**'
pull_request:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency
concurrency:
group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions:
contents: read # Required to check out the code
contents: read
jobs:
test-on-kubernetes-matrix:
name: Test on Kubernetes
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
# Here support the latest three minor releases of Kubernetes, this can be considered to be roughly
# the same as the End of Life of the Kubernetes release: https://kubernetes.io/releases/
# Please remember to update the CI Schedule Workflow when we add a new version.
k8s: [ v1.29.0, v1.30.0, v1.31.0 ]
steps:
- name: checkout code
uses: actions/checkout@v4
with:
# Number of commits to fetch. 0 indicates all history for all branches and tags.
# We need to guess version via git tags.
fetch-depth: 0
- name: install Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Build karmadactl
run: |
mkdir -p ${HOME}/go/bin
go build -o ${HOME}/go/bin/karmadactl ./cmd/karmadactl
echo "${HOME}/go/bin" >> $GITHUB_PATH
- name: run karmadactl init test
run: |
export CLUSTER_VERSION=kindest/node:${{ matrix.k8s }}
# init e2e environment
hack/cli-testing-environment.sh
# run a single e2e
export KUBECONFIG=${HOME}/karmada/karmada-apiserver.config
GO111MODULE=on go install github.com/onsi/ginkgo/v2/ginkgo
ginkgo -v --race --trace -p --focus="[BasicPropagation] propagation testing deployment propagation testing" ./test/e2e/
- name: Get token info
id: token
run: |
export KUBECONFIG=${HOME}/karmada/karmada-apiserver.config
CMD=$(karmadactl token create --print-register-command --kubeconfig $KUBECONFIG)
TOKEN=$(echo "$CMD" | grep -o '\--token [^ ]*' | cut -d' ' -f2)
HASH=$(echo "$CMD" | grep -o '\--discovery-token-ca-cert-hash [^ ]*' | cut -d' ' -f2)
ENDPOINT=$(kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}' | sed 's|^https://||')
echo "token=$TOKEN" >> $GITHUB_OUTPUT
echo "hash=$HASH" >> $GITHUB_OUTPUT
echo "endpoint=$ENDPOINT" >> $GITHUB_OUTPUT
- name: Update /etc/hosts for karmada-host
run: |
ENDPOINT_IP=$(echo "${{ steps.token.outputs.endpoint }}" | cut -d':' -f1)
echo "$ENDPOINT_IP karmada-host-control-plane" | sudo tee -a /etc/hosts
- name: Configure RBAC for certificate signing
run: |
export KUBECONFIG=${HOME}/karmada/karmada-apiserver.config
kubectl create clusterrolebinding karmada-bootstrap-csr \
--clusterrole=system:node-bootstrapper \
--group=system:bootstrappers
- name: Configure CSR Auto-Approval
run: |
export KUBECONFIG=${HOME}/karmada/karmada-apiserver.config
kubectl apply -f - <<EOF
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: auto-approve-csrs-for-bootstrappers
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:certificates.k8s.io:certificatesigningrequests:nodeclient
subjects:
- kind: Group
name: system:bootstrappers
apiGroup: rbac.authorization.k8s.io
EOF
- name: Register cluster
run: |
karmadactl register ${{ steps.token.outputs.endpoint }} \
--token ${{ steps.token.outputs.token }} \
--discovery-token-ca-cert-hash ${{ steps.token.outputs.hash }} \
--discovery-timeout=10m \
--kubeconfig ${HOME}/karmada/karmada-apiserver.config
- name: export logs
if: always()
run: |
export ARTIFACTS_PATH=${{ github.workspace }}/karmadactl-test-logs/${{ matrix.k8s }}/
mkdir -p $ARTIFACTS_PATH
mkdir -p $ARTIFACTS_PATH/karmada-host
kind export logs --name=karmada-host $ARTIFACTS_PATH/karmada-host
- name: upload logs
if: always()
uses: actions/upload-artifact@v4
Expand All @@ -124,7 +53,6 @@ jobs:
strategy:
fail-fast: false
matrix:
# Latest three minor releases of Kubernetes
k8s: [ v1.29.0, v1.30.0, v1.31.0 ]
steps:
- name: checkout code
Expand All @@ -135,41 +63,44 @@ jobs:
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Build karmadactl
run: |
# Ensure the target directory exists and is writable
mkdir -p ${HOME}/go/bin
# Build karmadactl to the user-controlled directory
go build -o ${HOME}/go/bin/karmadactl ./cmd/karmadactl
# Add the binary directory to PATH
echo "${HOME}/go/bin" >> $GITHUB_PATH
- name: Run karmadactl init with config file test
- name: run karmadactl init with config file test
run: |
export CLUSTER_VERSION=kindest/node:${{ matrix.k8s }}
hack/cli-testing-init-with-config.sh
export KUBECONFIG=${HOME}/karmada/karmada-apiserver.config
GO111MODULE=on go install github.com/onsi/ginkgo/v2/ginkgo
ginkgo -v --race --trace -p --focus="[BasicPropagation] propagation testing deployment propagation testing" ./test/e2e/
- name: Generate registration command
ginkgo -v --race --trace -p --focus="[BasicPropagation] propagation testing deployment propagation testing" ./test/e2e/
- name: Get token info for registration
id: token
run: |
export KUBECONFIG=${HOME}/karmada/karmada-apiserver.config
karmadactl token create --print-register-command > register-command.sh
chmod +x register-command.sh
- name: Register cluster in pull mode
CMD=$(karmadactl token create --print-register-command --kubeconfig $KUBECONFIG)
TOKEN=$(echo "$CMD" | grep -o '\--token [^ ]*' | cut -d' ' -f2)
HASH=$(echo "$CMD" | grep -o '\--discovery-token-ca-cert-hash [^ ]*' | cut -d' ' -f2)
ENDPOINT=$(kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}' | sed 's|^https://||')
echo "token=$TOKEN" >> $GITHUB_OUTPUT
echo "hash=$HASH" >> $GITHUB_OUTPUT
echo "endpoint=$ENDPOINT" >> $GITHUB_OUTPUT
- name: Register cluster using token
run: |
./register-command.sh --cluster-name ${{ matrix.k8s }} --kubeconfig ${HOME}/karmada/karmada-apiserver.config
karmadactl register ${{ steps.token.outputs.endpoint }} \
--token ${{ steps.token.outputs.token }} \
--discovery-token-ca-cert-hash ${{ steps.token.outputs.hash }} \
--discovery-timeout=10m \
--kubeconfig ${HOME}/karmada/karmada-apiserver.config
- name: export logs for config test
if: always()
run: |
export ARTIFACTS_PATH=${{ github.workspace }}/karmadactl-test-logs/${{ matrix.k8s }}/config
mkdir -p $ARTIFACTS_PATH
mkdir -p $ARTIFACTS_PATH/karmada-host
kind export logs --name=karmada-host $ARTIFACTS_PATH/karmada-host
- name: upload config test logs
if: always()
uses: actions/upload-artifact@v4
with:
name: karmadactl_config_test_logs_${{ matrix.k8s }}
path: ${{ github.workspace }}/karmadactl-test-logs/${{ matrix.k8s }}/config/
if: always()
run: |
export ARTIFACTS_PATH=${{ github.workspace }}/karmadactl-test-logs/${{ matrix.k8s }}/config
mkdir -p $ARTIFACTS_PATH
mkdir -p $ARTIFACTS_PATH/karmada-host
kind export logs --name=karmada-host $ARTIFACTS_PATH/karmada-host
- name: upload config test logs
if: always()
uses: actions/upload-artifact@v4
with:
name: karmadactl_config_test_logs_${{ matrix.k8s }}
path: ${{ github.workspace }}/karmadactl-test-logs/${{ matrix.k8s }}/config/

0 comments on commit fd74a37

Please sign in to comment.