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 poolcoordinator controller and webhooks to replace nodelifecycle … #1040

Merged

Conversation

LindaYu17
Copy link
Member

…controller

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespace from that line:
/kind bug
/kind documentation
/kind enhancement
/kind good-first-issue
/kind feature
/kind question
/kind design
/sig ai
/sig iot
/sig network
/sig storage

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

@openyurt-bot
Copy link
Collaborator

@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.
For more information please see the contributor guide

In response to this:

…controller

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespace from that line:
/kind bug
/kind documentation
/kind enhancement
/kind good-first-issue
/kind feature
/kind question
/kind design
/sig ai
/sig iot
/sig network
/sig storage

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

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.

@openyurt-bot openyurt-bot added the kind/feature kind/feature label Oct 29, 2022
@openyurt-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: LindaYu17
To complete the pull request process, please assign kadisi
You can assign the PR to them by writing /assign @kadisi in a comment when ready.

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

@luc99hen
Copy link
Member

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

@rambohe-ch
Copy link
Member

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 kube-controller-manager instead of kubebuilder.

@@ -0,0 +1,41 @@
package client
Copy link
Member

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 {
Copy link
Member

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)
Copy link
Member

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" {
Copy link
Member

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),
Copy link
Member

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
Copy link

codecov bot commented Oct 31, 2022

Codecov Report

❗ No coverage uploaded for pull request base (pool-coordinator-dev@0db2b87). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head 2e7024e differs from pull request most recent head 1f25094. Consider uploading reports for the commit 1f25094 to get more accurate results

@@                   Coverage Diff                   @@
##             pool-coordinator-dev    #1040   +/-   ##
=======================================================
  Coverage                        ?   49.29%           
=======================================================
  Files                           ?      101           
  Lines                           ?    12201           
  Branches                        ?        0           
=======================================================
  Hits                            ?     6015           
  Misses                          ?     5662           
  Partials                        ?      524           
Flag Coverage Δ
unittests 49.29% <0.00%> (?)

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.

@LindaYu17 LindaYu17 force-pushed the pool-coordinator-dev branch 6 times, most recently from a085a2c to 20222a7 Compare November 1, 2022 11:51
"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"
Copy link
Member

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)
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 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

Copy link
Member

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

@LindaYu17 LindaYu17 force-pushed the pool-coordinator-dev branch from 20222a7 to e46af29 Compare November 2, 2022 09:12
Comment on lines 256 to 265
nc.nodeInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: onNodeCreate,
UpdateFunc: onNodeUpdate,
DeleteFunc: onNodeDelete,
})
nc.leaseInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: onLeaseCreate,
UpdateFunc: onLeaseUpdate,
DeleteFunc: nil,
})
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

@LindaYu17 LindaYu17 force-pushed the pool-coordinator-dev branch 3 times, most recently from 8f1118d to 9c834b4 Compare November 4, 2022 08:36
}

var (
ctl *Controller
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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
Copy link
Member

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.

name: pool-coordinator-webhook
namespace: {{ .Release.Namespace }}
labels:
helm.sh/chart: pool-coordinator-0.1.0
Copy link
Member

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"
Copy link
Member

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
Copy link
Member

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 {
Copy link
Member

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
Copy link
Member

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 "".

@LindaYu17 LindaYu17 force-pushed the pool-coordinator-dev branch from 2e7024e to 1f25094 Compare December 5, 2022 13:21
@rambohe-ch rambohe-ch merged commit 7fa0805 into openyurtio:pool-coordinator-dev Dec 7, 2022
gnunu pushed a commit to gnunu/openyurt that referenced this pull request Jan 15, 2023
…controller (openyurtio#1040)

make yurt-controller-manager take care of webhook configurations and certs

add unit tests
gnunu pushed a commit to gnunu/openyurt that referenced this pull request Jan 15, 2023
…controller (openyurtio#1040)

make yurt-controller-manager take care of webhook configurations and certs

add unit tests
gnunu pushed a commit to gnunu/openyurt that referenced this pull request Jan 17, 2023
…controller (openyurtio#1040)

make yurt-controller-manager take care of webhook configurations and certs

add unit tests
gnunu pushed a commit to gnunu/openyurt that referenced this pull request Jan 17, 2023
…controller (openyurtio#1040)

make yurt-controller-manager take care of webhook configurations and certs

add unit tests
gnunu pushed a commit to gnunu/openyurt that referenced this pull request Jan 17, 2023
…controller (openyurtio#1040)

make yurt-controller-manager take care of webhook configurations and certs

add unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants