Node body: `$patch: delete` + redeclare of the same document loses the redeclared fields

Aperta
#268 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go, kubernetes
Ambito
backend

Direzione di ricerca

Start by locating engine.MergeFileAsPatch, which the issue identifies as the function used by talm template and apply, and trace how it prunes body fields before merging documents. Use the two YAML files in the reproduction to check how a deleted identity that is redeclared is handled. Done means the redeclared BondConfig retains all its fields and matches the documented talosctl machineconfig patch result.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

talm version: v0.36.0 (preset cozystack, Talos v1.14 multi-doc)

What happens

A node body that deletes a rendered document and declares it again in full (a common way to replace a document, since a strategic merge can only append to lists) does not survive MergeFileAsPatch. Before merging, talm prunes every body field that already equals the rendered value. The redeclared document is pruned down to the fields that differ, then the $patch: delete next to it removes the rendered document, so whatever the rendered side provided is gone.

Depending on what differs, the document either disappears entirely or is left without required fields. In our case talm apply -i on a node in maintenance mode failed with:

BondConfig/bond0: bond mode must be specified

talosctl machineconfig patch applies the same body correctly, so the body itself is valid.

Why we need it

On a running control-plane node, discovery reports a Layer2 VIP that is not floatingIP/vips (here, a second public API VIP declared as its own Layer2VIPConfig in the node body) as an address of the bond. The rendered BondConfig then carries the VIP as a static /32, and a merge can only append to addresses. Deleting and redeclaring the bond in the node body is the only way we found to keep the VIP out of the static addresses.

Minimal reproduction

rendered.yaml (what the chart renders with discovery):

version: v1alpha1
machine:
  type: worker
  token: dummy
  ca: {crt: "", key: ""}
cluster:
  controlPlane: {endpoint: "https://192.0.2.10:6443"}
---
apiVersion: v1alpha1
kind: BondConfig
name: bond0
links: [eth0, eth1]
bondMode: 802.3ad
miimon: 100
addresses:
  - address: 192.0.2.5/24
  - address: 198.51.100.7/32   # VIP seen by discovery on a running node
routes:
  - gateway: 192.0.2.1

node.yaml (node body):

apiVersion: v1alpha1
kind: BondConfig
name: bond0
$patch: delete
---
apiVersion: v1alpha1
kind: BondConfig
name: bond0
links: [eth0, eth1]
bondMode: 802.3ad
miimon: 100
addresses:
  - address: 192.0.2.5/24
routes:
  - gateway: 192.0.2.1

Driver (calls the same function talm template/apply use for the node body):

package main

import (
	"fmt"
	"os"

	"github.com/cozystack/talm/pkg/engine"
)

func main() {
	r, _ := os.ReadFile(os.Args[1])
	out, err := engine.MergeFileAsPatch(r, os.Args[2])
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	os.Stdout.Write(out)
}
Result
Output for bond0
talosctl machineconfig patch rendered.yaml --patch @node.yaml (expected) full BondConfig bond0 with links, bondMode, miimon, one address, the route
engine.MergeFileAsPatch(rendered.yaml, node.yaml) no BondConfig bond0 at all
same, with miimon: 100 removed from rendered.yaml BondConfig bond0 with only miimon: 100, so talosctl validate fails with bond mode must be specified

Expected

When a body contains a $patch: delete for a document identity and also redeclares that identity, the redeclared document should be applied as written: no pruning against the rendered document that is being deleted. This matches talosctl machineconfig patch.

Workaround

Render with talm template --offline --full, apply the body with talosctl machineconfig patch --patch @nodes/<host>.yaml, and apply the result with talosctl apply-config.

Lingua principale
Go
Stelle
493
Fork
23
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cozystack/talm

Tutte le issue di cozystack/talm

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.