Skip to content

Commit 7d1bb9b

Browse files
authored
Kafkacluster controler tests (#191)
test: add basic object lifecycle tests for KafkaCluster controller Tests verify: - KafkaCluster CRs can be created successfully - KafkaCluster specs can be updated - Multiple clusters can coexist in same namespace These are true unit tests that don't require full reconciliation and don't interfere with other controller tests in the suite.
1 parent 82c378d commit 7d1bb9b

File tree

9 files changed

+866
-65
lines changed

9 files changed

+866
-65
lines changed

.github/workflows/e2e-test.yaml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ concurrency:
1111
cancel-in-progress: true
1212

1313
env:
14-
REPOSITORY: koperator_e2e_test
14+
REPOSITORY: koperator_e2e_test
1515

1616
jobs:
1717
build:
@@ -20,7 +20,7 @@ jobs:
2020
steps:
2121
- name: Checkout code
2222
uses: actions/checkout@v5
23-
23+
2424
- name: Clean workspace
2525
run: |
2626
# Remove any existing go.work files to ensure clean module resolution
@@ -35,7 +35,7 @@ jobs:
3535
uses: azure/setup-helm@v4
3636
with:
3737
version: '3.19.0'
38-
38+
3939
- name: Clean Go module cache
4040
run: |
4141
# Clean any existing Go module cache to avoid conflicts
@@ -47,13 +47,17 @@ jobs:
4747
# Ensure proper permissions
4848
chmod -R 755 ~/go/pkg/mod
4949
chmod -R 755 ~/.cache/go-build
50-
51-
# Enable Tmate Session if you'd like to Debut the E2E Kind Cluster
52-
# - name: Setup tmate session
53-
# uses: mxschmitt/action-tmate@v3
54-
# with:
55-
# detached: true
56-
50+
51+
# Enable Tmate Session to debug the E2E Kind Cluster
52+
# Only activates when re-running the workflow in debug mode
53+
- name: Setup tmate session
54+
if: ${{ runner.debug == '1' }}
55+
continue-on-error: true
56+
uses: mxschmitt/action-tmate@v3
57+
with:
58+
detached: true
59+
limit-access-to-actor: true
60+
5761
- name: Build docker image
5862
run: |
5963
IMG=$REPOSITORY:$GITHUB_SHA make docker-build
@@ -75,7 +79,7 @@ jobs:
7579
cd properties && go mod download && cd ..
7680
cd tests/e2e && go mod download && cd ../..
7781
78-
82+
7983
- name: Run E2E tests
8084
env:
8185
KUBECONFIG: ${{ steps.setup-kind.outputs.kubeconfig }}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ metadata:
8484
namespace: zookeeper
8585
spec:
8686
replicas: 1
87+
image:
88+
repository: ghcr.io/adobe/zookeeper-operator/zookeeper
89+
tag: 3.8.4-0.2.15-adobe-20250923
8790
persistence:
8891
reclaimPolicy: Delete
8992
EOF

api/v1beta1/common_types.go

Lines changed: 135 additions & 48 deletions
Large diffs are not rendered by default.

charts/kafka-operator/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ operator:
3131
# the Cert-manager's Custom Resource Namespace must be included in the comma separated list.
3232
# When it is empty, all namespaces will be watched.
3333
# -- List of namespaces where Operator watches for custom resources.<br><br>**Note** that the operator still requires to read the cluster-scoped `Node` labels to configure `rack awareness`. Make sure the operator ServiceAccount is granted `get` permissions on this `Node` resource when using limited RBACs.
34-
namespaces: ""
34+
namespaces: "kafka, cert-manager"
3535
# -- Enable verbose logging
3636
verboseLogging: false
3737
# -- Enable development logging

controllers/kafkacluster_controller.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ func (r *KafkaClusterReconciler) Reconcile(ctx context.Context, request ctrl.Req
194194
if err := k8sutil.UpdateRollingUpgradeState(r.Client, instance, time.Now(), log); err != nil {
195195
return requeueWithError(log, err.Error(), err)
196196
}
197+
// Don't transition to Running state while rolling upgrade is in progress
198+
// The state will be updated to Running by the kafka reconciler when the upgrade completes
199+
log.Info("Rolling upgrade in progress, keeping current state")
200+
return reconciled()
197201
}
198202

199203
if err := k8sutil.UpdateCRStatus(r.Client, instance, v1beta1.KafkaClusterRunning, log); err != nil {
@@ -300,16 +304,15 @@ func (r *KafkaClusterReconciler) checkFinalizers(ctx context.Context, cluster *v
300304
// user finalizations are done before it does its final cleanup
301305
log.Info("Tearing down any PKI resources for the kafkacluster")
302306
if err = pki.GetPKIManager(r.Client, cluster, v1beta1.PKIBackendProvided).FinalizePKI(ctx); err != nil {
303-
switch err.(type) {
304-
case errorfactory.ResourceNotReady:
307+
// Use errors.As for consistency with the rest of the controller
308+
if errors.As(err, &errorfactory.ResourceNotReady{}) {
305309
log.Info("The PKI is not ready to be torn down")
306310
return ctrl.Result{
307311
Requeue: true,
308312
RequeueAfter: time.Duration(5) * time.Second,
309313
}, nil
310-
default:
311-
return requeueWithError(log, "failed to finalize PKI", err)
312314
}
315+
return requeueWithError(log, "failed to finalize PKI", err)
313316
}
314317
}
315318

@@ -356,6 +359,7 @@ func (r *KafkaClusterReconciler) updateAndFetchLatest(ctx context.Context, clust
356359
if err != nil {
357360
return nil, err
358361
}
362+
359363
cluster.TypeMeta = typeMeta
360364
return cluster, nil
361365
}

0 commit comments

Comments
 (0)