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 531
feat: remove openshift/generic-admission-server #1263
Merged
k8s-ci-robot
merged 2 commits into
kubernetes-retired:master
from
makkes:makkes/rip-generic-admission-server
Aug 5, 2020
+149
−243
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,92 @@ | ||
package app | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"k8s.io/component-base/logs" | ||
"k8s.io/klog" | ||
"sigs.k8s.io/controller-runtime/pkg/healthz" | ||
"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" | ||
) | ||
|
||
var ( | ||
certDir, kubeconfig, masterURL string | ||
port = 8443 | ||
) | ||
|
||
// 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(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.") | ||
cmd.Flags().StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.") | ||
cmd.Flags().StringVar(&certDir, "cert-dir", "", "The directory where the TLS certs are located.") | ||
cmd.Flags().IntVar(&port, "secure-port", port, "The port on which to serve HTTPS.") | ||
|
||
return cmd | ||
} | ||
|
||
// Run runs the webhook with options. This should never exit. | ||
func Run(stopChan <-chan struct{}) error { | ||
logs.InitLogs() | ||
defer logs.FlushLogs() | ||
|
||
config, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfig) | ||
if err != nil { | ||
klog.Fatalf("error setting up webhook's config: %s", err) | ||
} | ||
mgr, err := manager.New(config, manager.Options{ | ||
Port: port, | ||
CertDir: certDir, | ||
}) | ||
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{}}) | ||
|
||
hookServer.WebhookMux.Handle("/readyz/", http.StripPrefix("/readyz/", &healthz.Handler{})) | ||
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding a liveness probe too to
/healthz
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer not to introduce any additional bigger changes in this PR to have a clear path to track back possible issues that might be caused by these changes. Would you agree on me adding a livenessProbe in a subsequent PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's fine.