Skip to content

Latest commit

 

History

History
118 lines (96 loc) · 3.34 KB

File metadata and controls

118 lines (96 loc) · 3.34 KB

GatewayClass Controller Implementation Summary

Overview

Implementation of a simple Kubernetes controller for Gateway API's GatewayClass resource in OKE environment. This initial implementation will focus solely on watching GatewayClass resources and logging events.

Dependencies

require (
    sigs.k8s.io/controller-runtime v0.20.4
    sigs.k8s.io/gateway-api v1.2.1
    k8s.io/client-go v0.32.3
)

Code Structure

/internal/app/
  gatewayclass_controller.go    # Main controller implementation
  gatewayclass_controller_test.go

Implementation Details

1. Dependencies

// k8sClient defines the interface for Kubernetes client operations
// This is an internal interface used only to describe what we need from the client
type k8sClient interface {
    Get(ctx context.Context, key client.ObjectKey, obj client.Object) error
    List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
}

2. Controller Implementation (Struct)

// GatewayClassController is a simple controller that watches GatewayClass resources
type GatewayClassController struct {
    client k8sClient
    logger *slog.Logger
}

// GatewayClassControllerDeps contains the dependencies for the GatewayClassController
type GatewayClassControllerDeps struct {
    dig.In

    RootLogger *slog.Logger
    K8sClient  k8sClient
}

// NewGatewayClassController creates a new GatewayClassController
func NewGatewayClassController(deps GatewayClassControllerDeps) *GatewayClassController {
    return &GatewayClassController{
        client: deps.K8sClient,
        logger: deps.RootLogger,
    }
}

// Reconcile implements the reconcile.Reconciler interface
func (r *GatewayClassController) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) {
    var gatewayClass gatewayv1.GatewayClass
    if err := r.client.Get(ctx, req.NamespacedName, &gatewayClass); err != nil {
        return reconcile.Result{}, client.IgnoreNotFound(err)
    }

    r.logger.Info("Reconciling GatewayClass",
        "name", gatewayClass.Name,
        "controller", gatewayClass.Spec.ControllerName,
    )

    // For now, we just log the reconciliation and do nothing
    return reconcile.Result{}, nil
}

3. Integration Points

  • Dependency injection via dig
  • Configuration via viper
  • Logging via slog
  • Graceful shutdown coordination

Testing Strategy

1. Unit Tests

  • Mock client interactions
  • Test reconciliation logic
  • Test error handling

2. Integration Tests

  • Use envtest for Kubernetes API testing

Implementation Phases

  1. Phase 1: Basic Structure

    • Set up project structure
    • Add dependencies
    • Create basic controller struct
  2. Phase 2: Core Implementation

    • Add basic reconciliation logic (just logging)
    • Set up logging
  3. Phase 3: Integration

    • Integrate with HTTP server
    • Add configuration
    • Implement graceful shutdown
  4. Phase 4: Testing

    • Add unit tests
    • Add integration tests
    • Test coverage requirements

Notes

  • Controller name: oracle.com/oke-gateway-controller
  • Initial implementation focuses solely on watching GatewayClass resources
  • No status updates or complex logic in first version
  • Error handling follows project patterns
  • Following "interface in struct out" pattern for better testability
  • Using dig for dependency injection with struct-based deps