-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
gatewayclass_reconcile.go
55 lines (45 loc) · 1.8 KB
/
gatewayclass_reconcile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package gateway_api
import (
"context"
"github.com/sirupsen/logrus"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
ctrl "sigs.k8s.io/controller-runtime"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
"github.com/cilium/cilium/pkg/logging/logfields"
)
// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.12.2/pkg/reconcile
func (r *gatewayClassReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
scopedLog := log.WithContext(ctx).WithFields(logrus.Fields{
logfields.Controller: "gatewayclass",
logfields.Resource: req.NamespacedName,
})
scopedLog.Info("Reconciling GatewayClass")
gwc := &gatewayv1beta1.GatewayClass{}
if err := r.Client.Get(ctx, req.NamespacedName, gwc); err != nil {
if k8serrors.IsNotFound(err) {
return success()
}
return fail(err)
}
// Ignore deleted GatewayClass, this can happen when foregroundDeletion is enabled
// The reconciliation loop will automatically kick off for related Gateway resources.
if gwc.GetDeletionTimestamp() != nil {
return success()
}
// TODO(tam): Support spec.ParametersRef later for different use cases
// Right now, we will still support multiple gateway class, but no support for parameters.
// Hence, just set gateway class Accepted condition to true blindly.
setGatewayClassAccepted(gwc, true)
if err := r.Client.Status().Update(ctx, gwc); err != nil {
scopedLog.WithError(err).Error("Failed to update GatewayClass status")
return fail(err)
}
scopedLog.Info("Successfully reconciled GatewayClass")
return success()
}