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

Convert EndpointSlice Reconciler to a library in staging. #118953

Merged
merged 4 commits into from Jul 14, 2023

Conversation

mskrocki
Copy link
Contributor

@mskrocki mskrocki commented Jun 28, 2023

What type of PR is this?

/kind feature

What this PR does / why we need it:

See KEP-3685

Which issue(s) this PR fixes:

Fixes (kubernetes/enhancements#3685)

Special notes for your reviewer:

SIG-ARCH approval for new staging repo: https://groups.google.com/g/kubernetes-sig-architecture/c/Myu9NPxjp9U

Does this PR introduce a user-facing change?

New staging repo has been created for the EndpointSlice reconciler.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

- [KEP]: https://github.com/kubernetes/enhancements/pull/3686/commits/f0e118c01e95b335a2ed8101f0b6a935232d3b8f

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 28, 2023
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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.

@k8s-ci-robot k8s-ci-robot added needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/dependency Issues or PRs related to dependency changes sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/network Categorizes an issue or PR as relevant to SIG Network. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 28, 2023
staging/src/k8s.io/endpointslice/utils.go Outdated Show resolved Hide resolved
@@ -85,7 +85,7 @@ func NewPortMapKey(endpointPorts []discovery.EndpointPort) PortMapKey {
// DeepHashObjectToString creates a unique hash string from a go object.
func DeepHashObjectToString(objectToWrite interface{}) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

The only other consumer of this is util/endpointslice. I wonder if it makes sense to combine k8s.io/endpointslice/util/endpoint and k8s.io/endpointslice/util/endpointslice into k8s.io/endpointslice/util to reduce the public API surface.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe even flatten k8s.io/endpointslice/util into k8s.io/endpointslice? Looking at some of the functions like ShouldPodBeInEndpoints, I think they belong in the main pkg. See https://www.kubernetes.dev/docs/guide/coding-convention/#directory-and-file-conventions:

Avoid general utility packages. Packages called “util” are suspect.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, it does not make have much sense have so many utils folders, in theory k8s.io/endpointslice/util/endpoint should only be used for the endpoints controller, but I'm not surprised we ended mixing things

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we have to limit ourselves to k8s.io/endpointslice/util, since k8s.io/endpointslice/topologycache and k8s.io/endpointslice/metrics import utils as well, and if not mistaken, we will end up with cyclic imports

Copy link
Contributor

@akhilles akhilles Jul 6, 2023

Choose a reason for hiding this comment

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

It looks like k8s.io/endpointslice/topologycache no longer depends on k8s.io/endpointslice/util, and only k8s.io/endpointslice/metrics does. But now I'm wondering whether metrics should be flattened into k8s.io/endpointslice as well ..

Is there any value in having metrics be a separate module? It's only really used by the reconciler and doesn't seem like it can be reused anywhere else. This would let us reduce the API surface substantially.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are a bunch of /util functions that are only used within k8s.io/endpointslice (incl. metrics and topologycache) but they're part of the public API. Instead of flattening, maybe a better approach is to move those functions into /internal instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

printer.Fprintf(hasher, "%#v", objectToWrite)
}

func IsPodReady(pod *v1.Pod) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we flatten the relevant utils into k8s.io/endpointslice, then this can be made private.

Copy link
Member

@robscott robscott left a comment

Choose a reason for hiding this comment

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

Thanks @mskrocki! Agree with all of the comments from @akhilles, added a few tiny ones as well. One other note, I think this PR would benefit from a release note. I think it's worth highlighting that a new staging repo has been created for the EndpointSlice reconciler.

staging/src/k8s.io/endpointslice/OWNERS Outdated Show resolved Hide resolved
staging/src/k8s.io/endpointslice/OWNERS Outdated Show resolved Hide resolved
@@ -38,10 +38,10 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
endpointsliceutil "k8s.io/endpointslice/util/endpointslice"
Copy link
Member

Choose a reason for hiding this comment

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

It's unfortunate that the EndpointSlice reconciler library is not sufficiently generic to be used by the EndpointSlice Mirroring controller. Although it's out of scope for this PR, it would probably be good to document somewhere, either in the EndpointSlice mirroring controller or in the new EndpointSlice staging lib why that is. I believe it comes down to the fact that the reconciler in the EndpointSlice mirroring controller has a 1:1 mapping between Service/Endpoints and EndpointSlice, which results in a simpler implementation that the EndpointSlice staging lib.

Now that the code is in a place that it could be shared, we probably want to at least describe why it's not currently shared, and state that contributions to move towards the shared code being used by the mirroring controller would be welcome.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure it is the right place, but added above to the README.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Jun 30, 2023
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. area/release-eng Issues or PRs related to the Release Engineering subproject sig/release Categorizes an issue or PR as relevant to SIG Release. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 30, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 30, 2023
@@ -62,7 +61,7 @@ func GetPodServiceMemberships(serviceLister v1listers.ServiceLister, pod *v1.Pod
// if the service has a nil selector this means selectors match nothing, not everything.
continue
}
key, err := controller.KeyFunc(service)
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(service)
Copy link
Member

Choose a reason for hiding this comment

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

Interesting, I think that this is not needed at all, but I leave this just as a comment to not forget and revisit later https://github.com/kubernetes/kubernetes/pull/84280/files#r1247603063, no action required

}

