Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Watch namespace does not fall back to operator namespace if unset #26

Merged
merged 1 commit into from
Feb 5, 2020
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
33 changes: 20 additions & 13 deletions pkg/cmd/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,37 @@ import (
"code.cloudfoundry.org/quarks-utils/pkg/config"
)

// Namespaces sets the namespaces for our operators
func Namespaces(cfg *config.Config, log *zap.SugaredLogger, name string) string {
// OperatorNamespace is the namespace of the service, which points to the webhook server
func OperatorNamespace(cfg *config.Config, log *zap.SugaredLogger, name string) string {
operatorNamespace := viper.GetString(name)
watchNamespace := viper.GetString("watch-namespace")
if watchNamespace == "" {
log.Infof("No watch namespace defined. Falling back to the operator namespace.")
watchNamespace = operatorNamespace
}

cfg.OperatorNamespace = operatorNamespace
cfg.Namespace = watchNamespace

return operatorNamespace
}

// WatchNamespace sets the namespace which is watched and where most resources are created
func WatchNamespace(cfg *config.Config, log *zap.SugaredLogger) string {
watchNamespace := viper.GetString("watch-namespace")
cfg.Namespace = watchNamespace
return watchNamespace
}

// NamespacesFlags adds to viper flags
func NamespacesFlags(pf *flag.FlagSet, argToEnv map[string]string, name string) {
pf.StringP(name, "n", "default", "The operator namespace")
pf.StringP("watch-namespace", "", "", "Namespace to watch for BOSH deployments")
// OperatorNamespaceFlags adds to viper flags
func OperatorNamespaceFlags(pf *flag.FlagSet, argToEnv map[string]string, name string) {
pf.StringP(name, "n", "default", "The operator namespace, for the webhook service")

viper.BindPFlag(name, pf.Lookup(name))
viper.BindPFlag("watch-namespace", pf.Lookup("watch-namespace"))

argToEnv[name] = envName(name)
}

// WatchNamespaceFlags adds to viper flags
func WatchNamespaceFlags(pf *flag.FlagSet, argToEnv map[string]string) {
pf.StringP("watch-namespace", "a", "staging", "Act on this namespace, watch for BOSH deployments and create resources")

viper.BindPFlag("watch-namespace", pf.Lookup("watch-namespace"))

argToEnv["watch-namespace"] = "WATCH_NAMESPACE"
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ const (

// Config controls the behaviour of different controllers
type Config struct {
CtxTimeOut time.Duration
MeltdownDuration time.Duration
MeltdownRequeueAfter time.Duration
Namespace string
CtxTimeOut time.Duration
MeltdownDuration time.Duration
MeltdownRequeueAfter time.Duration
// Namespace that is being watched by controllers
Namespace string
// OperatorNamespace is where the webhook services of the operator are placed
OperatorNamespace string
WebhookUseServiceRef bool
WebhookServerHost string
Expand Down