Skip to content

Commit c1a562a

Browse files
syscod3claude
andcommitted
test: OCI interface + fake client + reconciler unit tests
- Extract oci.Interface so the reconciler accepts any implementation - fake.Client records every OCI call, returns configurable results — no real OCI endpoint needed in CI - 7 controller tests: finalizer, first assignment, externalIPs patch, status fields, node failover, deletion cleanup, election balance - 73% statement coverage on the controller package - fix: pre-commit golangci hook uses make lint (logcheck needs custom binary) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d245b36 commit c1a562a

6 files changed

Lines changed: 499 additions & 58 deletions

File tree

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ repos:
1818
- id: golangci-lint
1919
name: golangci-lint
2020
language: system
21-
entry: golangci-lint run --fix
21+
entry: make
22+
args: [lint]
2223
types: [go]
2324
pass_filenames: false
2425

internal/controller/pivotip_controller.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ import (
3737
)
3838

3939
const (
40-
finalizerName = "pivot.oci.io/finalizer"
41-
defaultCompartment = "" // overridden by controller flag at startup
40+
finalizerName = "pivot.oci.io/finalizer"
41+
defaultCompartment = "" // overridden by controller flag at startup
4242
)
4343

4444
// PivotIPReconciler reconciles PivotIP objects.
4545
type PivotIPReconciler struct {
4646
client.Client
47-
Scheme *runtime.Scheme
48-
OCI *ociutil.Client
49-
DefaultCompartment string
47+
Scheme *runtime.Scheme
48+
OCI ociutil.Interface
49+
DefaultCompartment string
5050
}
5151

5252
// +kubebuilder:rbac:groups=pivot.oci.io,resources=pivotips,verbs=get;list;watch;create;update;patch;delete
@@ -87,11 +87,6 @@ func (r *PivotIPReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
8787
func (r *PivotIPReconciler) reconcileNormal(ctx context.Context, pip *pivotv1alpha1.PivotIP) (ctrl.Result, error) {
8888
log := logf.FromContext(ctx)
8989

90-
compartment := pip.Spec.CompartmentID
91-
if compartment == "" {
92-
compartment = r.DefaultCompartment
93-
}
94-
9590
// Elect the best node (fewest current pivot assignments, must be Ready).
9691
elected, err := r.electNode(ctx, pip)
9792
if err != nil {
@@ -120,7 +115,6 @@ func (r *PivotIPReconciler) reconcileNormal(ctx context.Context, pip *pivotv1alp
120115
if err := r.OCI.DeletePrivateIP(ctx, privateIPOCID); err != nil {
121116
log.Error(err, "failed to delete old secondary private IP (continuing)", "ocid", privateIPOCID)
122117
}
123-
privateIPOCID = ""
124118
}
125119

126120
// Create a new secondary private IP on the elected node's VNIC.

0 commit comments

Comments
 (0)