18
"github.com/hashicorp/go-multierror"
19
kerrors "k8s.io/apimachinery/pkg/api/errors"
20
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21
"k8s.io/apimachinery/pkg/types"
22
k8sv1 "sigs.k8s.io/gateway-api/apis/v1"
23
gateway "sigs.k8s.io/gateway-api/apis/v1beta1"
25
"istio.io/istio/pilot/pkg/model/kstatus"
26
"istio.io/istio/pkg/kube"
27
"istio.io/istio/pkg/kube/controllers"
28
"istio.io/istio/pkg/kube/kclient"
29
"istio.io/istio/pkg/util/istiomultierror"
38
type ClassController struct {
39
queue controllers.Queue
40
classes kclient.Client[*gateway.GatewayClass]
43
func NewClassController(kc kube.Client) *ClassController {
44
gc := &ClassController{}
45
gc.queue = controllers.NewQueue("gateway class",
46
controllers.WithReconciler(gc.Reconcile),
47
controllers.WithMaxAttempts(25))
49
gc.classes = kclient.New[*gateway.GatewayClass](kc)
50
gc.classes.AddEventHandler(controllers.FilteredObjectHandler(gc.queue.AddObject, func(o controllers.Object) bool {
51
_, f := builtinClasses[gateway.ObjectName(o.GetName())]
57
func (c *ClassController) Run(stop <-chan struct{}) {
59
c.queue.Add(types.NamespacedName{})
63
func (c *ClassController) Reconcile(types.NamespacedName) error {
64
err := istiomultierror.New()
65
for class := range builtinClasses {
66
err = multierror.Append(err, c.reconcileClass(class))
68
return err.ErrorOrNil()
71
func (c *ClassController) reconcileClass(class gateway.ObjectName) error {
72
if c.classes.Get(string(class), "") != nil {
73
log.Debugf("GatewayClass/%v already exists, no action", class)
76
controller := builtinClasses[class]
77
classInfo, f := classInfos[controller]
82
gc := &gateway.GatewayClass{
83
ObjectMeta: metav1.ObjectMeta{
86
Spec: gateway.GatewayClassSpec{
87
ControllerName: gateway.GatewayController(classInfo.controller),
88
Description: &classInfo.description,
91
_, err := c.classes.Create(gc)
92
if err != nil && !kerrors.IsConflict(err) {
94
} else if err != nil && kerrors.IsConflict(err) {
96
log.Infof("Attempted to create GatewayClass/%v, but it was already created", class)
105
func GetClassStatus(existing *k8sv1.GatewayClassStatus, gen int64) k8sv1.GatewayClassStatus {
107
existing = &k8sv1.GatewayClassStatus{}
109
existing.Conditions = kstatus.UpdateConditionIfChanged(existing.Conditions, metav1.Condition{
110
Type: string(k8sv1.GatewayClassConditionStatusAccepted),
111
Status: kstatus.StatusTrue,
112
ObservedGeneration: gen,
113
LastTransitionTime: metav1.Now(),
114
Reason: string(k8sv1.GatewayClassConditionStatusAccepted),
115
Message: "Handled by Istio controller",