crossplane-contrib / crossplane-contrib/function-patch-and-transform

Patching from a non-existent 'from' field deletes the 'to' field

Ouverte
#85 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

known-issue
Langage dominant
Go
Étoiles
46
Forks
41
Merge moyen
1 j 10 h
PR mergées (30 j)
3

Description

Background

I plan to include https://github.com/crossplane-contrib/function-patch-and-transform/pull/81 in the v0.3.0 release of this function.

#81 changes how this function handles patch errors. This includes how the function handles patching from a field path that doesn't exist, which is a kind of patch error.

Most patch errors now cause the function to return a fatal result. A fatal result stops the entire function pipeline. The fatal result will appear as an event associated with the XR. For example a type mismatch like patching from an integer field to an array field would cause a fatal error.

We treat errors that occur due to missing 'from' field paths specially. Each patch can configure whether the 'from' field path is optional (the default) or required. This is because more than any other kind of error, a missing field path is likely to fix itself eventually.

Consider for example a composition that patches from MR A's status to the XR's spec, then patches that XR spec field to MR B's spec. MR B's spec is derived from MR A's status. It's normal for the patches to fail due to a missing field path until the status field is populated from the external system.

Sometimes it's fine for MR B to be created, then have its spec field derived from MR A's status once that status becomes available. You use an optional field path patch for this.

Other times MR B should not be created at all until the data from MR A's status is available. You use a required field path patch for this.

After #81 this function behaves per this table:

Patch Policy Patch From Patch To Result
Required XR New composed resource Emit an event. Don't create the composed resource.
Required XR Existing composed resource Emit an event. Skip the patch.
Required Env New composed resource Emit an event. Don't create the composed resource.
Required Env Existing composed resource Emit an event. Skip the patch.
Required * XR Emit an event. Skip the patch.
Required * Env Emit an event. Skip the patch.
Optional XR New composed resource Skip the patch. Create the composed resource.
Optional XR Existing composed resource Skip the patch.
Optional Env New composed resource Skip the patch. Create the composed resource.
Optional Env Existing composed resource Skip the patch.
Optional * XR Skip the patch.
Optional * Env Skip the patch.

Another way to look at this is:

  • The only purpose of a required 'from' field path is to block creation of the new 'to' resource.
  • If the 'to' resource already exists, we treat a required 'from' field path like optional, but emit a warning.
The Issue

This function computes desired state similarly to native P&T, but applies it differently. Functions use server-side apply (SSA), while native P&T uses client-side apply. One of the benefits of server-side apply is that it supports deleting fields. Our client-side apply implementation does not. This leads to issues like https://github.com/crossplane/crossplane/issues/4162.

This means that when native P&T skips a patch, the field it's patching to just remains how it was.

Because SSA interprets omitting a field from desired state as a desired to delete that field, when this functions skips a patch the field will be deleted.

This means that:

  • If you're patching to a resource that exists (e.g. the XR or an existing composed resource), and...
  • The patch has previously succeeded in patching from the 'from' field path to the 'to' field path, and...
  • The patch begins to fail because the 'to' field path no longer exists

This function will omit the 'to' field path from its desired state, causing it to be deleted.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Aucun fichier source ni aucun test n'est nommé dans l'issue. Commencez par lire #81 et suivre l'impact de l'absence d'un champ 'from' sur l'état souhaité d'une ressource existante, en comparant le comportement avec P&T natif. La tâche est terminée lorsque l'omission du patch ne supprime plus un champ 'to' existant et que la transition décrite est couverte.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
go
Domaine
api, backend
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.