Skip to content

Commit b1ba3bd

Browse files
committed
BUG/MINOR: gracefully handle missing RBAC for Gateway API CRDs
Update IsGatewayAPIInstalled to use standard k8s error helpers (IsForbidden and IsNotFound) when checking for the Gateway API CRD availability. Previously, if the ingress controller lacked RBAC permissions to read CustomResourceDefinitions (resulting in a 403 Forbidden error), it logged a generic error. This change explicitly intercepts the 403 error to log a clear, descriptive warning about the missing RBAC permissions. It also ensures that any error when fetching the CRD correctly flags the Gateway API as disabled by returning false, improving both readability and log clarity in environments with restricted permissions.
1 parent a1dea9c commit b1ba3bd

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

pkg/controller/global_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,26 @@ func TestGlobalCfgConvergesWithoutLogConfig(t *testing.T) {
5353
"steady-state globalCfg must not request a reload when nothing changed")
5454
}
5555

56+
// TestDefaultsCfgConvergesWithoutConfig guards the defaults path against the same
57+
// class of endless-reload bug: a steady-state sync must not request a reload.
58+
func TestDefaultsCfgConvergesWithoutConfig(t *testing.T) {
59+
c := buildGlobalTestController(t)
60+
61+
require.NoError(t, c.haproxy.APIStartTransaction())
62+
c.defaultsCfg()
63+
require.NoError(t, c.haproxy.APICommitTransaction())
64+
c.haproxy.APIDisposeTransaction()
65+
instance.Reset()
66+
67+
require.NoError(t, c.haproxy.APIStartTransaction())
68+
c.defaultsCfg()
69+
require.NoError(t, c.haproxy.APICommitTransaction())
70+
c.haproxy.APIDisposeTransaction()
71+
72+
require.False(t, instance.NeedReload(),
73+
"steady-state defaultsCfg must not request a reload when nothing changed")
74+
}
75+
5676
func buildGlobalTestController(t *testing.T) *HAProxyController {
5777
t.Helper()
5878
tempDir := t.TempDir()

pkg/k8s/main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,13 @@ func (k k8s) IsGatewayAPIInstalled(gatewayControllerName string) (installed bool
422422
installed = true
423423
gatewayCrd, err := k.crdClient.ApiextensionsV1().CustomResourceDefinitions().Get(context.Background(), "gateways.gateway.networking.k8s.io", metav1.GetOptions{})
424424
if err != nil {
425-
var errStatus *errGw.StatusError
426-
if !errors.As(err, &errStatus) || errStatus.ErrStatus.Code != 404 {
425+
// Missing CRD (404) or no RBAC to read CRDs (403) both mean Gateway API is unavailable.
426+
if errGw.IsForbidden(err) {
427+
logger.Warningf("Gateway API support disabled, missing RBAC to read CustomResourceDefinitions: %s", err)
428+
} else if !errGw.IsNotFound(err) {
427429
logger.Error(err)
428-
return false
429430
}
431+
return false
430432
}
431433

432434
if gatewayCrd.Name == "" {

0 commit comments

Comments
 (0)