|
| 1 | +name: Integration Test on GCP Workflow |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - develop |
| 7 | + - main |
| 8 | + |
| 9 | +jobs: |
| 10 | + build-operator-image: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + env: |
| 13 | + SPLUNK_ENTERPRISE_IMAGE: ${{ secrets.SPLUNK_ENTERPRISE_IMAGE }} |
| 14 | + SPLUNK_OPERATOR_IMAGE_NAME: splunk/splunk-operator |
| 15 | + ARTIFACT_REGISTRY: ${{ secrets.GCP_ARTIFACT_REGISTRY }} # Updated for Artifact Registry |
| 16 | + steps: |
| 17 | + - name: Checkout Code |
| 18 | + uses: actions/checkout@v2 |
| 19 | + |
| 20 | + - name: Load Environment Variables |
| 21 | + id: dotenv |
| 22 | + uses: falti/dotenv-action@d4d12eaa0e1dd06d5bdc3d7af3bf4c8c93cb5359 |
| 23 | + with: |
| 24 | + path: .env # Adjust the path if your dotenv file is located elsewhere |
| 25 | + |
| 26 | + - name: Setup Go |
| 27 | + uses: actions/setup-go@v2 |
| 28 | + with: |
| 29 | + go-version: ${{ steps.dotenv.outputs.GO_VERSION }} |
| 30 | + |
| 31 | + - name: Set up Docker Buildx |
| 32 | + |
| 33 | + |
| 34 | + - name: Install Operator SDK |
| 35 | + run: | |
| 36 | + ARCH=$(case $(uname -m) in |
| 37 | + x86_64) echo -n amd64 ;; |
| 38 | + aarch64) echo -n arm64 ;; |
| 39 | + *) echo -n $(uname -m) ;; |
| 40 | + esac) |
| 41 | + OS=$(uname | awk '{print tolower($0)}') |
| 42 | + OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/${{ steps.dotenv.outputs.OPERATOR_SDK_VERSION }} |
| 43 | + curl -LO ${OPERATOR_SDK_DL_URL}/operator-sdk_${OS}_${ARCH} |
| 44 | + chmod +x operator-sdk_${OS}_${ARCH} |
| 45 | + sudo mv operator-sdk_${OS}_${ARCH} /usr/local/bin/operator-sdk |
| 46 | +
|
| 47 | + - name: Authenticate to GCP |
| 48 | + uses: google-github-actions/auth@v1 |
| 49 | + with: |
| 50 | + credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} |
| 51 | + |
| 52 | + - name: Login to GCR |
| 53 | + uses: docker/login-action@v3 |
| 54 | + with: |
| 55 | + registry: ${{ secrets.GCP_ARTIFACT_REGISTRY }} |
| 56 | + username: _json_key |
| 57 | + password: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} |
| 58 | + |
| 59 | + - name: Build Splunk Operator Image |
| 60 | + run: | |
| 61 | + make docker-buildx IMG=${{ secrets.GCP_ARTIFACT_REGISTRY }}/${{ env.SPLUNK_OPERATOR_IMAGE_NAME }}:$GITHUB_SHA |
| 62 | +
|
| 63 | + create-cluster-and-run-tests: |
| 64 | + strategy: |
| 65 | + matrix: |
| 66 | + test_focus: |
| 67 | + - { order: 1, name: "c3_gcp_sanity" } |
| 68 | + - { order: 2, name: "c3_mgr_gcp_sanity" } |
| 69 | + - { order: 3, name: "m4_gcp_sanity" } |
| 70 | + - { order: 4, name: "m4_mgr_gcp_sanity" } |
| 71 | + - { order: 5, name: "s1_gcp_sanity" } |
| 72 | + runs-on: ubuntu-latest |
| 73 | + needs: build-operator-image |
| 74 | + env: |
| 75 | + CLUSTER_WORKERS: 5 |
| 76 | + TEST_CLUSTER_PLATFORM: gcp |
| 77 | + CLUSTER_PROVIDER: gcp |
| 78 | + ARTIFACT_REGISTRY: ${{ secrets.GCP_ARTIFACT_REGISTRY }} |
| 79 | + GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} |
| 80 | + GCP_REGION: ${{ secrets.GCP_REGION }} |
| 81 | + AWS_S3_REGION: ${{ secrets.GCP_REGION }} |
| 82 | + GCP_ZONE: ${{ secrets.GCP_ZONE }} |
| 83 | + GCP_NETWORK: default # Adjust if using a custom network |
| 84 | + GCP_SUBNETWORK: default # Adjust if using a custom subnetwork |
| 85 | + TEST_FOCUS: ${{ matrix.test_focus.name }} |
| 86 | + CLUSTER_NODES: 2 |
| 87 | + SPLUNK_ENTERPRISE_IMAGE: ${{ secrets.SPLUNK_ENTERPRISE_IMAGE }} |
| 88 | + SPLUNK_ENTERPRISE_RELEASE_IMAGE: ${{ secrets.SPLUNK_ENTERPRISE_RELEASE_IMAGE }} |
| 89 | + SPLUNK_OPERATOR_IMAGE_NAME: splunk/splunk-operator |
| 90 | + SPLUNK_OPERATOR_IMAGE_FILENAME: splunk-operator |
| 91 | + TEST_TO_SKIP: "^(?:[^s]+|s(?:$|[^m]|m(?:$|[^o]|o(?:$|[^k]|k(?:$|[^e])))))*$" |
| 92 | + TEST_BUCKET: ${{ secrets.TEST_BUCKET }} |
| 93 | + TEST_S3_BUCKET: ${{ secrets.TEST_BUCKET }} |
| 94 | + TEST_INDEXES_S3_BUCKET: ${{ secrets.TEST_INDEXES_S3_BUCKET }} |
| 95 | + INDEXES_S3_BUCKET: ${{ secrets.TEST_INDEXES_S3_BUCKET }} |
| 96 | + GCP_ENTERPRISE_LICENSE_LOCATION: "test_licenses" |
| 97 | + ENTERPRISE_LICENSE_LOCATION: "test_licenses" |
| 98 | + ENTERPRISE_LICENSE_S3_PATH: "test_licenses" |
| 99 | + REGISTRY_REPOSITORY: ${{ secrets.GCP_ARTIFACT_REGISTRY }} |
| 100 | + CLUSTER_WIDE: "true" |
| 101 | + GCP_SERVICE_ACCOUNT_ENABLED: "false" |
| 102 | + PRIVATE_REGISTRY: ${{ secrets.GCP_ARTIFACT_REGISTRY }} |
| 103 | + GCP_STORAGE_ACCOUNT: ${{ secrets.GCP_STORAGE_ACCOUNT }} |
| 104 | + GCP_STORAGE_ACCOUNT_KEY: ${{ secrets.GCP_STORAGE_ACCOUNT_KEY }} |
| 105 | + GCP_TEST_CONTAINER: ${{ secrets.GCP_TEST_CONTAINER}} |
| 106 | + GCP_INDEXES_CONTAINER: ${{ secrets.GCP_INDEXES_CONTAINER}} |
| 107 | + ECR_REPOSITORY: ${{ secrets.GCP_ARTIFACT_REGISTRY }} |
| 108 | + GCP_CONTAINER_REGISTRY_LOGIN_SERVER: ${{ secrets.AZURE_ACR_LOGIN_SERVER }} |
| 109 | + steps: |
| 110 | + - name: Set Test Cluster Name |
| 111 | + run: | |
| 112 | + echo "CLUSTER_NAME=gke-${{ matrix.test_focus.order }}-$GITHUB_RUN_ID" >> $GITHUB_ENV |
| 113 | + echo "TEST_CLUSTER_NAME=gke-${{ matrix.test_focus.order }}-$GITHUB_RUN_ID" >> $GITHUB_ENV |
| 114 | + - name: Checkout Code |
| 115 | + uses: actions/checkout@v2 |
| 116 | + |
| 117 | + - name: Load Environment Variables |
| 118 | + id: dotenv |
| 119 | + uses: falti/dotenv-action@d4d12eaa0e1dd06d5bdc3d7af3bf4c8c93cb5359 |
| 120 | + with: |
| 121 | + path: .env |
| 122 | + |
| 123 | + - name: Authenticate to GCP |
| 124 | + uses: google-github-actions/auth@v1 |
| 125 | + with: |
| 126 | + credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} |
| 127 | + |
| 128 | + - name: Set up Cloud SDK |
| 129 | + uses: google-github-actions/setup-gcloud@v1 |
| 130 | + with: |
| 131 | + project_id: ${{ secrets.GCP_PROJECT_ID }} |
| 132 | + install_components: 'kubectl' |
| 133 | + |
| 134 | + - name: Set GCP Project |
| 135 | + run: | |
| 136 | + gcloud config set project ${{ env.GCP_PROJECT_ID }} |
| 137 | +
|
| 138 | + - name: Create GKE Cluster |
| 139 | + run: | |
| 140 | + export EKS_CLUSTER_K8_VERSION=${{ steps.dotenv.outputs.EKS_CLUSTER_K8_VERSION }} |
| 141 | + export GKE_CLUSTER_K8_VERSION=${{ steps.dotenv.outputs.EKS_CLUSTER_K8_VERSION }} |
| 142 | + make cluster-up |
| 143 | +
|
| 144 | + - name: Get Kubernetes Credentials |
| 145 | + run: | |
| 146 | + gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }} --zone ${{ env.GCP_ZONE }} --project ${{ env.GCP_PROJECT_ID }} |
| 147 | +
|
| 148 | + - name: Allow Pulling from Artifact Registry |
| 149 | + run: | |
| 150 | + gcloud auth configure-docker ${{ secrets.GCP_ARTIFACT_REGISTRY }} |
| 151 | +
|
| 152 | + - name: Set up Cloud SDK |
| 153 | + uses: google-github-actions/setup-gcloud@v1 |
| 154 | + with: |
| 155 | + project_id: ${{ secrets.GCP_PROJECT_ID }} |
| 156 | + install_components: 'kubectl' |
| 157 | + |
| 158 | + - name: Change Splunk Enterprise Image on Main Branches |
| 159 | + if: github.ref == 'refs/heads/main' |
| 160 | + run: | |
| 161 | + echo "SPLUNK_ENTERPRISE_IMAGE=${{ steps.dotenv.outputs.SPLUNK_ENTERPRISE_RELEASE_IMAGE }}" >> $GITHUB_ENV |
| 162 | +
|
| 163 | + - name: Authenticate to GCP |
| 164 | + uses: google-github-actions/auth@v1 |
| 165 | + with: |
| 166 | + credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} |
| 167 | + |
| 168 | + - name: Set GCP Project |
| 169 | + run: | |
| 170 | + gcloud config set project ${{ env.GCP_PROJECT_ID }} |
| 171 | +
|
| 172 | + - name: Install Kubectl |
| 173 | + uses: azure/setup-kubectl@v3 |
| 174 | + with: |
| 175 | + version: ${{ steps.dotenv.outputs.KUBECTL_VERSION }} |
| 176 | + |
| 177 | + - name: Install Python |
| 178 | + uses: actions/setup-python@v2 |
| 179 | + with: |
| 180 | + python-version: '3.x' # Specify the Python version if needed |
| 181 | + |
| 182 | + - name: Setup Go |
| 183 | + uses: actions/setup-go@v2 |
| 184 | + with: |
| 185 | + go-version: ${{ steps.dotenv.outputs.GO_VERSION }} |
| 186 | + |
| 187 | + - name: Install Go Lint |
| 188 | + run: | |
| 189 | + go version |
| 190 | + go install golang.org/x/lint/golint@latest |
| 191 | +
|
| 192 | + - name: Install Ginkgo |
| 193 | + run: | |
| 194 | + make setup/ginkgo |
| 195 | +
|
| 196 | + - name: Set up Docker Buildx |
| 197 | + |
| 198 | + |
| 199 | + - name: Login to GCR |
| 200 | + uses: docker/login-action@v3 |
| 201 | + with: |
| 202 | + registry: ${{ secrets.GCP_ARTIFACT_REGISTRY }} |
| 203 | + username: _json_key |
| 204 | + password: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} |
| 205 | + |
| 206 | + - name: Pull Splunk Enterprise Image |
| 207 | + run: docker pull ${{ env.SPLUNK_ENTERPRISE_IMAGE }} |
| 208 | + |
| 209 | + - name: Pull Splunk Operator Image Locally |
| 210 | + run: | |
| 211 | + docker pull ${{ secrets.GCP_ARTIFACT_REGISTRY }}/${{ env.SPLUNK_OPERATOR_IMAGE_NAME }}:$GITHUB_SHA |
| 212 | + docker tag ${{ secrets.GCP_ARTIFACT_REGISTRY }}/${{ env.SPLUNK_OPERATOR_IMAGE_NAME }}:$GITHUB_SHA ${{ env.SPLUNK_OPERATOR_IMAGE_NAME }}:$GITHUB_SHA |
| 213 | + echo "SPLUNK_OPERATOR_IMAGE=${{ env.SPLUNK_OPERATOR_IMAGE_NAME }}:$GITHUB_SHA" >> $GITHUB_ENV |
| 214 | +
|
| 215 | + - name: Tag and Push Splunk Enterprise Image to Artifact Registry |
| 216 | + run: | |
| 217 | + docker tag ${{ env.SPLUNK_ENTERPRISE_IMAGE }} ${{ secrets.GCP_ARTIFACT_REGISTRY }}/${{ env.SPLUNK_ENTERPRISE_IMAGE }} |
| 218 | + docker push ${{ secrets.GCP_ARTIFACT_REGISTRY }}/${{ env.SPLUNK_ENTERPRISE_IMAGE }} |
| 219 | +
|
| 220 | + - name: Get Kubernetes Credentials |
| 221 | + run: | |
| 222 | + gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }} --zone ${{ env.GCP_ZONE }} --project ${{ env.GCP_PROJECT_ID }} |
| 223 | +
|
| 224 | + - name: Get GKE Credentials |
| 225 | + uses: google-github-actions/get-gke-credentials@v1 |
| 226 | + with: |
| 227 | + cluster_name: ${{ env.CLUSTER_NAME }} |
| 228 | + location: ${{ env.GCP_ZONE }} |
| 229 | + |
| 230 | + - name: Install Metrics Server |
| 231 | + run: | |
| 232 | + kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml |
| 233 | +
|
| 234 | + - name: Install Kubernetes Dashboard |
| 235 | + run: | |
| 236 | + kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.5/aio/deploy/recommended.yaml |
| 237 | +
|
| 238 | + - name: Setup Kustomize |
| 239 | + run: | |
| 240 | + curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash |
| 241 | + sudo mv kustomize /usr/local/bin/ |
| 242 | +
|
| 243 | + - name: Verify kubectl Configuration |
| 244 | + run: | |
| 245 | + kubectl config current-context |
| 246 | + |
| 247 | + - name: Apply StorageClass |
| 248 | + run: | |
| 249 | + kubectl apply -f test/gcp-storageclass.yaml |
| 250 | +
|
| 251 | + - name: Run Integration Tests |
| 252 | + run: | |
| 253 | + export GCP_SERVICE_ACCOUNT_KEY=${{ secrets.GCP_SERVICE_ACCOUNT_KEY_BASE64 }} |
| 254 | + make int-test |
| 255 | +
|
| 256 | + - name: Collect Test Logs |
| 257 | + if: ${{ always() }} |
| 258 | + run: | |
| 259 | + mkdir -p /tmp/pod_logs |
| 260 | + find ./test -name "*.log" -exec cp {} /tmp/pod_logs \; |
| 261 | +
|
| 262 | + - name: Archive Pod Logs |
| 263 | + if: ${{ always() }} |
| 264 | + uses: actions/upload-artifact@v4 |
| 265 | + with: |
| 266 | + name: splunk-pods-logs-artifacts-${{ matrix.test_focus.name }} |
| 267 | + path: /tmp/pod_logs/** |
| 268 | + - name: Cleanup Test Case Artifacts |
| 269 | + if: ${{ always() }} |
| 270 | + run: | |
| 271 | + export EKS_CLUSTER_K8_VERSION=${{ steps.dotenv.outputs.EKS_CLUSTER_K8_VERSION }} |
| 272 | + export GKE_CLUSTER_K8_VERSION=${{ steps.dotenv.outputs.EKS_CLUSTER_K8_VERSION }} |
| 273 | + tools/cleanup.sh |
| 274 | + - name: Cleanup up EKS cluster |
| 275 | + if: ${{ always() }} |
| 276 | + run: | |
| 277 | + make cluster-down |
0 commit comments