-
Notifications
You must be signed in to change notification settings - Fork 407
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 poolcoordinator controller and webhooks to replace nodelifecycle … #1040
add poolcoordinator controller and webhooks to replace nodelifecycle … #1040
Conversation
@LindaYu17: GitHub didn't allow me to assign the following users: your_reviewer. Note that only openyurtio members, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time. 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. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: LindaYu17 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
It seems that this controller follows the code style of kubebuilder. If this is fine, I will build my cert management part based on this framework. @rambohe-ch |
@LindaYu17 @luc99hen I think that newly added controllers should follow the code style of |
@@ -0,0 +1,41 @@ | |||
package client |
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 add license header for newly added file.
} | ||
|
||
// extracts pod from admission request | ||
func (pv *PodAdmission) getPod() error { |
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.
pv --> pa?
klog.Error(err) | ||
return false | ||
} | ||
diff := time.Now().Sub(lease.GetCreationTimestamp().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.
we should use lease.Spec.RenewTime
instead of GetCreationTimestamp()
to specify the last heartbeat time
return reviewResponse(pv.request.UID, false, http.StatusBadRequest, e), err | ||
} | ||
|
||
if pv.pod.Annotations == nil || pv.pod.Annotations[constant.PodAvailableAnnotation] != "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.
toleration should also be added to pods for node with autonomy
annotation.
|
||
func NewNodepoolMap() *NodepoolMap { | ||
return &NodepoolMap{ | ||
nodepools: make(map[string]*NodeSet), |
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 use sets.String
instead of defining NodeSet
?
Codecov Report
@@ Coverage Diff @@
## pool-coordinator-dev #1040 +/- ##
=======================================================
Coverage ? 49.29%
=======================================================
Files ? 101
Lines ? 12201
Branches ? 0
=======================================================
Hits ? 6015
Misses ? 5662
Partials ? 524
Flags with carried forward coverage won't be shown. Click here to find out more. Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
a085a2c
to
20222a7
Compare
"github.com/openyurtio/openyurt/pkg/controller/poolcoordinator/constant" | ||
"github.com/openyurtio/openyurt/pkg/controller/poolcoordinator/lister" | ||
"github.com/openyurtio/openyurt/pkg/controller/poolcoordinator/utils" | ||
"github.com/openyurtio/openyurt/pkg/controller/poolcoordinator/webhook" |
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.
lib of openyurt should be put at the last and independent section.
func CreateNodeInformer(client client.Interface, factory informers.SharedInformerFactory, stopper chan (struct{})) v1.NodeInformer { | ||
nodeInformer := factory.Core().V1().Nodes() | ||
factory.Start(stopper) | ||
factory.WaitForCacheSync(stopper) |
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.
we can not start informer at here, because all of informers will be started at https://github.com/openyurtio/openyurt/blob/master/cmd/yurt-controller-manager/app/controllermanager.go#L208
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.
and factory.WaitForCacheSync(stopper)
should be executed in a independent goroutine, you can take YurtCSRApprover controller as a example: https://github.com/openyurtio/openyurt/blob/master/pkg/controller/certificates/csrapprover.go#L181
20222a7
to
e46af29
Compare
nc.nodeInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ | ||
AddFunc: onNodeCreate, | ||
UpdateFunc: onNodeUpdate, | ||
DeleteFunc: onNodeDelete, | ||
}) | ||
nc.leaseInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ | ||
AddFunc: onLeaseCreate, | ||
UpdateFunc: onLeaseUpdate, | ||
DeleteFunc: nil, | ||
}) |
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 moving these configurations to the NewController
func
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.
updated
8f1118d
to
9c834b4
Compare
} | ||
|
||
var ( | ||
ctl *Controller |
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 do not define Controller var.
var ( | ||
ctl *Controller | ||
|
||
ldc *LeaseDelegatedCounter |
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.
ditto
go pcc.nodePoolWorker() | ||
|
||
klog.Info("create webhook") | ||
go webhook.Run(pcc.nodeLister, pcc.leaseLister, pcc.nodepoolMap) |
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.
maybe it's hard to understand that run webhook in the controller, how about create an independent webhook server for all webhooks in yurt-controller-manager? so it's easy to add other webhooks in the new server in the future.
ldc.Inc(nl.Name) | ||
if ldc.Counter(nl.Name) >= constant.LeaseDelegationThreshold { | ||
item.taint = true | ||
GetController().nodeUpdateQueue.Add(item) |
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.
in order to improve the readability of code, maybe we can add node name instead nodeTaintItem into nodeUpdateQueue.
|
||
nodeLister listerv1.NodeLister | ||
leaseLister leaselisterv1.LeaseNamespaceLister | ||
nodepoolMap *utils.NodepoolMap |
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.
we should try best not to define file-scope var.
9c834b4
to
f743a57
Compare
f743a57
to
9023aba
Compare
f87a711
to
3a15a1d
Compare
7a82781
to
198a747
Compare
3a15a1d
to
0db2b87
Compare
198a747
to
2e7024e
Compare
name: pool-coordinator-webhook | ||
namespace: {{ .Release.Namespace }} | ||
labels: | ||
helm.sh/chart: pool-coordinator-0.1.0 |
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.
helm releated labels should be removed, as it will be generated when helm install.
env: | ||
- name: WEBHOOK_CERT_DIR | ||
value: "/tmp/k8s-webhook-server/serving-certs" |
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.
maybe change to {{ .Values.admissionWebhooks.certificate.mountPath }}
name: https | ||
selector: | ||
app.kubernetes.io/name: pool-coordinator | ||
app.kubernetes.io/instance: pool-coordinator |
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.
yurt-controller-manager pod should add the labels.
MaxRetries = 30 | ||
) | ||
|
||
type PoolCoordinatorWebhook struct { |
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.
Could we use controller-runtime
implement the webhook, as it could make the code more elegant, just like https://github.com/openyurtio/yurt-app-manager/blob/master/pkg/yurtappmanager/webhook/nodepool/nodepool_validation.go
name: vpoolcoordinator.kb.io | ||
rules: | ||
- apiGroups: | ||
- pool-coordinator.openyurt.io |
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.
If the webhook validate pod resources, the apigroup may change to "".
2e7024e
to
1f25094
Compare
…controller (openyurtio#1040) make yurt-controller-manager take care of webhook configurations and certs add unit tests
…controller (openyurtio#1040) make yurt-controller-manager take care of webhook configurations and certs add unit tests
…controller (openyurtio#1040) make yurt-controller-manager take care of webhook configurations and certs add unit tests
…controller (openyurtio#1040) make yurt-controller-manager take care of webhook configurations and certs add unit tests
…controller (openyurtio#1040) make yurt-controller-manager take care of webhook configurations and certs add unit tests
…controller
What type of PR is this?
What this PR does / why we need it:
replace with nodelifecycle controller from k8s with pool-coordinator's pod management.
Which issue(s) this PR fixes:
Fixes #776
Special notes for your reviewer:
Does this PR introduce a user-facing change?
other Note