Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase datastore pool at startup #2354

Merged
merged 1 commit into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions cmd/aws-vpc-cni/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
package main

import (
"bytes"
"encoding/json"
"net"
"os"
Expand Down Expand Up @@ -171,13 +170,11 @@ type Range struct {
Gateway net.IP `json:"gateway,omitempty"`
}

// Wait for IPAMD health check to pass. Note that if IPAMD fails to start, wait happens indefinitely until liveness probe kills pod
func waitForIPAM() bool {
for {
cmd := exec.Command("./grpc-health-probe", "-addr", "127.0.0.1:50051", ">", "/dev/null", "2>&1")
var outb bytes.Buffer
cmd.Stdout = &outb
cmd.Run()
if outb.String() == "" {
if err := cmd.Run(); err == nil {
return true
}
}
Expand Down Expand Up @@ -443,7 +440,7 @@ func _main() int {

err = cp.CopyFile(tmpAWSconflistFile, defaultHostCNIConfDirPath+awsConflistFile)
if err != nil {
log.WithError(err).Errorf("Failed to copy 10-awsconflist")
log.WithError(err).Errorf("Failed to copy %s", awsConflistFile)
return 1
}
log.Infof("Successfully copied CNI plugin binary and config file.")
Expand Down
2 changes: 1 addition & 1 deletion pkg/awsutils/awsutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func (i instrumentedIMDS) GetMetadataWithContext(ctx context.Context, p string)

// New creates an EC2InstanceMetadataCache
func New(useCustomNetworking, disableLeakedENICleanup, v4Enabled, v6Enabled bool, eventRecorder *eventrecorder.EventRecorder) (*EC2InstanceMetadataCache, error) {
//ctx is passed to initWithEC2Metadata func to cancel spawned go-routines when tests are run
// ctx is passed to initWithEC2Metadata func to cancel spawned go-routines when tests are run
ctx := context.Background()

// Initializes prometheus metrics
Expand Down
25 changes: 12 additions & 13 deletions pkg/ipamd/datastore/data_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ type AddressInfo struct {

// CidrInfo
type CidrInfo struct {
//Either v4/v6 Host or LPM Prefix
// Either v4/v6 Host or LPM Prefix
Cidr net.IPNet
//Key is individual IP addresses from the Prefix - /32 (v4) or /128 (v6)
// Key is individual IP addresses from the Prefix - /32 (v4) or /128 (v6)
IPAddresses map[string]*AddressInfo
//true if Cidr here is an LPM prefix
// true if Cidr here is an LPM prefix
IsPrefix bool
//IP Address Family of the Cidr
// IP Address Family of the Cidr
AddressFamily string
}

Expand All @@ -200,8 +200,8 @@ func (cidr *CidrInfo) Size() int {
}

func (e *ENI) findAddressForSandbox(ipamKey IPAMKey) (*CidrInfo, *AddressInfo) {
//Either v4 or v6 for now.
//Check in V4 prefixes
// Either v4 or v6 for now.
// Check in V4 prefixes
for _, availableCidr := range e.AvailableIPv4Cidrs {
for _, addr := range availableCidr.IPAddresses {
if addr.IPAMKey == ipamKey {
Expand All @@ -210,7 +210,7 @@ func (e *ENI) findAddressForSandbox(ipamKey IPAMKey) (*CidrInfo, *AddressInfo) {
}
}

//Check in V6 prefixes
// Check in V6 prefixes
for _, availableCidr := range e.IPv6Cidrs {
for _, addr := range availableCidr.IPAddresses {
if addr.IPAMKey == ipamKey {
Expand Down Expand Up @@ -495,7 +495,7 @@ func (ds *DataStore) AddENI(eniID string, deviceNumber int, isPrimary, isTrunk,
ds.lock.Lock()
defer ds.lock.Unlock()

ds.log.Debugf("DataStore Add an ENI %s", eniID)
ds.log.Debugf("DataStore add an ENI %s", eniID)

_, ok := ds.eniPool[eniID]
if ok {
Expand Down Expand Up @@ -712,7 +712,7 @@ func (ds *DataStore) AssignPodIPv4Address(ipamKey IPAMKey, ipamMetadata IPAMMeta
ds.lock.Lock()
defer ds.lock.Unlock()

ds.log.Debugf("AssignIPv4Address: IP address pool stats: total: %d, assigned %d", ds.total, ds.assigned)
ds.log.Debugf("AssignIPv4Address: IP address pool stats: total %d, assigned %d", ds.total, ds.assigned)

if eni, _, addr := ds.eniPool.FindAddressForSandbox(ipamKey); addr != nil {
ds.log.Infof("AssignPodIPv4Address: duplicate pod assign for sandbox %s", ipamKey)
Expand Down Expand Up @@ -1123,8 +1123,7 @@ func (ds *DataStore) RemoveENIFromDataStore(eniID string, force bool) error {
func (ds *DataStore) UnassignPodIPAddress(ipamKey IPAMKey) (e *ENI, ip string, deviceNumber int, err error) {
ds.lock.Lock()
defer ds.lock.Unlock()
ds.log.Debugf("UnassignPodIPAddress: IP address pool stats: total:%d, assigned %d, sandbox %s",
ds.total, ds.assigned, ipamKey)
ds.log.Debugf("UnassignPodIPAddress: IP address pool stats: total %d, assigned %d, sandbox %s", ds.total, ds.assigned, ipamKey)

eni, availableCidr, addr := ds.eniPool.FindAddressForSandbox(ipamKey)
if addr == nil {
Expand Down Expand Up @@ -1241,7 +1240,7 @@ func (ds *DataStore) GetENIInfos() *ENIInfos {
tmpENIInfo := *eniInfo
tmpENIInfo.AvailableIPv4Cidrs = make(map[string]*CidrInfo, len(eniInfo.AvailableIPv4Cidrs))
tmpENIInfo.IPv6Cidrs = make(map[string]*CidrInfo, len(eniInfo.IPv6Cidrs))
for cidr, _ := range eniInfo.AvailableIPv4Cidrs {
for cidr := range eniInfo.AvailableIPv4Cidrs {
tmpENIInfo.AvailableIPv4Cidrs[cidr] = &CidrInfo{
Cidr: eniInfo.AvailableIPv4Cidrs[cidr].Cidr,
IPAddresses: make(map[string]*AddressInfo, len(eniInfo.AvailableIPv4Cidrs[cidr].IPAddresses)),
Expand All @@ -1253,7 +1252,7 @@ func (ds *DataStore) GetENIInfos() *ENIInfos {
tmpENIInfo.AvailableIPv4Cidrs[cidr].IPAddresses[ip] = &ipAddrInfo
}
}
for cidr, _ := range eniInfo.IPv6Cidrs {
for cidr := range eniInfo.IPv6Cidrs {
tmpENIInfo.IPv6Cidrs[cidr] = &CidrInfo{
Cidr: eniInfo.IPv6Cidrs[cidr].Cidr,
IPAddresses: make(map[string]*AddressInfo, len(eniInfo.IPv6Cidrs[cidr].IPAddresses)),
Expand Down
Loading