Skip to content

Commit

Permalink
Refactoring TF operator code (#767)
Browse files Browse the repository at this point in the history
* Refactoring TF operator code

* Fixing go imports

* Restructuring files into separate packages
  • Loading branch information
johnugeorge authored and k8s-ci-robot committed Aug 3, 2018
1 parent 90259e7 commit bb430c9
Show file tree
Hide file tree
Showing 25 changed files with 607 additions and 479 deletions.
2 changes: 1 addition & 1 deletion cmd/tf-operator.v2/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
tfjobclientset "github.com/kubeflow/tf-operator/pkg/client/clientset/versioned"
"github.com/kubeflow/tf-operator/pkg/client/clientset/versioned/scheme"
tfjobinformers "github.com/kubeflow/tf-operator/pkg/client/informers/externalversions"
controller "github.com/kubeflow/tf-operator/pkg/controller.v2"
controller "github.com/kubeflow/tf-operator/pkg/controller.v2/tfcontroller"
"github.com/kubeflow/tf-operator/pkg/util/signals"
"github.com/kubeflow/tf-operator/pkg/version"
)
Expand Down
5 changes: 2 additions & 3 deletions pkg/control/pod_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/testapi"

"github.com/kubeflow/tf-operator/pkg/generator"
"github.com/kubeflow/tf-operator/pkg/util/testutil"
)

Expand All @@ -58,7 +57,7 @@ func TestCreatePods(t *testing.T) {
testName := "pod-name"
podTemplate := testutil.NewTFReplicaSpecTemplate()
podTemplate.Name = testName
podTemplate.Labels = generator.GenLabels(tfJob.Name)
podTemplate.Labels = testutil.GenLabels(tfJob.Name)
podTemplate.SetOwnerReferences([]metav1.OwnerReference{})

// Make sure createReplica sends a POST to the apiserver with a pod from the controllers pod template
Expand All @@ -67,7 +66,7 @@ func TestCreatePods(t *testing.T) {

expectedPod := v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Labels: generator.GenLabels(tfJob.Name),
Labels: testutil.GenLabels(tfJob.Name),
Name: testName,
},
Spec: podTemplate.Spec,
Expand Down
7 changes: 3 additions & 4 deletions pkg/control/service_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
utiltesting "k8s.io/client-go/util/testing"
"k8s.io/kubernetes/pkg/api/testapi"

"github.com/kubeflow/tf-operator/pkg/generator"
"github.com/kubeflow/tf-operator/pkg/util/testutil"
)

Expand Down Expand Up @@ -67,7 +66,7 @@ func TestCreateService(t *testing.T) {

expectedService := v1.Service{
ObjectMeta: metav1.ObjectMeta{
Labels: generator.GenLabels(tfJob.Name),
Labels: testutil.GenLabels(tfJob.Name),
Name: testName,
Namespace: ns,
},
Expand Down Expand Up @@ -107,15 +106,15 @@ func TestCreateServicesWithControllerRef(t *testing.T) {
service := testutil.NewBaseService(testName, tfJob, t)
service.SetOwnerReferences([]metav1.OwnerReference{})

ownerRef := generator.GenOwnerReference(tfJob)
ownerRef := testutil.GenOwnerReference(tfJob)

// Make sure createReplica sends a POST to the apiserver with a pod from the controllers pod template
err := serviceControl.CreateServicesWithControllerRef(ns, service, tfJob, ownerRef)
assert.NoError(t, err, "unexpected error: %v", err)

expectedService := v1.Service{
ObjectMeta: metav1.ObjectMeta{
Labels: generator.GenLabels(tfJob.Name),
Labels: testutil.GenLabels(tfJob.Name),
Name: testName,
Namespace: ns,
OwnerReferences: []metav1.OwnerReference{*ownerRef},
Expand Down
19 changes: 9 additions & 10 deletions pkg/control/service_ref_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"k8s.io/apimachinery/pkg/types"

tfv1alpha2 "github.com/kubeflow/tf-operator/pkg/apis/tensorflow/v1alpha2"
"github.com/kubeflow/tf-operator/pkg/generator"
"github.com/kubeflow/tf-operator/pkg/util/testutil"
)

Expand All @@ -42,13 +41,13 @@ func TestClaimServices(t *testing.T) {
func() test {
tfJob := testutil.NewTFJob(1, 0)
tfJobLabelSelector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
MatchLabels: generator.GenLabels(tfJob.Name),
MatchLabels: testutil.GenLabels(tfJob.Name),
})
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
testService := testutil.NewBaseService("service2", tfJob, nil)
testService.Labels[generator.LabelGroupName] = "testing"
testService.Labels[testutil.LabelGroupName] = "testing"

return test{
name: "Claim services with correct label",
Expand All @@ -64,7 +63,7 @@ func TestClaimServices(t *testing.T) {
func() test {
controller := testutil.NewTFJob(1, 0)
controllerLabelSelector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
MatchLabels: generator.GenLabels(controller.Name),
MatchLabels: testutil.GenLabels(controller.Name),
})
if err != nil {
t.Errorf("Unexpected error: %v", err)
Expand All @@ -90,7 +89,7 @@ func TestClaimServices(t *testing.T) {
func() test {
controller := testutil.NewTFJob(1, 0)
controllerLabelSelector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
MatchLabels: generator.GenLabels(controller.Name),
MatchLabels: testutil.GenLabels(controller.Name),
})
if err != nil {
t.Errorf("Unexpected error: %v", err)
Expand All @@ -114,7 +113,7 @@ func TestClaimServices(t *testing.T) {
func() test {
controller := testutil.NewTFJob(1, 0)
controllerLabelSelector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
MatchLabels: generator.GenLabels(controller.Name),
MatchLabels: testutil.GenLabels(controller.Name),
})
if err != nil {
t.Errorf("Unexpected error: %v", err)
Expand All @@ -136,14 +135,14 @@ func TestClaimServices(t *testing.T) {
func() test {
controller := testutil.NewTFJob(1, 0)
controllerLabelSelector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
MatchLabels: generator.GenLabels(controller.Name),
MatchLabels: testutil.GenLabels(controller.Name),
})
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
controller.UID = types.UID(controllerUID)
testService2 := testutil.NewBaseService("service2", controller, t)
testService2.Labels[generator.LabelGroupName] = "testing"
testService2.Labels[testutil.LabelGroupName] = "testing"
return test{
name: "Controller releases claimed services when selector doesn't match",
manager: NewServiceControllerRefManager(&FakeServiceControl{},
Expand All @@ -158,15 +157,15 @@ func TestClaimServices(t *testing.T) {
func() test {
controller := testutil.NewTFJob(1, 0)
controllerLabelSelector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
MatchLabels: generator.GenLabels(controller.Name),
MatchLabels: testutil.GenLabels(controller.Name),
})
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
controller.UID = types.UID(controllerUID)
testService1 := testutil.NewBaseService("service1", controller, t)
testService2 := testutil.NewBaseService("service2", controller, t)
testService2.Labels[generator.LabelGroupName] = "testing"
testService2.Labels[testutil.LabelGroupName] = "testing"
now := metav1.Now()
testService1.DeletionTimestamp = &now
testService2.DeletionTimestamp = &now
Expand Down
Loading

0 comments on commit bb430c9

Please sign in to comment.