提交 ace121e8 编写于 作者: L liqingping

refactor: refactor code structure

1. move packages to pkg dir
上级 49ff2994
......@@ -93,11 +93,11 @@ lint:
.PHONY: test
test: ginkgo ## Run tests.
$(GINKGO) -nodes 4 -v -cover -coverprofile=coverage.out ./api/v1alpha1 ./controllers ./server/http ./common/gpuallocator
go tool cover -func=./api/v1alpha1/coverage.out
go tool cover -func=./controllers/coverage.out
go tool cover -func=./server/http/coverage.out
go tool cover -func=./common/gpuallocator/coverage.out
$(GINKGO) -nodes 4 -v -cover -coverprofile=coverage.out ./pkg/...
go tool cover -func=./pkg/api/v1alpha1/coverage.out
go tool cover -func=./pkg/controllers/coverage.out
go tool cover -func=./pkg/server/http/coverage.out
go tool cover -func=./pkg/common/gpuallocator/coverage.out
##@ Build
......
......@@ -31,9 +31,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/common"
"opendilab.org/di-orchestrator/controllers"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/pkg/common"
"opendilab.org/di-orchestrator/pkg/controllers"
//+kubebuilder:scaffold:imports
)
......
......@@ -21,10 +21,10 @@ import (
"k8s.io/client-go/tools/leaderelection/resourcelock"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
dicommon "opendilab.org/di-orchestrator/common"
gpualloc "opendilab.org/di-orchestrator/common/gpuallocator"
serverdynamic "opendilab.org/di-orchestrator/server/dynamic"
serverhttp "opendilab.org/di-orchestrator/server/http"
dicommon "opendilab.org/di-orchestrator/pkg/common"
gpualloc "opendilab.org/di-orchestrator/pkg/common/gpuallocator"
serverdynamic "opendilab.org/di-orchestrator/pkg/server/dynamic"
serverhttp "opendilab.org/di-orchestrator/pkg/server/http"
)
var (
......
......@@ -31,7 +31,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
//+kubebuilder:scaffold:imports
)
......
......@@ -9,7 +9,7 @@ spec:
spec:
containers:
- name: di-container
image: opendilab/ding:2021-09-26
image: opendilab/ding:nightly-atari
imagePullPolicy: Always
env:
- name: PYTHONUNBUFFERED
......
......@@ -19,7 +19,7 @@ spec:
spec:
containers:
- name: di-container
image: opendilab/ding:2021-09-26
image: opendilab/ding:nightly-atari
imagePullPolicy: Always
env:
- name: PYTHONUNBUFFERED
......@@ -166,7 +166,7 @@ spec:
spec:
containers:
- name: di-container
image: opendilab/ding:2021-09-26
image: opendilab/ding:nightly-atari
imagePullPolicy: Always
env:
- name: PYTHONUNBUFFERED
......@@ -193,7 +193,7 @@ spec:
spec:
containers:
- name: di-container
image: opendilab/ding:2021-09-26
image: opendilab/ding:nightly-atari
imagePullPolicy: Always
env:
- name: PYTHONUNBUFFERED
......
......@@ -19,7 +19,7 @@ spec:
spec:
containers:
- name: di-container
image: opendilab/ding:2021-09-26
image: opendilab/ding:nightly-atari
imagePullPolicy: Always
env:
- name: PYTHONUNBUFFERED
......@@ -169,7 +169,7 @@ spec:
spec:
containers:
- name: di-container
image: opendilab/ding:2021-09-26
image: opendilab/ding:nightly-atari
imagePullPolicy: Always
env:
- name: PYTHONUNBUFFERED
......@@ -199,7 +199,7 @@ spec:
spec:
containers:
- name: di-container
image: opendilab/ding:2021-09-26
image: opendilab/ding:nightly-atari
imagePullPolicy: Always
env:
- name: PYTHONUNBUFFERED
......
......@@ -16,7 +16,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
)
func TestE2E(t *testing.T) {
......
......@@ -16,10 +16,10 @@ import (
"k8s.io/apimachinery/pkg/util/yaml"
"sigs.k8s.io/controller-runtime/pkg/client"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/common"
diutil "opendilab.org/di-orchestrator/utils"
testutil "opendilab.org/di-orchestrator/utils/testutils"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/pkg/common"
diutil "opendilab.org/di-orchestrator/pkg/utils"
testutil "opendilab.org/di-orchestrator/pkg/utils/testutils"
)
const (
......
......@@ -196,6 +196,7 @@ github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh
github.com/go-openapi/validate v0.18.0/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4=
github.com/go-openapi/validate v0.19.2/go.mod h1:1tRCw7m3jtI8eNWEEliiAqUIcBztB2KDnRCRMUi7GTA=
github.com/go-openapi/validate v0.19.5/go.mod h1:8DJv2CVJQ6kGNpFW6eV9N3JviE1C85nY1c2z52x1Gk4=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
......@@ -278,12 +279,14 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.10 h1:6q5mVkdH/vYmqngx7kZQTjJ5HRsx+ImorDIEQ+beJgc=
github.com/imdario/mergo v0.3.10/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
......
......@@ -65,10 +65,10 @@ var _ = BeforeSuite(func() {
By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: false,
WebhookInstallOptions: envtest.WebhookInstallOptions{
Paths: []string{filepath.Join("..", "..", "config", "webhook")},
Paths: []string{filepath.Join("..", "..", "..", "config", "webhook")},
LocalServingPort: 8100 + config.GinkgoConfig.ParallelNode,
},
}
......
......@@ -14,9 +14,9 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/common"
diutil "opendilab.org/di-orchestrator/utils"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/pkg/common"
diutil "opendilab.org/di-orchestrator/pkg/utils"
)
func isSucceeded(job *div1alpha1.DIJob) bool {
......
......@@ -34,8 +34,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/source"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
diutil "opendilab.org/di-orchestrator/utils"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
diutil "opendilab.org/di-orchestrator/pkg/utils"
)
// DIJobReconciler reconciles a DIJob object
......
......@@ -12,11 +12,11 @@ import (
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/common"
commontypes "opendilab.org/di-orchestrator/common/types"
diutil "opendilab.org/di-orchestrator/utils"
testutil "opendilab.org/di-orchestrator/utils/testutils"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/pkg/common"
commontypes "opendilab.org/di-orchestrator/pkg/common/types"
diutil "opendilab.org/di-orchestrator/pkg/utils"
testutil "opendilab.org/di-orchestrator/pkg/utils/testutils"
)
var _ = Describe("DIJob Controller", func() {
......
......@@ -9,10 +9,10 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/common"
diutil "opendilab.org/di-orchestrator/utils"
testutil "opendilab.org/di-orchestrator/utils/testutils"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/pkg/common"
diutil "opendilab.org/di-orchestrator/pkg/utils"
testutil "opendilab.org/di-orchestrator/pkg/utils/testutils"
)
var _ = Describe("DIJob Specification", func() {
......
......@@ -9,9 +9,9 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/common"
diutil "opendilab.org/di-orchestrator/utils"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/pkg/common"
diutil "opendilab.org/di-orchestrator/pkg/utils"
)
func (r *DIJobReconciler) reconcilePodsAndServices(ctx context.Context, job *div1alpha1.DIJob, pods []*corev1.Pod, services []*corev1.Service) error {
......
......@@ -10,9 +10,9 @@ import (
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/common"
diutil "opendilab.org/di-orchestrator/utils"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/pkg/common"
diutil "opendilab.org/di-orchestrator/pkg/utils"
)
const (
......
......@@ -35,8 +35,8 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
testutil "opendilab.org/di-orchestrator/utils/testutils"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
testutil "opendilab.org/di-orchestrator/pkg/utils/testutils"
//+kubebuilder:scaffold:imports
)
......@@ -66,7 +66,7 @@ var _ = BeforeSuite(func() {
By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: true,
}
......
......@@ -8,7 +8,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
)
func GetPodFromObject(obj interface{}) (*corev1.Pod, error) {
......
......@@ -11,7 +11,7 @@ import (
"k8s.io/client-go/informers"
"k8s.io/client-go/tools/cache"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
)
var (
......
......@@ -11,10 +11,10 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/common"
commontypes "opendilab.org/di-orchestrator/common/types"
diutil "opendilab.org/di-orchestrator/utils"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/pkg/common"
commontypes "opendilab.org/di-orchestrator/pkg/common/types"
diutil "opendilab.org/di-orchestrator/pkg/utils"
)
func (s *DIServer) getDIJob(namespace, modulePodName string) (*div1alpha1.DIJob, error) {
......
......@@ -12,8 +12,8 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
commontypes "opendilab.org/di-orchestrator/common/types"
diutil "opendilab.org/di-orchestrator/utils"
commontypes "opendilab.org/di-orchestrator/pkg/common/types"
diutil "opendilab.org/di-orchestrator/pkg/utils"
)
func (s *DIServer) getPodsByNames(namespace string, names []string) ([]*corev1.Pod, error) {
......
......@@ -17,12 +17,12 @@ import (
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/common"
gpualloc "opendilab.org/di-orchestrator/common/gpuallocator"
commontypes "opendilab.org/di-orchestrator/common/types"
serverdynamic "opendilab.org/di-orchestrator/server/dynamic"
diutil "opendilab.org/di-orchestrator/utils"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/pkg/common"
gpualloc "opendilab.org/di-orchestrator/pkg/common/gpuallocator"
commontypes "opendilab.org/di-orchestrator/pkg/common/types"
serverdynamic "opendilab.org/di-orchestrator/pkg/server/dynamic"
diutil "opendilab.org/di-orchestrator/pkg/utils"
)
var (
......
......@@ -16,11 +16,11 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
"sigs.k8s.io/controller-runtime/pkg/client"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/common"
commontypes "opendilab.org/di-orchestrator/common/types"
diutil "opendilab.org/di-orchestrator/utils"
testutil "opendilab.org/di-orchestrator/utils/testutils"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/pkg/common"
commontypes "opendilab.org/di-orchestrator/pkg/common/types"
diutil "opendilab.org/di-orchestrator/pkg/utils"
testutil "opendilab.org/di-orchestrator/pkg/utils/testutils"
)
var _ = Describe("Server Test", func() {
......
......@@ -43,9 +43,9 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
serverdynamic "opendilab.org/di-orchestrator/server/dynamic"
testutil "opendilab.org/di-orchestrator/utils/testutils"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
serverdynamic "opendilab.org/di-orchestrator/pkg/server/dynamic"
testutil "opendilab.org/di-orchestrator/pkg/utils/testutils"
//+kubebuilder:scaffold:imports
)
......@@ -83,7 +83,7 @@ var _ = BeforeSuite(func() {
By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: true,
}
......
......@@ -9,7 +9,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
dicommon "opendilab.org/di-orchestrator/common"
dicommon "opendilab.org/di-orchestrator/pkg/common"
)
func BuildPodAndService(
......
......@@ -9,9 +9,9 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/common"
diutil "opendilab.org/di-orchestrator/utils"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/pkg/common"
diutil "opendilab.org/di-orchestrator/pkg/utils"
)
func NewDIJob() *div1alpha1.DIJob {
......
......@@ -14,7 +14,7 @@ import (
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/client"
dicommon "opendilab.org/di-orchestrator/common"
dicommon "opendilab.org/di-orchestrator/pkg/common"
)
func NewPod(name, jobName string, ownRefer metav1.OwnerReference) *corev1.Pod {
......
......@@ -16,9 +16,9 @@ import (
utilrand "k8s.io/apimachinery/pkg/util/rand"
"sigs.k8s.io/controller-runtime/pkg/client"
div1alpha1 "opendilab.org/di-orchestrator/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/common"
commontypes "opendilab.org/di-orchestrator/common/types"
div1alpha1 "opendilab.org/di-orchestrator/pkg/api/v1alpha1"
dicommon "opendilab.org/di-orchestrator/pkg/common"
commontypes "opendilab.org/di-orchestrator/pkg/common/types"
)
const (
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册