Skip to content

Update service tests to use discoveryv1.EndpointSlice instead of deprecated core.Endpoints #20679

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Victorthedev
Copy link

This PR addresses the deprecation warnings for core.Endpoints which is deprecated in Kubernetes v1.33+ in favor of discoveryv1.EndpointSlice.

Changes:

  • Replaced all core.Endpoints references with discoveryv1.EndpointSlice
  • Updated mock interfaces and test data structures to use the new API
  • Maintained all existing test functionality and assertions
  • No behavioral changes - just API modernization

Fixes #20677

discoveryv1.EndpointSlice instead of deprecated core.Endpoints

This PR addresses the deprecation warnings for core.Endpoints which is deprecated in Kubernetes v1.33+ in favor of discoveryv1.EndpointSlice.

Changes:
- Replaced all core.Endpoints references with discoveryv1.EndpointSlice
- Updated mock interfaces and test data structures to use the new API
- Maintained all existing test functionality and assertions
- No behavioral changes - just API modernization

Fixes kubernetes#20677
@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Apr 29, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Victorthedev
Once this PR has been reviewed and has the lgtm label, please assign prezha for approval. For more information see the Code Review Process.

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

Copy link

linux-foundation-easycla bot commented Apr 29, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Apr 29, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @Victorthedev!

It looks like this is your first PR to kubernetes/minikube 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/minikube has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 29, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @Victorthedev. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 29, 2025
@minikube-bot
Copy link
Collaborator

Can one of the admins verify this patch?

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Apr 30, 2025
@medyagh
Copy link
Member

medyagh commented Apr 30, 2025

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 30, 2025
@minikube-pr-bot

This comment has been minimized.

Copy link
Member

@medyagh medyagh left a comment

Choose a reason for hiding this comment

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

@Victorthedev thank you for this PR, do you mind fixing the lint issue ?

you can run "make lint" to see the errors

pkg/minikube/service/service.go:1: : # k8s.io/minikube/pkg/minikube/service [k8s.io/minikube/pkg/minikube/service.test]
Error: pkg/minikube/service/service_test.go:191:9: cannot use &MockDiscoveryV1Interface{…} (value of type *MockDiscoveryV1Interface) as "k8s.io/client-go/kubernetes/typed/discovery/v1".DiscoveryV1Interface value in return statement: *MockDiscoveryV1Interface does not implement "k8s.io/client-go/kubernetes/typed/discovery/v1".DiscoveryV1Interface (wrong type for method RESTClient)
		have RESTClient() interface{}
		want RESTClient() "k8s.io/client-go/rest".Interface
