in controllers/hosting/endpointconfig_reconciler.go [70:137]
func (r *endpointConfigReconciler) Reconcile(ctx context.Context, desiredDeployment *hostingv1.HostingDeployment, shouldDeleteUnusedResources bool) error {
r.log.Info("Reconciling EndpointConfigs")
var err error
var desiredEndpointConfig *endpointconfigv1.EndpointConfig
if desiredEndpointConfig, err = r.extractDesiredEndpointConfigFromHostingDeployment(ctx, desiredDeployment); err != nil {
return errors.Wrap(err, "Unable to interpret HostingDeployment endpoint config")
}
if desiredEndpointConfig != nil {
r.log.Info("Desired endpoint config", "desired", desiredEndpointConfig)
}
var actualEndpointConfigs map[string]*endpointconfigv1.EndpointConfig
if actualEndpointConfigs, err = r.getActualEndpointConfigsForHostingDeployment(ctx, desiredDeployment); err != nil {
return errors.Wrap(err, "Unable to get actual endpoint config")
}
r.log.Info("Actual endpoint config", "actual", actualEndpointConfigs)
actions := r.determineActionForEndpointConfig(desiredEndpointConfig, actualEndpointConfigs)
for action, endpointConfigs := range actions {
r.log.Info("action", "action", action, "ecs", getEndpointConfigNamesFromMap(endpointConfigs))
switch action {
case NeedsNoop:
// Do nothing.
case NeedsCreate:
for _, endpointConfig := range endpointConfigs {
if err := r.k8sClient.Create(ctx, endpointConfig); err != nil {
return errors.Wrapf(err, "Unable to create Kubernetes EndpointConfig '%s'", types.NamespacedName{
Name: endpointConfig.ObjectMeta.Name,
Namespace: endpointConfig.ObjectMeta.Namespace,
})
}
}
case NeedsDelete:
if !shouldDeleteUnusedResources {
r.log.Info("Not deleting unused resources", "shouldDeleteUnusedResources", shouldDeleteUnusedResources)
break
}
for _, endpointConfig := range endpointConfigs {
if err := r.k8sClient.Delete(ctx, endpointConfig); err != nil {
if !apierrs.IsNotFound(err) {
return errors.Wrapf(err, "Unable to delete Kubernetes EndpointConfig '%s'", types.NamespacedName{
Name: endpointConfig.ObjectMeta.Name,
Namespace: endpointConfig.ObjectMeta.Namespace,
})
}
}
}
case NeedsUpdate:
for _, endpointConfig := range endpointConfigs {
if err = r.k8sClient.Update(ctx, endpointConfig); err != nil {
return errors.Wrapf(err, "Unable to update Kubernetes EndpointConfig '%s'", types.NamespacedName{
Name: endpointConfig.ObjectMeta.Name,
Namespace: endpointConfig.ObjectMeta.Namespace,
})
}
}
}
}
return nil
}