github.com/cilium/cilium@v1.16.2/operator/pkg/gateway-api/gatewayclass_reconcile.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package gateway_api
     5  
     6  import (
     7  	"context"
     8  
     9  	"github.com/sirupsen/logrus"
    10  	k8serrors "k8s.io/apimachinery/pkg/api/errors"
    11  	ctrl "sigs.k8s.io/controller-runtime"
    12  	gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
    13  
    14  	controllerruntime "github.com/cilium/cilium/operator/pkg/controller-runtime"
    15  	"github.com/cilium/cilium/pkg/logging/logfields"
    16  )
    17  
    18  // Reconcile is part of the main kubernetes reconciliation loop which aims to
    19  // move the current state of the cluster closer to the desired state.
    20  //
    21  // For more details, check Reconcile and its Result here:
    22  // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.12.2/pkg/reconcile
    23  func (r *gatewayClassReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
    24  	scopedLog := log.WithContext(ctx).WithFields(logrus.Fields{
    25  		logfields.Controller: "gatewayclass",
    26  		logfields.Resource:   req.NamespacedName,
    27  	})
    28  
    29  	scopedLog.Info("Reconciling GatewayClass")
    30  	gwc := &gatewayv1.GatewayClass{}
    31  	if err := r.Client.Get(ctx, req.NamespacedName, gwc); err != nil {
    32  		if k8serrors.IsNotFound(err) {
    33  			return controllerruntime.Success()
    34  		}
    35  		return controllerruntime.Fail(err)
    36  	}
    37  
    38  	// Ignore deleted GatewayClass, this can happen when foregroundDeletion is enabled
    39  	// The reconciliation loop will automatically kick off for related Gateway resources.
    40  	if gwc.GetDeletionTimestamp() != nil {
    41  		return controllerruntime.Success()
    42  	}
    43  
    44  	// TODO(tam): Support spec.ParametersRef later for different use cases
    45  	// Right now, we will still support multiple gateway class, but no support for parameters.
    46  	// Hence, just set gateway class Accepted condition to true blindly.
    47  	setGatewayClassAccepted(gwc, true)
    48  
    49  	// List of features supported by Cilium.
    50  	// The same is used in GHA CI .github/workflows/conformance-gateway-api.yaml
    51  	gwc.Status.SupportedFeatures = []gatewayv1.SupportedFeature{
    52  		"Gateway",
    53  		//"GatewayPort8080",
    54  		//"GatewayStaticAddresses",
    55  		"HTTPRoute",
    56  		"HTTPRouteDestinationPortMatching",
    57  		"HTTPRouteHostRewrite",
    58  		"HTTPRouteMethodMatching",
    59  		"HTTPRoutePathRedirect",
    60  		"HTTPRoutePathRewrite",
    61  		"HTTPRoutePortRedirect",
    62  		"HTTPRouteQueryParamMatching",
    63  		"HTTPRouteRequestMirror",
    64  		"HTTPRouteRequestMultipleMirrors",
    65  		"HTTPRouteResponseHeaderModification",
    66  		"HTTPRouteSchemeRedirect",
    67  		//"Mesh",
    68  		"ReferenceGrant",
    69  		"TLSRoute",
    70  	}
    71  
    72  	if err := r.Client.Status().Update(ctx, gwc); err != nil {
    73  		scopedLog.WithError(err).Error("Failed to update GatewayClass status")
    74  		return controllerruntime.Fail(err)
    75  	}
    76  	scopedLog.Info("Successfully reconciled GatewayClass")
    77  	return controllerruntime.Success()
    78  }