Skip to content

Commit

Permalink
Release cce-network-v2/2.12.15
Browse files Browse the repository at this point in the history
  • Loading branch information
gola committed Feb 28, 2025
1 parent 886a63a commit 24b5a0f
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 54 deletions.
2 changes: 1 addition & 1 deletion cce-network-v2/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.12.14
2.12.15
Binary file modified cce-network-v2/deploy/cce-network-v2-2.12.tar.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions cce-network-v2/deploy/cce-network-v2/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 2.12.14
version: 2.12.15

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "2.12.14"
appVersion: "2.12.15"
6 changes: 6 additions & 0 deletions cce-network-v2/docs/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ v2 版本新架构,支持VPC-ENI 辅助IP和vpc路由。版本发布历史如
3. 增加节点网络配置集功能 NetResourceConfigSet,支持指定节点独立配置网络资源。
4. 增加对 HPAS 实例的支持

#### 2.12.15 [20250227]
1. [Optimize] 优化 NetworkresourceSet.Spec.Addresses 的添加规则,避免重复添加节点 IP
2. [Bug] 修复 VPC-ENI 模式下,访问 ENI 接口失败时,误将 ENI 对象的 VPCStatus 标记为 None 的问题
3. [Optimize] 创建/lib/systemd/network/98-default.link文件,监控并持续维持其macAddressPolicy为None,解决该参数被意外修改后导致 veth 的 mac 地址被非预期变更的问题
4. [Bug] 修复 VPC-ENI 模式下,弹性网卡预挂载 eni-pre-allocate-num 配置在等于 eniQuota 时数量少一个的问题,增大重试次数避免 ENI 串行创建失败的问题

