Skip to content

Commit 1afc041

Browse files
committed
chore(scripts): update scripting usability
1 parent d5c6b78 commit 1afc041

File tree

4 files changed

+127
-38
lines changed

4 files changed

+127
-38
lines changed

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ vet: ## Run go vet against code.
6464
test: manifests generate fmt vet envtest ## Run tests.
6565
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
6666

67-
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
68-
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
69-
test-e2e:
67+
# Run e2e tests against the current kubeconfig context (set USE_MINIKUBE=true to use minikube instead)
68+
# Configure e2e/.env with Command instance credentials before running
69+
.PHONY: test-e2e
70+
test-e2e: ## Run e2e tests against a Kubernetes cluster
7071
cd e2e && source .env && ./run_tests.sh
7172

7273
.PHONY: lint

e2e/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
.env
12
certs/*
23
!**/.gitkeep

e2e/README.md

Lines changed: 83 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,26 @@ The test suite does the following:
1313
This is currently configured as a Bash script, so it is necessary to run this on a UNIX-compatible machine.
1414

1515
## Requirements
16-
- An available Command instance is running and configured as described in the [root README](../README.md#configuring-command)
17-
- OAuth is used to communicate with Command
16+
17+
**Local tools:**
1818
- Docker (>= 28.2.2)
19-
- Minikube (>= v1.35.0)
2019
- kubectl (>= v1.32.2)
2120
- helm (>= v3.17.1)
2221
- cmctl (>= v2.1.1)
22+
- Minikube (>= v1.35.0) - only required if using `USE_MINIKUBE=true`
23+
24+
**Kubernetes cluster:**
25+
- By default, tests run against your current kubeconfig context
26+
- Set `USE_MINIKUBE=true` to use minikube instead
2327

24-
On the Command side:
25-
- An enrollment pattern is created called "Test Enrollment Pattern" that is has CSR Enrollment, CSR Generation, and PFX Enrollment enabled
26-
- A security role by the name of "InstanceOwner" exists and has the ability to perform Enrollment
28+
**Command instance:**
29+
- An available Command instance configured as described in the [root README](../README.md#configuring-command)
30+
- OAuth credentials for API access
31+
- An enrollment pattern (default: "Default Pattern") with CSR Enrollment enabled
32+
- A security role (default: "InstanceOwner") with Enrollment permissions
2733

2834
## Configuring the environment variables
35+
2936
command-cert-manager-issuer interacts with an external Command instance. An environment variable file `.env` can be used to store the environment variables to be used to talk to the Command instance.
3037

3138
A `.env.example` file is available as a template for your environment variables.
@@ -35,24 +42,86 @@ A `.env.example` file is available as a template for your environment variables.
3542
cp .env.example .env
3643
```
3744

38-
Modify the fields as needed.
45+
### Required variables
46+
47+
| Variable | Description |
48+
|----------|-------------|
49+
| `HOSTNAME` | Command instance hostname |
50+
| `API_PATH` | API path (default: `KeyfactorAPI`) |
51+
| `OAUTH_TOKEN_URL` | OAuth token endpoint URL |
52+
| `OAUTH_CLIENT_ID` | OAuth client ID |
53+
| `OAUTH_CLIENT_SECRET` | OAuth client secret |
54+
| `CERTIFICATE_TEMPLATE` | Certificate template short name |
55+
| `CERTIFICATE_AUTHORITY_LOGICAL_NAME` | CA logical name in Command |
56+
57+
### Optional variables
58+
59+
| Variable | Description | Default |
60+
|----------|-------------|---------|
61+
| `IMAGE_TAG` | Docker image version to test | `2.5.0` |
62+
| `HELM_CHART_VERSION` | Helm chart version | `2.5.0` |
63+
| `E2E_ENROLLMENT_PATTERN_NAME` | Enrollment pattern name | `Default Pattern` |
64+
| `E2E_OWNER_ROLE_NAME` | Owner role name | `InstanceOwner` |
65+
| `DISABLE_CA_CHECK` | Skip TLS CA verification | `false` |
66+
| `USE_MINIKUBE` | Use minikube instead of current kubeconfig | `false` |
67+
| `IMAGE_REGISTRY` | Registry to push local builds (when `IMAGE_TAG=local`) | - |
3968

4069
## Configuring the trusted certificate store
70+
4171
The issuer created in the end-to-end tests can leverage the `caSecretName` specification to determine a collection of CAs to trust in order to establish a trusted connection with the remote Keyfactor Command instance. The certificates defined in this secret will be pulled from the `certs` folder in this directory.
4272

43-
Please place the CA certificates for the Keyfactor Command instance you'd like to connect to (the intermediate and/or root CAs) under `certs` directory.
73+
Place the CA certificates for the Keyfactor Command instance you'd like to connect to (the intermediate and/or root CAs) under `certs` directory.
4474

4575
> NOTE: This check can be disabled by setting the env variable `DISABLE_CA_CHECK=true`.
4676
47-
## Running the script
77+
## Running the tests
78+
79+
### Using current kubeconfig context (default)
4880

4981
```bash
50-
# enable the script to be executed
51-
chmod +x ./run_tests.sh
82+
# Configure your .env file first
83+
source .env
5284

53-
# load the environment variables
85+
# Run the tests
86+
./run_tests.sh
87+
```
88+
89+
Or from the project root:
90+
```bash
91+
make test-e2e
92+
```
93+
94+
### Using minikube
95+
96+
```bash
97+
export USE_MINIKUBE=true
5498
source .env
99+
./run_tests.sh
100+
```
101+
102+
### Testing a specific version
103+
104+
```bash
105+
export IMAGE_TAG="2.4.0"
106+
export HELM_CHART_VERSION="2.4.0"
107+
source .env
108+
./run_tests.sh
109+
```
55110

56-
# run the end-to-end tests
111+
### Testing local changes
112+
113+
```bash
114+
# With minikube (image built directly into minikube's docker)
115+
export IMAGE_TAG="local"
116+
export HELM_CHART_VERSION="local"
117+
export USE_MINIKUBE=true
118+
source .env
57119
./run_tests.sh
58-
```
120+
121+
# With a remote cluster (requires pushing to a registry)
122+
export IMAGE_TAG="local"
123+
export HELM_CHART_VERSION="local"
124+
export IMAGE_REGISTRY="your-registry.com/your-repo"
125+
source .env
126+
./run_tests.sh
127+
```

e2e/run_tests.sh

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@
3636
## ===========================================================================
3737

3838

39-
IMAGE_REPO="keyfactor"
40-
IMAGE_NAME="command-cert-manager-issuer"
41-
# IMAGE_TAG="2.2.0-rc.9" # Uncomment if you want to use an existing image from the repository
42-
IMAGE_TAG="local" # Uncomment if you want to build the image locally
39+
# Image configuration - can be overridden via environment variables
40+
# Set IMAGE_TAG=local to build locally, or use a published version (default: 2.5.0)
41+
IMAGE_REPO="${IMAGE_REPO:-keyfactor}"
42+
IMAGE_NAME="${IMAGE_NAME:-command-cert-manager-issuer}"
43+
IMAGE_TAG="${IMAGE_TAG:-2.5.0}"
4344
FULL_IMAGE_NAME="${IMAGE_REPO}/${IMAGE_NAME}:${IMAGE_TAG}"
4445

46+
# Helm chart configuration - can be overridden via environment variables
47+
# Set HELM_CHART_VERSION=local to use the local chart, or use a published version (default: 2.5.0)
4548
HELM_CHART_NAME="command-cert-manager-issuer"
46-
# HELM_CHART_VERSION="2.1.0" # Uncomment if you want to use a specific version from the Helm repository
47-
HELM_CHART_VERSION="local" # Uncomment if you want to use the local Helm chart
49+
HELM_CHART_VERSION="${HELM_CHART_VERSION:-2.5.0}"
4850

4951
IS_LOCAL_DEPLOYMENT=$([ "$IMAGE_TAG" = "local" ] && echo "true" || echo "false")
5052
IS_LOCAL_HELM=$([ "$HELM_CHART_VERSION" = "local" ] && echo "true" || echo "false")
@@ -58,11 +60,11 @@ ISSUER_CR_NAME="issuer"
5860
ISSUER_CRD_FQTN="issuers.command-issuer.keyfactor.com"
5961
CLUSTER_ISSUER_CRD_FQTN="clusterissuers.command-issuer.keyfactor.com"
6062

61-
ENROLLMENT_PATTERN_ID=1
62-
ENROLLMENT_PATTERN_NAME="Test Enrollment Pattern"
63+
ENROLLMENT_PATTERN_ID=${E2E_ENROLLMENT_PATTERN_ID:-1}
64+
ENROLLMENT_PATTERN_NAME="${E2E_ENROLLMENT_PATTERN_NAME:-Default Pattern}"
6365

64-
OWNER_ROLE_ID=2
65-
OWNER_ROLE_NAME="InstanceOwner"
66+
OWNER_ROLE_ID=${E2E_OWNER_ROLE_ID:-2}
67+
OWNER_ROLE_NAME="${E2E_OWNER_ROLE_NAME:-InstanceOwner}"
6668

6769
CHART_PATH="./deploy/charts/command-cert-manager-issuer"
6870

@@ -854,18 +856,20 @@ cd ..
854856
echo "⚙️ Local image deployment: ${IS_LOCAL_DEPLOYMENT}"
855857
echo "⚙️ Local Helm chart: ${IS_LOCAL_HELM}"
856858

857-
if ! minikube status &> /dev/null; then
858-
echo "Error: Minikube is not running. Please start it with 'minikube start'"
859-
exit 1
859+
# Use existing kubeconfig context (set USE_MINIKUBE=true to use minikube)
860+
if [ "${USE_MINIKUBE:-false}" = "true" ]; then
861+
if ! minikube status &> /dev/null; then
862+
echo "Error: Minikube is not running. Please start it with 'minikube start'"
863+
exit 1
864+
fi
865+
kubectl config use-context minikube
866+
echo "📡 Connecting to Minikube Docker environment..."
867+
eval $(minikube docker-env)
868+
else
869+
echo "📡 Using current kubeconfig context..."
860870
fi
861-
862-
kubectl config use-context minikube
863871
echo "Connected to Kubernetes context: $(kubectl config current-context)..."
864-
865-
# 1. Connect to minikube Docker env
866-
echo "📡 Connecting to Minikube Docker environment..."
867-
eval $(minikube docker-env)
868-
echo "🚀 Starting deployment to Minikube..."
872+
echo "🚀 Starting deployment..."
869873

870874
# 2. Deploy cert-manager Helm chart if not exists
871875
echo "🔐 Checking for cert-manager installation..."
@@ -883,11 +887,25 @@ kubectl create namespace ${MANAGER_NAMESPACE} --dry-run=client -o yaml | kubectl
883887

884888
# 4. Build the command-cert-manager-issuer Docker image
885889
# This step is only needed if the image tag is "local"
886-
if "$IS_LOCAL_DEPLOYMENT" = "true"; then
890+
if [ "$IS_LOCAL_DEPLOYMENT" = "true" ]; then
891+
if [ "${USE_MINIKUBE:-false}" != "true" ]; then
892+
echo "⚠️ WARNING: Local deployment without minikube requires pushing the image to a registry."
893+
echo "⚠️ Set IMAGE_REGISTRY env var to push, or use a published IMAGE_TAG instead."
894+
fi
887895
echo "🐳 Building ${FULL_IMAGE_NAME} Docker image..."
888896
docker build -t ${FULL_IMAGE_NAME} .
889897
echo "✅ Docker image built successfully"
890898

899+
# If IMAGE_REGISTRY is set, push the image
900+
if [ -n "${IMAGE_REGISTRY:-}" ]; then
901+
REMOTE_IMAGE="${IMAGE_REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}"
902+
echo "📤 Tagging and pushing image to ${REMOTE_IMAGE}..."
903+
docker tag ${FULL_IMAGE_NAME} ${REMOTE_IMAGE}
904+
docker push ${REMOTE_IMAGE}
905+
FULL_IMAGE_NAME="${REMOTE_IMAGE}"
906+
echo "✅ Image pushed successfully"
907+
fi
908+
891909
echo "📦 Listing Docker images..."
892910
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.CreatedAt}}\t{{.Size}}" | head -5
893911
fi

0 commit comments

Comments
 (0)