Skip to content

Commit

Permalink
Fix controller tests
Browse files Browse the repository at this point in the history
Signed-off-by: terashima <[email protected]>
  • Loading branch information
terassyi committed Dec 23, 2024
1 parent da602a7 commit 9c72524
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 0 additions & 2 deletions v2/cmd/coil-egress/sub/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ func init() {

// +kubebuilder:scaffold:scheme

metrics.Registry.MustRegister(controllers.ClientPods)
metrics.Registry.MustRegister(controllers.ClientPodInfo)
metrics.Registry.MustRegister(egressMetrics.NfConnctackCount)
metrics.Registry.MustRegister(egressMetrics.NfConnctackLimit)
metrics.Registry.MustRegister(egressMetrics.NfTableMasqueradeBytes)
Expand Down
15 changes: 14 additions & 1 deletion v2/controllers/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (t *mockFoUTunnel) AddPeer(ip net.IP, sportAuto bool) (netlink.Link, error)
defer t.mu.Unlock()

t.peers[ip.String()] = sportAuto
return nil, nil
return &mockLink{name: ip.String()}, nil
}

func (t *mockFoUTunnel) DelPeer(ip net.IP) error {
Expand Down Expand Up @@ -211,3 +211,16 @@ func (e *mockEgress) GetClients() map[string]bool {
}
return m
}

// mockLink implements netlink.Link interface
type mockLink struct {
name string
}

func (m *mockLink) Attrs() *netlink.LinkAttrs {
return &netlink.LinkAttrs{Name: m.name}
}

func (m *mockLink) Type() string {
return "mock-link"
}
6 changes: 6 additions & 0 deletions v2/controllers/pod_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/metrics"
)

var (
Expand All @@ -45,6 +46,11 @@ var (
)
)

func init() {
metrics.Registry.MustRegister(ClientPods)
metrics.Registry.MustRegister(ClientPodInfo)
}

// +kubebuilder:rbac:groups="",resources=pods,verbs=get;list;watch

// SetupPodWatcher registers pod watching reconciler to mgr.
Expand Down

0 comments on commit 9c72524

Please sign in to comment.