#### 2.12.14 [20250213]
1. [Bug] 修复 VPC-ENI 模式下的 remove ENI finalizer 更新逻辑,解决因节点删除时 ENI finalizer 未清理导致 ENI 对象残留的问题
2. [Bug] 修复 VPC-ENI 模式下,因启动时序导致在 cce-network-operator 启动过程中, PSTS 固定 IP 跨节点分配时可能导致的 panic 问题
Expand Down
5 changes: 3 additions & 2 deletions cce-network-v2/pkg/bce/bcesync/eni.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func (esm *eniStateMachine) start() error {
esm.scopeLog.Info("update eni spec success")
} else {
_, err = esm.es.remoteSyncer.statENI(esm.ctx, esm.resource.Name)
if err != nil {
if cloud.IsErrorReasonNoSuchObject(err) {
esm.scopeLog.Infof("eni state machine failed to get inuse eni(%s): %v", esm.resource.Name, err)
(&esm.resource.Status).AppendVPCStatus(ccev2.VPCENIStatusNone)
// update spec
Expand All @@ -395,6 +395,8 @@ func (esm *eniStateMachine) start() error {
}
esm.scopeLog.Info("update eni spec success")
return nil
} else if err != nil {
return fmt.Errorf("eni state machine failed to refresh eni(%s) status: %v", esm.resource.Name, err)
}
}
} else if esm.resource.Status.VPCStatus != ccev2.VPCENIStatusDeleted {
Expand All @@ -404,7 +406,6 @@ func (esm *eniStateMachine) start() error {
// eni not found, will delete it which not inuse
log.WithField("eniID", esm.resource.Name).Error("not inuse eni not found in vpc, will delete it")
return esm.deleteENI()

} else if err != nil {
return fmt.Errorf("eni state machine failed to refresh eni(%s) status: %v", esm.resource.Name, err)
}
Expand Down
9 changes: 6 additions & 3 deletions cce-network-v2/pkg/bce/vpceni/node_super.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func (n *bceNetworkResourceSet) getENIQuota() ENIQuotaManager {
if n.k8sObj.Annotations != nil && n.k8sObj.Annotations[k8s.AnnotationIPResourceCapacitySynced] != "" {
lastResyncTime := n.k8sObj.Annotations[k8s.AnnotationIPResourceCapacitySynced]
t, err := time.Parse(time.RFC3339, lastResyncTime)
// if the last resync time is not set or expired one day ago, go to slow path
if err != nil || t.Add(DayDuration).Before(time.Now()) {
goto slowPath
}
Expand Down Expand Up @@ -549,21 +550,22 @@ func (n *bceNetworkResourceSet) CreateInterface(ctx context.Context, allocation
inums, msg, err := n.real.createInterface(ctx, allocation, scopedLog)
n.creatingEni.add(-1)

preAllocateENINum := math.IntMin(eniQuota.GetMaxENI()-1, n.k8sObj.Spec.ENI.PreAllocateENI)
preAllocateENINum := math.IntMin(eniQuota.GetMaxENI(), n.k8sObj.Spec.ENI.PreAllocateENI)
preAllocateENINum = preAllocateENINum - availableENICount - 1
retryTimes := preAllocateENINum * 2
for i := 0; i < preAllocateENINum; i++ {
inums++
go func() {
retry := 0
for retry < preAllocateENINum {
for retry < retryTimes {
n.creatingEni.add(1)
_, _, e := n.real.createInterface(ctx, allocation, scopedLog)
n.creatingEni.add(-1)
if e == nil {
scopedLog.Infof("create addition interface success")
return
}
scopedLog.WithError(e).Errorf("create addition interface failed, retry later for %ds(%d/%d)", retryDelay, retry+1, preAllocateENINum)
scopedLog.WithError(e).Warnf("create addition interface failed, retry later for %ds(%d/%d)", retryDelay, retry+1, retryTimes)
retry++
// attaching ENI is need to wait serveral seconds (<15s) for the ENI to be attached,
// so we can retry preAllocateENINum times for every retryDelay(15s) seconds later.
Expand Down Expand Up @@ -824,6 +826,7 @@ func (n *bceNetworkResourceSet) AllocateIPs(ctx context.Context, allocation *ipa
return err
} else {
// if partial success, we will continue to allocate
// DO NOT EDIT HERE!Because the actual allocation is indeed not this much, but it can guarantee exiting the loop.
ipv4ToAllocate -= ipv4PaticalToAllocate
ipv6ToAllocate -= ipv6PaticalToAllocate
continue
Expand Down
1 change: 1 addition & 0 deletions cce-network-v2/pkg/ipam/net_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ func (n *NetResource) determineMaintenanceAction() (*maintenanceAction, error) {
// Validate that the node still requires addresses to be released, the
// request may have been resolved in the meantime.
// we will disable the release of excess IPs for burstable ENI mode.
// getMaxIPBurstableIPCount() == 0 meanes that we are not in burstable ENI mode.
if n.manager.releaseExcessIPs && stats.ExcessIPs > 0 && n.getMaxIPBurstableIPCount() == 0 {
a.release = n.ops.PrepareIPRelease(stats.ExcessIPs, scopedLog)
return a, nil
Expand Down
8 changes: 4 additions & 4 deletions cce-network-v2/pkg/nodediscovery/nodediscovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,7 @@ func (n *NodeDiscovery) updateLocalNode() {
if err != nil {
log.WithError(err).Fatal("Unable to detect OS distribution")
}
err = release.HostOS().DisableAndMonitorMacPersistant()
if err != nil {
log.WithError(err).Fatal("Unable to disable mac persist")
}
_ = release.HostOS().DisableAndMonitorMacPersistant()

if k8s.IsEnabled() {
// CRD IPAM endpoint restoration depends on the completion of this
Expand Down Expand Up @@ -322,6 +319,9 @@ func (n *NodeDiscovery) UpdateNetResourceSetResource() {
}

func (n *NodeDiscovery) mutateNodeResource(nodeResource *ccev2.NetResourceSet) error {
// reset NetworkresourceSet.Spec.Addresses to avoid stale data
nodeResource.Spec.Addresses = []ccev2.NodeAddress{}

// If we are unable to fetch the K8s Node resource and the NetResourceSet does
// not have an OwnerReference set, then somehow we are running in an
// environment where only the NetResourceSet exists. Do not proceed as this is
Expand Down
35 changes: 26 additions & 9 deletions cce-network-v2/pkg/os/systemd_networkd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package os
import (
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"

Expand All @@ -11,19 +12,19 @@ import (

const (
usrPath = "/usr-host"
defaultLinkPath = usrPath + "/lib/systemd/network/99-default.link"
defaultLinkPath = usrPath + "/lib/systemd/network/98-default.link"
macAddressPolicyKey = "MACAddressPolicy"
macAddressPolicyValueNone = "none"

defaultLinkTemplate = `
[Match]
OriginalName=*
[Link]
NamePolicy=keep kernel database onboard slot path
AlternativeNamesPolicy=database onboard slot path
MACAddressPolicy=none
`
[Match]
OriginalName=*
[Link]
NamePolicy=keep kernel database onboard slot path
AlternativeNamesPolicy=database onboard slot path
MACAddressPolicy=none
`
)

func UpdateSystemdConfigOption(linkPath, key, value string) error {
Expand Down Expand Up @@ -94,3 +95,19 @@ func CheckIfLinkOptionConfigured(linkPath, key, value string) (bool, error) {

return false, fmt.Errorf("failed to find %s in %s, the key is missing", key, linkPath)
}

// PrintFileContent reads the entire content of the specified file into a string, and then prints it
func PrintFileContent(filename string) error {
log.Info(filename, " file content:")
// Read the entire file
data, err := ioutil.ReadFile(filename)
if err != nil {
return fmt.Errorf("unable to read file: %v", err)
}

// Convert the data to a string and print it
content := string(data)
log.Info(content)

return nil
}
103 changes: 103 additions & 0 deletions cce-network-v2/pkg/os/systemd_networkd_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package os

import (
"io/ioutil"
"os"
"testing"

"github.com/baidubce/baiducloud-cce-cni-driver/cce-network-v2/test/testdata"
Expand Down Expand Up @@ -32,3 +34,104 @@ func TestUpdateSystemdConfigOption(t *testing.T) {
UpdateSystemdConfigOption(tt.args.linkPath, tt.args.key, tt.args.value)
}
}

func TestPrintFileContent(t *testing.T) {
type args struct {
filename string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "File exists and can be read",
args: args{
filename: "testfile.txt",
},
wantErr: false,
},
{
name: "File does not exist",
args: args{
filename: "nonexistent.txt",
},
wantErr: true,
},
}

// Create a temporary valid file for the test
tempFileContent := "Hello, World!"
tempFile, err := ioutil.TempFile("", "testfile.txt")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tempFile.Name()) // Clean up the file afterwards

if _, err := tempFile.WriteString(tempFileContent); err != nil {
t.Fatal(err)
}
tempFile.Close()

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var err error
if tt.args.filename == "testfile.txt" {
err = PrintFileContent(tempFile.Name())
} else {
err = PrintFileContent(tt.args.filename)
}

if (err != nil) != tt.wantErr {
t.Errorf("PrintFileContent() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

func TestCheckIfLinkOptionConfigured(t *testing.T) {
type args struct {
linkPath string
key string
value string
}
tests := []struct {
name string
args args
want bool
wantErr bool
}{
{
name: "check systemd config option",
args: args{
linkPath: testdata.Path("os/ubuntu/systemd/default.link"),
key: macAddressPolicyKey,
value: "none",
},
want: true,
wantErr: false,
},
{
name: "file does not exist",
args: args{
linkPath: testdata.Path(""),
key: macAddressPolicyKey,
value: "none",
},
want: false,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := CheckIfLinkOptionConfigured(tt.args.linkPath, tt.args.key, tt.args.value)
if (err != nil) != tt.wantErr {
t.Errorf("CheckIfLinkOptionConfigured() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("CheckIfLinkOptionConfigured() got = %v, want %v", got, tt.want)
}
})
}
}
Loading

0 comments on commit 24b5a0f

Please sign in to comment.