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

Add leader election #113

Merged
merged 2 commits into from
Jul 21, 2021
Merged

Add leader election #113

merged 2 commits into from
Jul 21, 2021

Conversation

dougbtv
Copy link
Member

@dougbtv dougbtv commented Jun 24, 2021

Uses k8s.io/client-go/tools/leaderelection to add leader election to choose a leader during CRD read/write in order to properly handle concurrency before ippools are calculated and modified.

@coveralls
Copy link

coveralls commented Jun 24, 2021

Pull Request Test Coverage Report for Build 1052431734

  • 23 of 247 (9.31%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-4.0%) to 33.12%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/storage/etcd.go 0 67 0.0%
pkg/storage/kubernetes.go 0 157 0.0%
Totals Coverage Status
Change from base Build 1012211977: -4.0%
Covered Lines: 363
Relevant Lines: 1096

💛 - Coveralls

Comment on lines 290 to 291
/*
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove it.

Comment on lines 267 to 270
LeaseDuration: 1500 * time.Millisecond,
RenewDeadline: 1000 * time.Millisecond,
RetryPeriod: 500 * time.Millisecond,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make it configurable from CNI json config? It might be key for performance tuning.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added changes for configurable parameters for lease/renew/retry durations


var rl = &resourcelock.LeaseLock{
LeaseMeta: metav1.ObjectMeta{
Name: "whereabouts",
Copy link
Collaborator

@crandles crandles Jun 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could potentially use the name of the pool here (perhaps with whereabouts as a prefix), so that allocations in other pools are not also blocked

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we should use leaselock to lock whole whereabouts, not per ip pool basis because Kubernetes/etcd does not support fine grain lock (because etcd is not DB, just KVS).

Comment on lines +159 to +164
switch ipamConf.Datastore {
case types.DatastoreETCD:
ipam, err = NewETCDIPAM(ipamConf)
case types.DatastoreKubernetes:
ipam, err = NewKubernetesIPAM(containerID, ipamConf)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems strange to me to find this switch in the etcd implementation. Shouldn't the correct config be passed as a parameter to the implementations ?

@dougbtv
Copy link
Member Author

dougbtv commented Jun 29, 2021

New commit addresses configurability of the duration parameters, adds defaults based on original code

func IPManagementKubernetesUpdate(mode int, ipam *KubernetesIPAM, ipamConf whereaboutstypes.IPAMConfig, containerID string, podRef string) (net.IPNet, error) {
logging.Debugf("IPManagement -- mode: %v / containerID: %v / podRef: %v", mode, containerID, podRef)

now := time.Now()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this because it is only for debug purpose.

Comment on lines 432 to 433
//XXX
logging.Debugf("Took: %vms\n", time.Since(now).Milliseconds())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this because it is only for debug purpose.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! And this line causes the openshift img build failure, since it uses golang-1.12 - time.Milliseconds is available on golang >= 1.13 as per https://golang.org/pkg/time/#Duration.Milliseconds

@maiqueb maiqueb mentioned this pull request Jul 5, 2021
Copy link
Collaborator

@maiqueb maiqueb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It misses hack/update-deps.sh .

@dougbtv dougbtv merged commit 6cb8c1b into master Jul 21, 2021
@s1061123 s1061123 deleted the add-leader-election branch July 21, 2021 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants