Skip to content

Commit

Permalink
Agent leader election config
Browse files Browse the repository at this point in the history
Signed-off-by: Qing Hao <[email protected]>
  • Loading branch information
haoqing0110 committed Nov 22, 2024
1 parent cb7ce98 commit e75ef44
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ spec:
type: object
additionalProperties:
type: string
disableLeaderElection:
description: Disable leader election. Use the klusterlet agent default value if this field is not defined.
type: boolean
featureGates:
description: "FeatureGates represents the list of feature gates for registration If it is set empty, default feature gates will be used. If it is set, featuregate/Foo is an example of one item in FeatureGates: 1. If featuregate/Foo does not exist, registration-operator will discard it 2. If featuregate/Foo exists and is false by default. It is now possible to set featuregate/Foo=[false|true] 3. If featuregate/Foo exists and is true by default. If a cluster-admin upgrading from 1 to 2 wants to continue having featuregate/Foo=false, \the can set featuregate/Foo=false before upgrading. Let's say the cluster-admin wants featuregate/Foo=false."
type: array
Expand Down Expand Up @@ -185,6 +188,18 @@ spec:
type: integer
format: int32
default: 50
leaderElectionLeaseDuration:
description: The duration that non-leader candidates will wait after observing a leadership renewal until attempting to acquire leadership of a led but unrenewed leader slot. This is effectively the maximum duration that a leader can be stopped before it is replaced by another candidate. This is only applicable if leader election is enabled. Use the klusterlet agent default value if this field is not defined.
type: string
pattern: ^([0-9]+(s|m|h))+$
leaderElectionRenewDeadline:
description: The interval between attempts by the acting master to renew a leadership slot before it stops leading. This must be less than or equal to the lease duration. This is only applicable if leader election is enabled. Use the klusterlet agent default value if this field is not defined.
type: string
pattern: ^([0-9]+(s|m|h))+$
leaderElectionRetryPeriod:
description: The duration the clients should wait between attempting acquisition and renewal of a leadership. This is only applicable if leader election is enabled. Use the klusterlet agent default value if this field is not defined.
type: string
pattern: ^([0-9]+(s|m|h))+$
registrationDriver:
description: This provides driver details required to register with hub
type: object
Expand Down Expand Up @@ -267,6 +282,9 @@ spec:
description: AppliedManifestWorkEvictionGracePeriod is the eviction grace period the work agent will wait before evicting the AppliedManifestWorks, whose corresponding ManifestWorks are missing on the hub cluster, from the managed cluster. If not present, the default value of the work agent will be used.
type: string
pattern: ^([0-9]+(s|m|h))+$
disableLeaderElection:
description: Disable leader election. Use the klusterlet agent default value if this field is not defined.
type: boolean
featureGates:
description: "FeatureGates represents the list of feature gates for work If it is set empty, default feature gates will be used. If it is set, featuregate/Foo is an example of one item in FeatureGates: 1. If featuregate/Foo does not exist, registration-operator will discard it 2. If featuregate/Foo exists and is false by default. It is now possible to set featuregate/Foo=[false|true] 3. If featuregate/Foo exists and is true by default. If a cluster-admin upgrading from 1 to 2 wants to continue having featuregate/Foo=false, \the can set featuregate/Foo=false before upgrading. Let's say the cluster-admin wants featuregate/Foo=false."
type: array
Expand Down Expand Up @@ -295,6 +313,18 @@ spec:
type: integer
format: int32
default: 50
leaderElectionLeaseDuration:
description: The duration that non-leader candidates will wait after observing a leadership renewal until attempting to acquire leadership of a led but unrenewed leader slot. This is effectively the maximum duration that a leader can be stopped before it is replaced by another candidate. This is only applicable if leader election is enabled. Use the klusterlet agent default value if this field is not defined.
type: string
pattern: ^([0-9]+(s|m|h))+$
leaderElectionRenewDeadline:
description: The interval between attempts by the acting master to renew a leadership slot before it stops leading. This must be less than or equal to the lease duration. This is only applicable if leader election is enabled. Use the klusterlet agent default value if this field is not defined.
type: string
pattern: ^([0-9]+(s|m|h))+$
leaderElectionRetryPeriod:
description: The duration the clients should wait between attempting acquisition and renewal of a leadership. This is only applicable if leader election is enabled. Use the klusterlet agent default value if this field is not defined.
type: string
pattern: ^([0-9]+(s|m|h))+$
workImagePullSpec:
description: WorkImagePullSpec represents the desired image configuration of work agent. quay.io/open-cluster-management.io/work:latest will be used if unspecified.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ spec:
ClusterAnnotations is annotations with the reserve prefix "agent.open-cluster-management.io" set on
ManagedCluster when creating only, other actors can update it afterwards.
type: object
disableLeaderElection:
description: |-
Disable leader election.
Use the klusterlet agent default value if this field is not defined.
type: boolean
featureGates:
description: "FeatureGates represents the list of feature gates
for registration\nIf it is set empty, default feature gates
Expand Down Expand Up @@ -289,6 +294,31 @@ spec:
If it is set empty, use the default value: 50
format: int32
type: integer
leaderElectionLeaseDuration:
description: |-
The duration that non-leader candidates will wait after observing a leadership
renewal until attempting to acquire leadership of a led but unrenewed leader
slot. This is effectively the maximum duration that a leader can be stopped
before it is replaced by another candidate. This is only applicable if leader
election is enabled.
Use the klusterlet agent default value if this field is not defined.
pattern: ^([0-9]+(s|m|h))+$
type: string
leaderElectionRenewDeadline:
description: |-
The interval between attempts by the acting master to renew a leadership slot
before it stops leading. This must be less than or equal to the lease duration.
This is only applicable if leader election is enabled.
Use the klusterlet agent default value if this field is not defined.
pattern: ^([0-9]+(s|m|h))+$
type: string
leaderElectionRetryPeriod:
description: |-
The duration the clients should wait between attempting acquisition and renewal
of a leadership. This is only applicable if leader election is enabled.
Use the klusterlet agent default value if this field is not defined.
pattern: ^([0-9]+(s|m|h))+$
type: string
registrationDriver:
description: This provides driver details required to register
with hub
Expand Down Expand Up @@ -407,6 +437,11 @@ spec:
the managed cluster. If not present, the default value of the work agent will be used.
pattern: ^([0-9]+(s|m|h))+$
type: string
disableLeaderElection:
description: |-
Disable leader election.
Use the klusterlet agent default value if this field is not defined.
type: boolean
featureGates:
description: "FeatureGates represents the list of feature gates
for work\nIf it is set empty, default feature gates will be
Expand Down Expand Up @@ -451,6 +486,31 @@ spec:
If it is set empty, use the default value: 50
format: int32
type: integer
leaderElectionLeaseDuration:
description: |-
The duration that non-leader candidates will wait after observing a leadership
renewal until attempting to acquire leadership of a led but unrenewed leader
slot. This is effectively the maximum duration that a leader can be stopped
before it is replaced by another candidate. This is only applicable if leader
election is enabled.
Use the klusterlet agent default value if this field is not defined.
pattern: ^([0-9]+(s|m|h))+$
type: string
leaderElectionRenewDeadline:
description: |-
The interval between attempts by the acting master to renew a leadership slot
before it stops leading. This must be less than or equal to the lease duration.
This is only applicable if leader election is enabled.
Use the klusterlet agent default value if this field is not defined.
pattern: ^([0-9]+(s|m|h))+$
type: string
leaderElectionRetryPeriod:
description: |-
The duration the clients should wait between attempting acquisition and renewal
of a leadership. This is only applicable if leader election is enabled.
Use the klusterlet agent default value if this field is not defined.
pattern: ^([0-9]+(s|m|h))+$
type: string
type: object
workImagePullSpec:
description: |-
Expand Down
44 changes: 44 additions & 0 deletions operator/v1/types_klusterlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ type RegistrationConfiguration struct {
// +kubebuilder:default:=100
KubeAPIBurst int32 `json:"kubeAPIBurst,omitempty"`

// Leader election configuration
// +optional
LeaderElectionConfig `json:",inline"`

// BootstrapKubeConfigs defines the ordered list of bootstrap kubeconfigs. The order decides which bootstrap kubeconfig to use first when rebootstrap.
//
// When the agent loses the connection to the current hub over HubConnectionTimeoutSeconds, or the managedcluster CR
Expand Down Expand Up @@ -269,6 +273,10 @@ type WorkAgentConfiguration struct {
// +kubebuilder:default:=100
KubeAPIBurst int32 `json:"kubeAPIBurst,omitempty"`

// Leader election configuration
// +optional
LeaderElectionConfig `json:",inline"`

// AppliedManifestWorkEvictionGracePeriod is the eviction grace period the work agent will wait before
// evicting the AppliedManifestWorks, whose corresponding ManifestWorks are missing on the hub cluster, from
// the managed cluster. If not present, the default value of the work agent will be used.
Expand All @@ -278,6 +286,42 @@ type WorkAgentConfiguration struct {
AppliedManifestWorkEvictionGracePeriod *metav1.Duration `json:"appliedManifestWorkEvictionGracePeriod,omitempty"`
}

// Leader election configuration
type LeaderElectionConfig struct {
// Disable leader election.
// Use the klusterlet agent default value if this field is not defined.
// +optional
DisableLeaderElection bool `json:"disableLeaderElection,omitempty"`

// The duration that non-leader candidates will wait after observing a leadership
// renewal until attempting to acquire leadership of a led but unrenewed leader
// slot. This is effectively the maximum duration that a leader can be stopped
// before it is replaced by another candidate. This is only applicable if leader
// election is enabled.
// Use the klusterlet agent default value if this field is not defined.
// +optional
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([0-9]+(s|m|h))+$"
LeaderElectionLeaseDuration *metav1.Duration `json:"leaderElectionLeaseDuration,omitempty"`

// The interval between attempts by the acting master to renew a leadership slot
// before it stops leading. This must be less than or equal to the lease duration.
// This is only applicable if leader election is enabled.
// Use the klusterlet agent default value if this field is not defined.
// +optional
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([0-9]+(s|m|h))+$"
LeaderElectionRenewDeadline *metav1.Duration `json:"leaderElectionRenewDeadline,omitempty"`

// The duration the clients should wait between attempting acquisition and renewal
// of a leadership. This is only applicable if leader election is enabled.
// Use the klusterlet agent default value if this field is not defined.
// +optional
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([0-9]+(s|m|h))+$"
LeaderElectionRetryPeriod *metav1.Duration `json:"leaderElectionRetryPeriod,omitempty"`
}

const (
// ClusterAnnotationsKeyPrefix is the prefix of annotations set on ManagedCluster when creating only.
ClusterAnnotationsKeyPrefix = "agent.open-cluster-management.io"
Expand Down
33 changes: 33 additions & 0 deletions operator/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions operator/v1/zz_generated.swagger_doc_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e75ef44

Please sign in to comment.