Merge 0.0.6 mvp_demo to main #139
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test on Pull Request | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| - mvp_demo | |
| types: [opened, synchronize, reopened] | |
| env: | |
| GO_VERSION: '1.24.7' | |
| OPERATOR_IMAGE: quay.io/kruize/kruize-operator:pr-${{ github.event.pull_request.number }} | |
| NAMESPACE: monitoring | |
| jobs: | |
| build-and-test: | |
| name: Build and Test Operator | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| cache: true | |
| - name: Install dependencies | |
| run: | | |
| go mod download | |
| go mod verify | |
| - name: Create Kind config | |
| run: | | |
| cat <<EOF > /tmp/kind-config.yaml | |
| kind: Cluster | |
| apiVersion: kind.x-k8s.io/v1alpha4 | |
| nodes: | |
| - role: control-plane | |
| extraPortMappings: | |
| - containerPort: 30080 | |
| hostPort: 30080 | |
| protocol: TCP | |
| EOF | |
| - name: Set up Kind cluster | |
| uses: helm/kind-action@v1 | |
| with: | |
| cluster_name: kruize-test-cluster | |
| wait: 120s | |
| config: /tmp/kind-config.yaml | |
| - name: Verify Kind cluster | |
| run: | | |
| kubectl cluster-info | |
| kubectl get nodes | |
| kubectl version | |
| - name: Build operator image | |
| run: | | |
| make docker-build IMG=${{ env.OPERATOR_IMAGE }} | |
| - name: Load image to Kind cluster | |
| run: | | |
| kind load docker-image ${{ env.OPERATOR_IMAGE }} --name kruize-test-cluster | |
| - name: Install Prometheus with cadvisor | |
| run: | | |
| PROMETHEUS_TAG="v0.13.0" | |
| PROMETHEUS_NS="monitoring" | |
| CADVISOR_TAG="v0.56.2" | |
| echo "Info: Checking if Prometheus is already installed..." | |
| if kubectl get pods -n ${PROMETHEUS_NS} -l app.kubernetes.io/name=prometheus \ | |
| --field-selector=status.phase=Running --no-headers 2>/dev/null | grep -q '.'; then | |
| echo "Prometheus is already installed and running." | |
| else | |
| echo "Info: Installing cadvisor and Prometheus" | |
| # Create downloads directory | |
| mkdir -p /tmp/kind_downloads | |
| cd /tmp/kind_downloads | |
| # Install cadvisor | |
| echo "Info: Downloading cadvisor git release - ${CADVISOR_TAG}" | |
| git clone --depth 1 -b ${CADVISOR_TAG} https://github.com/google/cadvisor.git 2>/dev/null || echo "cadvisor already cloned" | |
| cd cadvisor/deploy/kubernetes/base | |
| echo "Info: Installing cadvisor" | |
| kubectl kustomize . | kubectl apply -f- | |
| cd /tmp/kind_downloads | |
| # Install Prometheus | |
| echo "Info: Downloading prometheus git release - ${PROMETHEUS_TAG}" | |
| git clone --depth 1 -b ${PROMETHEUS_TAG} https://github.com/coreos/kube-prometheus.git 2>/dev/null || echo "kube-prometheus already cloned" | |
| cd kube-prometheus/manifests | |
| echo "Info: Installing prometheus setup" | |
| kubectl apply -f setup --server-side | |
| echo "Info: Installing prometheus manifests" | |
| kubectl apply -f . --server-side | |
| # Wait for Prometheus pods to be ready | |
| echo "Info: Waiting for Prometheus pods to be ready..." | |
| sleep 30 | |
| kubectl wait \ | |
| --for=condition=ready pod \ | |
| -l app.kubernetes.io/name=prometheus \ | |
| -n "${PROMETHEUS_NS}" \ | |
| --timeout=300s | |
| echo "Info: Verifying Prometheus installation..." | |
| kubectl get statefulset prometheus-k8s -n ${PROMETHEUS_NS} | |
| kubectl get svc prometheus-k8s -n ${PROMETHEUS_NS} | |
| kubectl get pods -n ${PROMETHEUS_NS} -l app.kubernetes.io/name=prometheus | |
| echo "Info: Prometheus installation completed successfully" | |
| fi | |
| - name: Reduce operator resource requests for Kind | |
| run: | | |
| echo "Reducing CPU/memory requests for resource-constrained Kind cluster..." | |
| echo "Using pre-installed yq from GitHub runner" | |
| # Create temporary directory for modified configs | |
| mkdir -p /tmp/ci-config/manager | |
| mkdir -p /tmp/ci-config/default | |
| # Copy original files to temporary location | |
| cp config/manager/manager.yaml /tmp/ci-config/manager/manager.yaml | |
| # Reduce manager container resources in temporary copy | |
| echo "Updating manager container resources..." | |
| yq -i '(.spec.template.spec.containers[] | select(.name == "manager").resources.requests.cpu) = "1m"' /tmp/ci-config/manager/manager.yaml | |
| yq -i '(.spec.template.spec.containers[] | select(.name == "manager").resources.requests.memory) = "32Mi"' /tmp/ci-config/manager/manager.yaml | |
| # Copy modified files back to config directory for deployment | |
| cp /tmp/ci-config/manager/manager.yaml config/manager/manager.yaml | |
| echo "Updated resource requests:" | |
| echo "Manager container:" | |
| yq '.spec.template.spec.containers[] | select(.name == "manager").resources.requests' config/manager/manager.yaml | |
| - name: Run E2E tests | |
| run: | | |
| set -o pipefail | |
| make test-e2e \ | |
| CLUSTER_TYPE=kind \ | |
| OPERATOR_IMAGE=${{ env.OPERATOR_IMAGE }} \ | |
| NAMESPACE=${{ env.NAMESPACE }} \ | |
| 2>&1 | sed -r 's/\x1b\[[0-9;]*[mGKHF]//g' | tee /tmp/e2e-test-output.log | |
| - name: Upload E2E test logs | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: operator-e2e-test-logs-pr-${{ github.event.pull_request.number }} | |
| path: | | |
| /tmp/e2e-test-output.log | |
| /tmp/pod-logs/ | |
| retention-days: 1 | |
| - name: Summary | |
| if: success() | |
| run: | | |
| echo "✓ PR Check Passed!" | |
| echo "✓ Operator image built successfully" | |
| echo "✓ Operator deployed successfully" | |
| echo "✓ Kruize components verified" | |
| echo "✓ All checks completed" |