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

Watch controller Pods and make then available in k8sStore #3455

Merged
merged 1 commit into from
Nov 27, 2018

Conversation

wayt
Copy link
Contributor

@wayt wayt commented Nov 21, 2018

What this PR does / why we need it:

This add controller pod tracking for ingress-nginx. The list is available from the store ListControllerPods() function.

The purpose behind this is to track the number of running replicas.

A PR will follow to push this into a lua shared dict.

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #

Special notes for your reviewer:

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 21, 2018
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 21, 2018
}

// hasSameOwner returns true if both Pods share at least 1 owner
func hasSameOwner(pod1, pod2 *corev1.Pod) bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aledbf do you know any better way of validating two Pods are deployed by the same Deployment?


// getCurrentPod returns the current Pod based on environment namespace and name
func (s k8sStore) getCurrentPod() *corev1.Pod {
ns := os.Getenv("POD_NAMESPACE")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aledbf do you know any better of getting current controller Pod?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -924,6 +924,10 @@ stream {

{{ template "CUSTOM_ERRORS" (buildCustomErrorDeps $all.ProxySetHeaders (collectCustomErrorsPerServer $server)) }}

location /debug {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for example purpose, I'll remove that

@aledbf
Copy link
Member

aledbf commented Nov 22, 2018

@wayt what are you trying to do exactly?

I don't want to add an additional listener (pod listener will increase the apiserver pressure considerably)

@aledbf aledbf added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 22, 2018
@wayt
Copy link
Contributor Author

wayt commented Nov 22, 2018

We would like to have the controller pod list available within the nginx configuration templating.
In order to use them for Lua modules.

I understand that would add pressure on the apiserver, would you have any better idea regarding this?

This doesn't require a high reactivity and could be done much more lazily.

@ElvinEfendi
Copy link
Member

ElvinEfendi commented Nov 22, 2018

Is there an HTTP endpoint to get current number of replicas (in corresponding deployment resource) from API server?

Or maybe just HTTP GET current list of replicas from API server?

The problem with this is when a replica dies we won't know it.

@aledbf
Copy link
Member

aledbf commented Nov 22, 2018

@wayt with the current information we already have about the pod, using the pod-template-hash label to build a watch. This approach is a lot better than adding an informer for all the pods.

@wayt
Copy link
Contributor Author

wayt commented Nov 22, 2018

@aledbf oh great! I didn't know about that. I'll have a look.
Thanks!

@aledbf
Copy link
Member

aledbf commented Nov 22, 2018

@wayt using the current information about the pod to build a watcher using the same labels that the pod is also another option (cleaner)

@wayt wayt force-pushed the controller-pod branch 2 times, most recently from 41362de to 8eb5eb2 Compare November 26, 2018 20:11
@wayt wayt changed the title [WIP] Add controller pod list in nginx configuration templating Watch controller Pods and make then available in k8sStore Nov 26, 2018
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 26, 2018
@wayt
Copy link
Contributor Author

wayt commented Nov 26, 2018

I've updated the PR, it now keeps track of the controller Pods based on labels.

/assign @ElvinEfendi

)

// PodLister makes a Store that lists Pods.
type PodLister struct {
Copy link
Member

@aledbf aledbf Nov 26, 2018

Choose a reason for hiding this comment

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

Why are you adding a podlister?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For https://github.com/kubernetes/ingress-nginx/pull/3455/files#diff-ece58b3bebec02a6d3173c8d8099d298R141

Do you think I can only use a cache.Store ? Since we don't need any custom function.

Copy link
Member

Choose a reason for hiding this comment

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

No, it's fine. I posted the comment before reading the complete PR, sorry :)

@aledbf
Copy link
Member

aledbf commented Nov 26, 2018

/approve

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 26, 2018
@aledbf
Copy link
Member

aledbf commented Nov 26, 2018

@wayt waiting @ElvinEfendi lgtm

@@ -773,3 +835,20 @@ func (s k8sStore) Run(stopCh chan struct{}) {
go wait.Until(s.checkSSLChainIssues, 60*time.Second, stopCh)
}
}

// ListControllerPods returns a list of ingress-nginx controller Pods
func (s k8sStore) ListControllerPods() []*corev1.Pod {
Copy link
Member

Choose a reason for hiding this comment

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

Can you make this clear that it returns only Running pods? Something like ListRunningControllerPods

return client.CoreV1().Pods(store.pod.Namespace).List(options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {

Copy link
Member

Choose a reason for hiding this comment

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

no need for this newline. same as above

@ElvinEfendi
Copy link
Member

/lgtm

The two comments can be addressed in the subsequent PR when we implement posting this data to Lua.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 27, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aledbf, ElvinEfendi, wayt

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ElvinEfendi
Copy link
Member

/remove hold

@ElvinEfendi
Copy link
Member

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 27, 2018
@k8s-ci-robot k8s-ci-robot merged commit 8299652 into kubernetes:master Nov 27, 2018
@ElvinEfendi ElvinEfendi deleted the controller-pod branch November 27, 2018 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants