-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(trial): Refactor trial controller and add basic test cases (#528)
* feat(trial): Add test * vendor: Update Signed-off-by: Ce Gao <[email protected]> * feat(trial): Add test cases Signed-off-by: Ce Gao <[email protected]> * chore: Add mockgen and test crd Signed-off-by: Ce Gao <[email protected]> * fix: Update test Signed-off-by: Ce Gao <[email protected]> * fix: Update Signed-off-by: Ce Gao <[email protected]> * fix: Fix export path Signed-off-by: Ce Gao <[email protected]> * fix: Introduce the dependency Signed-off-by: Ce Gao <[email protected]> * feat: Add status handler Signed-off-by: Ce Gao <[email protected]> * Fix: Use 1.0.7 Signed-off-by: Ce Gao <[email protected]> * fix: Fix v1alpha1 Signed-off-by: Ce Gao <[email protected]> * fix: Update deploy scripts Signed-off-by: Ce Gao <[email protected]> * chore: Rebase master Signed-off-by: Ce Gao <[email protected]>
- Loading branch information
1 parent
0712177
commit bc343ff
Showing
31 changed files
with
1,567 additions
and
111 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: apiextensions.k8s.io/v1beta1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
name: trials.kubeflow.org | ||
spec: | ||
additionalPrinterColumns: | ||
- JSONPath: .status.conditions[-1:].type | ||
name: Status | ||
type: string | ||
- JSONPath: .metadata.creationTimestamp | ||
name: Age | ||
type: date | ||
group: kubeflow.org | ||
version: v1alpha2 | ||
scope: Namespaced | ||
subresources: | ||
status: {} | ||
names: | ||
kind: Trial | ||
singular: trial | ||
plural: trials |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package trial | ||
|
||
import ( | ||
"context" | ||
|
||
trialsv1alpha2 "github.com/kubeflow/katib/pkg/api/operators/apis/trial/v1alpha2" | ||
) | ||
|
||
type updateStatusFunc func(instance *trialsv1alpha2.Trial) error | ||
|
||
func (r *ReconcileTrial) updateStatus(instance *trialsv1alpha2.Trial) error { | ||
err := r.Status().Update(context.TODO(), instance) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
79 changes: 79 additions & 0 deletions
79
pkg/controller/v1alpha2/trial/trial_controller_suite_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package trial | ||
|
||
import ( | ||
stdlog "log" | ||
"os" | ||
"path/filepath" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/onsi/gomega" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
"k8s.io/client-go/rest" | ||
"sigs.k8s.io/controller-runtime/pkg/envtest" | ||
"sigs.k8s.io/controller-runtime/pkg/manager" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
|
||
"github.com/kubeflow/katib/pkg/api/operators/apis" | ||
) | ||
|
||
var cfg *rest.Config | ||
|
||
func TestMain(m *testing.M) { | ||
t := &envtest.Environment{ | ||
CRDDirectoryPaths: []string{ | ||
filepath.Join("..", "..", "..", "..", "manifests", "v1alpha2", "katib-controller"), | ||
filepath.Join("..", "..", "..", "..", "test", "unit", "v1alpha2", "crds"), | ||
}, | ||
} | ||
apis.AddToScheme(scheme.Scheme) | ||
|
||
var err error | ||
if cfg, err = t.Start(); err != nil { | ||
stdlog.Fatal(err) | ||
} | ||
|
||
code := m.Run() | ||
t.Stop() | ||
os.Exit(code) | ||
} | ||
|
||
// SetupTestReconcile returns a reconcile.Reconcile implementation that delegates to inner and | ||
// writes the request to requests after Reconcile is finished. | ||
func SetupTestReconcile(inner reconcile.Reconciler) (reconcile.Reconciler, chan reconcile.Request) { | ||
requests := make(chan reconcile.Request) | ||
fn := reconcile.Func(func(req reconcile.Request) (reconcile.Result, error) { | ||
result, err := inner.Reconcile(req) | ||
requests <- req | ||
return result, err | ||
}) | ||
return fn, requests | ||
} | ||
|
||
// StartTestManager adds recFn | ||
func StartTestManager(mgr manager.Manager, g *gomega.GomegaWithT) (chan struct{}, *sync.WaitGroup) { | ||
stop := make(chan struct{}) | ||
wg := &sync.WaitGroup{} | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
g.Expect(mgr.Start(stop)).NotTo(gomega.HaveOccurred()) | ||
}() | ||
return stop, wg | ||
} |
Oops, something went wrong.