Skip to content

Commit

Permalink
update build-workflow to build helm-values for the operator
Browse files Browse the repository at this point in the history
  • Loading branch information
waveywaves committed Mar 27, 2024
1 parent 4117e8a commit a002815
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 61 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/build-operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Build - Uffizzi Cluster Operator

on:
pull_request:
branches: [ main ]
types: [opened,reopened,synchronize,closed]

permissions:
contents: read
pull-requests: write
id-token: write

jobs:
build-operator:
name: Build and Push `operator` Image
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
outputs:
tags: ${{ steps.meta.outputs.tags }}
uuid: ${{ env.UUID_OPERATOR }}
steps:
- name: Checkout git repo
uses: actions/checkout@v3
- name: Generate UUID image name
id: uuid
run: echo "UUID_OPERATOR=$(uuidgen)" >> $GITHUB_ENV
- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
# An anonymous, emphemeral registry built on ttl.sh
images: registry.uffizzi.com/${{ env.UUID_OPERATOR }}
tags: type=raw,value=48h
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and Push Image to Uffizzi Ephemeral Registry
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
context: ./
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Create Helm Values File
run: |
cat <<EOF > helm-values.yaml
image:
repository: registry.uffizzi.com/${{ env.UUID_OPERATOR }}
tag: 48h
EOF
cat helm-values.yaml # For debugging, to check the contents of the file.
- name: Upload Helm Values as Artifact
uses: actions/upload-artifact@v3
with:
name: helm-values
path: helm-values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: EnvTest with Cluster
name: Tests - E2E - EnvTest with Cluster # e2e tests running against a k8s cluster

on:
pull_request:
Expand All @@ -19,12 +19,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Flux CLI
- name: Setup Flux CLI # used in the make command
uses: fluxcd/flux2/action@main

- name: Setup k3d
uses: ./.github/actions/k3d

- name: Run e2e tests against current cluster
run: |
make test-e2e-with-cluster-local
Expand All @@ -43,12 +40,31 @@ jobs:
- name: Setup Flux CLI
uses: fluxcd/flux2/action@main

- name: Setup k3d
uses: ./.github/actions/k3d

- name: Run e2e tests against current tainted cluster
run: |
make test-e2e-with-tainted-cluster-local
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3

minikube-perf-test:
name: Run e2e tests against Minikube
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Flux CLI
uses: fluxcd/flux2/action@main

- name: Start Minikube
run: |
make start-test-minikube
- name: Run e2e tests against current cluster
run: |
make test-e2e-perf-with-cluster-local
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,6 @@ permissions:
id-token: write

jobs:
build-operator:
name: Build and Push `operator` Image
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
outputs:
tags: ${{ steps.meta.outputs.tags }}
uuid: ${{ env.UUID_OPERATOR }}
steps:
- name: Checkout git repo
uses: actions/checkout@v3
- name: Generate UUID image name
id: uuid
run: echo "UUID_OPERATOR=$(uuidgen)" >> $GITHUB_ENV
- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
# An anonymous, emphemeral registry built on ttl.sh
images: registry.uffizzi.com/${{ env.UUID_OPERATOR }}
tags: type=raw,value=48h
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and Push Image to Uffizzi Ephemeral Registry
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
context: ./
cache-from: type=gha
cache-to: type=gha,mode=max

uffizzi-cluster:
name: Deploy Helm chart to Uffizzi Virtual Cluster
needs:
Expand All @@ -53,6 +21,11 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Download Helm Values Artifact
uses: actions/download-artifact@v3
with:
name: helm-values