Error: pkg/minikube/service/service_test.go:339:3: unknown field endpointsMap in struct literal of type MockCoreClient
Error: pkg/minikube/service/service_test.go:339:17: undefined: endpointNamespaces
Error: pkg/minikube/service/service_test.go:5[14](https://github.com/kubernetes/minikube/actions/runs/14724184141/job/41444930650?pr=20679#step:6:15):5: unknown field endpointsMap in struct literal of type MockClientGetter
Error: pkg/minikube/service/service_test.go:514:19: undefined: endpointNamespaces
Error: pkg/minikube/service/service_test.go:582:5: unknown field endpointsMap in struct literal of type MockClientGetter
Error: pkg/minikube/service/service_test.go:582:19: undefined: endpointNamespaces
Error: pkg/minikube/service/service_test.go:719:5: unknown field endpointsMap in struct literal of type MockClientGetter
Error: pkg/minikube/service/service_test.go:719:19: undefined: endpointNamespaces
Error: pkg/minikube/service/service_test.go:769:19: undefined: endpointNamespaces
Error: pkg/minikube/service/service_test.go:769:[19](https://github.com/kubernetes/minikube/actions/runs/14724184141/job/41444930650?pr=20679#step:6:20): too many errors (typecheck)

@Victorthedev
Copy link
Author

@medyagh on it!

- make lint now runs without error
…lient initialization

This commit addresses a series of nil pointer dereference panics in the test suite for pkg/minikube/service, ensuring all tests pass reliably. The changes focus on improving the initialization of mock Kubernetes clients to prevent nil pointer dereferences in the fake client's `Invokes` method. The fixes include:

1. **TestPrintURLsForService/throw_error_without_template Panic**:
   - Issue: A panic occurred due to an uninitialized `FakeCoreV1` field in `MockCoreClient`, causing a nil pointer dereference when `Services().Get` was called.
   - Fix: Initialized `FakeCoreV1` with `Fake: &testing_fake.Fake{}` in the `TestPrintURLsForService` setup, ensuring the fake client is properly configured.

2. **TestGetServiceURLs/correctly_return_serviceURLs Panic**:
   - Issue: A similar panic occurred in `GetServiceURLs` due to the `FakeCoreV1` field not being initialized in `MockCoreClient` returned by `MockClientGetter`.
   - Fix: Updated `MockClientGetter.GetCoreClient` to initialize `FakeCoreV1` with `Fake: &testing_fake.Fake{}`, ensuring all tests using `MockClientGetter` have a properly initialized client.

3. **TestDeleteSecret/ok Panic**:
   - Issue: A panic occurred in `DeleteSecret` when calling `secrets.Delete` for the `foo` namespace, as `secretsNamespaces` lacked an entry for `foo`, returning a nil interface.
   - Fix: Added a `MockSecretInterface` for the `foo` namespace to `secretsNamespaces`, ensuring `client.Secrets("foo")` returns a valid interface. Updated `initializeMockObjects` to verify the `Fake` field for the new entry.

Additional improvements:
- Ensured `initializeMockObjects` consistently initializes `Fake` fields across all mock interfaces (`serviceNamespaces`, `serviceNamespaceOther`, `endpointSliceNamespaces`, and `secretsNamespaces`).
- Verified that all test setups align with mock configurations, preventing similar issues in other tests (e.g., `TestCreateSecret`, `TestWaitAndMaybeOpenService`).
- Confirmed no linting issues with `make lint` and validated all tests pass with `go test -v ./pkg/minikube/service/...`.
@k8s-ci-robot
Copy link
Contributor

Keywords which can automatically close issues and at(@) or hashtag(#) mentions are not allowed in commit messages.

The list of commits with invalid commit messages:

  • 4a5824b Update service tests to use-

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

@Victorthedev
Copy link
Author

@medyagh fixed the lint issue and nil pointer dereference panics in the test suite for pkg/minikube/service

@Victorthedev Victorthedev requested a review from medyagh May 2, 2025 13:25
@minikube-pr-bot
Copy link

kvm2 driver with docker runtime

+----------------+----------+---------------------+
|    COMMAND     | MINIKUBE | MINIKUBE (PR 20679) |
+----------------+----------+---------------------+
| minikube start | 54.5s    | 55.5s               |
| enable ingress | 19.6s    | 19.1s               |
+----------------+----------+---------------------+

Times for minikube start: 56.0s 54.3s 54.9s 53.2s 54.1s
Times for minikube (PR 20679) start: 58.2s 54.8s 54.3s 56.2s 54.3s

Times for minikube ingress: 18.7s 19.1s 20.7s 20.1s 19.2s
Times for minikube (PR 20679) ingress: 19.7s 16.7s 19.7s 19.1s 20.2s

docker driver with docker runtime

+----------------+----------+---------------------+
|    COMMAND     | MINIKUBE | MINIKUBE (PR 20679) |
+----------------+----------+---------------------+
| minikube start | 25.7s    | 24.8s               |
| enable ingress | 13.2s    | 13.1s               |
+----------------+----------+---------------------+

Times for minikube start: 26.5s 24.3s 24.1s 26.6s 26.8s
Times for minikube (PR 20679) start: 23.8s 23.8s 24.0s 26.2s 26.3s

Times for minikube ingress: 12.4s 13.4s 13.4s 13.4s 13.4s
Times for minikube (PR 20679) ingress: 12.4s 13.4s 13.4s 13.9s 12.4s

docker driver with containerd runtime

+----------------+----------+---------------------+
|    COMMAND     | MINIKUBE | MINIKUBE (PR 20679) |
+----------------+----------+---------------------+
| minikube start | 23.4s    | 25.1s               |
| enable ingress | 23.1s    | 22.8s               |
+----------------+----------+---------------------+

Times for minikube start: 22.2s 26.4s 23.0s 22.5s 22.9s
Times for minikube (PR 20679) start: 27.3s 24.0s 23.4s 25.5s 25.2s

Times for minikube ingress: 22.9s 22.9s 22.8s 23.9s 22.9s
Times for minikube (PR 20679) ingress: 22.8s 22.8s 22.8s 22.8s 22.8s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

Lint: core.Endpoints is deprecated: Use discoveryv1.EndpointSlice. (staticcheck)
5 participants