diff --git a/CHANGELOG.md b/CHANGELOG.md index 20c7e339..2cfa6b9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed a bug when using `wwctl container import --force` to replace an existing container will generate an error #474 - Create `/etc/systemd/network/10-persistent-net-.link` file per network device +- Fix the issue that the same tag added in `node set` is ignored. #967 ### Changed diff --git a/internal/app/wwctl/node/set/main_test.go b/internal/app/wwctl/node/set/main_test.go index 466f889f..355e8223 100644 --- a/internal/app/wwctl/node/set/main_test.go +++ b/internal/app/wwctl/node/set/main_test.go @@ -414,3 +414,69 @@ nodes: run_test(t, tt) } } + +func Test_Node_Add(t *testing.T) { + tests := []test_description{ + { + args: []string{"--tagadd=email=node", "n01"}, + wantErr: false, + stdout: "", + inDB: `WW_INTERNAL: 43 +nodeprofiles: + default: + comment: testit + tags: + email: profile +nodes: + n01: + profiles: + - default`, + outDb: `WW_INTERNAL: 43 +nodeprofiles: + default: + comment: testit + tags: + email: profile +nodes: + n01: + profiles: + - default + tags: + email: node +`}, + { + args: []string{"--tagadd=newtag=newval", "n01"}, + wantErr: false, + stdout: "", + inDB: `WW_INTERNAL: 43 +nodeprofiles: + default: + comment: testit + tags: + email: profile +nodes: + n01: + profiles: + - default + tags: + email: node`, + outDb: `WW_INTERNAL: 43 +nodeprofiles: + default: + comment: testit + tags: + email: profile +nodes: + n01: + profiles: + - default + tags: + email: node + newtag: newval +`}, + } + + for _, tt := range tests { + run_test(t, tt) + } +} diff --git a/internal/pkg/node/transformers.go b/internal/pkg/node/transformers.go index 61ff21d0..4fafe19b 100644 --- a/internal/pkg/node/transformers.go +++ b/internal/pkg/node/transformers.go @@ -206,6 +206,11 @@ func recursiveSetter(source, target interface{}, nameArg string, setter func(*En newEntr := new(Entry) setter(newEntr, sourceIter.Value().String(), nameArg) targetValue.Elem().Field(i).SetMapIndex(sourceIter.Key(), reflect.ValueOf(newEntr)) + } else { + // update the entry with latest value + if entry, ok := targetValue.Elem().Field(i).MapIndex(sourceIter.Key()).Interface().(*Entry); ok { + setter(entry, sourceIter.Value().String(), nameArg) + } } } } else {