Skip to content

Commit

Permalink
fixed webhook (flyteorg#427)
Browse files Browse the repository at this point in the history
Signed-off-by: Ketan Umare <[email protected]>
  • Loading branch information
kumare3 authored Apr 13, 2022
1 parent 99acef1 commit fe1981b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
15 changes: 14 additions & 1 deletion cmd/controller/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"os"
"runtime"

"github.com/flyteorg/flytepropeller/pkg/controller/executors"
"sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/flyteorg/flytestdlib/profutils"
"github.com/flyteorg/flytestdlib/promutils"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -107,7 +110,17 @@ func executeRootCmd(baseCtx context.Context, cfg *config2.Config) error {

// Add the propeller subscope because the MetricsPrefix only has "flyte:" to get uniform collection of metrics.
propellerScope := promutils.NewScope(cfg.MetricsPrefix).NewSubScope("propeller").NewSubScope(cfg.LimitNamespace)
mgr, err := controller.CreateControllerManager(ctx, cfg, defaultNamespace, &propellerScope)
limitNamespace := ""
if cfg.LimitNamespace != defaultNamespace {
limitNamespace = cfg.LimitNamespace
}
options := manager.Options{
Namespace: limitNamespace,
SyncPeriod: &cfg.DownstreamEval.Duration,
ClientBuilder: executors.NewFallbackClientBuilder(propellerScope.NewSubScope("kube")),
}

mgr, err := controller.CreateControllerManager(ctx, cfg, options)
if err != nil {
logger.Fatalf(ctx, "Failed to create controller manager. Error: %v", err)
return err
Expand Down
29 changes: 18 additions & 11 deletions cmd/controller/cmd/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package cmd
import (
"context"

"github.com/flyteorg/flytepropeller/pkg/controller/executors"
"sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/flyteorg/flytepropeller/pkg/controller"
"github.com/flyteorg/flytestdlib/promutils"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -82,8 +85,20 @@ func runWebhook(origContext context.Context, propellerCfg *config.Config, cfg *w
// set up signals so we handle the first shutdown signal gracefully
ctx := signals.SetupSignalHandler(origContext)

propellerScope := promutils.NewScope(cfg.MetricsPrefix).NewSubScope("propeller").NewSubScope(propellerCfg.LimitNamespace)
mgr, err := controller.CreateControllerManager(ctx, propellerCfg, defaultNamespace, &propellerScope)
webhookScope := promutils.NewScope(cfg.MetricsPrefix).NewSubScope("webhook")
limitNamespace := ""
if propellerCfg.LimitNamespace != defaultNamespace {
limitNamespace = propellerCfg.LimitNamespace
}
options := manager.Options{
Namespace: limitNamespace,
SyncPeriod: &propellerCfg.DownstreamEval.Duration,
ClientBuilder: executors.NewFallbackClientBuilder(webhookScope),
CertDir: cfg.CertDir,
Port: cfg.ListenPort,
}

mgr, err := controller.CreateControllerManager(ctx, propellerCfg, options)
if err != nil {
logger.Fatalf(ctx, "Failed to create controller manager. Error: %v", err)
return err
Expand All @@ -99,15 +114,7 @@ func runWebhook(origContext context.Context, propellerCfg *config.Config, cfg *w
})

g.Go(func() error {
err := controller.StartControllerManager(childCtx, mgr)
if err != nil {
logger.Fatalf(childCtx, "Failed to start controller manager. Error: %v", err)
}
return err
})

g.Go(func() error {
err := webhook.Run(childCtx, propellerCfg, cfg, defaultNamespace, &propellerScope, mgr)
err := webhook.Run(childCtx, propellerCfg, cfg, defaultNamespace, &webhookScope, mgr)
if err != nil {
logger.Fatalf(childCtx, "Failed to start webhook. Error: %v", err)
}
Expand Down
13 changes: 2 additions & 11 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,23 +493,14 @@ func SharedInformerOptions(cfg *config.Config, defaultNamespace string) []inform
return opts
}

func CreateControllerManager(ctx context.Context, cfg *config.Config,
defaultNamespace string, scope *promutils.Scope) (*manager.Manager, error) {
func CreateControllerManager(ctx context.Context, cfg *config.Config, options manager.Options) (*manager.Manager, error) {

_, kubecfg, err := utils.GetKubeConfig(ctx, cfg)
if err != nil {
return nil, errors.Wrapf(err, "error building Kubernetes Clientset")
}

limitNamespace := ""
if cfg.LimitNamespace != defaultNamespace {
limitNamespace = cfg.LimitNamespace
}
mgr, err := manager.New(kubecfg, manager.Options{
Namespace: limitNamespace,
SyncPeriod: &cfg.DownstreamEval.Duration,
ClientBuilder: executors.NewFallbackClientBuilder((*scope).NewSubScope("kube")),
})
mgr, err := manager.New(kubecfg, options)
if err != nil {
return nil, errors.Wrapf(err, "failed to initialize controller-runtime manager")
}
Expand Down
3 changes: 3 additions & 0 deletions propeller-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,6 @@ catalog-cache:
logger:
level: 5
show-source: true
webhook:
certDir: /etc/webhook/certs
serviceName: flyte-pod-webhook

0 comments on commit fe1981b

Please sign in to comment.