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

feat(bff): Use envtest for kubernetes testing instead of hardcoded mock #490

Merged
merged 3 commits into from
Nov 1, 2024

Conversation

ederign
Copy link
Member

@ederign ederign commented Oct 18, 2024

Use envtest for kubernetes testing instead of hardcoded mock

Description

This PR starts to use envtest for Kubernetes mocking. It also fixes a minor issue when there are no annotations on the service.

How Has This Been Tested?

make run MOCK_K8S_CLIENT=true MOCK_MR_CLIENT=true and also ran the web app:

Screenshot 2024-10-18 at 11 18 59 AM Screenshot 2024-10-18 at 11 19 24 AM

Merge criteria:

  • All the commits have been signed-off (To pass the DCO check)
  • The commits have meaningful messages; the author will squash them after approval or in case of manual merges will ask to merge with squash.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work.
  • Code changes follow the kubeflow contribution guidelines.

No UI changes.


projectRoot, err := getProjectRoot()
if err != nil {
logger.Error("failed to find project root to locate binaries", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

go vet was failing on this line and the other logger.Error lines due to:

slog.Logger.Error arg "err" should be a string or a slog.Attr (possible missing key or value)

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed! But I don't know why I didn't get this error locally! :P

Comment on lines +69 to +72
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
$(ENVTEST): $(LOCALBIN)
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the run command try to do this if the mock-k8s-client option is passed to the makefile?

If you try to run make run MOCK_K8S_CLIENT=true MOCK_MR_CLIENT=true before the binary is installed you get:

time=2024-10-21T15:23:49.306-04:00 level=ERROR msg="failed to start test environment" error="unable to start control plane itself: failed to start the controlplane. retried 5 times: fork/exec /home/gsulliva/Programming/model-registry/clients/ui/bff/bin/k8s/1.29.0-linux-amd64/etcd: no such file or directory"

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch! Fixed!

description := ""

if service.Annotations != nil {
displayName = service.Annotations["displayName"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this cause a key error if you had annotations but not displayName or description in there?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nop! If the key doesn't exist, it will return an empty string ("").

Copy link
Contributor

@alexcreasy alexcreasy left a comment

Choose a reason for hiding this comment

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

Tested locally, works fine!

Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexcreasy, Griffin-Sullivan

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

@alexcreasy
Copy link
Contributor

/lgtm

@google-oss-prow google-oss-prow bot added the lgtm label Nov 1, 2024
@google-oss-prow google-oss-prow bot merged commit 709a2db into kubeflow:main Nov 1, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants