Skip to content

Commit a3592c0

Browse files
authored
backport "feat: Consume the NCStatus to be able to append subnet is full error to Pod IP reservation failures" to release/v1.4 (#2252)
* Feat: Created a Network Container Status Section to be updated with the latest error code (#2193) * Added Network Conatiner Status to include the latest error code for a Network Container * Updated the crd to have the Status field included into the Network Container * Updated the names and added Status and ErrorText as two fields in NC Status * Fixed the casing and json values for these variables * Added error code to the NC Status and removed the latest prefix from the varibale names * Removed the timestamp variable from the NC Status * Moved the Status object inside the NC Status to be able to accurately define the status of each NC for the node * Changed to having an enum representing the NC Status which DNC-RC will update after inferring the error and CNS can use this field to propagate and NCRequest failures * Made the validation of the new enum optional to keep it backward compatible * feat: Consume the NCStatus to be able to append subnet is full error to Pod IP reservation failures (#2202) * Added Network Conatiner Status to include the latest error code for a Network Container * Updated the crd to have the Status field included into the Network Container * Updated the names and added Status and ErrorText as two fields in NC Status * Fixed the casing and json values for these variables * Propagated the NC Status inside the CNS and IPAM Monitor pool states * Fixed the lint error of missing comma * Saved the updated NC Status into the CNS statefile * Updated the IP assignment to check and error out subnet is Full when there are no more available IPs for CNS to assign * Fixed a minor compilation issue * Fixed lint failures * Fixed lint failures * Removed the reference from the metastate of the ipam monitor * Added Update Success and Update Failed statuses to the NC Status to be able to clearly indicate response status inside the NNC from DNC-RC * Updated the error to use errors pkg instead of fmt * Updating the cns reconcillation logic to skip if there is a failure updating the NC and there are no IPs allocated for the NC * Handled PR comments: * Updated the code to have the NC status be part of the error directly so that it can be consumed by containerD and cx can perform actions on it. * Code update to not use dynamic slices. * Removed the logic which handled 0 IPs allocated to NNC in CNS reconcile Signed-off-by: GitHub <[email protected]> * Addressed the PR comment which helped delete a block of code to store ncIDs and also added more error codes to the NCStatus --------- Signed-off-by: GitHub <[email protected]> * Fixed all the compilation failures in the files after chery-pick --------- Signed-off-by: GitHub <[email protected]>
1 parent 5d25eb1 commit a3592c0

File tree

7 files changed

+40
-9
lines changed

7 files changed

+40
-9
lines changed

cns/NetworkContainerContract.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99

1010
"github.com/Azure/azure-container-networking/cns/types"
11+
"github.com/Azure/azure-container-networking/crd/nodenetworkconfig/api/v1alpha"
1112
"github.com/pkg/errors"
1213
corev1 "k8s.io/api/core/v1"
1314
)
@@ -92,16 +93,17 @@ type CreateNetworkContainerRequest struct {
9293
AllowHostToNCCommunication bool
9394
AllowNCToHostCommunication bool
9495
EndpointPolicies []NetworkContainerRequestPolicies
96+
NCStatus v1alpha.NCStatus
9597
}
9698

9799
// CreateNetworkContainerRequest implements fmt.Stringer for logging
98100
func (req *CreateNetworkContainerRequest) String() string {
99101
return fmt.Sprintf("CreateNetworkContainerRequest"+
100102
"{Version: %s, NetworkContainerType: %s, NetworkContainerid: %s, PrimaryInterfaceIdentifier: %s, "+
101103
"LocalIPConfiguration: %+v, IPConfiguration: %+v, SecondaryIPConfigs: %+v, MultitenancyInfo: %+v, "+
102-
"AllowHostToNCCommunication: %t, AllowNCToHostCommunication: %t}",
104+
"AllowHostToNCCommunication: %t, AllowNCToHostCommunication: %t, NCStatus: %s}",
103105
req.Version, req.NetworkContainerType, req.NetworkContainerid, req.PrimaryInterfaceIdentifier, req.LocalIPConfiguration,
104-
req.IPConfiguration, req.SecondaryIPConfigs, req.MultiTenancyInfo, req.AllowHostToNCCommunication, req.AllowNCToHostCommunication)
106+
req.IPConfiguration, req.SecondaryIPConfigs, req.MultiTenancyInfo, req.AllowHostToNCCommunication, req.AllowNCToHostCommunication, string(req.NCStatus))
105107
}
106108

107109
// NetworkContainerRequestPolicies - specifies policies associated with create network request

cns/kubecontroller/nodenetworkconfig/conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func CreateNCRequestFromDynamicNC(nc v1alpha.NetworkContainer) (*cns.CreateNetwo
6666
IPSubnet: subnet,
6767
GatewayIPAddress: nc.DefaultGateway,
6868
},
69+
NCStatus: nc.Status,
6970
}, nil
7071
}
7172

