This repository has been archived by the owner on Apr 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: remove openshift/generic-admission-server
- Loading branch information
Max Jonas Werner
committed
Aug 3, 2020
1 parent
31d26fe
commit ac2a764
Showing
11 changed files
with
145 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package app | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"k8s.io/client-go/rest" | ||
|
||
"github.com/spf13/cobra" | ||
"k8s.io/component-base/logs" | ||
"k8s.io/klog" | ||
"sigs.k8s.io/controller-runtime/pkg/manager" | ||
"sigs.k8s.io/controller-runtime/pkg/manager/signals" | ||
ctrwebhook "sigs.k8s.io/controller-runtime/pkg/webhook" | ||
"sigs.k8s.io/kubefed/pkg/controller/webhook/federatedtypeconfig" | ||
"sigs.k8s.io/kubefed/pkg/controller/webhook/kubefedcluster" | ||
"sigs.k8s.io/kubefed/pkg/controller/webhook/kubefedconfig" | ||
"sigs.k8s.io/kubefed/pkg/version" | ||
) | ||
|
||
const ( | ||
metricsDefaultBindAddress = ":9090" | ||
healthzDefaultBindAddress = ":8080" | ||
) | ||
|
||
var ( | ||
metricsAddr, healthzAddr string | ||
) | ||
|
||
// NewWebhookCommand creates a *cobra.Command object with default parameters | ||
func NewWebhookCommand(stopChan <-chan struct{}) *cobra.Command { | ||
verFlag := false | ||
|
||
cmd := &cobra.Command{ | ||
Use: "webhook", | ||
Short: "Start a kubefed webhook server", | ||
Long: "Start a kubefed webhook server", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Fprintf(os.Stdout, "KubeFed webhook version: %s\n", fmt.Sprintf("%#v", version.Get())) | ||
if verFlag { | ||
os.Exit(0) | ||
} | ||
// PrintFlags(cmd.Flags()) | ||
|
||
if err := Run(stopChan); err != nil { | ||
fmt.Fprintf(os.Stderr, "%v\n", err) | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
|
||
// Add the command line flags from other dependencies(klog, kubebuilder, etc.) | ||
cmd.Flags().AddGoFlagSet(flag.CommandLine) | ||
|
||
cmd.Flags().StringVar(&healthzAddr, "healthz-addr", healthzDefaultBindAddress, "The address the healthz endpoint binds to.") | ||
cmd.Flags().StringVar(&metricsAddr, "metrics-addr", metricsDefaultBindAddress, "The address the metric endpoint binds to.") | ||
cmd.Flags().BoolVar(&verFlag, "version", false, "Prints the Version info of controller-manager.") | ||
|
||
return cmd | ||
} | ||
|
||
// Run runs the webhook with options. This should never exit. | ||
func Run(stopChan <-chan struct{}) error { | ||
logs.InitLogs() | ||
defer logs.FlushLogs() | ||
|
||
config := rest.Config{} | ||
mgr, err := manager.New(&config, manager.Options{}) | ||
if err != nil { | ||
klog.Fatalf("error setting up webhook manager: %s", err) | ||
} | ||
hookServer := mgr.GetWebhookServer() | ||
|
||
hookServer.Register("/validate-federatedtypeconfigs", &ctrwebhook.Admission{Handler: &federatedtypeconfig.FederatedTypeConfigAdmissionHook{}}) | ||
hookServer.Register("/validate-kubefedcluster", &ctrwebhook.Admission{Handler: &kubefedcluster.KubeFedClusterAdmissionHook{}}) | ||
hookServer.Register("/validate-kubefedconfig", &ctrwebhook.Admission{Handler: &kubefedconfig.KubeFedConfigValidator{}}) | ||
hookServer.Register("/default-kubefedconfig", &ctrwebhook.Admission{Handler: &kubefedconfig.KubeFedConfigDefaulter{}}) | ||
|
||
if err := mgr.Start(signals.SetupSignalHandler()); err != nil { | ||
klog.Fatalf("unable to run manager: %s", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.