Skip to content

Added namespaced to kubernetes.go #965

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,19 @@ func cmdKubernetes(
logger log.Logger,
metricsAddr string,
_, genericRules, disableWebhooks bool,
namespaced bool,
certFile, privateKeyFile string,
) int {
setupLog := ctrl.Log.WithName("setup")
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))

webhookServer := webhook.NewServer(webhook.Options{Port: 9443})

var namespace string
if namespaced {
namespace = os.Getenv("POD_NAMESPACE")
} else {
namespace = ""
}
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Metrics: metricsserver.Options{
Expand All @@ -77,6 +83,7 @@ func cmdKubernetes(
WebhookServer: webhookServer,
LeaderElection: false,
LeaderElectionID: "9d76195a.pyrra.dev",
Namespace: namespace,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ var CLI struct {
ConfigMapMode bool `default:"false" help:"If the generated recording rules should instead be saved to config maps in the default Prometheus format."`
GenericRules bool `default:"false" help:"Enabled generic recording rules generation to make it easier for tools like Grafana."`
DisableWebhooks bool `default:"true" env:"DISABLE_WEBHOOKS" help:"Disable webhooks so the controller doesn't try to read certificates"`
Namespaced bool `default:"false" help:"Set the controller to namespaced context instead of cluster."`
TLSCertFile string `default:"" help:"File containing the default x509 Certificate for HTTPS."`
TLSPrivateKeyFile string `default:"" help:"File containing the default x509 private key matching --tls-cert-file."`
} `cmd:"" help:"Runs Pyrra's Kubernetes operator and backend for the API."`
Expand Down Expand Up @@ -175,6 +176,7 @@ func main() {
CLI.Kubernetes.ConfigMapMode,
CLI.Kubernetes.GenericRules,
CLI.Kubernetes.DisableWebhooks,
CLI.Kubernetes.Namespaced,
CLI.Kubernetes.TLSCertFile,
CLI.Kubernetes.TLSPrivateKeyFile,
)
Expand Down