// IsPodReady returns true if Pods Ready condition is true
// copied from k8s.io/kubernetes/pkg/api/v1/pod
Copy link
Member

Choose a reason for hiding this comment

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

@thockin @BenTheElder do you know some magic to keep these things in sync?
some linter maybe?

Copy link
Member

Choose a reason for hiding this comment

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

no, I don't have a good answer. Most of them are API based, and we won't intentionally break that, so it's another case "a little copy is better than a little dep", probably.

@aojea
Copy link
Member

aojea commented Jun 30, 2023

pull-kubernetes-verify
pull-publishing-bot-validate

jobs failures are legit, something with the rules and restrictions, I'm not very familiar with this to be able to pinpoint the problem

2023/06/30 02:48:09 Inspecting imports under ./vendor/k8s.io/endpointslice/...
2023/06/30 02:48:10 - validating imports for 4 packages in the tree
2023/06/30 02:48:10 -- found forbidden imports for k8s.io/kubernetes/vendor/k8s.io/endpointslice:
2023/06/30 02:48:10 --- k8s.io/endpointslice/metrics
2023/06/30 02:48:10 --- k8s.io/endpointslice/topologycache
2023/06/30 02:48:10 --- k8s.io/endpointslice/util
2023/06/30 02:48:10 -- found forbidden imports for k8s.io/kubernetes/vendor/k8s.io/endpointslice/metrics:
2023/06/30 02:48:10 --- k8s.io/endpointslice/util
I0630 02:05:23.138769    1629 rules.go:98] loading rules file : /home/prow/go/src/k8s.io/kubernetes/staging/publishing/rules.yaml
I0[6](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/118953/pull-publishing-bot-validate/1674599288581132288#1:build-log.txt%3A6)30 02:05:23.145222    1629 rules.go:134] validating repository order
I0630 02:05:23.145436    1629 rules.go:156] validating go versions
F0630 02:05:23.14560[7](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/118953/pull-publishing-bot-validate/1674599288581132288#1:build-log.txt%3A7)    1629 main.go:41] Invalid rules file "/home/prow/go/src/k[8](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/118953/pull-publishing-bot-validate/1674599288581132288#1:build-log.txt%3A8)s.io/kubernetes/staging/publishing/rules.yaml": validation errors:
- unknown dependency "klog" in repository rules of "endpointslice"
- unknown dependency "utils" in repository rules of "endpointslice"

/test pull-kubernetes-node-e2e-containerd

the rest looks pretty nice, right?


// EndpointReady returns true if an Endpoint has the Ready condition set to
// true.
func EndpointReady(endpoint discovery.Endpoint) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be a private function? This shouldn't really be part of the public API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is used in the reconciler tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can it be private and copied to the call sites? It's a fairly trivial function. EndpointReady really has nothing to do with topologycache.

pkg/controller/endpointslice/endpointslice_controller.go Outdated Show resolved Hide resolved
@@ -85,7 +85,7 @@ func NewPortMapKey(endpointPorts []discovery.EndpointPort) PortMapKey {
// DeepHashObjectToString creates a unique hash string from a go object.
func DeepHashObjectToString(objectToWrite interface{}) string {
Copy link
Contributor

@akhilles akhilles Jul 6, 2023

Choose a reason for hiding this comment

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

It looks like k8s.io/endpointslice/topologycache no longer depends on k8s.io/endpointslice/util, and only k8s.io/endpointslice/metrics does. But now I'm wondering whether metrics should be flattened into k8s.io/endpointslice as well ..

Is there any value in having metrics be a separate module? It's only really used by the reconciler and doesn't seem like it can be reused anywhere else. This would let us reduce the API surface substantially.

pkg/controller/util/endpoint/OWNERS Show resolved Hide resolved
@@ -354,7 +355,7 @@ func (c *Controller) syncService(key string) error {

esLabelSelector := labels.Set(map[string]string{
discovery.LabelServiceName: service.Name,
discovery.LabelManagedBy: controllerName,
discovery.LabelManagedBy: c.reconciler.GetControllerName(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can use controllerName directly here. Would eliminate the need for the GetControllerName function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to expose controllerName.


// ManagedByChanged returns true if one of the provided EndpointSlices is
// managed by the EndpointSlice controller while the other is not.
func (r *Reconciler) ManagedByChanged(endpointSlice1, endpointSlice2 *discovery.EndpointSlice) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be moved to pkg/controller/endpointslice/endpointslice_controller.go and made private. It's only used there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you want to have that function as library, to identify if the particular object is managed by this controller.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, I can see how this can be useful for external consumers


// ManagedByController returns true if the controller of the provided
// EndpointSlices is the EndpointSlice controller.
func (r *Reconciler) ManagedByController(endpointSlice *discovery.EndpointSlice) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above. Can be moved to pkg/controller/endpointslice/endpointslice_controller.go and made private.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same comment as above, you want to have that function as library, to identify if the particular object is managed by this controller.

Copy link
Member

Choose a reason for hiding this comment

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

agree with Maciej

@mskrocki
Copy link
Contributor Author

/test pull-kubernetes-integration

@mskrocki
Copy link
Contributor Author

/assign @robscott

@mskrocki
Copy link
Contributor Author

/test pull-kubernetes-unit

@mskrocki
Copy link
Contributor Author

/test pull-kubernetes-unit

@aojea
Copy link
Member

aojea commented Jul 13, 2023

failure is legit

go: downloading gopkg.in/yaml.v2 v2.4.0
I0711 18:12:19.881974    1614 rules.go:98] loading rules file : /home/prow/go/src/k8s.io/kubernetes/staging/publishing/rules.yaml
I0711 18:12:19.888[5](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/118953/pull-publishing-bot-validate/1678828898579648512#1:build-log.txt%3A5)07    1[6](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/118953/pull-publishing-bot-validate/1678828898579648512#1:build-log.txt%3A6)14 rules.go:134] validating repository order
I0[7](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/118953/pull-publishing-bot-validate/1678828898579648512#1:build-log.txt%3A7)11 1[8](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/118953/pull-publishing-bot-validate/1678828898579648512#1:build-log.txt%3A8):12:19.888742    1614 rules.go:156] validating go versions
I0711 18:12:19.888919    1614 validate.go:37] validating directories exist in the kubernetes branch
E0711 18:12:20.540731    1614 main.go:46] Error : endpointslice not found in branch master
F0711 18:12:20.54132[9](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/118953/pull-publishing-bot-validate/1678828898579648512#1:build-log.txt%3A9)    1614 main.go:48] Invalid rules file "/home/prow/go/src/k8s.io/kubernetes/staging/publishing/rules.yaml"

@aojea
Copy link
Member

aojea commented Jul 13, 2023

/lgtm
/approve

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

LGTM label has been added.

Git tree hash: b97ff1a21421fe675f898cf34e46eaa9e6534853

Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

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

Thanks!

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aojea, mskrocki, thockin

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 13, 2023
@k8s-triage-robot
Copy link

The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass.

This bot retests PRs for certain kubernetes repos according to the following rules:

  • The PR does have any do-not-merge/* labels
  • The PR does not have the needs-ok-to-test label
  • The PR is mergeable (does not have a needs-rebase label)
  • The PR is approved (has cncf-cla: yes, lgtm, approved labels)
  • The PR is failing tests required for merge

You can:

/retest

@k8s-ci-robot
Copy link
Contributor

@mskrocki: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-publishing-bot-validate 43b509d link false /test pull-publishing-bot-validate

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot merged commit 5c72df7 into kubernetes:master Jul 14, 2023
13 of 14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.28 milestone Jul 14, 2023
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. area/dependency Issues or PRs related to dependency changes area/release-eng Issues or PRs related to the Release Engineering subproject cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/network Categorizes an issue or PR as relevant to SIG Network. sig/release Categorizes an issue or PR as relevant to SIG Release. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants