Skip to content

Commit

Permalink
fix(krnode): apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Tom Wieczorek <[email protected]>
  • Loading branch information
aauren and twz123 committed Sep 29, 2024
1 parent 7d55309 commit e4fa335
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 233 deletions.
2 changes: 1 addition & 1 deletion pkg/controllers/netpol/network_policy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var (

// NetworkPolicyController struct to hold information required by NetworkPolicyController
type NetworkPolicyController struct {
krNode utils.NodeAware
krNode utils.NodeIPAndFamilyAware
serviceClusterIPRanges []net.IPNet
serviceExternalIPRanges []net.IPNet
serviceLoadBalancerIPRanges []net.IPNet
Expand Down
8 changes: 5 additions & 3 deletions pkg/controllers/proxy/network_services_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@ var _ = Describe("NetworkServicesController", func() {
fatalf("failed to create existing services: %v", err)
}

krNode := &utils.KRNode{
NodeName: "node-1",
PrimaryIP: net.ParseIP("10.0.0.0"),
krNode := &utils.LocalKRNode{
KRNode: utils.KRNode{
NodeName: "node-1",
PrimaryIP: net.ParseIP("10.0.0.0"),
},
}
nsc = &NetworkServicesController{
krNode: krNode,
Expand Down
16 changes: 10 additions & 6 deletions pkg/controllers/proxy/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ func getMoqNSC() *NetworkServicesController {
setupRoutesForExternalIPForDSRFunc: lnm.setupRoutesForExternalIPForDSR,
}

krNode := &utils.KRNode{
NodeName: "node-1",
PrimaryIP: net.ParseIP("10.0.0.0"),
krNode := &utils.LocalKRNode{
KRNode: utils.KRNode{
NodeName: "node-1",
PrimaryIP: net.ParseIP("10.0.0.0"),
},
}
return &NetworkServicesController{
krNode: krNode,
Expand Down Expand Up @@ -191,9 +193,11 @@ func TestIsValidKubeRouterServiceArtifact(t *testing.T) {
loadBalancerIPs: []string{"172.16.0.3"},
}

krNode := &utils.KRNode{
NodeName: "node-1",
PrimaryIP: net.ParseIP("192.168.1.10"),
krNode := &utils.LocalKRNode{
KRNode: utils.KRNode{
NodeName: "node-1",
PrimaryIP: net.ParseIP("192.168.1.10"),
},
}

nsc := &NetworkServicesController{
Expand Down
6 changes: 4 additions & 2 deletions pkg/controllers/routing/bgp_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ type PolicyTestCase struct {
}

func Test_AddPolicies(t *testing.T) {
ipv4CapableKRNode := &utils.KRNode{
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.IPv4(10, 10, 10, 10)}},
ipv4CapableKRNode := &utils.LocalKRNode{
KRNode: utils.KRNode{
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.IPv4(10, 10, 10, 10)}},
},
}
testcases := []PolicyTestCase{
{
Expand Down
136 changes: 85 additions & 51 deletions pkg/controllers/routing/ecmp_vip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ func Test_getVIPsForService(t *testing.T) {
advertiseClusterIP: true,
advertiseExternalIP: true,
advertiseLoadBalancerIP: true,
krNode: &utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
krNode: &utils.LocalKRNode{
KRNode: utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
},
},
},
serviceAdvertisedIPs: []*ServiceAdvertisedIPs{
Expand Down Expand Up @@ -98,9 +100,11 @@ func Test_getVIPsForService(t *testing.T) {
advertiseClusterIP: false,
advertiseExternalIP: false,
advertiseLoadBalancerIP: false,
krNode: &utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
krNode: &utils.LocalKRNode{
KRNode: utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
},
},
},
serviceAdvertisedIPs: []*ServiceAdvertisedIPs{
Expand Down Expand Up @@ -140,9 +144,11 @@ func Test_getVIPsForService(t *testing.T) {
advertiseClusterIP: true,
advertiseExternalIP: false,
advertiseLoadBalancerIP: false,
krNode: &utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
krNode: &utils.LocalKRNode{
KRNode: utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
},
},
},
serviceAdvertisedIPs: []*ServiceAdvertisedIPs{
Expand Down Expand Up @@ -182,9 +188,11 @@ func Test_getVIPsForService(t *testing.T) {
advertiseClusterIP: false,
advertiseExternalIP: true,
advertiseLoadBalancerIP: false,
krNode: &utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
krNode: &utils.LocalKRNode{
KRNode: utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
},
},
},
serviceAdvertisedIPs: []*ServiceAdvertisedIPs{
Expand Down Expand Up @@ -224,9 +232,11 @@ func Test_getVIPsForService(t *testing.T) {
advertiseClusterIP: false,
advertiseExternalIP: false,
advertiseLoadBalancerIP: true,
krNode: &utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
krNode: &utils.LocalKRNode{
KRNode: utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
},
},
},
serviceAdvertisedIPs: []*ServiceAdvertisedIPs{
Expand Down Expand Up @@ -266,9 +276,11 @@ func Test_getVIPsForService(t *testing.T) {
advertiseClusterIP: false,
advertiseExternalIP: false,
advertiseLoadBalancerIP: false,
krNode: &utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
krNode: &utils.LocalKRNode{
KRNode: utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
},
},
},
serviceAdvertisedIPs: []*ServiceAdvertisedIPs{
Expand Down Expand Up @@ -337,9 +349,11 @@ func Test_getVIPsForService(t *testing.T) {
advertiseClusterIP: true,
advertiseExternalIP: true,
advertiseLoadBalancerIP: true,
krNode: &utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
krNode: &utils.LocalKRNode{
KRNode: utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
},
},
},
serviceAdvertisedIPs: []*ServiceAdvertisedIPs{
Expand Down Expand Up @@ -395,9 +409,11 @@ func Test_getVIPsForService(t *testing.T) {
advertiseClusterIP: true,
advertiseExternalIP: true,
advertiseLoadBalancerIP: true,
krNode: &utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
krNode: &utils.LocalKRNode{
KRNode: utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
},
},
},
serviceAdvertisedIPs: []*ServiceAdvertisedIPs{
Expand Down Expand Up @@ -445,9 +461,11 @@ func Test_getVIPsForService(t *testing.T) {
advertiseClusterIP: true,
advertiseExternalIP: true,
advertiseLoadBalancerIP: true,
krNode: &utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv6),
NodeIPv6Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv6)}},
krNode: &utils.LocalKRNode{
KRNode: utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv6),
NodeIPv6Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv6)}},
},
},
},
serviceAdvertisedIPs: []*ServiceAdvertisedIPs{
Expand Down Expand Up @@ -495,9 +513,11 @@ func Test_getVIPsForService(t *testing.T) {
advertiseClusterIP: true,
advertiseExternalIP: true,
advertiseLoadBalancerIP: true,
krNode: &utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
krNode: &utils.LocalKRNode{
KRNode: utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
},
},
},
serviceAdvertisedIPs: []*ServiceAdvertisedIPs{
Expand Down Expand Up @@ -541,9 +561,11 @@ func Test_getVIPsForService(t *testing.T) {
advertiseClusterIP: true,
advertiseExternalIP: true,
advertiseLoadBalancerIP: true,
krNode: &utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv6),
NodeIPv6Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv6)}},
krNode: &utils.LocalKRNode{
KRNode: utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv6),
NodeIPv6Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv6)}},
},
},
},
serviceAdvertisedIPs: []*ServiceAdvertisedIPs{
Expand Down Expand Up @@ -587,9 +609,11 @@ func Test_getVIPsForService(t *testing.T) {
advertiseClusterIP: true,
advertiseExternalIP: true,
advertiseLoadBalancerIP: true,
krNode: &utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv6Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv6)}},
krNode: &utils.LocalKRNode{
KRNode: utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv6Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv6)}},
},
},
},
serviceAdvertisedIPs: []*ServiceAdvertisedIPs{
Expand Down Expand Up @@ -637,9 +661,11 @@ func Test_getVIPsForService(t *testing.T) {
advertiseClusterIP: true,
advertiseExternalIP: true,
advertiseLoadBalancerIP: true,
krNode: &utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv6),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
krNode: &utils.LocalKRNode{
KRNode: utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv6),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
},
},
},
serviceAdvertisedIPs: []*ServiceAdvertisedIPs{
Expand Down Expand Up @@ -687,9 +713,11 @@ func Test_getVIPsForService(t *testing.T) {
advertiseClusterIP: true,
advertiseExternalIP: true,
advertiseLoadBalancerIP: true,
krNode: &utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
krNode: &utils.LocalKRNode{
KRNode: utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
},
},
},
serviceAdvertisedIPs: []*ServiceAdvertisedIPs{
Expand Down Expand Up @@ -733,9 +761,11 @@ func Test_getVIPsForService(t *testing.T) {
advertiseClusterIP: true,
advertiseExternalIP: true,
advertiseLoadBalancerIP: true,
krNode: &utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv6),
NodeIPv6Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv6)}},
krNode: &utils.LocalKRNode{
KRNode: utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv6),
NodeIPv6Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv6)}},
},
},
},
serviceAdvertisedIPs: []*ServiceAdvertisedIPs{
Expand Down Expand Up @@ -779,9 +809,11 @@ func Test_getVIPsForService(t *testing.T) {
advertiseClusterIP: true,
advertiseExternalIP: true,
advertiseLoadBalancerIP: true,
krNode: &utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
krNode: &utils.LocalKRNode{
KRNode: utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv4),
NodeIPv4Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv4)}},
},
},
},
serviceAdvertisedIPs: []*ServiceAdvertisedIPs{
Expand Down Expand Up @@ -825,9 +857,11 @@ func Test_getVIPsForService(t *testing.T) {
advertiseClusterIP: true,
advertiseExternalIP: true,
advertiseLoadBalancerIP: true,
krNode: &utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv6),
NodeIPv6Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv6)}},
krNode: &utils.LocalKRNode{
KRNode: utils.KRNode{
PrimaryIP: net.ParseIP(testNodeIPv6),
NodeIPv6Addrs: map[v1core.NodeAddressType][]net.IP{v1core.NodeInternalIP: {net.ParseIP(testNodeIPv6)}},
},
},
},
serviceAdvertisedIPs: []*ServiceAdvertisedIPs{
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/routing/network_routes_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ func (nrc *NetworkRoutingController) syncNodeIPSets(nodeIPAware utils.NodeIPAwar
}

var ipv4Addrs, ipv6Addrs [][]string
for _, nodeIPv4 := range nodeIPAware.GetNodeIPv6Addrs() {
for _, nodeIPv4 := range nodeIPAware.GetNodeIPv4Addrs() {
ipv4Addrs = append(ipv4Addrs, []string{nodeIPv4.String(), utils.OptionTimeout, "0"})
}
for _, nodeIPv6 := range nodeIPAware.GetNodeIPv6Addrs() {
Expand Down
Loading

0 comments on commit e4fa335

Please sign in to comment.