mirror of
https://github.com/hanzo-ml/katib.git
synced 2026-09-24 00:31:27 +00:00
* upgrade kubebuilder version from v2.3.0 to v3.2.0 * fix envtest for experiment-controller * fix suite test To avoid the `timeout waiting for process kube-apiserver to stop` error, we must use the `context.WithCancel`. Ref: https://github.com/kubernetes-sigs/controller-runtime/issues/1571#issuecomment-945535598 * update Go version to v1.17 in kubeflow-katib-presubmit To avoid the `../../../../pkg/mod/k8s.io/[email protected].2/plugin/pkg/client/auth/exec/metrics.go:21:2: package io/fs is not in GOROOT (/usr/local/go/src/io/fs)` error, we must use Go v1.16 or later, but as described in https://github.com/kubeflow/training-operator/issues/1581, we do not have permission to update `public.ecr.aws/j1r0q0g6/kubeflow-testing:latest` so we need to update it in this.
81 lines
2.2 KiB
Go
81 lines
2.2 KiB
Go
/*
|
|
Copyright 2022 The Kubeflow 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 experiment
|
|
|
|
import (
|
|
"context"
|
|
stdlog "log"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"k8s.io/client-go/kubernetes/scheme"
|
|
"k8s.io/client-go/rest"
|
|
"sigs.k8s.io/controller-runtime/pkg/envtest"
|
|
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
|
|
|
apis "github.com/kubeflow/katib/pkg/apis/controller"
|
|
)
|
|
|
|
var (
|
|
cfg *rest.Config
|
|
ctx context.Context
|
|
cancel context.CancelFunc
|
|
controlPlaneStartTimeout = 60 * time.Second
|
|
controlPlaneStopTimeout = 60 * time.Second
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
// To avoid the `timeout waiting for process kube-apiserver to stop` error,
|
|
// we must use the `context.WithCancel`.
|
|
// Ref: https://github.com/kubernetes-sigs/controller-runtime/issues/1571#issuecomment-945535598
|
|
ctx, cancel = context.WithCancel(context.TODO())
|
|
|
|
t := &envtest.Environment{
|
|
ControlPlaneStartTimeout: controlPlaneStartTimeout,
|
|
ControlPlaneStopTimeout: controlPlaneStopTimeout,
|
|
CRDDirectoryPaths: []string{
|
|
filepath.Join("..", "..", "..", "manifests", "v1beta1", "components", "crd"),
|
|
},
|
|
}
|
|
var err error
|
|
if err = apis.AddToScheme(scheme.Scheme); err != nil {
|
|
stdlog.Fatal(err)
|
|
}
|
|
|
|
if cfg, err = t.Start(); err != nil {
|
|
stdlog.Fatal(err)
|
|
}
|
|
|
|
code := m.Run()
|
|
cancel()
|
|
if err = t.Stop(); err != nil {
|
|
stdlog.Fatal(err)
|
|
}
|
|
os.Exit(code)
|
|
}
|
|
|
|
// SetupTestReconcile returns a reconcile.Reconcile implementation that delegates to inner.
|
|
func SetupTestReconcile(inner reconcile.Reconciler) reconcile.Reconciler {
|
|
fn := reconcile.Func(func(ctx context.Context, req reconcile.Request) (reconcile.Result, error) {
|
|
result, err := inner.Reconcile(ctx, req)
|
|
return result, err
|
|
})
|
|
return fn
|
|
}
|