in pkg/node/manager/manager.go [363:402]
func (m *manager) updateSubnetIfUsingENIConfig(cachedNode node.Node, k8sNode *v1.Node) error {
eniConfigName, isPresent := k8sNode.Labels[config.CustomNetworkingLabel]
var cniNodeEnabled bool
var err error
if !isPresent {
if cniNodeEnabled, err = m.customNetworkEnabledInCNINode(k8sNode); err != nil {
return err
}
}
if isPresent || cniNodeEnabled {
if !isPresent {
var err error
eniConfigName, err = m.GetEniConfigName(k8sNode)
// if we couldn't find the name from CNINode, this should be a misconfiguration
// as long as the feature is registered in CNINode, we couldn't easily use "" as eniconfig name
// when not able to find the name from CNINode.
if err != nil {
if errors.Is(err, utils.ErrNotFound) {
utils.SendNodeEventWithNodeObject(
m.wrapper.K8sAPI, k8sNode, utils.EniConfigNameNotFoundReason, err.Error(), v1.EventTypeWarning, m.Log)
}
return err
}
}
eniConfig, err := m.wrapper.K8sAPI.GetENIConfig(eniConfigName)
if err != nil {
return fmt.Errorf("failed to find the ENIConfig %s: %v", eniConfigName, err)
}
if eniConfig.Spec.Subnet != "" {
m.Log.V(1).Info("node is using custom networking, updating the subnet", "node", k8sNode.Name,
"subnet", eniConfig.Spec.Subnet)
cachedNode.UpdateCustomNetworkingSpecs(eniConfig.Spec.Subnet, eniConfig.Spec.SecurityGroups)
return nil
}
} else {
cachedNode.UpdateCustomNetworkingSpecs("", nil)
}
return nil
}