From 0a1d12e6d44a649da78793a19048f8e2e2e05e04 Mon Sep 17 00:00:00 2001 From: MatthewHink Date: Fri, 13 Jun 2025 12:10:53 -0700 Subject: [PATCH] Fail API add node if node exists --- CHANGELOG.md | 1 + internal/pkg/warewulfd/api/node.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b45ae406..9e324bea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Updated 70-persistent-net.rules.ww to use `(lower $netdev.Type)` for case-insensitive comparison of "infiniband". - Fixed a regression in SELinux support by restoring the `/run` mount during wwinit. #1910 - Fixed `wwctl profile set` for disks, partitions and file systems. #1883 +- Do not let API add a node that exists ### Changed diff --git a/internal/pkg/warewulfd/api/node.go b/internal/pkg/warewulfd/api/node.go index ba8f120d..955ba33d 100644 --- a/internal/pkg/warewulfd/api/node.go +++ b/internal/pkg/warewulfd/api/node.go @@ -123,9 +123,13 @@ func addNode() usecase.Interactor { u := usecase.NewInteractor(func(ctx context.Context, input addNodeInput, output *node.Node) error { wwlog.Debug("api.addNode(ID:%v, Node:%+v)", input.ID, input.Node) + // registry is the warewulf node "db" yaml file. if registry, err := node.New(); err != nil { return err } else { + if _, ok := registry.Nodes[input.ID]; ok { + return status.Wrap(fmt.Errorf("node name '%s' already exists", input.ID), status.InvalidArgument) + } for _, profile := range input.Node.Profiles { if _, ok := registry.NodeProfiles[profile]; !ok { return status.Wrap(fmt.Errorf("profile '%s' does not exist", profile), status.InvalidArgument)