From dce93a42502d03cdfee5bc95873826b5205b0f06 Mon Sep 17 00:00:00 2001 From: Jian Wang Date: Tue, 17 Sep 2024 17:11:50 +0200 Subject: [PATCH] Replace with generated resources Signed-off-by: Jian Wang --- cmd/network-helper/main.go | 2 +- cmd/webhook/main.go | 8 +++--- pkg/config/context.go | 2 +- .../agent/linkmonitor/controller.go | 28 ++++++------------- pkg/controller/agent/nad/controller.go | 2 +- pkg/controller/agent/vlanconfig/controller.go | 2 +- .../manager/clusternetwork/controller.go | 2 +- pkg/controller/manager/nad/controller.go | 2 +- pkg/helper/helper.go | 4 +-- pkg/utils/vmi.go | 2 +- pkg/webhook/nad/validator.go | 2 +- pkg/webhook/vlanconfig/validator.go | 4 +-- 12 files changed, 24 insertions(+), 36 deletions(-) diff --git a/cmd/network-helper/main.go b/cmd/network-helper/main.go index 197c08205..3643796bf 100644 --- a/cmd/network-helper/main.go +++ b/cmd/network-helper/main.go @@ -4,12 +4,12 @@ import ( "fmt" "os" - ctlcni "github.com/harvester/harvester/pkg/generated/controllers/k8s.cni.cncf.io" "github.com/urfave/cli" "k8s.io/client-go/tools/clientcmd" "k8s.io/klog" "github.com/harvester/harvester-network-controller/pkg/controller/manager/nad" + ctlcni "github.com/harvester/harvester-network-controller/pkg/generated/controllers/k8s.cni.cncf.io" "github.com/harvester/harvester-network-controller/pkg/helper" "github.com/harvester/harvester-network-controller/pkg/utils" ) diff --git a/cmd/webhook/main.go b/cmd/webhook/main.go index 94de69de5..9abf118a1 100644 --- a/cmd/webhook/main.go +++ b/cmd/webhook/main.go @@ -5,10 +5,6 @@ import ( "fmt" "os" - ctlcni "github.com/harvester/harvester/pkg/generated/controllers/k8s.cni.cncf.io" - ctlcniv1 "github.com/harvester/harvester/pkg/generated/controllers/k8s.cni.cncf.io/v1" - ctlkubevirt "github.com/harvester/harvester/pkg/generated/controllers/kubevirt.io" - ctlkubevirtv1 "github.com/harvester/harvester/pkg/generated/controllers/kubevirt.io/v1" "github.com/harvester/harvester/pkg/indexeres" "github.com/harvester/webhook/pkg/config" "github.com/harvester/webhook/pkg/server" @@ -22,6 +18,10 @@ import ( "k8s.io/client-go/rest" kubevirtv1 "kubevirt.io/api/core/v1" + ctlcni "github.com/harvester/harvester-network-controller/pkg/generated/controllers/k8s.cni.cncf.io" + ctlcniv1 "github.com/harvester/harvester-network-controller/pkg/generated/controllers/k8s.cni.cncf.io/v1" + ctlkubevirt "github.com/harvester/harvester-network-controller/pkg/generated/controllers/kubevirt.io" + ctlkubevirtv1 "github.com/harvester/harvester-network-controller/pkg/generated/controllers/kubevirt.io/v1" ctlnetwork "github.com/harvester/harvester-network-controller/pkg/generated/controllers/network.harvesterhci.io" ctlnetworkv1 "github.com/harvester/harvester-network-controller/pkg/generated/controllers/network.harvesterhci.io/v1beta1" "github.com/harvester/harvester-network-controller/pkg/webhook/clusternetwork" diff --git a/pkg/config/context.go b/pkg/config/context.go index c095d804b..97fcc84bf 100644 --- a/pkg/config/context.go +++ b/pkg/config/context.go @@ -3,7 +3,6 @@ package config import ( "context" - ctlcni "github.com/harvester/harvester/pkg/generated/controllers/k8s.cni.cncf.io" "github.com/harvester/harvester/pkg/util/crd" cniv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" "github.com/rancher/lasso/pkg/controller" @@ -24,6 +23,7 @@ import ( "k8s.io/client-go/tools/record" networkv1 "github.com/harvester/harvester-network-controller/pkg/apis/network.harvesterhci.io/v1beta1" + ctlcni "github.com/harvester/harvester-network-controller/pkg/generated/controllers/k8s.cni.cncf.io" ctlnetwork "github.com/harvester/harvester-network-controller/pkg/generated/controllers/network.harvesterhci.io" ) diff --git a/pkg/controller/agent/linkmonitor/controller.go b/pkg/controller/agent/linkmonitor/controller.go index 57e025de7..c980f53f9 100644 --- a/pkg/controller/agent/linkmonitor/controller.go +++ b/pkg/controller/agent/linkmonitor/controller.go @@ -3,6 +3,7 @@ package linkmonitor import ( "context" "fmt" + "reflect" ctlcorev1 "github.com/rancher/wrangler/pkg/generated/controllers/core/v1" "github.com/vishvananda/netlink" @@ -154,19 +155,20 @@ func linkToLinkStatus(l netlink.Link) networkv1.LinkStatus { return linkStatus } -func (h Handler) updateStatus(lm *networkv1.LinkMonitor, linkStatusList []networkv1.LinkStatus) error { - var currentLinkStatusList []networkv1.LinkStatus +func (h Handler) updateStatus(lm *networkv1.LinkMonitor, linkStatusList networkv1.LinkStatusList) error { + var currentLinkStatusList networkv1.LinkStatusList if lm.Status.LinkStatus != nil { currentLinkStatusList = lm.Status.LinkStatus[h.nodeName] } - if compareLinkStatusList(currentLinkStatusList, linkStatusList) { + + if reflect.DeepEqual(currentLinkStatusList, linkStatusList) { return nil } lmCopy := lm.DeepCopy() - if lm.Status.LinkStatus == nil { - lmCopy.Status.LinkStatus = make(map[string][]networkv1.LinkStatus) + if lmCopy.Status.LinkStatus == nil { + lmCopy.Status.LinkStatus = make(map[string]networkv1.LinkStatusList) } lmCopy.Status.LinkStatus[h.nodeName] = linkStatusList @@ -177,27 +179,13 @@ func (h Handler) updateStatus(lm *networkv1.LinkMonitor, linkStatusList []networ return nil } -func compareLinkStatusList(m, n []networkv1.LinkStatus) bool { - if len(m) != len(n) { - return false - } - - for i, linkStatus := range m { - if linkStatus != n[i] { - return false - } - } - - return true -} - func (h Handler) syncLinkStatus(lm *networkv1.LinkMonitor) error { pattern := h.linkMonitor.GetPattern(lm.Name) links, err := h.linkMonitor.ScanLinks(pattern) if err != nil { return err } - linkStatusList := make([]networkv1.LinkStatus, len(links)) + linkStatusList := make(networkv1.LinkStatusList, len(links)) for i, link := range links { linkStatusList[i] = linkToLinkStatus(link) } diff --git a/pkg/controller/agent/nad/controller.go b/pkg/controller/agent/nad/controller.go index 940287dce..e349992e5 100644 --- a/pkg/controller/agent/nad/controller.go +++ b/pkg/controller/agent/nad/controller.go @@ -6,13 +6,13 @@ import ( "fmt" "strconv" - ctlcniv1 "github.com/harvester/harvester/pkg/generated/controllers/k8s.cni.cncf.io/v1" nadv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" "github.com/vishvananda/netlink" "k8s.io/apimachinery/pkg/labels" "k8s.io/klog" "github.com/harvester/harvester-network-controller/pkg/config" + ctlcniv1 "github.com/harvester/harvester-network-controller/pkg/generated/controllers/k8s.cni.cncf.io/v1" "github.com/harvester/harvester-network-controller/pkg/network/vlan" "github.com/harvester/harvester-network-controller/pkg/utils" ) diff --git a/pkg/controller/agent/vlanconfig/controller.go b/pkg/controller/agent/vlanconfig/controller.go index 4f1ff9266..ac74e34b7 100644 --- a/pkg/controller/agent/vlanconfig/controller.go +++ b/pkg/controller/agent/vlanconfig/controller.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" - ctlcniv1 "github.com/harvester/harvester/pkg/generated/controllers/k8s.cni.cncf.io/v1" ctlcorev1 "github.com/rancher/wrangler/pkg/generated/controllers/core/v1" "github.com/vishvananda/netlink" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -18,6 +17,7 @@ import ( networkv1 "github.com/harvester/harvester-network-controller/pkg/apis/network.harvesterhci.io/v1beta1" "github.com/harvester/harvester-network-controller/pkg/config" "github.com/harvester/harvester-network-controller/pkg/controller/agent/nad" + ctlcniv1 "github.com/harvester/harvester-network-controller/pkg/generated/controllers/k8s.cni.cncf.io/v1" ctlnetworkv1 "github.com/harvester/harvester-network-controller/pkg/generated/controllers/network.harvesterhci.io/v1beta1" "github.com/harvester/harvester-network-controller/pkg/network/iface" "github.com/harvester/harvester-network-controller/pkg/network/vlan" diff --git a/pkg/controller/manager/clusternetwork/controller.go b/pkg/controller/manager/clusternetwork/controller.go index 640a34fdb..b2a734d9d 100644 --- a/pkg/controller/manager/clusternetwork/controller.go +++ b/pkg/controller/manager/clusternetwork/controller.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/cenk/backoff" - ctlcniv1 "github.com/harvester/harvester/pkg/generated/controllers/k8s.cni.cncf.io/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" @@ -13,6 +12,7 @@ import ( networkv1 "github.com/harvester/harvester-network-controller/pkg/apis/network.harvesterhci.io/v1beta1" "github.com/harvester/harvester-network-controller/pkg/config" + ctlcniv1 "github.com/harvester/harvester-network-controller/pkg/generated/controllers/k8s.cni.cncf.io/v1" ctlnetworkv1 "github.com/harvester/harvester-network-controller/pkg/generated/controllers/network.harvesterhci.io/v1beta1" "github.com/harvester/harvester-network-controller/pkg/network/iface" "github.com/harvester/harvester-network-controller/pkg/utils" diff --git a/pkg/controller/manager/nad/controller.go b/pkg/controller/manager/nad/controller.go index da96ea7e5..3087d3f1f 100644 --- a/pkg/controller/manager/nad/controller.go +++ b/pkg/controller/manager/nad/controller.go @@ -9,7 +9,6 @@ import ( "time" "github.com/go-ping/ping" - ctlcniv1 "github.com/harvester/harvester/pkg/generated/controllers/k8s.cni.cncf.io/v1" cniv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" ctlbatchv1 "github.com/rancher/wrangler/pkg/generated/controllers/batch/v1" batchv1 "k8s.io/api/batch/v1" @@ -22,6 +21,7 @@ import ( "github.com/harvester/harvester-network-controller/pkg/apis/network.harvesterhci.io" networkv1 "github.com/harvester/harvester-network-controller/pkg/apis/network.harvesterhci.io/v1beta1" "github.com/harvester/harvester-network-controller/pkg/config" + ctlcniv1 "github.com/harvester/harvester-network-controller/pkg/generated/controllers/k8s.cni.cncf.io/v1" ctlnetworkv1 "github.com/harvester/harvester-network-controller/pkg/generated/controllers/network.harvesterhci.io/v1beta1" "github.com/harvester/harvester-network-controller/pkg/network/iface" "github.com/harvester/harvester-network-controller/pkg/utils" diff --git a/pkg/helper/helper.go b/pkg/helper/helper.go index f5513d0eb..d4cdd2f52 100644 --- a/pkg/helper/helper.go +++ b/pkg/helper/helper.go @@ -3,12 +3,12 @@ package helper import ( "net" - ctlcni "github.com/harvester/harvester/pkg/generated/controllers/k8s.cni.cncf.io" - ctlcniv1 "github.com/harvester/harvester/pkg/generated/controllers/k8s.cni.cncf.io/v1" nadv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/klog" + ctlcni "github.com/harvester/harvester-network-controller/pkg/generated/controllers/k8s.cni.cncf.io" + ctlcniv1 "github.com/harvester/harvester-network-controller/pkg/generated/controllers/k8s.cni.cncf.io/v1" "github.com/harvester/harvester-network-controller/pkg/utils" ) diff --git a/pkg/utils/vmi.go b/pkg/utils/vmi.go index 3595b439e..2c87985fe 100644 --- a/pkg/utils/vmi.go +++ b/pkg/utils/vmi.go @@ -4,7 +4,7 @@ import ( "fmt" mapset "github.com/deckarep/golang-set/v2" - ctlkubevirtv1 "github.com/harvester/harvester/pkg/generated/controllers/kubevirt.io/v1" + ctlkubevirtv1 "github.com/harvester/harvester-network-controller/pkg/generated/controllers/kubevirt.io/v1" "github.com/harvester/harvester/pkg/indexeres" nadv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" kubevirtv1 "kubevirt.io/api/core/v1" diff --git a/pkg/webhook/nad/validator.go b/pkg/webhook/nad/validator.go index ce92c14a7..cbc652ae9 100644 --- a/pkg/webhook/nad/validator.go +++ b/pkg/webhook/nad/validator.go @@ -6,12 +6,12 @@ import ( "reflect" "strings" - ctlkubevirtv1 "github.com/harvester/harvester/pkg/generated/controllers/kubevirt.io/v1" "github.com/harvester/webhook/pkg/server/admission" cniv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" admissionregv1 "k8s.io/api/admissionregistration/v1" "k8s.io/apimachinery/pkg/runtime" + ctlkubevirtv1 "github.com/harvester/harvester-network-controller/pkg/generated/controllers/kubevirt.io/v1" "github.com/harvester/harvester-network-controller/pkg/network/iface" "github.com/harvester/harvester-network-controller/pkg/utils" ) diff --git a/pkg/webhook/vlanconfig/validator.go b/pkg/webhook/vlanconfig/validator.go index fd6315055..bbc6b1ec7 100644 --- a/pkg/webhook/vlanconfig/validator.go +++ b/pkg/webhook/vlanconfig/validator.go @@ -7,8 +7,6 @@ import ( "strings" mapset "github.com/deckarep/golang-set/v2" - ctlcniv1 "github.com/harvester/harvester/pkg/generated/controllers/k8s.cni.cncf.io/v1" - ctlkubevirtv1 "github.com/harvester/harvester/pkg/generated/controllers/kubevirt.io/v1" "github.com/harvester/webhook/pkg/server/admission" admissionregv1 "k8s.io/api/admissionregistration/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -17,6 +15,8 @@ import ( kubevirtv1 "kubevirt.io/api/core/v1" networkv1 "github.com/harvester/harvester-network-controller/pkg/apis/network.harvesterhci.io/v1beta1" + ctlcniv1 "github.com/harvester/harvester-network-controller/pkg/generated/controllers/k8s.cni.cncf.io/v1" + ctlkubevirtv1 "github.com/harvester/harvester-network-controller/pkg/generated/controllers/kubevirt.io/v1" ctlnetworkv1 "github.com/harvester/harvester-network-controller/pkg/generated/controllers/network.harvesterhci.io/v1beta1" "github.com/harvester/harvester-network-controller/pkg/network/iface" "github.com/harvester/harvester-network-controller/pkg/utils"