Files
open-cluster-management/pkg/cmd/webhook/webhook.go
DangPeng Liu b8a1f9d676 set default in webhook (#205)
Signed-off-by: ldpliu <daliu@redhat.com>
2022-03-02 11:06:28 -05:00

48 lines
1.3 KiB
Go

package webhook
import (
"os"
admissionserver "github.com/openshift/generic-admission-server/pkg/cmd/server"
"github.com/spf13/cobra"
genericapiserver "k8s.io/apiserver/pkg/server"
"open-cluster-management.io/registration/pkg/features"
clusterwebhook "open-cluster-management.io/registration/pkg/webhook/cluster"
clustersetbindingwebhook "open-cluster-management.io/registration/pkg/webhook/clustersetbinding"
)
func NewAdmissionHook() *cobra.Command {
o := admissionserver.NewAdmissionServerOptions(
os.Stdout,
os.Stderr,
&clusterwebhook.ManagedClusterValidatingAdmissionHook{},
&clusterwebhook.ManagedClusterMutatingAdmissionHook{},
&clustersetbindingwebhook.ManagedClusterSetBindingValidatingAdmissionHook{})
cmd := &cobra.Command{
Use: "webhook",
Short: "Start Managed Cluster Admission Server",
RunE: func(c *cobra.Command, args []string) error {
stopCh := genericapiserver.SetupSignalHandler()
if err := o.Complete(); err != nil {
return err
}
if err := o.Validate(args); err != nil {
return err
}
if err := o.RunAdmissionServer(stopCh); err != nil {
return err
}
return nil
},
}
o.RecommendedOptions.AddFlags(cmd.Flags())
flags := cmd.Flags()
features.DefaultHubMutableFeatureGate.AddFlag(flags)
return cmd
}