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

Abierto
#268 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
65/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go, kubernetes
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Go
Estrellas
493
Forks
23
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de cozystack/talm

Todos los issues de cozystack/talm

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.