in projects/k8s-hybrid-neg-controller/pkg/reconciler/service.go [89:126]
func (r *serviceReconciler) reconcile(ctx context.Context, logger logr.Logger, serviceNamespacedName types.NamespacedName) error {
service := &corev1.Service{}
if err := r.Get(ctx, serviceNamespacedName, service); err != nil {
// Ignore not-found errors, since they can't be fixed by an immediate requeue.
return client.IgnoreNotFound(err)
}
if !service.ObjectMeta.DeletionTimestamp.IsZero() {
if err := r.handleDelete(ctx, logger, service); err != nil {
return err
}
// Stop reconciliation as the item is being deleted
return nil
}
negConfig, negConfigAnnotationExists, err := getHybridNEGConfig(service.ObjectMeta.Annotations)
if err != nil {
r.recorder.Event(service, "Warning", "ConfigError", err.Error())
return reconcile.TerminalError(err)
}
logger.V(4).Info("Hybrid NEG config annotation", "negConfig", negConfig)
negStatus, negStatusAnnotationExists, err := getHybridNEGStatus(service.ObjectMeta.Annotations)
if err != nil {
r.recorder.Event(service, "Warning", "ConfigError", err.Error())
logger.Error(err, "Problem reading the hybrid NEG status annotation, proceeding as if it does not exist")
}
logger.V(4).Info("Hybrid NEG status annotation", "negStatus", negStatus)
if !negConfigAnnotationExists && !negStatusAnnotationExists {
// No hybrid NEG annotations, do nothing.
return nil
}
negsToCreate, negsToDelete := r.syncNEGs(ctx, logger, serviceNamespacedName, negConfig, negStatus)
if err := r.updateService(ctx, logger, service, negStatus, negsToCreate, negsToDelete); err != nil {
return err
}
return nil
}