Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve lease lock for yurt-manager component #1741

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion charts/yurt-manager/templates/yurt-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ spec:
key: node-role.kubernetes.io/control-plane
containers:
- args:
- --enable-leader-election=true
- --metrics-addr=:{{ .Values.ports.metrics }}
- --health-probe-addr=:{{ .Values.ports.healthProbe }}
- --webhook-port={{ .Values.ports.webhook }}
- --logtostderr=true
- --v={{ .Values.log.level }}
- --working-namespace={{ .Release.Namespace }}
{{- if .Values.leaderElectResourceName }}
- --leader-elect-resource-name={{ .Values.leaderElectResourceName }}
{{- end }}
{{- if .Values.controllers }}
- --controllers={{ .Values.controllers }}
{{- end }}
Expand Down
2 changes: 2 additions & 0 deletions charts/yurt-manager/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ controllers: "*"
# format should be "foo,*"
disableIndependentWebhooks: ""

leaderElectResourceName: "cloud-yurt-manager"

# resources of yurt-manager container
resources:
limits:
Expand Down
9 changes: 4 additions & 5 deletions cmd/yurt-manager/app/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/leaderelection/resourcelock"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/cli/globalflag"
"k8s.io/component-base/term"
Expand Down Expand Up @@ -157,10 +156,10 @@ func Run(c *config.CompletedConfig, stopCh <-chan struct{}) error {
Scheme: scheme,
MetricsBindAddress: c.ComponentConfig.Generic.MetricsAddr,
HealthProbeBindAddress: c.ComponentConfig.Generic.HealthProbeAddr,
LeaderElection: c.ComponentConfig.Generic.EnableLeaderElection,
LeaderElectionID: YurtManager,
LeaderElectionNamespace: c.ComponentConfig.Generic.LeaderElectionNamespace,
LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
LeaderElection: c.ComponentConfig.Generic.LeaderElection.LeaderElect,
LeaderElectionID: c.ComponentConfig.Generic.LeaderElection.ResourceName,
LeaderElectionNamespace: c.ComponentConfig.Generic.LeaderElection.ResourceNamespace,
LeaderElectionResourceLock: c.ComponentConfig.Generic.LeaderElection.ResourceLock,
Port: util.GetWebHookPort(),
Namespace: "",
Logger: setupLog,
Expand Down
33 changes: 20 additions & 13 deletions cmd/yurt-manager/app/options/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (

"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/tools/leaderelection/resourcelock"
componentbaseconfig "k8s.io/component-base/config"
"k8s.io/component-base/config/options"

"github.com/openyurtio/openyurt/pkg/features"
"github.com/openyurtio/openyurt/pkg/yurtmanager/controller/apis/config"
Expand All @@ -34,16 +37,20 @@ type GenericOptions struct {
func NewGenericOptions() *GenericOptions {
return &GenericOptions{
&config.GenericConfiguration{
Version: false,
MetricsAddr: ":10271",
HealthProbeAddr: ":10272",
WebhookPort: 10273,
EnableLeaderElection: true,
LeaderElectionNamespace: "kube-system",
RestConfigQPS: 30,
RestConfigBurst: 50,
WorkingNamespace: "kube-system",
DisabledWebhooks: []string{},
Version: false,
MetricsAddr: ":10271",
HealthProbeAddr: ":10272",
WebhookPort: 10273,
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
LeaderElect: true,
ResourceLock: resourcelock.LeasesResourceLock,
ResourceName: "yurt-manager",
ResourceNamespace: "kube-system",
},
RestConfigQPS: 30,
RestConfigBurst: 50,
WorkingNamespace: "kube-system",
DisabledWebhooks: []string{},
},
}
}
Expand Down Expand Up @@ -86,8 +93,8 @@ func (o *GenericOptions) ApplyTo(cfg *config.GenericConfiguration, controllerAli
cfg.MetricsAddr = o.MetricsAddr
cfg.HealthProbeAddr = o.HealthProbeAddr
cfg.WebhookPort = o.WebhookPort
cfg.EnableLeaderElection = o.EnableLeaderElection
cfg.LeaderElectionNamespace = o.WorkingNamespace
cfg.LeaderElection = o.LeaderElection
cfg.LeaderElection.ResourceNamespace = o.WorkingNamespace
cfg.RestConfigQPS = o.RestConfigQPS
cfg.RestConfigBurst = o.RestConfigBurst
cfg.WorkingNamespace = o.WorkingNamespace
Expand Down Expand Up @@ -119,7 +126,7 @@ func (o *GenericOptions) AddFlags(fs *pflag.FlagSet, allControllers, disabledByD
fs.StringVar(&o.MetricsAddr, "metrics-addr", o.MetricsAddr, "The address the metric endpoint binds to.")
fs.StringVar(&o.HealthProbeAddr, "health-probe-addr", o.HealthProbeAddr, "The address the healthz/readyz endpoint binds to.")
fs.IntVar(&o.WebhookPort, "webhook-port", o.WebhookPort, "The port on which to serve HTTPS for webhook server. It can't be switched off with 0")
fs.BoolVar(&o.EnableLeaderElection, "enable-leader-election", o.EnableLeaderElection, "Whether you need to enable leader election.")
options.BindLeaderElectionFlags(&o.LeaderElection, fs)
fs.IntVar(&o.RestConfigQPS, "rest-config-qps", o.RestConfigQPS, "rest-config-qps.")
fs.IntVar(&o.RestConfigBurst, "rest-config-burst", o.RestConfigBurst, "rest-config-burst.")
fs.StringVar(&o.WorkingNamespace, "working-namespace", o.WorkingNamespace, "The namespace where the yurt-manager is working.")
Expand Down
18 changes: 9 additions & 9 deletions pkg/yurtmanager/controller/apis/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package config

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
componentbaseconfig "k8s.io/component-base/config"

nodepoolconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/nodepool/config"
platformadminconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/platformadmin/config"
Expand Down Expand Up @@ -55,15 +56,14 @@ type YurtManagerConfiguration struct {
}

type GenericConfiguration struct {
Version bool
MetricsAddr string
HealthProbeAddr string
WebhookPort int
EnableLeaderElection bool
LeaderElectionNamespace string
RestConfigQPS int
RestConfigBurst int
WorkingNamespace string
Version bool
MetricsAddr string
HealthProbeAddr string
WebhookPort int
LeaderElection componentbaseconfig.LeaderElectionConfiguration
RestConfigQPS int
RestConfigBurst int
WorkingNamespace string
// Controllers is the list of controllers to enable or disable
// '*' means "all enabled by default controllers"
// 'foo' means "enable 'foo'"
Expand Down
1 change: 0 additions & 1 deletion test/e2e/cmd/init/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ spec:
hostNetwork: true
containers:
- args:
- --enable-leader-election
- --metrics-addr=:10271
- --health-probe-addr=:10272
- --webhook-port=10273
Expand Down
Loading