Skip to content

Commit

Permalink
refactor: cleanup imports
Browse files Browse the repository at this point in the history
Signed-off-by: Chin-Ya Huang <chin-ya.huang@suse.com>
  • Loading branch information
c3y1huang authored and David Ko committed Sep 19, 2023
1 parent 714bc96 commit 57ee711
Show file tree
Hide file tree
Showing 34 changed files with 181 additions and 112 deletions.
3 changes: 2 additions & 1 deletion scheduler/replica_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"github.com/sirupsen/logrus"

"github.com/longhorn/longhorn-manager/datastore"
longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
"github.com/longhorn/longhorn-manager/types"
"github.com/longhorn/longhorn-manager/util"

longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
)

const (
Expand Down
89 changes: 45 additions & 44 deletions scheduler/replica_scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ import (
"fmt"
"testing"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/tools/cache"
"k8s.io/kubernetes/pkg/controller"

corev1 "k8s.io/api/core/v1"
apiextensionsfake "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/longhorn/longhorn-manager/datastore"
"github.com/longhorn/longhorn-manager/types"
"github.com/longhorn/longhorn-manager/util"

longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
lhfake "github.com/longhorn/longhorn-manager/k8s/pkg/client/clientset/versioned/fake"
lhinformerfactory "github.com/longhorn/longhorn-manager/k8s/pkg/client/informers/externalversions"
apiextensionsfake "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake"

. "gopkg.in/check.v1"
)
Expand Down Expand Up @@ -66,19 +67,19 @@ func newReplicaScheduler(lhInformerFactory lhinformerfactory.SharedInformerFacto
return NewReplicaScheduler(ds)
}

func newDaemonPod(phase v1.PodPhase, name, namespace, nodeID, podIP string) *v1.Pod {
return &v1.Pod{
func newDaemonPod(phase corev1.PodPhase, name, namespace, nodeID, podIP string) *corev1.Pod {
return &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: map[string]string{
"app": "longhorn-manager",
},
},
Spec: v1.PodSpec{
Spec: corev1.PodSpec{
NodeName: nodeID,
},
Status: v1.PodStatus{
Status: corev1.PodStatus{
Phase: phase,
PodIP: podIP,
},
Expand Down Expand Up @@ -232,7 +233,7 @@ func (s *TestSuite) SetUpTest(c *C) {

type ReplicaSchedulerTestCase struct {
volume *longhorn.Volume
daemons []*v1.Pod
daemons []*corev1.Pod
nodes map[string]*longhorn.Node
engineImage *longhorn.EngineImage
storageOverProvisioningPercentage string
Expand Down Expand Up @@ -284,10 +285,10 @@ func (s *TestSuite) TestReplicaScheduler(c *C) {
testCases := map[string]*ReplicaSchedulerTestCase{}
// Test only node1 could schedule replica
tc := generateSchedulerTestCase()
daemon1 := newDaemonPod(v1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 := newDaemonPod(v1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
daemon3 := newDaemonPod(v1.PodRunning, TestDaemon3, TestNamespace, TestNode3, TestIP3)
tc.daemons = []*v1.Pod{
daemon1 := newDaemonPod(corev1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 := newDaemonPod(corev1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
daemon3 := newDaemonPod(corev1.PodRunning, TestDaemon3, TestNamespace, TestNode3, TestIP3)
tc.daemons = []*corev1.Pod{
daemon1,
daemon2,
daemon3,
Expand Down Expand Up @@ -358,9 +359,9 @@ func (s *TestSuite) TestReplicaScheduler(c *C) {

// Test no disks on each nodes, volume should not schedule to any node
tc = generateSchedulerTestCase()
daemon1 = newDaemonPod(v1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 = newDaemonPod(v1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
tc.daemons = []*v1.Pod{
daemon1 = newDaemonPod(corev1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 = newDaemonPod(corev1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
tc.daemons = []*corev1.Pod{
daemon1,
daemon2,
}
Expand All @@ -381,9 +382,9 @@ func (s *TestSuite) TestReplicaScheduler(c *C) {

// Test engine image is not deployed on any node
tc = generateSchedulerTestCase()
daemon1 = newDaemonPod(v1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 = newDaemonPod(v1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
tc.daemons = []*v1.Pod{
daemon1 = newDaemonPod(corev1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 = newDaemonPod(corev1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
tc.daemons = []*corev1.Pod{
daemon1,
daemon2,
}
Expand Down Expand Up @@ -434,9 +435,9 @@ func (s *TestSuite) TestReplicaScheduler(c *C) {

// Test anti affinity nodes, replica should schedule to both node1 and node2
tc = generateSchedulerTestCase()
daemon1 = newDaemonPod(v1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 = newDaemonPod(v1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
tc.daemons = []*v1.Pod{
daemon1 = newDaemonPod(corev1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 = newDaemonPod(corev1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
tc.daemons = []*corev1.Pod{
daemon1,
daemon2,
}
Expand Down Expand Up @@ -535,9 +536,9 @@ func (s *TestSuite) TestReplicaScheduler(c *C) {

// Test no available disks
tc = generateSchedulerTestCase()
daemon1 = newDaemonPod(v1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 = newDaemonPod(v1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
tc.daemons = []*v1.Pod{
daemon1 = newDaemonPod(corev1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 = newDaemonPod(corev1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
tc.daemons = []*corev1.Pod{
daemon1,
daemon2,
}
Expand Down Expand Up @@ -604,9 +605,9 @@ func (s *TestSuite) TestReplicaScheduler(c *C) {

// Test no available disks due to volume.Status.ActualSize
tc = generateSchedulerTestCase()
daemon1 = newDaemonPod(v1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 = newDaemonPod(v1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
tc.daemons = []*v1.Pod{
daemon1 = newDaemonPod(corev1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 = newDaemonPod(corev1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
tc.daemons = []*corev1.Pod{
daemon1,
daemon2,
}
Expand Down Expand Up @@ -674,9 +675,9 @@ func (s *TestSuite) TestReplicaScheduler(c *C) {

// Test schedule to disk with the most usable storage
tc = generateSchedulerTestCase()
daemon1 = newDaemonPod(v1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 = newDaemonPod(v1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
tc.daemons = []*v1.Pod{
daemon1 = newDaemonPod(corev1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 = newDaemonPod(corev1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
tc.daemons = []*corev1.Pod{
daemon1,
daemon2,
}
Expand Down Expand Up @@ -764,8 +765,8 @@ func (s *TestSuite) TestReplicaScheduler(c *C) {

// Test schedule to a second disk on the same node even if the first has more available storage
tc = generateSchedulerTestCase()
daemon1 = newDaemonPod(v1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
tc.daemons = []*v1.Pod{
daemon1 = newDaemonPod(corev1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
tc.daemons = []*corev1.Pod{
daemon1,
}
node1 = newNode(TestNode1, TestNamespace, TestZone1, true, longhorn.ConditionStatusTrue)
Expand Down Expand Up @@ -820,8 +821,8 @@ func (s *TestSuite) TestReplicaScheduler(c *C) {

// Test fail scheduling when replicaDiskSoftAntiAffinity is false
tc = generateSchedulerTestCase()
daemon1 = newDaemonPod(v1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
tc.daemons = []*v1.Pod{
daemon1 = newDaemonPod(corev1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
tc.daemons = []*corev1.Pod{
daemon1,
}
node1 = newNode(TestNode1, TestNamespace, TestZone1, true, longhorn.ConditionStatusTrue)
Expand Down Expand Up @@ -867,9 +868,9 @@ func (s *TestSuite) TestReplicaScheduler(c *C) {

// Test fail scheduling when zoneSoftAntiAffinity is false
tc = generateSchedulerTestCase()
daemon1 = newDaemonPod(v1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 = newDaemonPod(v1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
tc.daemons = []*v1.Pod{
daemon1 = newDaemonPod(corev1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 = newDaemonPod(corev1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
tc.daemons = []*corev1.Pod{
daemon1,
daemon2,
}
Expand Down Expand Up @@ -928,9 +929,9 @@ func (s *TestSuite) TestReplicaScheduler(c *C) {

// Test schedule when zoneSoftAntiAffinity is false but there is an evicting replica
tc = generateSchedulerTestCase()
daemon1 = newDaemonPod(v1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 = newDaemonPod(v1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
tc.daemons = []*v1.Pod{
daemon1 = newDaemonPod(corev1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 = newDaemonPod(corev1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
tc.daemons = []*corev1.Pod{
daemon1,
daemon2,
}
Expand Down Expand Up @@ -1006,12 +1007,12 @@ func (s *TestSuite) TestReplicaScheduler(c *C) {

// Test fail scheduling when doing so would reuse an invalid evicting node
tc = generateSchedulerTestCase()
daemon1 = newDaemonPod(v1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 = newDaemonPod(v1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
daemon1 = newDaemonPod(corev1.PodRunning, TestDaemon1, TestNamespace, TestNode1, TestIP1)
daemon2 = newDaemonPod(corev1.PodRunning, TestDaemon2, TestNamespace, TestNode2, TestIP2)
// Implement with three nodes to create the scenario posed by
// https://github.com/longhorn/longhorn-manager/pull/2094#discussion_r1290839641.
daemon3 = newDaemonPod(v1.PodRunning, TestDaemon3, TestNamespace, TestNode3, TestIP3)
tc.daemons = []*v1.Pod{
daemon3 = newDaemonPod(corev1.PodRunning, TestDaemon3, TestNamespace, TestNode3, TestIP3)
tc.daemons = []*corev1.Pod{
daemon1,
daemon2,
daemon3,
Expand Down
3 changes: 2 additions & 1 deletion webhook/admission/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"github.com/rancher/wrangler/pkg/webhook"
"github.com/sirupsen/logrus"

admissionv1 "k8s.io/api/admission/v1"
"k8s.io/apimachinery/pkg/runtime"

admissionv1 "k8s.io/api/admission/v1"

werror "github.com/longhorn/longhorn-manager/webhook/error"
)

Expand Down
3 changes: 2 additions & 1 deletion webhook/admission/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (

"github.com/rancher/wrangler/pkg/webhook"

admissionv1 "k8s.io/api/admission/v1"
"k8s.io/apimachinery/pkg/runtime"

admissionv1 "k8s.io/api/admission/v1"
)

type Request struct {
Expand Down
3 changes: 2 additions & 1 deletion webhook/admission/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package admission
import (
"fmt"

admissionregv1 "k8s.io/api/admissionregistration/v1"
"k8s.io/apimachinery/pkg/runtime"

admissionregv1 "k8s.io/api/admissionregistration/v1"
)

type Resource struct {
Expand Down
3 changes: 2 additions & 1 deletion webhook/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"k8s.io/apimachinery/pkg/runtime"

"github.com/longhorn/longhorn-manager/datastore"
longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
"github.com/longhorn/longhorn-manager/types"
"github.com/longhorn/longhorn-manager/util"

longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
)

var (
Expand Down
5 changes: 3 additions & 2 deletions webhook/conversion/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (

"github.com/sirupsen/logrus"

apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/conversion"

apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

longhornV1beta1 "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta1"
longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
)
Expand Down
7 changes: 5 additions & 2 deletions webhook/resources/backingimage/mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import (
"strings"

"github.com/pkg/errors"
admissionregv1 "k8s.io/api/admissionregistration/v1"

"k8s.io/apimachinery/pkg/runtime"

admissionregv1 "k8s.io/api/admissionregistration/v1"

"github.com/longhorn/longhorn-manager/datastore"
longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
"github.com/longhorn/longhorn-manager/manager"
"github.com/longhorn/longhorn-manager/types"
"github.com/longhorn/longhorn-manager/util"
"github.com/longhorn/longhorn-manager/webhook/admission"
"github.com/longhorn/longhorn-manager/webhook/common"

longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
werror "github.com/longhorn/longhorn-manager/webhook/error"
)

Expand Down
6 changes: 4 additions & 2 deletions webhook/resources/backingimage/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ package backingimage
import (
"fmt"

admissionregv1 "k8s.io/api/admissionregistration/v1"
"k8s.io/apimachinery/pkg/runtime"

admissionregv1 "k8s.io/api/admissionregistration/v1"

"github.com/longhorn/longhorn-manager/datastore"
"github.com/longhorn/longhorn-manager/engineapi"
longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
"github.com/longhorn/longhorn-manager/manager"
"github.com/longhorn/longhorn-manager/types"
"github.com/longhorn/longhorn-manager/util"
"github.com/longhorn/longhorn-manager/webhook/admission"

longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
werror "github.com/longhorn/longhorn-manager/webhook/error"
)

Expand Down
6 changes: 4 additions & 2 deletions webhook/resources/backingimagedatasource/mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (

"github.com/pkg/errors"

admissionregv1 "k8s.io/api/admissionregistration/v1"
"k8s.io/apimachinery/pkg/runtime"

admissionregv1 "k8s.io/api/admissionregistration/v1"

"github.com/longhorn/longhorn-manager/datastore"
longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
"github.com/longhorn/longhorn-manager/webhook/admission"
"github.com/longhorn/longhorn-manager/webhook/common"

longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
werror "github.com/longhorn/longhorn-manager/webhook/error"
)

Expand Down
9 changes: 6 additions & 3 deletions webhook/resources/backingimagemanager/mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package backingimagemanager

import (
"github.com/pkg/errors"
admissionregv1 "k8s.io/api/admissionregistration/v1"

"k8s.io/apimachinery/pkg/runtime"

admissionregv1 "k8s.io/api/admissionregistration/v1"

"github.com/longhorn/longhorn-manager/datastore"
longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
"github.com/longhorn/longhorn-manager/webhook/admission"
common "github.com/longhorn/longhorn-manager/webhook/common"
"github.com/longhorn/longhorn-manager/webhook/common"

longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
werror "github.com/longhorn/longhorn-manager/webhook/error"
)

Expand Down
8 changes: 5 additions & 3 deletions webhook/resources/backup/mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import (

"github.com/pkg/errors"

admissionregv1 "k8s.io/api/admissionregistration/v1"
"k8s.io/apimachinery/pkg/runtime"

admissionregv1 "k8s.io/api/admissionregistration/v1"

"github.com/longhorn/longhorn-manager/datastore"
longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
"github.com/longhorn/longhorn-manager/types"
"github.com/longhorn/longhorn-manager/webhook/admission"
common "github.com/longhorn/longhorn-manager/webhook/common"
"github.com/longhorn/longhorn-manager/webhook/common"

longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
werror "github.com/longhorn/longhorn-manager/webhook/error"
)

Expand Down
Loading

0 comments on commit 57ee711

Please sign in to comment.