Skip to content

Commit 816eabe

Browse files
author
jc2543
authored
Merge branch 'master' into 842adependabot/go_modules/build/tools/sigs.k8s.io/controller-tools-0.16.4
2 parents 727a4bf + 571afbc commit 816eabe

File tree

22 files changed

+499
-191
lines changed

22 files changed

+499
-191
lines changed

azure-ipam/go.mod

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ toolchain go1.23.2
77
require (
88
github.com/Azure/azure-container-networking v1.5.21
99
github.com/containernetworking/cni v1.2.3
10-
github.com/containernetworking/plugins v1.5.1
10+
github.com/containernetworking/plugins v1.6.0
1111
github.com/pkg/errors v0.9.1
1212
github.com/stretchr/testify v1.9.0
1313
go.uber.org/zap v1.27.0
@@ -24,26 +24,26 @@ require (
2424
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
2525
github.com/Masterminds/semver v1.5.0 // indirect
2626
github.com/Microsoft/go-winio v0.6.2 // indirect
27-
github.com/Microsoft/hcsshim v0.12.3 // indirect
27+
github.com/Microsoft/hcsshim v0.12.7 // indirect
2828
github.com/avast/retry-go/v3 v3.1.1 // indirect
2929
github.com/beorn7/perks v1.0.1 // indirect
3030
github.com/billgraziano/dpapi v0.5.0 // indirect
31-
github.com/cespare/xxhash/v2 v2.2.0 // indirect
32-
github.com/containerd/cgroups/v3 v3.0.2 // indirect
31+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
32+
github.com/containerd/cgroups/v3 v3.0.3 // indirect
3333
github.com/containerd/errdefs v0.1.0 // indirect
34-
github.com/coreos/go-iptables v0.7.0 // indirect
34+
github.com/coreos/go-iptables v0.8.0 // indirect
3535
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
3636
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
3737
github.com/fsnotify/fsnotify v1.7.0 // indirect
38-
github.com/go-logr/logr v1.4.1 // indirect
38+
github.com/go-logr/logr v1.4.2 // indirect
3939
github.com/go-openapi/jsonpointer v0.20.0 // indirect
4040
github.com/go-openapi/jsonreference v0.20.2 // indirect
4141
github.com/go-openapi/swag v0.22.4 // indirect
4242
github.com/gofrs/uuid v4.4.0+incompatible // indirect
4343
github.com/gogo/protobuf v1.3.2 // indirect
4444
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
4545
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
46-
github.com/golang/protobuf v1.5.3 // indirect
46+
github.com/golang/protobuf v1.5.4 // indirect
4747
github.com/google/gnostic-models v0.6.8 // indirect
4848
github.com/google/gofuzz v1.2.0 // indirect
4949
github.com/google/uuid v1.6.0 // indirect
@@ -59,28 +59,27 @@ require (
5959
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
6060
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
6161
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
62-
github.com/prometheus/client_golang v1.18.0 // indirect
63-
github.com/prometheus/client_model v0.5.0 // indirect
64-
github.com/prometheus/common v0.46.0 // indirect
65-
github.com/prometheus/procfs v0.12.0 // indirect
62+
github.com/prometheus/client_golang v1.20.2 // indirect
63+
github.com/prometheus/client_model v0.6.1 // indirect
64+
github.com/prometheus/common v0.55.0 // indirect
65+
github.com/prometheus/procfs v0.15.1 // indirect
6666
github.com/sirupsen/logrus v1.9.3 // indirect
6767
github.com/spf13/pflag v1.0.5 // indirect
6868
github.com/vishvananda/netns v0.0.4 // indirect
6969
go.opencensus.io v0.24.0 // indirect
7070
go.uber.org/multierr v1.11.0 // indirect
71-
golang.org/x/crypto v0.24.0 // indirect
71+
golang.org/x/crypto v0.26.0 // indirect
7272
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
73-
golang.org/x/net v0.26.0 // indirect
74-
golang.org/x/oauth2 v0.16.0 // indirect
75-
golang.org/x/sync v0.7.0 // indirect
76-
golang.org/x/sys v0.21.0 // indirect
77-
golang.org/x/term v0.21.0 // indirect
78-
golang.org/x/text v0.16.0 // indirect
73+
golang.org/x/net v0.28.0 // indirect
74+
golang.org/x/oauth2 v0.21.0 // indirect
75+
golang.org/x/sync v0.8.0 // indirect
76+
golang.org/x/sys v0.26.0 // indirect
77+
golang.org/x/term v0.23.0 // indirect
78+
golang.org/x/text v0.17.0 // indirect
7979
golang.org/x/time v0.5.0 // indirect
80-
google.golang.org/appengine v1.6.8 // indirect
81-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
82-
google.golang.org/grpc v1.62.0 // indirect
83-
google.golang.org/protobuf v1.33.0 // indirect
80+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
81+
google.golang.org/grpc v1.66.0 // indirect
82+
google.golang.org/protobuf v1.34.2 // indirect
8483
gopkg.in/inf.v0 v0.9.1 // indirect
8584
gopkg.in/yaml.v2 v2.4.0 // indirect
8685
gopkg.in/yaml.v3 v3.0.1 // indirect

azure-ipam/go.sum

Lines changed: 52 additions & 72 deletions
Large diffs are not rendered by default.

cns/NetworkContainerContract.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,13 @@ const (
9999
Managed = "Managed"
100100
CRD = "CRD"
101101
MultiTenantCRD = "MultiTenantCRD"
102+
AzureHost = "AzureHost"
102103
)
103104

104-
var ErrInvalidNCID = errors.New("invalid NetworkContainerID")
105-
var ErrInvalidIP = errors.New("invalid IP")
105+
var (
106+
ErrInvalidNCID = errors.New("invalid NetworkContainerID")
107+
ErrInvalidIP = errors.New("invalid IP")
108+
)
106109

107110
// CreateNetworkContainerRequest specifies request to create a network container or network isolation boundary.
108111
type CreateNetworkContainerRequest struct {

cns/hnsclient/hnsclient_windows.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/pkg/errors"
1818
)
1919

20+
// TODO redesign hnsclient on windows
2021
const (
2122
// Name of the external hns network
2223
ExtHnsNetworkName = "ext"
@@ -53,6 +54,9 @@ const (
5354
// Name of the loopback adapter needed to create Host NC apipa network
5455
hostNCLoopbackAdapterName = "LoopbackAdapterHostNCConnectivity"
5556

57+
// HNS rehydration issue requires this GW to be different than the loopback adapter ip, so we set it to .2
58+
defaultHnsGwIPAddress = "169.254.128.2"
59+
hnsLoopbackAdapterIPAddress = "169.254.128.1"
5660
// protocolTCP indicates the TCP protocol identifier in HCN
5761
protocolTCP = "6"
5862

@@ -301,7 +305,7 @@ func createHostNCApipaNetwork(
301305
if interfaceExists, _ := networkcontainers.InterfaceExists(hostNCLoopbackAdapterName); !interfaceExists {
302306
ipconfig := cns.IPConfiguration{
303307
IPSubnet: cns.IPSubnet{
304-
IPAddress: localIPConfiguration.GatewayIPAddress,
308+
IPAddress: hnsLoopbackAdapterIPAddress,
305309
PrefixLength: localIPConfiguration.IPSubnet.PrefixLength,
306310
},
307311
GatewayIPAddress: localIPConfiguration.GatewayIPAddress,
@@ -510,7 +514,7 @@ func configureHostNCApipaEndpoint(
510514
endpointPolicies, err := configureAclSettingHostNCApipaEndpoint(
511515
protocolList,
512516
networkContainerApipaIP,
513-
hostApipaIP,
517+
hnsLoopbackAdapterIPAddress,
514518
allowNCToHostCommunication,
515519
allowHostToNCCommunication,
516520
ncPolicies)
@@ -573,6 +577,7 @@ func CreateHostNCApipaEndpoint(
573577
return endpoint.Id, nil
574578
}
575579

580+
updateGwForLocalIPConfiguration(&localIPConfiguration)
576581
if network, err = createHostNCApipaNetwork(localIPConfiguration); err != nil {
577582
logger.Errorf("[Azure CNS] Failed to create HostNCApipaNetwork. Error: %v", err)
578583
return "", err
@@ -604,6 +609,17 @@ func CreateHostNCApipaEndpoint(
604609
return endpoint.Id, nil
605610
}
606611

612+
// updateGwForLocalIPConfiguration applies change on gw IP address for apipa NW and endpoint.
613+
// Currently, cns using the same ip address "169.254.128.1" for both apipa gw and loopback adapter. This cause conflict issue when hns get restarted and not able to rehydrate the apipa endpoints.
614+
// This func is to overwrite the address to 169.254.128.2 when the gateway address is 169.254.128.1
615+
func updateGwForLocalIPConfiguration(localIPConfiguration *cns.IPConfiguration) {
616+
// When gw address is 169.254.128.1, should use .2 instead. If gw address is not .1, that mean this value is
617+
// configured from dnc, we should keep it
618+
if localIPConfiguration.GatewayIPAddress == "169.254.128.1" {
619+
localIPConfiguration.GatewayIPAddress = defaultHnsGwIPAddress
620+
}
621+
}
622+
607623
func getHostNCApipaEndpointName(
608624
networkContainerID string) string {
609625
return hostNCApipaEndpointNamePrefix + "-" + networkContainerID
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package hnsclient
2+
3+
import (
4+
"testing"
5+
6+
"github.com/Azure/azure-container-networking/cns"
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestAdhocAdjustIPConfig(t *testing.T) {
11+
tests := []struct {
12+
name string
13+
ipConfig cns.IPConfiguration
14+
expected cns.IPConfiguration
15+
}{
16+
{
17+
name: "expect no change when gw address is not 169.254.128.1",
18+
ipConfig: cns.IPConfiguration{GatewayIPAddress: "169.254.128.3"},
19+
expected: cns.IPConfiguration{GatewayIPAddress: "169.254.128.3"},
20+
},
21+
{
22+
name: "expect default gw address is set when gw address is 169.254.128.1",
23+
ipConfig: cns.IPConfiguration{GatewayIPAddress: "169.254.128.1"},
24+
expected: cns.IPConfiguration{GatewayIPAddress: "169.254.128.2"},
25+
},
26+
}
27+
28+
for _, tt := range tests {
29+
tt := tt
30+
t.Run(tt.name, func(t *testing.T) {
31+
updateGwForLocalIPConfiguration(&tt.ipConfig)
32+
assert.Equal(t, tt.expected.GatewayIPAddress, tt.ipConfig.GatewayIPAddress)
33+
})
34+
}
35+
}

cns/nodesubnet/initialization.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package nodesubnet
2+
3+
import (
4+
"context"
5+
6+
"github.com/Azure/azure-container-networking/cns"
7+
"github.com/Azure/azure-container-networking/cns/logger"
8+
cnstypes "github.com/Azure/azure-container-networking/cns/types"
9+
"github.com/pkg/errors"
10+
"golang.org/x/exp/maps"
11+
)
12+
13+
type ipamReconciler interface {
14+
ReconcileIPAMStateForNodeSubnet(ncRequests []*cns.CreateNetworkContainerRequest, podInfoByIP map[string]cns.PodInfo) cnstypes.ResponseCode
15+
}
16+
17+
func ReconcileInitialCNSState(_ context.Context, ipamReconciler ipamReconciler, podInfoByIPProvider cns.PodInfoByIPProvider) (int, error) {
18+
// Get previous PodInfo state from podInfoByIPProvider
19+
podInfoByIP, err := podInfoByIPProvider.PodInfoByIP()
20+
if err != nil {
21+
return 0, errors.Wrap(err, "provider failed to provide PodInfoByIP")
22+
}
23+
24+
logger.Printf("Reconciling initial CNS state with %d IPs", len(podInfoByIP))
25+
26+
// Create a network container request that holds all the IPs from PodInfoByIP
27+
secondaryIPs := maps.Keys(podInfoByIP)
28+
ncRequest := CreateNodeSubnetNCRequest(secondaryIPs)
29+
responseCode := ipamReconciler.ReconcileIPAMStateForNodeSubnet([]*cns.CreateNetworkContainerRequest{ncRequest}, podInfoByIP)
30+
31+
if responseCode != cnstypes.Success {
32+
return 0, errors.Errorf("failed to reconcile initial CNS state: %d", responseCode)
33+
}
34+
35+
return len(secondaryIPs), nil
36+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package nodesubnet_test
2+
3+
import (
4+
"context"
5+
"net"
6+
"testing"
7+
8+
"github.com/Azure/azure-container-networking/cns"
9+
"github.com/Azure/azure-container-networking/cns/cnireconciler"
10+
"github.com/Azure/azure-container-networking/cns/logger"
11+
"github.com/Azure/azure-container-networking/cns/nodesubnet"
12+
"github.com/Azure/azure-container-networking/cns/restserver"
13+
"github.com/Azure/azure-container-networking/cns/types"
14+
"github.com/Azure/azure-container-networking/store"
15+
)
16+
17+
func getMockStore() store.KeyValueStore {
18+
mockStore := store.NewMockStore("")
19+
endpointState := map[string]*restserver.EndpointInfo{
20+
"12e65d89e58cb23c784e97840cf76866bfc9902089bdc8e87e9f64032e312b0b": {
21+
PodName: "coredns-54b69f46b8-ldmwr",
22+
PodNamespace: "kube-system",
23+
IfnameToIPMap: map[string]*restserver.IPInfo{
24+
"eth0": {
25+
IPv4: []net.IPNet{
26+
{
27+
IP: net.IPv4(10, 10, 0, 52),
28+
Mask: net.CIDRMask(24, 32),
29+
},
30+
},
31+
},
32+
},
33+
},
34+
"1fc5176913a3a1a7facfb823dde3b4ded404041134fef4f4a0c8bba140fc0413": {
35+
PodName: "load-test-7f7d49687d-wxc9p",
36+
PodNamespace: "load-test",
37+
IfnameToIPMap: map[string]*restserver.IPInfo{
38+
"eth0": {
39+
IPv4: []net.IPNet{
40+
{
41+
IP: net.IPv4(10, 10, 0, 63),
42+
Mask: net.CIDRMask(24, 32),
43+
},
44+
},
45+
},
46+
},
47+
},
48+
}
49+
50+
err := mockStore.Write(restserver.EndpointStoreKey, endpointState)
51+
if err != nil {
52+
return nil
53+
}
54+
return mockStore
55+
}
56+
57+
type MockIpamStateReconciler struct{}
58+
59+
func (m *MockIpamStateReconciler) ReconcileIPAMStateForNodeSubnet(ncRequests []*cns.CreateNetworkContainerRequest, podInfoByIP map[string]cns.PodInfo) types.ResponseCode {
60+
if len(ncRequests) == 1 && len(ncRequests[0].SecondaryIPConfigs) == len(podInfoByIP) {
61+
return types.Success
62+
}
63+
64+
return types.UnexpectedError
65+
}
66+
67+
func TestNewCNSPodInfoProvider(t *testing.T) {
68+
tests := []struct {
69+
name string
70+
store store.KeyValueStore
71+
wantErr bool
72+
reconciler *MockIpamStateReconciler
73+
exp int
74+
}{
75+
{
76+
name: "happy_path",
77+
store: getMockStore(),
78+
wantErr: false,
79+
reconciler: &MockIpamStateReconciler{},
80+
exp: 2,
81+
},
82+
}
83+
84+
for _, tt := range tests {
85+
tt := tt
86+
87+
t.Run(tt.name, func(t *testing.T) {
88+
ctx, cancel := testContext(t)
89+
defer cancel()
90+
91+
podInfoByIPProvider, err := cnireconciler.NewCNSPodInfoProvider(tt.store)
92+
checkErr(t, err, false)
93+
94+
got, err := nodesubnet.ReconcileInitialCNSState(ctx, tt.reconciler, podInfoByIPProvider)
95+
checkErr(t, err, tt.wantErr)
96+
if got != tt.exp {
97+
t.Errorf("got %d IPs reconciled, expected %d", got, tt.exp)
98+
}
99+
})
100+
}
101+
}
102+
103+
// testContext creates a context from the provided testing.T that will be
104+
// canceled if the test suite is terminated.
105+
func testContext(t *testing.T) (context.Context, context.CancelFunc) {
106+
if deadline, ok := t.Deadline(); ok {
107+
return context.WithDeadline(context.Background(), deadline)
108+
}
109+
return context.WithCancel(context.Background())
110+
}
111+
112+
func init() {
113+
logger.InitLogger("testlogs", 0, 0, "./")
114+
}

cns/nodesubnet/nodesubnet_nc.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package nodesubnet
2+
3+
import (
4+
"strconv"
5+
6+
"github.com/Azure/azure-container-networking/cns"
7+
"github.com/Azure/azure-container-networking/crd/nodenetworkconfig/api/v1alpha"
8+
)
9+
10+
const (
11+
// ID for fake NC that we create to store NodeSubnet IPS
12+
NodeSubnetNCID = "55022629-3854-499b-7133-5e6887959f4ea" // md5sum of "NodeSubnetNC_IPv4"
13+
NodeSubnetNCVersion = 0
14+
NodeSubnetHostVersion = "0"
15+
NodeSubnetNCStatus = v1alpha.NCUpdateSuccess
16+
NodeSubnetHostPrimaryIP = ""
17+
)
18+
19+
// CreateNodeSubnetNCRequest generates a CreateNetworkContainerRequest that simply stores the static secondary IPs.
20+
func CreateNodeSubnetNCRequest(secondaryIPs []string) *cns.CreateNetworkContainerRequest {
21+
secondaryIPConfigs := map[string]cns.SecondaryIPConfig{}
22+
23+
for _, secondaryIP := range secondaryIPs {
24+
// iterate through all secondary IP addresses add them to the request as secondary IPConfigs.
25+
secondaryIPConfigs[secondaryIP] = cns.SecondaryIPConfig{
26+
IPAddress: secondaryIP,
27+
NCVersion: NodeSubnetNCVersion,
28+
}
29+
}
30+
31+
return &cns.CreateNetworkContainerRequest{
32+
HostPrimaryIP: NodeSubnetHostPrimaryIP,
33+
SecondaryIPConfigs: secondaryIPConfigs,
34+
NetworkContainerid: NodeSubnetNCID,
35+
NetworkContainerType: cns.Docker, // Using docker as the NC type for NodeSubnet to match Swift. (The NC is not real)
36+
Version: strconv.FormatInt(NodeSubnetNCVersion, 10), //nolint:gomnd // it's decimal
37+
IPConfiguration: cns.IPConfiguration{},
38+
NCStatus: NodeSubnetNCStatus,
39+
}
40+
}

0 commit comments

Comments
 (0)