Skip to content

Commit

Permalink
Replace with generated resources
Browse files Browse the repository at this point in the history
Signed-off-by: Jian Wang <jian.wang@suse.com>
  • Loading branch information
w13915984028 committed Sep 17, 2024
1 parent 2f45d9c commit dce93a4
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 36 deletions.
2 changes: 1 addition & 1 deletion cmd/network-helper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
8 changes: 4 additions & 4 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)

Expand Down
28 changes: 8 additions & 20 deletions pkg/controller/agent/linkmonitor/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package linkmonitor
import (
"context"
"fmt"
"reflect"

ctlcorev1 "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
"github.com/vishvananda/netlink"
Expand Down Expand Up @@ -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

Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/agent/nad/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/agent/vlanconfig/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/manager/clusternetwork/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ 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"
"k8s.io/klog/v2"

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"
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/manager/nad/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions pkg/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/vmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/nad/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/webhook/vlanconfig/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit dce93a4

Please sign in to comment.