-
Notifications
You must be signed in to change notification settings - Fork 1k
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
fix(app): Introduced flag to specify leader election behavious #2809
Conversation
Welcome @CharlesQQ! It looks like this is your first PR to volcano-sh/volcano 🎉 |
I think we should do some checks between those three parameters |
I agree with @lowang-bh is suggestion that the input parameters need to be verified. |
@lowang-bh @wangyang0616 volcano/vendor/k8s.io/client-go/tools/leaderelection/leaderelection.go Lines 76 to 109 in 86ff941
|
@@ -83,6 +93,19 @@ func (s *ServerOption) AddFlags(fs *pflag.FlagSet) { | |||
fs.BoolVar(&s.EnableLeaderElection, "leader-elect", true, "Start a leader election client and gain leadership before "+ | |||
"executing the main loop. Enable this when running replicated vc-controller-manager for high availability; it is enabled by default") | |||
fs.StringVar(&s.LockObjectNamespace, "lock-object-namespace", defaultLockObjectNamespace, "Define the namespace of the lock object; it is volcano-system by default") | |||
fs.DurationVar(&s.LeaseDuration, "leader-elect-lease-duration", defaultElectionLeaseDuration, ""+ |
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'm thinking here mainly about the string here, whether to comply with the 120-character requirement, or to support legibility, is it easier to read if the two lines of text description information are closed?
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'm thinking here mainly about the string here, whether to comply with the 120-character requirement, or to support legibility, is it easier to read if the two lines of text description information are closed?
It's same as kubernetes comments, sames that comply with the 120-character requirement
https://github.com/kubernetes/kubernetes/blob/ea30d100f6b13a47b4153362698b89256077776c/staging/src/k8s.io/component-base/config/options/leaderelectionconfig.go#L30C1-L42
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
/reopen |
@CharlesQQ: Reopened this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@@ -47,6 +54,9 @@ type ServerOption struct { | |||
CaCertData []byte | |||
EnableLeaderElection bool |
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.
Leader election related parameters can be placed in an independent flagset, please refer to kubernets to make it more graceful.
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.
@Monokaix updated! pls check again.
cmd/scheduler/app/options/options.go
Outdated
@@ -195,10 +192,10 @@ func (s *ServerOption) ParseCAFiles(decryptFunc DecryptFunc) error { | |||
return nil | |||
} | |||
|
|||
// Default new and registry a default one |
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.
Why is this commented?
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.
Why is this commented?
useless code, I will delete that.
pkg/util/util.go
Outdated
@@ -32,3 +47,31 @@ func GenerateSchedulerName(schedulerNames []string) string { | |||
|
|||
return defaultSchedulerName | |||
} | |||
|
|||
// BindLeaderElectionFlags binds the LeaderElectionConfiguration struct fields to a flagset | |||
func BindLeaderElectionFlags(l *config.LeaderElectionConfiguration, fs *pflag.FlagSet) { |
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 import k8s.io/component-base/config/options/leaderelectionconfig.go
directly?
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 import k8s.io/component-base/config/options/leaderelectionconfig.go directly?
en.., I want set default value in function BindLeaderElectionFlags
; if not, must add a function to set LeaderElectionConfiguration default values.
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.
But actually it's a copy from k8s: )
CertData []byte | ||
KeyData []byte | ||
CaCertData []byte | ||
EnableLeaderElection bool |
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 keeping the old one for better compatibility?
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.
leader-elect
flag is kept when using BindLeaderElectionFlags.
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 keeping the old one for better compatibility?
Use leaderElection flagSet instead, it's a leaderElectionOption field.
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.
But lock-object-namespace
flag seems has been removed.
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.
But lock-object-namespace flag seems has been removed.
use the leader-elect-resource-namespace
flag instead
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.
So plz also update params in helm
: )
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 think we should better keep the old flag and mark it deprecated first.
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.
So plz also update params in helm I think we should better keep the old flag and mark it deprecated first.
sure!
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 think we should better keep the old flag and mark it deprecated first.
I also means keeping the old one and marking it is deprecated in recent release.
cmd/scheduler/app/options/options.go
Outdated
return s | ||
} | ||
//// Default new and registry a default one | ||
//func Default() *ServerOption { |
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.
Please keep it. It is used in other test packages.
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.
Please keep it. It is used in other test packages.
all right!
"github.com/spf13/pflag" | ||
"k8s.io/component-base/config" | ||
"os" |
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.
Plz sort imports.
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.
Plz sort imports.
done!
7f4fff8
to
0e650a5
Compare
pkg/util/util.go
Outdated
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/tools/leaderelection/resourcelock" | ||
"k8s.io/component-base/config" | ||
"time" |
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.
sort imports.
cmd/scheduler/app/options/options.go
Outdated
@@ -147,7 +144,7 @@ func (s *ServerOption) AddFlags(fs *pflag.FlagSet) { | |||
|
|||
// CheckOptionOrDie check lock-object-namespace when LeaderElection is enabled. | |||
func (s *ServerOption) CheckOptionOrDie() error { | |||
if s.EnableLeaderElection && s.LockObjectNamespace == "" { | |||
if s.LeaderElection.LeaderElect && s.LeaderElection.ResourceLock == "" { | |||
return fmt.Errorf("lock-object-namespace must not be nil when LeaderElection is enabled") |
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.
Change the description too.
@@ -102,7 +100,7 @@ func (s *ServerOption) AddFlags(fs *pflag.FlagSet) { | |||
|
|||
// CheckOptionOrDie checks the LockObjectNamespace. | |||
func (s *ServerOption) CheckOptionOrDie() error { | |||
if s.EnableLeaderElection && s.LockObjectNamespace == "" { | |||
if s.LeaderElection.LeaderElect && s.LeaderElection.ResourceLock == "" { |
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.
Here we can call ValidateLeaderElectionConfiguration
to check all params.
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.
All that is updated!
e8bba62
to
e095df9
Compare
|
||
s.AddFlags(fs) | ||
commonutil.LeaderElectionDefault(&s.LeaderElection) | ||
componentbaseoptions.BindLeaderElectionFlags(&s.LeaderElection, fs) | ||
|
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.
Just mark LockObjectNamespace deprecated is not enough, we should set ResourceNamespace
value to LockObjectNamespace when it's not empty: )
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.
Just mark LockObjectNamespace deprecated is not enough, we should set ResourceNamespace value to LockObjectNamespace when it's not empty: )
All right!
f6892ba
to
2913c74
Compare
CertData []byte | ||
KeyData []byte | ||
CaCertData []byte | ||
EnableLeaderElection bool |
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 think we should better keep the old flag and mark it deprecated first.
I also means keeping the old one and marking it is deprecated in recent release.
@@ -84,9 +89,7 @@ func (s *ServerOption) AddFlags(fs *pflag.FlagSet) { | |||
"File containing the default x509 Certificate for HTTPS. (CA cert, if any, concatenated "+ | |||
"after server cert).") | |||
fs.StringVar(&s.KeyFile, "tls-private-key-file", s.KeyFile, "File containing the default x509 private key matching --tls-cert-file.") | |||
fs.BoolVar(&s.EnableLeaderElection, "leader-elect", true, "Start a leader election client and gain leadership before "+ |
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.
why this is removed?
// volcano scheduler will ignore pods with scheduler names other than specified with the option | ||
fs.StringArrayVar(&s.SchedulerNames, "scheduler-name", []string{defaultSchedulerName}, "vc-scheduler will handle pods whose .spec.SchedulerName is same as scheduler-name") | ||
fs.StringVar(&s.SchedulerConf, "scheduler-conf", "", "The absolute path of scheduler configuration file") | ||
fs.DurationVar(&s.SchedulePeriod, "schedule-period", defaultSchedulerPeriod, "The period between each scheduling cycle") | ||
fs.StringVar(&s.DefaultQueue, "default-queue", defaultQueue, "The default queue name of the job") | ||
fs.BoolVar(&s.EnableLeaderElection, "leader-elect", true, |
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.
why this is removed, how about deprecated?
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.
New flagset contains this flag, so it's not removed autually.
Signed-off-by: chang.qiangqiang <chang.qiangqiang@immomo.com>
/lgtm |
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.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: william-wang The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
resolve: #2798