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

RHOAIENG-17634: ref(odh-nbc/tests): create Gomega custom matcher for comparing CRs in kubeflow notebooks tests #502

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jiridanek
Copy link
Member

@jiridanek jiridanek commented Jan 10, 2025

https://issues.redhat.com/browse/RHOAIENG-17634

Description

This is the initial refactor to use a new custom matcher. The matcher has no new features compared to the old way.

I will do the meaningful-diffs part as a next PR (under the same Jira number). Currently (same as before) the diff also includes irrelevant parts of the struct under comparison.

How Has This Been Tested?

Here's how a failure is reported

By("By checking that the controller has restored the Route spec")
Eventually(func() (string, error) {
key := types.NamespacedName{Name: Name, Namespace: Namespace}
err := cli.Get(ctx, key, route)
if err != nil {
return "", err
}
return route.Spec.To.Name, nil
}, duration, interval).Should(Equal(Name))
Expect(CompareNotebookRoutes(*route, expectedRoute)).Should(BeTrueBecause(cmp.Diff(*route, expectedRoute)))

    Should reconcile the Route when modified [It]
    /Users/jdanek/IdeaProjects/kubeflow/components/odh-notebook-controller/controllers/notebook_controller_test.go:105

    Expected
        v1.Route{TypeMeta:v1.TypeMeta{Kind:"", APIVersion:""}, ObjectMeta:v1.ObjectMeta{Name:"test-notebook", GenerateName:"", Namespace:"default", SelfLink:"", UID:"bd00712a-9bff-4c3f-819e-525f29891761", ResourceVersion:"211", Generation:3, CreationTimestamp:time.Date(2025, time.January, 10, 13, 40, 31, 0, time.Local), DeletionTimestamp:<nil>, DeletionGracePeriodSeconds:(*int64)(nil), Labels:map[string]string{"notebook-name":"test-notebook"}, Annotations:map[string]string(nil), OwnerReferences:[]v1.OwnerReference{v1.OwnerReference{APIVersion:"kubeflow.org/v1", Kind:"Notebook", Name:"test-notebook", UID:"bec15653-6c39-4e01-b93e-5bdca8c332e8", Controller:(*bool)(0x1400037e8de), BlockOwnerDeletion:(*bool)(0x1400037e8dd)}}, Finalizers:[]string(nil), ManagedFields:[]v1.ManagedFieldsEntry{v1.ManagedFieldsEntry{Manager:"controllers.test", Operation:"Update", APIVersion:"route.openshift.io/v1", Time:time.Date(2025, time.January, 10, 13, 40, 37, 0, time.Local), FieldsType:"FieldsV1", FieldsV1:(*v1.FieldsV1)(0x14000fec1c8), Subresource:""}}}, Spec:v1.RouteSpec{Host:"", Subdomain:"", Path:"", To:v1.RouteTargetReference{Kind:"Service", Name:"test-notebook", Weight:(*int32)(0x1400037e948)}, AlternateBackends:[]v1.RouteTargetReference(nil), Port:(*v1.RoutePort)(0x14000034d00), TLS:(*v1.TLSConfig)(0x140003aba40), WildcardPolicy:"None"}, Status:v1.RouteStatus{Ingress:[]v1.RouteIngress{}}}
    to compare identical to
        v1.Route{TypeMeta:v1.TypeMeta{Kind:"", APIVersion:""}, ObjectMeta:v1.ObjectMeta{Name:"test-notebook", GenerateName:"", Namespace:"default", SelfLink:"", UID:"", ResourceVersion:"", Generation:0, CreationTimestamp:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), DeletionTimestamp:<nil>, DeletionGracePeriodSeconds:(*int64)(nil), Labels:map[string]string{"notebook-name":"test-notebook"}, Annotations:map[string]string(nil), OwnerReferences:[]v1.OwnerReference(nil), Finalizers:[]string(nil), ManagedFields:[]v1.ManagedFieldsEntry(nil)}, Spec:v1.RouteSpec{Host:"", Subdomain:"", Path:"", To:v1.RouteTargetReference{Kind:"No Such Service", Name:"test-notebook", Weight:(*int32)(0x1400000ee90)}, AlternateBackends:[]v1.RouteTargetReference(nil), Port:(*v1.RoutePort)(0x14000590340), TLS:(*v1.TLSConfig)(0x1400005c600), WildcardPolicy:"None"}, Status:v1.RouteStatus{Ingress:[]v1.RouteIngress{}}}
    but it differs in
      v1.Route{
        TypeMeta: {},
        ObjectMeta: v1.ObjectMeta{
                ... // 2 identical fields
                Namespace:                  "default",
                SelfLink:                   "",
    -           UID:                        "bd00712a-9bff-4c3f-819e-525f29891761",
    +           UID:                        "",
    -           ResourceVersion:            "211",
    +           ResourceVersion:            "",
    -           Generation:                 3,
    +           Generation:                 0,
    -           CreationTimestamp:          v1.Time{Time: s"2025-01-10 13:40:31 +0100 CET"},
    +           CreationTimestamp:          v1.Time{},
                DeletionTimestamp:          nil,
                DeletionGracePeriodSeconds: nil,
                Labels:                     {"notebook-name": "test-notebook"},
                Annotations:                nil,
    -           OwnerReferences: []v1.OwnerReference{
    -                   {
    -                           APIVersion:         "kubeflow.org/v1",
    -                           Kind:               "Notebook",
    -                           Name:               "test-notebook",
    -                           UID:                "bec15653-6c39-4e01-b93e-5bdca8c332e8",
    -                           Controller:         &true,
    -                           BlockOwnerDeletion: &true,
    -                   },
    -           },
    +           OwnerReferences: nil,
                Finalizers:      nil,
    -           ManagedFields: []v1.ManagedFieldsEntry{
    -                   {
    -                           Manager:    "controllers.test",
    -                           Operation:  "Update",
    -                           APIVersion: "route.openshift.io/v1",
    -                           Time:       s"2025-01-10 13:40:37 +0100 CET",
    -                           FieldsType: "FieldsV1",
    -                           FieldsV1:   s`{"f:metadata":{"f:labels":{".":{},"f:notebook-name":{}},"f:owner`...,
    -                   },
    -           },
    +           ManagedFields: nil,
        },
        Spec: v1.RouteSpec{
                Host:      "",
                Subdomain: "",
                Path:      "",
                To: v1.RouteTargetReference{
    -                   Kind:   "Service",
    +                   Kind:   "No Such Service",
                        Name:   "test-notebook",
                        Weight: &100,
                },
                AlternateBackends: nil,
                Port:              &{TargetPort: {Type: 1, StrVal: "http-test-notebook"}},
                ... // 2 identical fields
        },
        Status: {Ingress: {}},
      }
    

    /Users/jdanek/IdeaProjects/kubeflow/components/odh-notebook-controller/controllers/notebook_controller_test.go:120

In the above example, the only really relevant part of the diff is

    -                   Kind:   "Service",
    +                   Kind:   "No Such Service",

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • 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

…comparing CRs in kubeflow notebooks tests

This is the initial refactor to use a new custom matcher.
The matcher has no new features compared to the old way.

I will do the meaningful-diffs part as a next PR (under the same Jira number).
@openshift-ci openshift-ci bot requested review from caponetto and dibryant January 10, 2025 12:43
Copy link

openshift-ci bot commented Jan 10, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from jiridanek. 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

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.86%. Comparing base (330d816) to head (a8d721b).

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #502       +/-   ##
===========================================
+ Coverage   55.27%   70.86%   +15.58%     
===========================================
  Files           9        7        -2     
  Lines        2276     1335      -941     
===========================================
- Hits         1258      946      -312     
+ Misses        922      324      -598     
+ Partials       96       65       -31     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants