Skip to content

Commit

Permalink
Set-up basic uptest workflow (#163)
Browse files Browse the repository at this point in the history
This allows us to test that resources can be created and deleted. I will add new tests in future PRs.
  • Loading branch information
julienduchesne authored Jun 18, 2024
1 parent eb98abc commit f8b1427
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 80 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,18 @@ jobs:
env:
UPBOUND_MARKETPLACE_PUSH_ROBOT_USR: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR }}
UPBOUND_MARKETPLACE_PUSH_ROBOT_PSW: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_PSW }}

e2e:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- run: make e2e
env:
UPTEST_EXAMPLE_LIST: examples/oss/v1alpha1/dashboard.yaml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cover.out
/vendor
/.vendor-new
.DS_Store
/kubeconfig

# ignore IDE folders
.vscode/
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ GO_SUBDIRS += cmd internal apis
# ====================================================================================
# Setup Kubernetes tools

KIND_VERSION = v0.20.0
KIND_VERSION = v0.23.0
UP_VERSION = v0.31.0
UP_CHANNEL = stable
UPTEST_VERSION = v0.10.0
UPTEST_VERSION = v0.11.1
-include build/makelib/k8s_tools.mk

# ====================================================================================
Expand Down Expand Up @@ -167,7 +167,7 @@ CROSSPLANE_NAMESPACE = upbound-system

uptest: $(UPTEST) $(KUBECTL) $(KUTTL)
@$(INFO) running automated tests
@KUBECTL=$(KUBECTL) KUTTL=$(KUTTL) $(UPTEST) e2e "${UPTEST_EXAMPLE_LIST}" --setup-script=cluster/test/setup.sh || $(FAIL)
@CROSSPLANE_NAMESPACE=$(CROSSPLANE_NAMESPACE) KUBECTL=$(KUBECTL) KUTTL=$(KUTTL) $(UPTEST) e2e "${UPTEST_EXAMPLE_LIST}" --setup-script=cluster/test/setup.sh || $(FAIL)
@$(OK) running automated tests

local-deploy: build controlplane.up local.xpkg.deploy.provider.$(PROJECT_NAME)
Expand Down
38 changes: 38 additions & 0 deletions cluster/test/grafana.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: v1
kind: Namespace
metadata:
name: grafana
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: grafana
namespace: grafana
spec:
replicas: 1
selector:
matchLabels:
app: grafana
template:
metadata:
labels:
app: grafana
spec:
containers:
- name: grafana
image: grafana/grafana:latest
ports:
- containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
name: grafana
namespace: grafana
spec:
selector:
app: grafana
ports:
- protocol: TCP
port: 80
targetPort: 3000
28 changes: 28 additions & 0 deletions cluster/test/provider.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Grafana Provider Creds
apiVersion: v1
kind: Secret
metadata:
name: grafana-creds
namespace: upbound-system
type: Opaque
stringData:
credentials: |
{
"url": "http://grafana.grafana.svc.cluster.local",
"auth": "admin:admin"
}
---

# Grafana Provider
apiVersion: grafana.crossplane.io/v1beta1
kind: ProviderConfig
metadata:
name: grafana-provider
spec:
credentials:
source: Secret
secretRef:
name: grafana-creds
namespace: upbound-system
key: credentials
26 changes: 11 additions & 15 deletions cluster/test/setup.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
#!/usr/bin/env bash
set -aeuo pipefail

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

echo "Running setup.sh"
echo "Creating cloud credential secret..."
${KUBECTL} -n upbound-system create secret generic provider-secret --from-literal=credentials="{\"token\":\"${UPTEST_CLOUD_CREDENTIALS}\"}" --dry-run=client -o yaml | ${KUBECTL} apply -f -

echo "Starting grafana on the cluster..."
${KUBECTL} apply -f "${SCRIPT_DIR}/grafana.yaml"

echo "Creating provider..."
${KUBECTL} apply -f "${SCRIPT_DIR}/provider.yaml"

echo "Waiting for grafana to come online..."
${KUBECTL} -n grafana wait --for=condition=Available deployment/grafana --timeout=5m

echo "Waiting until provider is healthy..."
${KUBECTL} wait provider.pkg --all --for condition=Healthy --timeout 5m

echo "Waiting for all pods to come online..."
${KUBECTL} -n upbound-system wait --for=condition=Available deployment --all --timeout=5m

echo "Creating a default provider config..."
cat <<EOF | ${KUBECTL} apply -f -
apiVersion: grafana.com/v1beta1
kind: ProviderConfig
metadata:
name: default
spec:
credentials:
source: Secret
secretRef:
name: provider-secret
namespace: upbound-system
key: credentials
62 changes: 0 additions & 62 deletions examples/oss.yaml

This file was deleted.

37 changes: 37 additions & 0 deletions examples/oss/v1alpha1/dashboard.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: oss.grafana.crossplane.io/v1alpha1
kind: Dashboard
metadata:
annotations:
meta.upbound.io/example-id: oss/v1alpha1/dashboard
labels:
testing.upbound.io/example-name: test-dashboard
name: test-dashboard
spec:
forProvider:
configJson: |-
{
"title" : "My Dashboard",
"uid" : "my-dashboard-uid"
}
folderSelector:
matchLabels:
testing.upbound.io/example-name: test-dashboard
providerConfigRef:
name: grafana-provider

---

apiVersion: oss.grafana.crossplane.io/v1alpha1
kind: Folder
metadata:
annotations:
meta.upbound.io/example-id: oss/v1alpha1/dashboard
labels:
testing.upbound.io/example-name: test-dashboard
name: test-dashboard
spec:
forProvider:
title: My Folder
uid: my-folder-uid
providerConfigRef:
name: grafana-provider

0 comments on commit f8b1427

Please sign in to comment.