Skip to content

Commit

Permalink
Replace dummy client with fake client
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Iwai <[email protected]>
  • Loading branch information
tenzen-y committed May 31, 2023
1 parent 93c758c commit 73d9f4f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 82 deletions.
2 changes: 0 additions & 2 deletions docs/api/kubeflow.org_v1_generated.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ Package v1 is the v1 version of the API.

Package v1 contains API Schema definitions for the kubeflow.org v1 API group

Package util provides various helper routines.

.Resource Types
- xref:{anchor_prefix}-github-com-kubeflow-training-operator-pkg-apis-kubeflow-org-v1-mpijob[$$MPIJob$$]
- xref:{anchor_prefix}-github-com-kubeflow-training-operator-pkg-apis-kubeflow-org-v1-mpijoblist[$$MPIJobList$$]
Expand Down
23 changes: 10 additions & 13 deletions pkg/reconciler.v1/common/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package common_test

import (
"context"
"reflect"
"strings"
"testing"
Expand All @@ -25,7 +26,9 @@ import (
test_utilv1 "github.com/kubeflow/training-operator/test_job/test_util/v1"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func TestCreateNewService(t *testing.T) {
Expand Down Expand Up @@ -80,21 +83,15 @@ func TestCreateNewService(t *testing.T) {
t.Errorf("Got error when CreateNewService: %v", err)
continue
}

found := false
for _, obj := range testReconciler.DC.Cache {
if obj.GetName() == c.expectedService.GetName() && obj.GetNamespace() == c.expectedService.GetNamespace() {
found = true
svcCreated := obj.(*corev1.Service)
svcExpected := c.expectedService
if !reflect.DeepEqual(svcExpected.Spec, svcCreated.Spec) {
t.Errorf("Spec mismatch for service %s/%s", svcExpected.GetNamespace(), svcExpected.GetName())
}
var got corev1.Service
if err = testReconciler.FC.Get(context.Background(), client.ObjectKeyFromObject(c.expectedService), &got, &client.GetOptions{}); err != nil {
if apierrors.IsNotFound(err) {
t.Errorf("Cannot find Service %s/%s created", c.expectedService.GetNamespace(), c.expectedService.GetName())
}
t.Errorf("Got error when Get service: %v", err)
}

if !found {
t.Errorf("Cannot find Service %s/%s created", c.expectedService.GetNamespace(), c.expectedService.GetName())
if !reflect.DeepEqual(c.expectedService.Spec, got.Spec) {
t.Errorf("Spec mismatch for service %s/%s", c.expectedService.GetNamespace(), c.expectedService.GetName())
}
}
}
60 changes: 0 additions & 60 deletions test_job/reconciler.v1/test_job/dummy_client.go

This file was deleted.

15 changes: 8 additions & 7 deletions test_job/reconciler.v1/test_job/test_job_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/log"
)

Expand All @@ -24,7 +25,7 @@ type TestReconciler struct {
common_reconciler.VolcanoReconciler
common_reconciler.JobReconciler

DC *DummyClient
FC client.Client
Job *v1.TestJob
Pods []*corev1.Pod
Services []*corev1.Service
Expand All @@ -36,23 +37,23 @@ func NewTestReconciler() *TestReconciler {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(v1.AddToScheme(scheme))

dummy_client := &DummyClient{}
fakeClient := fake.NewClientBuilder().WithScheme(clientgoscheme.Scheme).Build()

r := &TestReconciler{
DC: dummy_client,
FC: fakeClient,
}

// Generate Bare Components
jobR := common_reconciler.BareJobReconciler(dummy_client)
jobR := common_reconciler.BareJobReconciler(fakeClient)
jobR.OverrideForJobInterface(r, r, r, r)

podR := common_reconciler.BarePodReconciler(dummy_client)
podR := common_reconciler.BarePodReconciler(fakeClient)
podR.OverrideForPodInterface(r, r, r)

svcR := common_reconciler.BareServiceReconciler(dummy_client)
svcR := common_reconciler.BareServiceReconciler(fakeClient)
svcR.OverrideForServiceInterface(r, r, r)

gangR := common_reconciler.BareVolcanoReconciler(dummy_client, nil, false)
gangR := common_reconciler.BareVolcanoReconciler(fakeClient, nil, false)
gangR.OverrideForGangSchedulingInterface(r)

Log := log.Log
Expand Down

0 comments on commit 73d9f4f

Please sign in to comment.