in pkg/node/node.go [152:198]
func (n *node) InitResources(resourceManager resource.ResourceManager) error {
n.lock.Lock()
defer n.lock.Unlock()
err := n.instance.LoadDetails(n.ec2API)
if err != nil {
if errors.Is(err, utils.ErrNotFound) {
// Send a node event for users' visibility
msg := fmt.Sprintf("The instance type %s is not supported yet by the vpc resource controller", n.instance.Type())
utils.SendNodeEventWithNodeName(n.k8sAPI, n.instance.Name(), utils.UnsupportedInstanceTypeReason, msg, v1.EventTypeWarning, n.log)
}
return &ErrInitResources{
Message: "failed to load instance details",
Err: err,
}
}
var initializedProviders []provider.ResourceProvider
var errInit error
for _, resourceProvider := range resourceManager.GetResourceProviders() {
// Check if the instance is supported and then initialize the provider
if resourceProvider.IsInstanceSupported(n.instance) {
errInit = resourceProvider.InitResource(n.instance)
if errInit != nil {
break
}
initializedProviders = append(initializedProviders, resourceProvider)
}
}
if errInit != nil {
// de-init all the providers that were already initialized, we will retry initialization
// in next resync period
for _, resourceProvider := range initializedProviders {
errDeInit := resourceProvider.DeInitResource(n.instance)
n.log.Error(errDeInit, "failed to de initialize resource")
}
// Return ErrInitResources so that the manager removes the node from the
// cache allowing it to be retried in next sync period.
return &ErrInitResources{
Message: "failed to init resources",
Err: errInit,
}
}
n.ready = true
return errInit
}