Skip to content

Commit 9016641

Browse files
committed
check gateway class and do not skip listeners when gateway class is not managed by KIC
1 parent 5eea70b commit 9016641

File tree

10 files changed

+63
-9
lines changed

10 files changed

+63
-9
lines changed

hack/generators/cache-stores/spec.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ var supportedTypes = []cacheStoreSupportedType{
6060
Type: "Gateway",
6161
Package: "gatewayapi",
6262
},
63+
{
64+
Type: "GatewayClass",
65+
Package: "gatewayapi",
66+
KeyFunc: clusterWideKeyFunc,
67+
},
6368
{
6469
Type: "BackendTLSPolicy",
6570
Package: "gatewayapi",

internal/controllers/gateway/gateway_controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ func (r *GatewayReconciler) gatewayHasMatchingGatewayClass(obj client.Object) bo
181181
r.Log.Error(err, "Could not retrieve gatewayclass", "gatewayclass", gateway.Spec.GatewayClassName)
182182
return false
183183
}
184+
184185
return isGatewayClassControlled(gatewayClass)
185186
}
186187

@@ -440,6 +441,11 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
440441
debug(log, gateway, "Ensured gateway was removed from the data-plane (if ever present)")
441442
return ctrl.Result{}, nil
442443
}
444+
err := r.DataplaneClient.UpdateObject(gwc)
445+
if err != nil {
446+
debug(log, gwc, "Failed to update GatewayClass in dataplane, requeueing")
447+
return ctrl.Result{}, err
448+
}
443449

444450
// if there's any deletion timestamp on the object, we can simply ignore it. At this point
445451
// with unmanaged mode being the only option supported there are no finalizers and

