Skip to content

Commit b6a3592

Browse files
authored
test: add full e2e tests (#83)
* feat: switch to kstatus-compatible status conditions * test: add full e2e tests * ci: add e2e workflow
1 parent 6280108 commit b6a3592

File tree

15 files changed

+811
-246
lines changed

15 files changed

+811
-246
lines changed

.github/workflows/e2e.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: E2E Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
e2e:
14+
name: E2E Tests
15+
runs-on: ubuntu-latest
16+
17+
env:
18+
KIND_CLUSTER: e2e
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Setup go
25+
uses: actions/setup-go@v5
26+
27+
- name: Setup ko
28+
uses: ko-build/[email protected]
29+
30+
- name: Setup helm
31+
uses: azure/setup-helm@v4
32+
33+
- name: Setup kind
34+
uses: helm/kind-action@v1
35+
with:
36+
cluster_name: ${{ env.KIND_CLUSTER }}
37+
38+
- name: Run E2E tests
39+
env:
40+
GTM_APP_ID: ${{ vars.GTM_APP_ID }}
41+
GTM_INSTALLATION_ID: ${{ vars.GTM_INSTALLATION_ID }}
42+
GTM_PROVIDER: file
43+
GTM_KEY: ${{ secrets.GTM_KEY }}
44+
run: |
45+
make test-e2e

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
bin/*
99
Dockerfile.cross
1010

11+
# Secrets
12+
test/e2e/values.yaml
13+
1114
# Test binary, built with `go test -c`
1215
*.test
1316

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ cleanup-test-e2e:
150150

151151
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
152152
.PHONY: test-e2e
153-
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
154-
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
153+
test-e2e: fmt vet setup-test-e2e ## Run the e2e tests. Expected an isolated environment using Kind.
154+
KUBE_CONTEXT=kind-$(KIND_CLUSTER) go test ./test/e2e/ -tags=e2e -v -ginkgo.v
155155
$(MAKE) cleanup-test-e2e
156156

157157
.PHONY: lint
@@ -213,7 +213,7 @@ build-installer: manifests generate kustomize ## Generate a consolidated YAML wi
213213
.PHONY: ko-build
214214
ko-build: ## Build the manager image using ko.
215215
KO_DOCKER_REPO=$(IMAGE_TAG_BASE) \
216-
ko build --bare --platform=$(PLATFORMS) --image-label org.opencontainers.image.source=$(IMAGE_SOURCE) --tags "latest,$(VERSION)" --push ./cmd/manager
216+
$(KO) build --bare --platform=$(PLATFORMS) --image-label org.opencontainers.image.source=$(IMAGE_SOURCE) --tags "latest,$(VERSION)" --push ./cmd/manager
217217

218218

219219
##@ Deployment
@@ -249,6 +249,7 @@ $(LOCALBIN):
249249
## Tool Binaries
250250
KUBECTL ?= kubectl
251251
KIND ?= kind
252+
KO ?= ko
252253
KUSTOMIZE ?= $(LOCALBIN)/kustomize
253254
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
254255
ENVTEST ?= $(LOCALBIN)/setup-envtest

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[![CodeQL](https://github.com/isometry/github-token-manager/actions/workflows/codeql.yaml/badge.svg)](https://github.com/isometry/github-token-manager/actions/workflows/codeql.yaml)
2+
[![E2E](https://github.com/isometry/github-token-manager/actions/workflows/e2e.yaml/badge.svg)](https://github.com/isometry/github-token-manager/actions/workflows/e2e.yaml)
23
[![Publish](https://github.com/isometry/github-token-manager/actions/workflows/publish.yaml/badge.svg)](https://github.com/isometry/github-token-manager/actions/workflows/publish.yaml)
34
[![Go Report Card](https://goreportcard.com/badge/github.com/isometry/github-token-manager)](https://goreportcard.com/report/github.com/isometry/github-token-manager)
45

@@ -158,8 +159,8 @@ More information can be found via the [Kubebuilder Documentation](https://book.k
158159
make ko-build IMG=<some-registry>/github-token-manager:tag
159160
```
160161

161-
**NOTE:** This image ought to be published in the personal registry you specified.
162-
And it is required to have access to pull the image from the working environment.
162+
**NOTE:** This image ought to be published in the personal registry you specified.
163+
And it is required to have access to pull the image from the working environment.
163164
Make sure you have the proper permission to the registry if the above commands don’t work.
164165

165166
#### Install the CRDs into the cluster:
@@ -174,7 +175,7 @@ make install
174175
make deploy IMG=<some-registry>/github-token-manager:tag
175176
```
176177

177-
> **NOTE**: If you encounter RBAC errors, you may need to grant yourself cluster-admin
178+
> **NOTE**: If you encounter RBAC errors, you may need to grant yourself cluster-admin
178179
privileges or be logged in as admin.
179180

180181
### To Uninstall

api/v1/conditions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package v1
22

33
const (
4-
// ConditionTypeAvailable represents the status of the Secret reconciliation
5-
ConditionTypeAvailable = "Available"
4+
// ConditionTypeReady is used to signal whether a reconciliation has completed successfully.
5+
ConditionTypeReady = "Ready"
66
)

go.mod

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/isometry/github-token-manager
22

3-
go 1.24.0
4-
5-
toolchain go1.24.5
3+
go 1.24.5
64

75
require (
86
github.com/go-logr/logr v1.4.3
@@ -12,10 +10,12 @@ require (
1210
github.com/onsi/gomega v1.37.0
1311
github.com/spf13/viper v1.20.1
1412
go.uber.org/automaxprocs v1.6.0
13+
golang.org/x/oauth2 v0.30.0
1514
k8s.io/api v0.33.2
1615
k8s.io/apimachinery v0.33.2
1716
k8s.io/client-go v0.33.2
1817
sigs.k8s.io/controller-runtime v0.21.0
18+
sigs.k8s.io/yaml v1.4.0
1919
)
2020

2121
require (
@@ -127,7 +127,6 @@ require (
127127
golang.org/x/crypto v0.40.0 // indirect
128128
golang.org/x/exp v0.0.0-20250606033433-dcc06ee1d476 // indirect
129129
golang.org/x/net v0.42.0 // indirect
130-
golang.org/x/oauth2 v0.30.0 // indirect
131130
golang.org/x/sync v0.16.0 // indirect
132131
golang.org/x/sys v0.34.0 // indirect
133132
golang.org/x/term v0.33.0 // indirect
@@ -154,5 +153,4 @@ require (
154153
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
155154
sigs.k8s.io/randfill v1.0.0 // indirect
156155
sigs.k8s.io/structured-merge-diff/v4 v4.7.0 // indirect
157-
sigs.k8s.io/yaml v1.4.0 // indirect
158156
)

internal/controller/clustertoken_controller.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ type ClusterTokenReconciler struct {
5555
// For more details, check Reconcile and its Result here:
5656
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
5757
func (r *ClusterTokenReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, err error) {
58-
log := log.FromContext(ctx)
58+
logger := log.FromContext(ctx)
5959

6060
if app == nil {
6161
app, err = ghapp.NewGHApp(ctx)
6262
if err != nil {
63-
log.Error(err, "failed to load GitHub App credentials")
63+
logger.Error(err, "failed to load GitHub App credentials")
6464
return ctrl.Result{RequeueAfter: time.Minute}, err
6565
}
6666
}
@@ -70,26 +70,26 @@ func (r *ClusterTokenReconciler) Reconcile(ctx context.Context, req ctrl.Request
7070
options := []tm.Option{
7171
tm.WithReconciler(r),
7272
tm.WithGHApp(app),
73-
tm.WithLogger(log),
73+
tm.WithLogger(logger),
7474
}
7575

7676
tokenSecret, err := tm.NewTokenSecret(ctx, req.NamespacedName, token, options...)
7777
if err != nil {
78-
log.Error(err, "failed to create ClusterToken reconciler")
78+
logger.Error(err, "failed to create ClusterToken reconciler")
7979
return ctrl.Result{}, err
8080
}
8181

8282
if tokenSecret == nil {
83-
log.Info("ClusterToken not found, skipping reconciliation")
83+
logger.Info("ClusterToken not found, skipping reconciliation")
8484
return ctrl.Result{}, nil
8585
}
8686

8787
result, err = tokenSecret.Reconcile()
8888
if err != nil {
89-
log.Error(err, "failed to reconcile ClusterToken")
89+
logger.Error(err, "failed to reconcile ClusterToken")
9090
return result, err
9191
}
92-
log.Info("reconciled", "requeueAfter", result.RequeueAfter)
92+
logger.Info("reconciled", "requeueAfter", result.RequeueAfter)
9393
return result, nil
9494
}
9595

internal/controller/token_controller.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ type TokenReconciler struct {
5555
// For more details, check Reconcile and its Result here:
5656
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
5757
func (r *TokenReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, err error) {
58-
log := log.FromContext(ctx)
58+
logger := log.FromContext(ctx)
5959

6060
if app == nil {
6161
app, err = ghapp.NewGHApp(ctx)
6262
if err != nil {
63-
log.Error(err, "failed to load GitHub App credentials")
63+
logger.Error(err, "failed to load GitHub App credentials")
6464
return ctrl.Result{RequeueAfter: time.Minute}, err
6565
}
6666
}
@@ -69,26 +69,26 @@ func (r *TokenReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resu
6969
options := []tm.Option{
7070
tm.WithReconciler(r),
7171
tm.WithGHApp(app),
72-
tm.WithLogger(log),
72+
tm.WithLogger(logger),
7373
}
7474

7575
tokenSecret, err := tm.NewTokenSecret(ctx, req.NamespacedName, token, options...)
7676
if err != nil {
77-
log.Error(err, "failed to create Token reconciler")
77+
logger.Error(err, "failed to create Token reconciler")
7878
return ctrl.Result{}, err
7979
}
8080

8181
if tokenSecret == nil {
82-
log.Info("Token not found, skipping reconciliation")
82+
logger.Info("Token not found, skipping reconciliation")
8383
return ctrl.Result{}, nil
8484
}
8585

8686
result, err = tokenSecret.Reconcile()
8787
if err != nil {
88-
log.Error(err, "failed to reconcile Token")
88+
logger.Error(err, "failed to reconcile Token")
8989
return result, err
9090
}
91-
log.Info("reconciled", "requeueAfter", result.RequeueAfter)
91+
logger.Info("reconciled", "requeueAfter", result.RequeueAfter)
9292
return result, nil
9393
}
9494

internal/ghapp/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (c *OperatorConfig) GetKey() string {
4141
const TokenValidity = time.Hour
4242

4343
func LoadConfig(ctx context.Context) (*OperatorConfig, error) {
44-
log := log.FromContext(ctx)
44+
logger := log.FromContext(ctx)
4545

4646
viper.AutomaticEnv()
4747
viper.SetEnvPrefix("GTM")
@@ -60,7 +60,7 @@ func LoadConfig(ctx context.Context) (*OperatorConfig, error) {
6060
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
6161
return nil, fmt.Errorf("error reading configuration file: %w", err)
6262
} else {
63-
log.Info("no configuration file found, continuing with environment variables only")
63+
logger.Info("no configuration file found, continuing with environment variables only")
6464
}
6565
}
6666

internal/ghapp/ghapp.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import (
99
)
1010

1111
func NewGHApp(ctx context.Context) (ghait.GHAIT, error) {
12-
log := log.FromContext(ctx)
12+
logger := log.FromContext(ctx)
1313

1414
cfg, err := LoadConfig(ctx)
1515
if err != nil {
1616
return nil, fmt.Errorf("configuration: %w", err)
1717
}
1818

19-
log.Info("loaded configuration", "config", cfg)
19+
logger.Info("loaded configuration", "config", cfg)
2020

2121
ghapp, err := ghait.NewGHAIT(ctx, cfg)
2222
if err != nil {

0 commit comments

Comments
 (0)