cns/kubecontroller/nodenetworkconfig/conversion_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ func createNCRequestFromStaticNCHelper(nc v1alpha.NetworkContainer, primaryIPPre
3232
IPSubnet: subnet,
3333
GatewayIPAddress: nc.DefaultGateway,
3434
},
35+
NCStatus: nc.Status,
3536
}
3637
}

cns/kubecontroller/nodenetworkconfig/conversion_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ func createNCRequestFromStaticNCHelper(nc v1alpha.NetworkContainer, primaryIPPre
4444
IPSubnet: subnet,
4545
GatewayIPAddress: nc.DefaultGateway,
4646
},
47+
NCStatus: nc.Status,
4748
}
4849
}

cns/restserver/ipam.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,9 @@ func (service *HTTPRestService) AssignAnyAvailableIPConfig(podInfo cns.PodInfo)
542542
service.Lock()
543543
defer service.Unlock()
544544

545+
var ncID string
545546
for _, ipState := range service.PodIPConfigState {
547+
ncID = ipState.NCID
546548
if ipState.GetState() == types.Available {
547549
if err := service.assignIPConfig(ipState, podInfo); err != nil {
548550
return cns.PodIpInfo{}, err
@@ -557,7 +559,8 @@ func (service *HTTPRestService) AssignAnyAvailableIPConfig(podInfo cns.PodInfo)
557559
}
558560
}
559561
//nolint:goerr113
560-
return cns.PodIpInfo{}, fmt.Errorf("no IPs available, waiting on Azure CNS to allocate more")
562+
return cns.PodIpInfo{}, errors.Errorf("not enough IPs available for %s, waiting on Azure CNS to allocate more with NC Status: %s",
563+
ncID, string(service.state.ContainerStatus[ncID].CreateNetworkContainerRequest.NCStatus))
561564
}
562565

563566
// If IPConfig is already assigned to pod, it returns that else it returns one of the available ipconfigs.

crd/nodenetworkconfig/api/v1alpha/nodenetworkconfig.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ const (
5858
Error Status = "Error"
5959
)
6060

61+
// NCStatus indicates the latest NC request status
62+
// +kubebuilder:validation:Enum=NCUpdateSubnetFullError;NCUpdateInternalServerError;NCUpdateUnauthorizedError;NCUpdateSuccess;NCUpdateFailed
63+
// +kubebuilder:validation:Optional
64+
type NCStatus string
65+
66+
const (
67+
NCUpdateSubnetFull NCStatus = "NCUpdateSubnetFullError"
68+
NCUpdateInternalServerError NCStatus = "NCUpdateInternalServerError"
69+
NCUpdateUnauthorizedError NCStatus = "NCUpdateUnauthorizedError"
70+
NCUpdateSuccess NCStatus = "NCUpdateSuccess"
71+
NCUpdateFailed NCStatus = "NCUpdateFailed"
72+
)
73+
6174
// NodeNetworkConfigStatus defines the observed state of NetworkConfig
6275
type NodeNetworkConfigStatus struct {
6376
// +kubebuilder:default=0
@@ -107,12 +120,13 @@ type NetworkContainer struct {
107120
SubnetAddressSpace string `json:"subnetAddressSpace,omitempty"`
108121
// +kubebuilder:default=0
109122
// +kubebuilder:validation:Optional
110-
Version int64 `json:"version"`
111-
NodeIP string `json:"nodeIP,omitempty"`
112-
SubscriptionID string `json:"subcriptionID,omitempty"`
113-
ResourceGroupID string `json:"resourceGroupID,omitempty"`
114-
VNETID string `json:"vnetID,omitempty"`
115-
SubnetID string `json:"subnetID,omitempty"`
123+
Version int64 `json:"version"`
124+
NodeIP string `json:"nodeIP,omitempty"`
125+
SubscriptionID string `json:"subcriptionID,omitempty"`
126+
ResourceGroupID string `json:"resourceGroupID,omitempty"`
127+
VNETID string `json:"vnetID,omitempty"`
128+
SubnetID string `json:"subnetID,omitempty"`
129+
Status NCStatus `json:"status,omitempty"`
116130
}
117131

118132
// IPAssignment groups an IP address and Name. Name is a UUID set by the the IP address assigner.

crd/nodenetworkconfig/manifests/acn.azure.com_nodenetworkconfigs.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ spec:
115115
type: string
116116
resourceGroupID:
117117
type: string
118+
status:
119+
description: NCStatus indicates the latest NC request status
120+
enum:
121+
- NCUpdateSubnetFullError
122+
- NCUpdateInternalServerError
123+
- NCUpdateUnauthorizedError
124+
- NCUpdateSuccess
125+
- NCUpdateFailed
126+
type: string
118127
subcriptionID:
119128
type: string
120129
subnetAddressSpace:

0 commit comments

Comments
 (0)