Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gateway_discovery): allow gateway discovery only in dbless mode #3642

Merged
merged 3 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@ Adding a new version? You'll need three changes:
[#3469](https://github.com/Kong/kubernetes-ingress-controller/pull/3469)
- Added Gateway discovery using Kong Admin API service configured via `--kong-admin-svc`
which accepts a namespaced name of a headless service which should have
Admin API endpoints exposed under a named port called `admin`.
Admin API endpoints exposed under a named port called `admin`. Gateway
discovery is only allowed to run with dbless kong gateways, because it is
unnecessary to run gateway discovery with DB-backed kong gateways
randmonkey marked this conversation as resolved.
Show resolved Hide resolved
[#3421](https://github.com/Kong/kubernetes-ingress-controller/pull/3421)
[#3642](https://github.com/Kong/kubernetes-ingress-controller/pull/3642)
- Added configurable port names for Gateway discovery through
`--kong-admin-svc-port-names`. This flag accepts a list of port names that
Admin API service ports will be matched against.
Expand Down Expand Up @@ -149,7 +152,7 @@ Adding a new version? You'll need three changes:
for the controller and the proxy. This enables the proxy to be scaled independently
of the controller. The old `all-in-one-dbless.yaml` manifest has been deprecated and
renamed to `all-in-one-dbless-legacy.yaml`. It will be removed in a future release.
[#3692](https://github.com/Kong/kubernetes-ingress-controller/pull/3629)
[#3629](https://github.com/Kong/kubernetes-ingress-controller/pull/3629)

### Fixed

Expand Down
13 changes: 13 additions & 0 deletions internal/manager/config_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,16 @@ func validateClientTLS(clientTLS adminapi.TLSClientConfig) error {

return nil
}

// ValidateGatewayDiscovery returns error if dbMode is not configured to db-less mode.
// gateway discovery is only supported in db-less mode in its initial release:
// https://github.com/Kong/kubernetes-ingress-controller/issues/3401
func (c *Config) ValidateGatewayDiscovery(dbMode string) error {
if c.KongAdminSvc.IsAbsent() {
return nil
}
if dbMode != "off" && dbMode != "" {
return fmt.Errorf("gateway discovery is only supported in dbless mode, not db %s", dbMode)
}
return nil
}
50 changes: 50 additions & 0 deletions internal/manager/config_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,53 @@ func TestConfigValidate(t *testing.T) {
})
})
}

func TestConfigValidateGatewayDiscovery(t *testing.T) {
testCases := []struct {
name string
gatewayDiscovery bool
dbMode string
expectError bool
}{
{
name: "gateway discovery disabled should pass in db-less mode",
gatewayDiscovery: false,
dbMode: "off",
expectError: false,
},
{
name: "gateway discovery disabled should pass in db-backed mode",
gatewayDiscovery: false,
dbMode: "postgres",
expectError: false,
},
{
name: "gateway discovery enabled should pass in db-less mode",
gatewayDiscovery: true,
dbMode: "",
expectError: false,
},
{
name: "gateway discovery enabled should not pass in db-backed mode",
gatewayDiscovery: true,
dbMode: "postgres",
expectError: true,
},
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
c := &manager.Config{}
if tc.gatewayDiscovery {
c.KongAdminSvc = mo.Some(types.NamespacedName{Name: "admin-svc", Namespace: "ns"})
}
err := c.ValidateGatewayDiscovery(tc.dbMode)
if !tc.expectError {
require.NoError(t, err)
} else {
require.Error(t, err)
}
})
}
}
6 changes: 6 additions & 0 deletions internal/manager/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ func Run(ctx context.Context, c *Config, diagnostic util.ConfigDumpDiagnostic, d
if err != nil {
return fmt.Errorf("could not validate Kong admin root(s) configuration: %w", err)
}

err = c.ValidateGatewayDiscovery(dbMode)
if err != nil {
return err
}

semV := semver.Version{Major: v.Major(), Minor: v.Minor(), Patch: v.Patch()}
versions.SetKongVersion(semV)

Expand Down