func()

in pkg/controllers/cloudmap_controller.go [115:155]


func (r *CloudMapReconciler) reconcileService(ctx context.Context, svc *model.Service) error {
	r.Log.Debug("syncing service", "namespace", svc.Namespace, "service", svc.Name)

	importedSvcPorts := ExtractServicePorts(svc.Endpoints)

	svcImport, err := r.getServiceImport(ctx, svc.Namespace, svc.Name)
	if err != nil {
		if !errors.IsNotFound(err) {
			return err
		}

		// create ServiceImport if it doesn't exist
		if svcImport, err = r.createAndGetServiceImport(ctx, svc.Namespace, svc.Name, importedSvcPorts); err != nil {
			return err
		}
	}

	derivedService, err := r.getDerivedService(ctx, svc.Namespace, svcImport.Annotations[DerivedServiceAnnotation])
	if err != nil {
		if !errors.IsNotFound(err) {
			return err
		}

		// create derived Service if it doesn't exist
		if derivedService, err = r.createAndGetDerivedService(ctx, svcImport, importedSvcPorts); err != nil {
			return err
		}
	}

	// update service import to match derived service cluster IP and imported ports if necessary
	if err = r.updateServiceImport(ctx, svcImport, derivedService, importedSvcPorts); err != nil {
		return err
	}

	// update derived service ports to match imported ports if necessary
	if err = r.updateDerivedService(ctx, derivedService, importedSvcPorts); err != nil {
		return err
	}

	return r.updateEndpointSlices(ctx, svcImport, svc.Endpoints, derivedService)
}