func()

in internal/controller/authproxyworkload_controller.go [130:171]


func (r *AuthProxyWorkloadReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
	l := log.FromContext(ctx)
	var err error

	resource := &cloudsqlapi.AuthProxyWorkload{}

	l.Info("Reconcile loop started AuthProxyWorkload", "name", req.NamespacedName)
	if err = r.Get(ctx, req.NamespacedName, resource); err != nil {
		// The resource can't be loaded.
		// If it was recently deleted, then ignore the error and don't requeue.
		if r.recentlyDeleted.get(req.NamespacedName) {
			return ctrl.Result{}, nil
		}

		// otherwise, report the error and requeue. This is likely caused by a delay
		// in reaching consistency in the eventually-consistent kubernetes API.
		l.Error(err, "unable to fetch resource")
		return requeueWithDelay, err
	}

	// If this was deleted, doDelete()
	// DeletionTimestamp metadata field is set by k8s when a resource
	// has been deleted but the finalizers are still present. We check that this
	// value is not zero To determine when a resource is deleted and waiting for
	// completion of finalizers.
	if !resource.ObjectMeta.DeletionTimestamp.IsZero() {
		l.Info("Reconcile delete for AuthProxyWorkload",
			"name", resource.GetName(),
			"namespace", resource.GetNamespace(),
			"gen", resource.GetGeneration())
		r.recentlyDeleted.set(req.NamespacedName, true)
		// the object has been deleted
		return r.doDelete(ctx, resource)
	}

	l.Info("Reconcile add/update for AuthProxyWorkload",
		"name", resource.GetName(),
		"namespace", resource.GetNamespace(),
		"gen", resource.GetGeneration())
	r.recentlyDeleted.set(req.NamespacedName, false)
	return r.doCreateUpdate(ctx, l, resource)
}