# Identify comment to be updated
- name: Find comment for Ephemeral Environment
uses: peter-evans/find-comment@v2
Expand Down Expand Up @@ -92,21 +65,6 @@ jobs:
- name: Apply Helm Chart
id: prev
run: |
# install krew
# set -x; cd "$(mktemp -d)" &&
# OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
# ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
# KREW="krew-${OS}_${ARCH}" &&
# curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
# tar zxvf "${KREW}.tar.gz" &&
# ./"${KREW}" install krew
# cd -
# install kuttl
# ./"${KREW}" install kuttl
if [[ ${RUNNER_DEBUG} == 1 ]]; then
echo "`pwd`"
echo "`ls`"
Expand All @@ -115,10 +73,7 @@ jobs:
export KUBECONFIG="`pwd`/kubeconfig"
helm dep update ./chart
helm upgrade --install --wait pr-${{ github.event.pull_request.number }} \
./chart --set image.repository=registry.uffizzi.com/${{ needs.build-operator.outputs.uuid }},image.tag=48h
# kubectl apply -f examples/k3s-manifest-basic.yml
# kubectl apply -f examples/k8s-manifest-basic.yml
./chart -f helm-values.yaml
- name: Create or Update Comment with Deployment URL
uses: peter-evans/create-or-update-comment@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/helm-release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release Helm Charts
name: Release - Helm Chart

on:
push:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit Tests and Coverage
name: Tests - Unit Tests and Coverage

on:
pull_request:
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ test-e2e-without-cluster: manifests generate fmt vet envtest ## Run test.
test-e2e-with-cluster: manifests generate fmt vet envtest ## Run test.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" ENVTEST_REMOTE=true go test ./... -coverprofile=coverage.txt -v

.PHONY: test-e2e-perf-with-cluster
test-e2e-perf-with-cluster: manifests generate fmt vet envtest ## Run test.
./hack/run-e2e-perf.sh

.PHONY: test-e2e-with-cluster-local
test-e2e-with-cluster-local: start-test-minikube test-e2e-with-cluster ## Run test.

Expand All @@ -180,6 +184,9 @@ test-e2e-with-tainted-cluster: manifests generate fmt vet envtest ## Run test.
.PHONY: test-e2e-with-tainted-cluster-local
test-e2e-with-tainted-cluster-local: start-test-minikube-tainted test-e2e-with-tainted-cluster ## Run test.

.PHONY: test-e2e-perf-with-cluster-local
test-e2e-perf-with-cluster-local: start-test-minikube test-e2e-perf-with-cluster ## Run test.

##@ Build

.PHONY: build
Expand Down
50 changes: 50 additions & 0 deletions hack/e2e/001-multicluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

# create multiple uffizzi clusters

for i in {1..10}; do
kubectl create -f hack/e2e/manifests/001-multicluster.yaml
done

# Retrieve the names of the newly created UffizziCluster resources
# Assuming 'uffizzicluster' is the kind for the UffizziCluster resources
uffizzi_clusters=($(kubectl get uffizzicluster -o jsonpath='{.items[*].metadata.name}'))

# Check if we have any clusters to monitor
if [ ${#uffizzi_clusters[@]} -eq 0 ]; then
echo "No UffizziClusters found. Exiting..."
exit 1
fi

echo "Monitoring the following UffizziClusters for readiness: ${uffizzi_clusters[@]}"

# Function to check the APIReady condition of a UffizziCluster
check_api_ready() {
local cluster_name=$1
api_ready=$(kubectl get uffizzicluster "$cluster_name" -o jsonpath='{.status.conditions[?(@.type=="APIReady")].status}')
echo "$api_ready"
}

# Monitor each UffizziCluster until the APIReady condition is True
start_time=$(date +%s)
for cluster in "${uffizzi_clusters[@]}"; do
while true; do
api_ready=$(check_api_ready "$cluster")
if [ "$api_ready" == "True" ]; then
echo "UffizziCluster $cluster is ready."
break
else
echo "Waiting for UffizziCluster $cluster to become ready..."
sleep 5
fi
done
done
end_time=$(date +%s)

# Calculate the total time taken for all UffizziClusters to become ready
total_time=$((end_time - start_time))
echo "All UffizziClusters are ready. Total time taken: $total_time seconds."
4 changes: 4 additions & 0 deletions hack/e2e/manifests/001-multicluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: UffizziCluster
apiVersion: uffizzi.com/v1alpha1
metadata:
generateName: multicluster-

0 comments on commit a002815

Please sign in to comment.