Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Add leader election code to MIC #277

Merged
merged 8 commits into from
Jul 24, 2019
Merged

Conversation

kkmsft
Copy link
Contributor

@kkmsft kkmsft commented Jul 5, 2019

Reason for Change:

Add leader election code to MIC to run it as ReplicaSet with multiple replicas which can come up and continue in case of a failure of the active MIC. Also added are deployment yamls which configures the ReplicaSet appropriately under deploy/master/replicaset.

Issue Fixed:

Notes for Reviewers:

TODO:

  1. Add tests in e2e

@kkmsft kkmsft requested review from cpuguy83 and aramase and removed request for cpuguy83 July 5, 2019 19:55
@kkmsft kkmsft changed the title [WIP] Add leader election code to MIC - initial commit [WIP] Add leader election code to MIC Jul 6, 2019
@kkmsft
Copy link
Contributor Author

kkmsft commented Jul 6, 2019

Ran 10 of 10 Specs in 2939.239 seconds
SUCCESS! -- 10 Passed | 0 Failed | 0 Pending | 0 Skipped
--- PASS: TestAADPodIdentity (2939.24s)

@kkmsft kkmsft force-pushed the leader_election branch 2 times, most recently from f4f27b3 to 4c928bb Compare July 16, 2019 05:03
@kkmsft kkmsft changed the title [WIP] Add leader election code to MIC Add leader election code to MIC Jul 16, 2019
@kkmsft kkmsft requested a review from khenidak July 16, 2019 05:33
@kkmsft kkmsft added this to the v1.5 milestone Jul 16, 2019
cmd/mic/main.go Outdated
)