internal/dataplane/fallback/graph_dependencies.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func ResolveDependencies(cache store.CacheStores, obj client.Object) ([]client.O
6262
*discoveryv1.EndpointSlice,
6363
*gatewayapi.ReferenceGrant,
6464
*gatewayapi.Gateway,
65+
*gatewayapi.GatewayClass,
6566
*gatewayapi.BackendTLSPolicy,
6667
*configurationv1.KongIngress,
6768
*configurationv1beta1.KongUpstreamPolicy,

internal/dataplane/translator/translate_certs.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/go-logr/logr"
1111
"github.com/kong/go-kong/kong"
12+
"github.com/samber/lo"
1213
corev1 "k8s.io/api/core/v1"
1314
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1415

@@ -55,11 +56,16 @@ func (t *Translator) getGatewayCerts() []certWrapper {
5556
return certs
5657
}
5758
for _, gateway := range gateways {
58-
statuses := make(map[gatewayapi.SectionName]gatewayapi.ListenerStatus, len(gateway.Status.Listeners))
59-
for _, status := range gateway.Status.Listeners {
60-
statuses[status.Name] = status
59+
gwc, err := s.GetGatewayClass(string(gateway.Spec.GatewayClassName))
60+
if err != nil {
61+
logger.Error(err, "Failed to get GatewayClass for Gateway, skipping", "gateway", gateway.Name, "gateway_class", gateway.Spec.GatewayClassName)
62+
continue
6163
}
6264

65+
statuses := lo.SliceToMap(gateway.Status.Listeners, func(status gatewayapi.ListenerStatus) (gatewayapi.SectionName, gatewayapi.ListenerStatus) {
66+
return status.Name, status
67+
})
68+
6369
for _, listener := range gateway.Spec.Listeners {
6470
status, ok := statuses[listener.Name]
6571
if !ok {
@@ -72,8 +78,8 @@ func (t *Translator) getGatewayCerts() []certWrapper {
7278
continue
7379
}
7480

75-
// Check if listener is marked as programmed
76-
if !util.CheckCondition(
81+
// Check if listener is marked as programmed when the gateway is fully managed by KIC.
82+
if gwc.Spec.ControllerName == gatewayapi.GatewayController(t.gatewayControllerName) && !util.CheckCondition(
7783
status.Conditions,
7884
util.ConditionType(gatewayapi.ListenerConditionProgrammed),
7985
util.ConditionReason(gatewayapi.ListenerReasonProgrammed),

internal/dataplane/translator/translator.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ type Translator struct {
109109
failuresCollector *failures.ResourceFailuresCollector
110110
translatedObjectsCollector *ObjectsCollector
111111

112-
clusterDomain string
113-
enableDrainSupport bool
112+
clusterDomain string
113+
enableDrainSupport bool
114+
gatewayControllerName string
114115
}
115116

116117
// Config is a configuration for the Translator.
@@ -120,6 +121,10 @@ type Config struct {
120121

121122
// ClusterDomain is the cluster domain used for translating Kubernetes objects.
122123
ClusterDomain string
124+
125+
// GatewayControllerName is the gateway controller name used by KIC.
126+
// GatewayClasses with this controller name in spec.ControllerName are managed by KIC, otherwise they are managed by other components(like Kong Operator).
127+
GatewayControllerName string
123128
}
124129

125130
// NewTranslator produces a new Translator object provided a logging mechanism
@@ -152,6 +157,7 @@ func NewTranslator(
152157
translatedObjectsCollector: translatedObjectsCollector,
153158
clusterDomain: config.ClusterDomain,
154159
enableDrainSupport: config.EnableDrainSupport,
160+
gatewayControllerName: config.GatewayControllerName,
155161
}, nil
156162
}
157163

internal/manager/run.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,9 @@ func New(
221221

222222
configTranslator, err := translator.NewTranslator(logger, storer, c.KongWorkspace, kongSemVersion, translatorFeatureFlags, NewSchemaServiceGetter(clientsManager),
223223
translator.Config{
224-
ClusterDomain: c.ClusterDomain,
225-
EnableDrainSupport: c.EnableDrainSupport,
224+
ClusterDomain: c.ClusterDomain,
225+
EnableDrainSupport: c.EnableDrainSupport,
226+
GatewayControllerName: c.GatewayAPIControllerName,
226227
},
227228
)
228229
if err != nil {

internal/store/fake_store.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type FakeObjects struct {
4141
GRPCRoutes []*gatewayapi.GRPCRoute
4242
ReferenceGrants []*gatewayapi.ReferenceGrant
4343
Gateways []*gatewayapi.Gateway
44+
GatewayClasses []*gatewayapi.GatewayClass
4445
BackendTLSPolicies []*gatewayapi.BackendTLSPolicy
4546
TCPIngresses []*configurationv1beta1.TCPIngress
4647
UDPIngresses []*configurationv1beta1.UDPIngress

internal/store/store.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ type Storer interface {
9999

100100
// Gateway API resources.
101101
GetGateway(namespace string, name string) (*gatewayapi.Gateway, error)
102+
GetGatewayClass(name string) (*gatewayapi.GatewayClass, error)
102103
ListHTTPRoutes() ([]*gatewayapi.HTTPRoute, error)
103104
ListUDPRoutes() ([]*gatewayapi.UDPRoute, error)
104105
ListTCPRoutes() ([]*gatewayapi.TCPRoute, error)
@@ -607,6 +608,18 @@ func (s Store) GetGateway(namespace string, name string) (*gatewayapi.Gateway, e
607608
return obj.(*gatewayapi.Gateway), nil
608609
}
609610

611+
// GetGatewayClass returns gatewayclass resource having the specified name.
612+
func (s Store) GetGatewayClass(name string) (*gatewayapi.GatewayClass, error) {
613+
obj, exists, err := s.stores.GatewayClass.GetByKey(name)
614+
if err != nil {
615+
return nil, err
616+
}
617+
if !exists {
618+
return nil, NotFoundError{fmt.Sprintf("GatewayClass %v not found", name)}
619+
}
620+
return obj.(*gatewayapi.GatewayClass), nil
621+
}
622+
610623
// GetKongVault returns kongvault resource having specified name.
611624
func (s Store) GetKongVault(name string) (*configurationv1alpha1.KongVault, error) {
612625
p, exists, err := s.stores.KongVault.GetByKey(name)

internal/store/zz_generated.cache_stores.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/store/zz_generated.cache_stores_test.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)