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

feat: Consume the NCStatus to be able to append subnet is full error to Pod IP reservation failures #2202

Merged
merged 17 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
6 changes: 4 additions & 2 deletions cns/NetworkContainerContract.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/Azure/azure-container-networking/cns/types"
"github.com/Azure/azure-container-networking/crd/nodenetworkconfig/api/v1alpha"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
)
Expand Down Expand Up @@ -95,16 +96,17 @@ type CreateNetworkContainerRequest struct {
AllowHostToNCCommunication bool
AllowNCToHostCommunication bool
EndpointPolicies []NetworkContainerRequestPolicies
NCStatus v1alpha.NCStatus
}

// CreateNetworkContainerRequest implements fmt.Stringer for logging
func (req *CreateNetworkContainerRequest) String() string {
return fmt.Sprintf("CreateNetworkContainerRequest"+
"{Version: %s, NetworkContainerType: %s, NetworkContainerid: %s, PrimaryInterfaceIdentifier: %s, "+
"LocalIPConfiguration: %+v, IPConfiguration: %+v, SecondaryIPConfigs: %+v, MultitenancyInfo: %+v, "+
"AllowHostToNCCommunication: %t, AllowNCToHostCommunication: %t}",
"AllowHostToNCCommunication: %t, AllowNCToHostCommunication: %t, NCStatus: %s}",
req.Version, req.NetworkContainerType, req.NetworkContainerid, req.PrimaryInterfaceIdentifier, req.LocalIPConfiguration,
req.IPConfiguration, req.SecondaryIPConfigs, req.MultiTenancyInfo, req.AllowHostToNCCommunication, req.AllowNCToHostCommunication)
req.IPConfiguration, req.SecondaryIPConfigs, req.MultiTenancyInfo, req.AllowHostToNCCommunication, req.AllowNCToHostCommunication, string(req.NCStatus))
}

// NetworkContainerRequestPolicies - specifies policies associated with create network request
Expand Down
1 change: 1 addition & 0 deletions cns/kubecontroller/nodenetworkconfig/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func CreateNCRequestFromDynamicNC(nc v1alpha.NetworkContainer) (*cns.CreateNetwo
IPSubnet: subnet,
GatewayIPAddress: nc.DefaultGateway,
},
NCStatus: nc.Status,
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions cns/kubecontroller/nodenetworkconfig/conversion_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ func createNCRequestFromStaticNCHelper(nc v1alpha.NetworkContainer, primaryIPPre
IPSubnet: subnet,
GatewayIPAddress: nc.DefaultGateway,
},
NCStatus: nc.Status,
}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ func createNCRequestFromStaticNCHelper(nc v1alpha.NetworkContainer, primaryIPPre
IPSubnet: subnet,
GatewayIPAddress: nc.DefaultGateway,
},
NCStatus: nc.Status,
}, nil
}
9 changes: 7 additions & 2 deletions cns/restserver/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,13 @@ func (service *HTTPRestService) AssignAvailableIPConfigs(podInfo cns.PodInfo) ([

// Checks to make sure we found one IP for each NC
if len(ipsToAssign) != numOfNCs {
//nolint:goerr113 // return error
return podIPInfo, fmt.Errorf("not enough IPs available, waiting on Azure CNS to allocate more")
for ncID := range service.state.ContainerStatus {
if _, found := ipsToAssign[ncID]; found {
continue
}
return podIPInfo, errors.Errorf("not enough IPs available for %s, waiting on Azure CNS to allocate more with NC Status: %s",
ncID, string(service.state.ContainerStatus[ncID].CreateNetworkContainerRequest.NCStatus))
}
}

failedToAssignIP := false
Expand Down
8 changes: 6 additions & 2 deletions crd/nodenetworkconfig/api/v1alpha/nodenetworkconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ const (
)

// NCStatus indicates the latest NC request status
// +kubebuilder:validation:Enum=SubnetFull
// +kubebuilder:validation:Enum=NCUpdateSubnetFullError;NCUpdateInternalServerError;NCUpdateUnauthorizedError;NCUpdateSuccess;NCUpdateFailed
// +kubebuilder:validation:Optional
type NCStatus string

const (
NCStatusSubnetFull NCStatus = "SubnetFull"
NCUpdateSubnetFull NCStatus = "NCUpdateSubnetFullError"
NCUpdateInternalServerError NCStatus = "NCUpdateInternalServerError"
NCUpdateUnauthorizedError NCStatus = "NCUpdateUnauthorizedError"
NCUpdateSuccess NCStatus = "NCUpdateSuccess"
NCUpdateFailed NCStatus = "NCUpdateFailed"
)

// NodeNetworkConfigStatus defines the observed state of NetworkConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ spec:
status:
description: NCStatus indicates the latest NC request status
enum:
- SubnetFull
- NCUpdateSubnetFullError
- NCUpdateInternalServerError
- NCUpdateUnauthorizedError
- NCUpdateSuccess
- NCUpdateFailed
type: string
subcriptionID:
type: string
Expand Down