func main() {
defer glog.Flush()
hostName, err := os.Hostname()
if err != nil {
glog.Fatalf("Get hostname failure.")
Copy link
Member

Choose a reason for hiding this comment

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

Need to include the error in the err msg

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

cmd/mic/main.go Outdated
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to the kube config")
flag.StringVar(&cloudconfig, "cloudconfig", "", "Path to cloud config e.g. Azure.json file")
flag.BoolVar(&forceNamespaced, "forceNamespaced", false, "Forces namespaced identities, binding, and assignment")
flag.BoolVar(&versionInfo, "version", false, "Prints the version information")
flag.DurationVar(&syncRetryDuration, "syncRetryDuration", 3600*time.Second, "The interval in seconds at which sync loop should periodically check for errors and reconcile.")

// Leader election parameters
flag.StringVar(&leaderElectionCfg.ResourceName, "leader-election-name", hostName, "leader name. default is 'hostname'")
flag.StringVar(&leaderElectionCfg.Namespace, "leader-election-namespace", "default", "name space to create leader election objects. default is 'default' namesapce")
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to explicitly say the default value in the usage. Since the default value is defined, pflag will show that in the output.

For instance -

  -syncRetryDuration duration
    	The interval in seconds at which sync loop should periodically check for errors and reconcile. (default 1h0m0s)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

serviceAccountName: aad-pod-id-mic-service-account
containers:
- name: mic
image: "mcr.microsoft.com/k8s/aad-pod-identity/mic:1.3"
Copy link
Member

Choose a reason for hiding this comment

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

Image should be 1.5-rc1 image here instead of 1.3

name: iptableslock
containers:
- name: nmi
image: "mcr.microsoft.com/k8s/aad-pod-identity/nmi:1.4"
Copy link
Member

Choose a reason for hiding this comment

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

Image should be 1.5-rc1 instead of 1.4

name: iptableslock
containers:
- name: nmi
image: "mcr.microsoft.com/k8s/aad-pod-identity/nmi:master"
Copy link
Member

Choose a reason for hiding this comment

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

same as above

Copy link
Member

Choose a reason for hiding this comment

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

@kkmsft looks like the image version is still master here?

spec:
containers:
- name: mic
image: "mcr.microsoft.com/k8s/aad-pod-identity/mic:master"
Copy link
Member

Choose a reason for hiding this comment

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

same as above

Copy link
Member

Choose a reason for hiding this comment

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

@kkmsft looks like the image version is still master here instead of rc?

pkg/mic/mic.go Outdated
Identity: c.ResourceName,
EventRecorder: recorder})
if err != nil {
glog.Errorf("Resource lock creation for leadeer election failed with error : %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

s/leadeer/leader

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

leaderElector, err = leaderelection.NewLeaderElector(config)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

We can skip the err != nil check here and return from here

@@ -140,6 +140,9 @@ rules:
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "patch"]
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["create", "get", "list", "watch", "update", "patch"]
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need create, update and patch?

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm we need create and get for sure, the rest i am not so sure about.

cmd/mic/main.go Outdated
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to the kube config")
flag.StringVar(&cloudconfig, "cloudconfig", "", "Path to cloud config e.g. Azure.json file")
flag.BoolVar(&forceNamespaced, "forceNamespaced", false, "Forces namespaced identities, binding, and assignment")
flag.BoolVar(&versionInfo, "version", false, "Prints the version information")
flag.DurationVar(&syncRetryDuration, "syncRetryDuration", 3600*time.Second, "The interval in seconds at which sync loop should periodically check for errors and reconcile.")

// Leader election parameters
flag.StringVar(&leaderElectionCfg.ResourceName, "leader-election-name", hostName, "leader name. default is 'hostname'")
Copy link
Contributor

Choose a reason for hiding this comment

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

default shouldn't be host name, default should be a well known string. Mic pods will get different host names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

isn't that for ID ? Shouldn't the resource name be unique ?

Copy link
Contributor

Choose a reason for hiding this comment

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

leaderElectionCfg.ResourceName throw me off. i thought it is for endpoint name, not for the identity of the leader. Let us try to avoid the same for future users.

  • rename the field ResourceName to leader identity or something of that sort.
  • rename field ID to Identity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ResourceName ==> Instance
ID ==> Name

cmd/mic/main.go Outdated
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to the kube config")
flag.StringVar(&cloudconfig, "cloudconfig", "", "Path to cloud config e.g. Azure.json file")
flag.BoolVar(&forceNamespaced, "forceNamespaced", false, "Forces namespaced identities, binding, and assignment")
flag.BoolVar(&versionInfo, "version", false, "Prints the version information")
flag.DurationVar(&syncRetryDuration, "syncRetryDuration", 3600*time.Second, "The interval in seconds at which sync loop should periodically check for errors and reconcile.")

// Leader election parameters
flag.StringVar(&leaderElectionCfg.ResourceName, "leader-election-name", hostName, "leader name. default is 'hostname'")
flag.StringVar(&leaderElectionCfg.Namespace, "leader-election-namespace", "default", "name space to create leader election objects. default is 'default' namesapce")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit namespace not name space

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

}
leaderElector, err := c.NewLeaderElector(clientSet, recorder, leaderElectionConfig)
if err != nil {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

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

please log here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -140,6 +140,9 @@ rules:
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "patch"]
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["create", "get", "list", "watch", "update", "patch"]
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm we need create and get for sure, the rest i am not so sure about.

OnStoppedLeading: func() {
glog.Errorf("Lost Leader Lease")
glog.Flush()
os.Exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit the case of log line consistent. don't use title case, and generally avoid caps all together.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed. Only first one is caps now.

@@ -0,0 +1,208 @@
apiVersion: v1
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have these new files, are they new?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right now the deployment file (https://github.com/Azure/aad-pod-identity/blob/master/deploy/infra/deployment-rbac.yaml) under the infra has the extra parameter with the binary name, because of a bug in the Docker packaging which we fixed later. That file needs to be remain as is so that anyone using the stable images can use that deployment file. These file contains the right yaml for the images from the master. When we do next release - 1.5 this file will move to (https://github.com/Azure/aad-pod-identity/blob/master/deploy/infra/deployment-rbac.yaml) so that stable images can be obtained by using the same deployment files and also have replicaset configuration.

@kkmsft kkmsft force-pushed the leader_election branch 2 times, most recently from a31f846 to 56c65b0 Compare July 24, 2019 18:00
@kkmsft
Copy link
Contributor Author

kkmsft commented Jul 24, 2019

Ran 12 of 12 Specs in 2723.302 seconds
SUCCESS! -- 12 Passed | 0 Failed | 0 Pending | 0 Skipped
--- PASS: TestAADPodIdentity (2723.30s)
PASS
ok github.com/Azure/aad-pod-identity/test/e2e 2723.340s

@kkmsft kkmsft merged commit 1aa529b into Azure:master Jul 24, 2019
@kkmsft kkmsft deleted the leader_election branch July 24, 2019 21:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants