Skip to content

Commit b39071b

Browse files
committed
Add webhook singleton command
Signed-off-by: Jian Qiu <[email protected]>
1 parent aad0848 commit b39071b

File tree

5 files changed

+62
-2
lines changed

5 files changed

+62
-2
lines changed

cmd/registration-operator/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func newNucleusCommand() *cobra.Command {
4848

4949
cmd.AddCommand(hub.NewHubOperatorCmd())
5050
cmd.AddCommand(hub.NewHubManagerCmd())
51+
cmd.AddCommand(hub.NewWebhookCmd())
5152
cmd.AddCommand(spoke.NewKlusterletOperatorCmd())
5253
cmd.AddCommand(spoke.NewKlusterletAgentCmd())
5354

pkg/cmd/hub/operator.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/spf13/cobra"
77
"k8s.io/utils/clock"
8+
ctrl "sigs.k8s.io/controller-runtime"
89

910
commonoptions "open-cluster-management.io/ocm/pkg/common/options"
1011
"open-cluster-management.io/ocm/pkg/operator/operators/clustermanager"
@@ -47,3 +48,24 @@ func NewHubManagerCmd() *cobra.Command {
4748
opts.AddFlags(flags)
4849
return cmd
4950
}
51+
52+
func NewWebhookCmd() *cobra.Command {
53+
webhookOptions := commonoptions.NewWebhookOptions()
54+
opts := hub.NewWebhookOptions()
55+
cmd := &cobra.Command{
56+
Use: "webhook-server",
57+
Short: "Start the registration webhook server",
58+
RunE: func(c *cobra.Command, args []string) error {
59+
if err := opts.SetupWebhookServer(webhookOptions); err != nil {
60+
return err
61+
}
62+
return webhookOptions.RunWebhookServer(ctrl.SetupSignalHandler())
63+
},
64+
}
65+
66+
flags := cmd.Flags()
67+
opts.AddFlags(flags)
68+
webhookOptions.AddFlags(flags)
69+
70+
return cmd
71+
}

pkg/singleton/hub/webhook.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package hub
2+
3+
import (
4+
"github.com/spf13/pflag"
5+
6+
commonoptions "open-cluster-management.io/ocm/pkg/common/options"
7+
registrationwebhook "open-cluster-management.io/ocm/pkg/registration/webhook"
8+
workwebhook "open-cluster-management.io/ocm/pkg/work/webhook"
9+
)
10+
11+
// Config contains the server (the webhook) cert and key.
12+
type WebhookOptions struct {
13+
workWebhookOptions *workwebhook.Options
14+
}
15+
16+
// NewWebhookOptions constructs a new set of default options for webhook.
17+
func NewWebhookOptions() *WebhookOptions {
18+
return &WebhookOptions{
19+
workWebhookOptions: workwebhook.NewOptions(),
20+
}
21+
}
22+
23+
func (c *WebhookOptions) AddFlags(fs *pflag.FlagSet) {
24+
c.workWebhookOptions.AddFlags(fs)
25+
}
26+
27+
func (c *WebhookOptions) SetupWebhookServer(opts *commonoptions.WebhookOptions) error {
28+
if err := registrationwebhook.SetupWebhookServer(opts); err != nil {
29+
return err
30+
}
31+
if err := c.workWebhookOptions.SetupWebhookServer(opts); err != nil {
32+
return err
33+
}
34+
35+
return nil
36+
}

pkg/work/webhook/option.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package webhook
22

3-
import "github.com/spf13/pflag"
3+
import (
4+
"github.com/spf13/pflag"
5+
)
46

57
// Config contains the server (the webhook) cert and key.
68
type Options struct {

pkg/work/webhook/start.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package webhook
22

33
import (
44
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
5-
_ "k8s.io/client-go/plugin/pkg/client/auth"
65

76
ocmfeature "open-cluster-management.io/api/feature"
87
workv1 "open-cluster-management.io/api/work/v1"

0 commit comments

Comments
 (0)