Skip to content

Commit

Permalink
Add versions and wait for k8s to be available on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
dramich committed Jun 21, 2021
1 parent 4d68112 commit 9e95240
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,32 @@ package main

import (
"context"
"fmt"
"os"

"github.com/rancher/webhook/pkg/server"
_ "github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io"
"github.com/rancher/wrangler/pkg/k8scheck"
"github.com/rancher/wrangler/pkg/kubeconfig"
"github.com/rancher/wrangler/pkg/ratelimit"
"github.com/rancher/wrangler/pkg/signals"
"github.com/sirupsen/logrus"
)

var (
Version = "dev"
GitCommit = "HEAD"
)

func main() {
if err := run(); err != nil {
logrus.Fatal(err)
}
}

func run() error {
logrus.Infof("Rancher-webhook version %s is starting", fmt.Sprintf("%s (%s)", Version, GitCommit))

cfg, err := kubeconfig.GetNonInteractiveClientConfig(os.Getenv("KUBECONFIG")).ClientConfig()
if err != nil {
return err
Expand All @@ -29,6 +38,12 @@ func run() error {
cfg.RateLimiter = ratelimit.None

ctx := signals.SetupSignalHandler(context.Background())

err = k8scheck.Wait(ctx, *cfg)
if err != nil {
return err
}

if err := server.ListenAndServe(ctx, cfg, os.Getenv("ENABLE_CAPI") == "true", os.Getenv("ENABLE_MCM") != "false"); err != nil {
return err
}
Expand Down
12 changes: 8 additions & 4 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ import (
"k8s.io/client-go/rest"
)

const (
namespace = "cattle-system"
tlsName = "rancher-webhook.cattle-system.svc"
certName = "cattle-webhook-tls"
caName = "cattle-webhook-ca"
)

var (
namespace = "cattle-system"
tlsName = "rancher-webhook.cattle-system.svc"
certName = "cattle-webhook-tls"
caName = "cattle-webhook-ca"
// These have to remain as vars since we need the address below
port = int32(443)
validationPath = "/v1/webhook/validation"
mutationPath = "/v1/webhook/mutation"
Expand Down

0 comments on commit 9e95240

Please sign in to comment.