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

Add -enable-webhooks flag #336

Merged
merged 1 commit into from
Sep 25, 2020
Merged
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
8 changes: 5 additions & 3 deletions subcommand/controller/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controller
import (
"flag"
"fmt"
"os"
"sync"

"github.com/hashicorp/consul-k8s/api/v1alpha1"
Expand All @@ -28,6 +27,7 @@ type Command struct {
flagMetricsAddr string
flagWebhookTLSCertDir string
flagEnableLeaderElection bool
flagEnableWebhooks bool

// Flags to support Consul Enterprise namespaces.
flagEnableNamespaces bool
Expand Down Expand Up @@ -71,6 +71,8 @@ func (c *Command) init() {
"discovery across Consul namespaces. Only necessary if ACLs are enabled.")
c.flagSet.StringVar(&c.flagWebhookTLSCertDir, "webhook-tls-cert-dir", "",
"Directory that contains the TLS cert and key required for the webhook. The cert and key files must be named 'tls.crt' and 'tls.key' respectively.")
c.flagSet.BoolVar(&c.flagEnableWebhooks, "enable-webhooks", true,
"Enable webhooks. Disable when running locally since Kube API server won't be able to route to local server.")

c.httpFlags = &flags.HTTPFlags{}
flags.Merge(c.flagSet, c.httpFlags.Flags())
Expand All @@ -88,7 +90,7 @@ func (c *Command) Run(args []string) int {
c.UI.Error("Invalid arguments: should have no non-flag arguments")
return 1
}
if c.flagWebhookTLSCertDir == "" {
if c.flagEnableWebhooks && c.flagWebhookTLSCertDir == "" {
c.UI.Error("Invalid arguments: -webhook-tls-cert-dir must be set")
return 1
}
Expand Down Expand Up @@ -138,7 +140,7 @@ func (c *Command) Run(args []string) int {
return 1
}

if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if c.flagEnableWebhooks {
// This webhook server sets up a Cert Watcher on the CertDir. This watches for file changes and updates the webhook certificates
// automatically when new certificates are available.
mgr.GetWebhookServer().CertDir = c.flagWebhookTLSCertDir
Expand Down