Skip to content

Commit

Permalink
Stateless CNI migration code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
behzad-mir committed Jan 5, 2024
1 parent 2869773 commit 0bd3047
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
18 changes: 3 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ ACN_VERSION ?= $(shell git describe --exclude "azure-ipam*" --exclude "dropgz
AZURE_IPAM_VERSION ?= $(notdir $(shell git describe --match "azure-ipam*" --tags --always))
CNI_VERSION ?= $(ACN_VERSION)
CNI_DROPGZ_VERSION ?= $(notdir $(shell git describe --match "dropgz*" --tags --always))
CNS_VERSION ?= "v1.5.15-22-g3d1fa46d"
CNS_VERSION ?= $(ACN_VERSION)
NPM_VERSION ?= $(ACN_VERSION)
ZAPAI_VERSION ?= $(notdir $(shell git describe --match "zapai*" --tags --always))

# Build directories.
AZURE_IPAM_DIR = $(REPO_ROOT)/azure-ipam
CNM_DIR = $(REPO_ROOT)/cnm/plugin
CNI_NET_DIR = $(REPO_ROOT)/cni/network/plugin
STATELESS_CNI_NET_DIR = $(REPO_ROOT)/cni/network/stateless
CNI_IPAM_DIR = $(REPO_ROOT)/cni/ipam/plugin
CNI_IPAMV6_DIR = $(REPO_ROOT)/cni/ipam/pluginv6
CNI_TELEMETRY_DIR = $(REPO_ROOT)/cni/telemetry/service
Expand All @@ -59,14 +58,11 @@ AZURE_IPAM_BUILD_DIR = $(BUILD_DIR)/azure-ipam
IMAGE_DIR = $(OUTPUT_DIR)/images
CNM_BUILD_DIR = $(BUILD_DIR)/cnm
CNI_BUILD_DIR = $(BUILD_DIR)/cni
STATELESS_CNI_BUILD_DIR = $(CNI_BUILD_DIR)/stateless
ACNCLI_BUILD_DIR = $(BUILD_DIR)/acncli
CNI_MULTITENANCY_BUILD_DIR = $(BUILD_DIR)/cni-multitenancy
CNI_MULTITENANCY_TRANSPARENT_VLAN_BUILD_DIR = $(BUILD_DIR)/cni-multitenancy-transparent-vlan
CNI_SWIFT_BUILD_DIR = $(BUILD_DIR)/cni-swift
STATELESS_CNI_SWIFT_BUILD_DIR = $(CNI_SWIFT_BUILD_DIR)/stateless
CNI_OVERLAY_BUILD_DIR = $(BUILD_DIR)/cni-overlay
STATELESS_CNI_OVERLAY_BUILD_DIR = $(CNI_OVERLAY_BUILD_DIR)/stateless
CNI_BAREMETAL_BUILD_DIR = $(BUILD_DIR)/cni-baremetal
CNI_DUALSTACK_BUILD_DIR = $(BUILD_DIR)/cni-dualstack
CNS_BUILD_DIR = $(BUILD_DIR)/cns
Expand Down Expand Up @@ -134,7 +130,7 @@ endif

# Shorthand target names for convenience.
azure-cnm-plugin: cnm-binary cnm-archive
azure-cni-plugin: azure-vnet-binary azure-vnet-stateless-binary azure-vnet-ipam-binary azure-vnet-ipamv6-binary azure-vnet-telemetry-binary cni-archive
azure-cni-plugin: azure-vnet-binary azure-vnet-ipam-binary azure-vnet-ipamv6-binary azure-vnet-telemetry-binary cni-archive
azure-cns: azure-cns-binary cns-archive
acncli: acncli-binary acncli-archive
azure-cnms: azure-cnms-binary cnms-archive
Expand Down Expand Up @@ -184,10 +180,6 @@ cnm-binary:
azure-vnet-binary:
cd $(CNI_NET_DIR) && CGO_ENABLED=0 go build -v -o $(CNI_BUILD_DIR)/azure-vnet$(EXE_EXT) -ldflags "-X main.version=$(CNI_VERSION)" -gcflags="-dwarflocationlists=true"

# Build the Azure CNI stateless network binary
azure-vnet-stateless-binary:
cd $(STATELESS_CNI_NET_DIR) && CGO_ENABLED=0 go build -v -o $(STATELESS_CNI_BUILD_DIR)/azure-vnet$(EXE_EXT) -ldflags "-X main.version=$(CNI_VERSION)" -gcflags="-dwarflocationlists=true"

# Build the Azure CNI IPAM binary.
azure-vnet-ipam-binary:
cd $(CNI_IPAM_DIR) && CGO_ENABLED=0 go build -v -o $(CNI_BUILD_DIR)/azure-vnet-ipam$(EXE_EXT) -ldflags "-X main.version=$(CNI_VERSION)" -gcflags="-dwarflocationlists=true"
Expand Down Expand Up @@ -683,16 +675,12 @@ endif
cp cni/azure-$(GOOS)-swift.conflist $(CNI_SWIFT_BUILD_DIR)/10-azure.conflist
cp telemetry/azure-vnet-telemetry.config $(CNI_SWIFT_BUILD_DIR)/azure-vnet-telemetry.config
cp $(CNI_BUILD_DIR)/azure-vnet$(EXE_EXT) $(CNI_BUILD_DIR)/azure-vnet-ipam$(EXE_EXT) $(CNI_BUILD_DIR)/azure-vnet-telemetry$(EXE_EXT) $(CNI_SWIFT_BUILD_DIR)
$(MKDIR) $(STATELESS_CNI_SWIFT_BUILD_DIR)
cp $(STATELESS_CNI_BUILD_DIR)/azure-vnet$(EXE_EXT) $(STATELESS_CNI_SWIFT_BUILD_DIR)
cd $(CNI_SWIFT_BUILD_DIR) && $(ARCHIVE_CMD) $(CNI_SWIFT_ARCHIVE_NAME) azure-vnet$(EXE_EXT) azure-vnet-ipam$(EXE_EXT) azure-vnet-telemetry$(EXE_EXT) 10-azure.conflist azure-vnet-telemetry.config

$(MKDIR) $(CNI_OVERLAY_BUILD_DIR)
cp cni/azure-$(GOOS)-swift-overlay.conflist $(CNI_OVERLAY_BUILD_DIR)/10-azure.conflist
cp telemetry/azure-vnet-telemetry.config $(CNI_OVERLAY_BUILD_DIR)/azure-vnet-telemetry.config
cp $(CNI_BUILD_DIR)/azure-vnet$(EXE_EXT) $(CNI_BUILD_DIR)/azure-vnet-ipam$(EXE_EXT) $(CNI_BUILD_DIR)/azure-vnet-telemetry$(EXE_EXT) $(CNI_OVERLAY_BUILD_DIR)
$(MKDIR) $(STATELESS_CNI_OVERLAY_BUILD_DIR)
cp $(STATELESS_CNI_BUILD_DIR)/azure-vnet$(EXE_EXT) $(STATELESS_CNI_OVERLAY_BUILD_DIR)
cd $(CNI_OVERLAY_BUILD_DIR) && $(ARCHIVE_CMD) $(CNI_OVERLAY_ARCHIVE_NAME) azure-vnet$(EXE_EXT) azure-vnet-ipam$(EXE_EXT) azure-vnet-telemetry$(EXE_EXT) 10-azure.conflist azure-vnet-telemetry.config

$(MKDIR) $(CNI_DUALSTACK_BUILD_DIR)
Expand Down Expand Up @@ -903,4 +891,4 @@ tools: acncli gocov gocov-xml go-junit-report golangci-lint gofumpt protoc ## Bu
##@ Help

help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
11 changes: 7 additions & 4 deletions cns/cnireconciler/podinfoprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,30 @@ func cniStateToCnsEndpointState(state *api.AzureCNIState) (map[string]*restserve
endpointState := map[string]*restserver.EndpointInfo{}
for _, endpoint := range state.ContainerInterfaces {

Check failure on line 114 in cns/cnireconciler/podinfoprovider.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, ubuntu-latest)

rangeValCopy: each iteration copies 136 bytes (consider pointers or indexing) (gocritic)

Check failure on line 114 in cns/cnireconciler/podinfoprovider.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, windows-latest)

rangeValCopy: each iteration copies 136 bytes (consider pointers or indexing) (gocritic)
endpointInfo := &restserver.EndpointInfo{PodName: endpoint.PodName, PodNamespace: endpoint.PodNamespace, HnsEndpointID: endpoint.HNSEndpointID, HostVethName: endpoint.HostIfName, IfnameToIPMap: make(map[string]*restserver.IPInfo)}

Check failure on line 115 in cns/cnireconciler/podinfoprovider.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, ubuntu-latest)

