Skip to content

Commit

Permalink
add type for OptionalNamespacedName
Browse files Browse the repository at this point in the history
  • Loading branch information
czeslavo committed Feb 27, 2023
1 parent 07e3177 commit 5c46810
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
12 changes: 7 additions & 5 deletions internal/manager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (
"github.com/kong/kubernetes-ingress-controller/v2/internal/manager/featuregates"
)

// Type override to be used with types.NamespacedName variables to override their type name printed in the help text.
var nnTypeNameOverride = WithTypeNameOverride[mo.Option[types.NamespacedName]]("namespacedName")
type OptionalNamespacedName = mo.Option[types.NamespacedName]

// Type override to be used with OptionalNamespacedName variables to override their type name printed in the help text.
var nnTypeNameOverride = WithTypeNameOverride[OptionalNamespacedName]("namespacedName")

// -----------------------------------------------------------------------------
// Controller Manager - Config
Expand Down Expand Up @@ -56,7 +58,7 @@ type Config struct {
MetricsAddr string
ProbeAddr string
KongAdminURLs []string
KongAdminSvc mo.Option[types.NamespacedName]
KongAdminSvc OptionalNamespacedName
KondAdminSvcPortNames []string
ProxySyncSeconds float32
ProxyTimeoutSeconds float32
Expand All @@ -72,8 +74,8 @@ type Config struct {
GatewayAPIControllerName string

// Ingress status
PublishServiceUDP mo.Option[types.NamespacedName]
PublishService mo.Option[types.NamespacedName]
PublishServiceUDP OptionalNamespacedName
PublishService OptionalNamespacedName
PublishStatusAddress []string
PublishStatusAddressUDP []string
UpdateStatus bool
Expand Down
8 changes: 4 additions & 4 deletions internal/manager/config_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ import (
// *FromFlagValue functions are used to validate single flag values and set those in Config.
// They're meant to be used together with ValidatedValue[T] type.

func namespacedNameFromFlagValue(flagValue string) (mo.Option[types.NamespacedName], error) {
func namespacedNameFromFlagValue(flagValue string) (OptionalNamespacedName, error) {
parts := strings.SplitN(flagValue, "/", 3)
if len(parts) != 2 {
return mo.Option[types.NamespacedName]{}, errors.New("the expected format is namespace/name")
return OptionalNamespacedName{}, errors.New("the expected format is namespace/name")
}
if parts[0] == "" {
return mo.Option[types.NamespacedName]{}, errors.New("namespace cannot be empty")
return OptionalNamespacedName{}, errors.New("namespace cannot be empty")
}
if parts[1] == "" {
return mo.Option[types.NamespacedName]{}, errors.New("name cannot be empty")
return OptionalNamespacedName{}, errors.New("name cannot be empty")
}

return mo.Some(types.NamespacedName{
Expand Down
2 changes: 1 addition & 1 deletion internal/manager/config_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func TestConfigValidate(t *testing.T) {

t.Run("enabled with no gateway service discovery enabled", func(t *testing.T) {
c := validEnabled()
c.KongAdminSvc = mo.Option[types.NamespacedName]{}
c.KongAdminSvc = manager.OptionalNamespacedName{}
require.ErrorContains(t, c.Validate(), "--kong-admin-svc has to be set when using --konnect-sync-enabled")
})
})
Expand Down
3 changes: 1 addition & 2 deletions internal/manager/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/bombsimon/logrusr/v2"
"github.com/go-logr/logr"
"github.com/kong/deck/cprint"
"github.com/samber/mo"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -211,7 +210,7 @@ func setupDataplaneAddressFinder(mgrc client.Client, c *Config, log logr.Logger)
return defaultAddressFinder, udpAddressFinder, nil
}

func buildDataplaneAddressFinder(mgrc client.Client, publishStatusAddress []string, publishServiceNN mo.Option[types.NamespacedName]) (*dataplane.AddressFinder, error) {
func buildDataplaneAddressFinder(mgrc client.Client, publishStatusAddress []string, publishServiceNN OptionalNamespacedName) (*dataplane.AddressFinder, error) {
addressFinder := dataplane.NewAddressFinder()

if len(publishStatusAddress) > 0 {
Expand Down

0 comments on commit 5c46810

Please sign in to comment.