Skip to content

Commit

Permalink
chore: isDBLess helper introduced
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Lavacca <[email protected]>
  • Loading branch information
mlavacca committed Jul 19, 2023
1 parent f25e52c commit 3bddbf2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion internal/dataplane/kong_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/kong/kubernetes-ingress-controller/v2/internal/metrics"
"github.com/kong/kubernetes-ingress-controller/v2/internal/store"
"github.com/kong/kubernetes-ingress-controller/v2/internal/util"
dataplaneutil "github.com/kong/kubernetes-ingress-controller/v2/internal/util/dataplane"
k8sobj "github.com/kong/kubernetes-ingress-controller/v2/internal/util/kubernetes/object"
"github.com/kong/kubernetes-ingress-controller/v2/internal/util/kubernetes/object/status"
)
Expand Down Expand Up @@ -391,7 +392,7 @@ func (c *KongClient) Update(ctx context.Context) error {
defer c.lock.Unlock()

// If Kong is running in dbless mode, we can fetch and store the last good configuration.
if c.dbmode == "" || c.dbmode == "off" {
if dataplaneutil.IsDBLessMode(c.dbmode) {
// Fetch the last valid configuration from the proxy only in case there is no valid
// configuration already stored in memory. This can happen when KIC restarts and there
// already is a Kong Proxy with a valid configuration loaded.
Expand Down
4 changes: 3 additions & 1 deletion internal/dataplane/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/bombsimon/logrusr/v2"
"github.com/go-logr/logr"
"github.com/sirupsen/logrus"

dataplaneutil "github.com/kong/kubernetes-ingress-controller/v2/internal/util/dataplane"
)

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -140,7 +142,7 @@ func (p *Synchronizer) IsReady() bool {
defer p.lock.RUnlock()
// If the proxy is has no database, it is only ready after a successful sync
// Otherwise, it has no configuration loaded
if p.dbMode == "off" {
if dataplaneutil.IsDBLessMode(p.dbMode) {
return p.configApplied
}
// If the proxy has a database, it is ready immediately
Expand Down
3 changes: 2 additions & 1 deletion internal/manager/config_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/kong/kubernetes-ingress-controller/v2/internal/adminapi"
cfgtypes "github.com/kong/kubernetes-ingress-controller/v2/internal/manager/config/types"
dataplaneutil "github.com/kong/kubernetes-ingress-controller/v2/internal/util/dataplane"
)

// https://github.com/kubernetes-sigs/gateway-api/blob/547122f7f55ac0464685552898c560658fb40073/apis/v1beta1/shared_types.go#L448-L463
Expand Down Expand Up @@ -131,7 +132,7 @@ func (c *Config) ValidateGatewayDiscovery(dbMode string) error {
if c.KongAdminSvc.IsAbsent() {
return nil
}
if dbMode != "off" && dbMode != "" {
if !dataplaneutil.IsDBLessMode(dbMode) {
return fmt.Errorf("gateway discovery is only supported in dbless mode, not db %s", dbMode)
}
return nil
Expand Down
3 changes: 2 additions & 1 deletion internal/manager/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/kong/kubernetes-ingress-controller/v2/internal/manager/utils/kongconfig"
"github.com/kong/kubernetes-ingress-controller/v2/internal/store"
"github.com/kong/kubernetes-ingress-controller/v2/internal/util"
dataplaneutil "github.com/kong/kubernetes-ingress-controller/v2/internal/util/dataplane"
"github.com/kong/kubernetes-ingress-controller/v2/internal/util/kubernetes/object/status"
"github.com/kong/kubernetes-ingress-controller/v2/internal/versions"
)
Expand Down Expand Up @@ -109,7 +110,7 @@ func Run(ctx context.Context, c *Config, diagnostic util.ConfigDumpDiagnostic, d

kongConfig := sendconfig.Config{
Version: kongSemVersion,
InMemory: (dbMode == "off") || (dbMode == ""),
InMemory: dataplaneutil.IsDBLessMode(dbMode),
Concurrency: c.Concurrency,
FilterTags: c.FilterTags,
SkipCACertificates: c.SkipCACertificates,
Expand Down
3 changes: 2 additions & 1 deletion internal/manager/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/kong/kubernetes-ingress-controller/v2/internal/dataplane"
"github.com/kong/kubernetes-ingress-controller/v2/internal/manager/scheme"
"github.com/kong/kubernetes-ingress-controller/v2/internal/util"
dataplaneutil "github.com/kong/kubernetes-ingress-controller/v2/internal/util/dataplane"
)

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -109,7 +110,7 @@ func leaderElectionEnabled(logger logr.Logger, c *Config, dbmode string) bool {
return true
}

if dbmode == "off" {
if dataplaneutil.IsDBLessMode(dbmode) {
if c.KongAdminSvc.IsPresent() {
logger.Info("DB-less mode detected with service detection, enabling leader election")
return true
Expand Down
6 changes: 6 additions & 0 deletions internal/util/dataplane/mode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dataplane

// IsDBLessMode can be used to detect the proxy mode (db or dbless)
func IsDBLessMode(mode string) bool {
return mode == "" || mode == "off"
}

0 comments on commit 3bddbf2

Please sign in to comment.