line is 232 characters (lll)

Check failure on line 115 in cns/cnireconciler/podinfoprovider.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, windows-latest)

line is 232 characters (lll)
ipInfo := &restserver.IPInfo{}
for _, epIP := range endpoint.IPAddresses {
if epIP.IP.To4() == nil { // is an ipv6 address
ipconfig := net.IPNet{IP: epIP.IP, Mask: epIP.Mask}
for _, ipconf := range endpointInfo.IfnameToIPMap[endpoint.IfName].IPv6 {
for _, ipconf := range ipInfo.IPv6 {
if ipconf.IP.Equal(ipconfig.IP) {
logger.Printf("Found existing ipv6 ipconfig for infra container %s", endpoint.ContainerID)
return nil, nil
}
}
endpointInfo.IfnameToIPMap[endpoint.IfName].IPv6 = append(endpointInfo.IfnameToIPMap[endpoint.IfName].IPv6, ipconfig)
ipInfo.IPv6 = append(ipInfo.IPv6, ipconfig)

} else {
ipconfig := net.IPNet{IP: epIP.IP, Mask: epIP.Mask}
for _, ipconf := range endpointInfo.IfnameToIPMap[endpoint.IfName].IPv4 {
for _, ipconf := range ipInfo.IPv4 {
if ipconf.IP.Equal(ipconfig.IP) {
logger.Printf("Found existing ipv4 ipconfig for infra container %s", endpoint.ContainerID)
return nil, nil
}
}
endpointInfo.IfnameToIPMap[endpoint.IfName].IPv4 = append(endpointInfo.IfnameToIPMap[endpoint.IfName].IPv4, ipconfig)
ipInfo.IPv4 = append(ipInfo.IPv4, ipconfig)
}
}
endpointInfo.IfnameToIPMap[endpoint.IfName] = ipInfo
endpointState[endpoint.ContainerID] = endpointInfo
}
return endpointState, nil
Expand Down
6 changes: 3 additions & 3 deletions cns/cnireconciler/podinfoprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestNewCNIPodInfoProvider(t *testing.T) {
{
name: "good",
exec: newCNIStateFakeExec(
`{"ContainerInterfaces":{"3f813b02-eth0":{"PodName":"metrics-server-77c8679d7d-6ksdh","PodNamespace":"kube-system","PodEndpointID":"3f813b02-eth0","ContainerID":"3f813b029429b4e41a09ab33b6f6d365d2ed704017524c78d1d0dece33cdaf46","IPAddresses":[{"IP":"10.241.0.17","Mask":"//8AAA=="}]},"6e688597-eth0":{"PodName":"tunnelfront-5d96f9b987-65xbn","PodNamespace":"kube-system","PodEndpointID":"6e688597-eth0","ContainerID":"6e688597eafb97c83c84e402cc72b299bfb8aeb02021e4c99307a037352c0bed","IPAddresses":[{"IP":"10.241.0.13","Mask":"//8AAA=="}]}}}`,
`{"ContainerInterfaces":{"3f813b02-eth0":{"PodName":"metrics-server-77c8679d7d-6ksdh","IfName":"eth0","PodNamespace":"kube-system","PodEndpointID":"3f813b02-eth0","ContainerID":"3f813b029429b4e41a09ab33b6f6d365d2ed704017524c78d1d0dece33cdaf46","IPAddresses":[{"IP":"10.241.0.17","Mask":"//8AAA=="}]},"6e688597-eth0":{"PodName":"tunnelfront-5d96f9b987-65xbn","IfName":"eth0","PodNamespace":"kube-system","PodEndpointID":"6e688597-eth0","ContainerID":"6e688597eafb97c83c84e402cc72b299bfb8aeb02021e4c99307a037352c0bed","IPAddresses":[{"IP":"10.241.0.13","Mask":"//8AAA=="}]}}}`,

Check failure on line 34 in cns/cnireconciler/podinfoprovider_test.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, ubuntu-latest)

line is 579 characters (lll)

Check failure on line 34 in cns/cnireconciler/podinfoprovider_test.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, windows-latest)

line is 579 characters (lll)
),
want: map[string]cns.PodInfo{
"10.241.0.13": cns.NewPodInfo("6e688597eafb97c83c84e402cc72b299bfb8aeb02021e4c99307a037352c0bed", "6e688597-eth0", "tunnelfront-5d96f9b987-65xbn", "kube-system"),
Expand All @@ -51,14 +51,14 @@ func TestNewCNIPodInfoProvider(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
got, _, err := newCNIPodInfoProvider(tt.exec)
got, endpointState, err := newCNIPodInfoProvider(tt.exec)
if tt.wantErr {
assert.Error(t, err)
return
}
assert.NoError(t, err)
podInfoByIP, _ := got.PodInfoByIP()
assert.Equal(t, tt.want, podInfoByIP)
assert.Equal(t, tt.want, podInfoByIP, endpointState)
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
logger.Printf("[Azure CNS] No endpoint state found, skipping initializing CNS state")
if cnsconfig.StatelessCNIMigration {
logger.Printf("StatelessCNI Migration is enabled")
logger.Printf("Initializing from Statefull CNI")
logger.Printf("initializing from Statefull CNI")
var endpointState map[string]*restserver.EndpointInfo
podInfoByIPProvider, endpointState, err = cnireconciler.NewCNIPodInfoProvider()
if err != nil {
Expand Down

0 comments on commit 0bd3047

Please sign in to comment.