Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support = and , in tag values in wwctl <node|profile> set --tagadd #1147

Open
1 task done
anderbubble opened this issue Mar 19, 2024 · 2 comments
Open
1 task done
Labels
enhancement New feature or request
Milestone

Comments

@anderbubble
Copy link
Collaborator

Summary

Support specifying a value with --tagadd that includes an equal sign, =.

Rationale

When attempting to wwctl profile set --yes --tagadd slurmdconf='Feature=standard CpuSpecList=1,33' standard

We get an error:

ERROR: invalid argument "slurmdconf=Feature=standard CpuSpecList=1,33" for "--tagadd" flag: 33 must be formatted as key=value

These values can be entered into nodes.conf manually; but are not permitted by wwctl

Description

No response

Additional information

No response

General information

  • I have searched the issues of this repo and believe this is not a duplicate
@anderbubble anderbubble added the enhancement New feature or request label Mar 19, 2024
@anderbubble anderbubble added the stake:ciq CIQ is a stakeholder of this issue label Mar 19, 2024
@anderbubble anderbubble added this to the v4.5.1 milestone Mar 19, 2024
@anderbubble anderbubble changed the title Support = in tag values in wwctl <node|profile> set --tagadd Support = and , in tag values in wwctl <node|profile> set --tagadd Mar 28, 2024
@anderbubble
Copy link
Collaborator Author

Transcribing @JasonYangShadow's comments from an internal ticket:

It is caused by pflags, we are using map[string]string as the tag field, and it is handled by pflags’s StringToStringVarP function.

https://github.com/spf13/pflag/blob/v1.0.5/string_to_string.go#L130

https://github.com/warewulf/warewulf/blob/main/internal/pkg/node/flags.go#L223

This function will interpret the = and , for retrieving the key and value.

A simple example to reproduce this issue

package main

import (
	"fmt"
	"os"

	"github.com/spf13/cobra"
)

func main() {
	var myMapFlag map[string]string
	// Create a new cobra command
	cmd := &cobra.Command{
		Use: "my-app",
		Run: func(cmd *cobra.Command, args []string) {
			// Use the myMapFlag variable in your application
			fmt.Printf("myMapFlag: %v\n", myMapFlag)
		},
	}

	// Define a map flag using StringToStringP
	cmd.PersistentFlags().StringToStringVarP(&myMapFlag, "my-map", "m", nil, "a string map")

	// Execute the command
	if err := cmd.Execute(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
[vagrant@localhost test]$ ./example.com --my-map newtag="k1=v1,k2"
Error: invalid argument "newtag=k1=v1,k2" for "-m, --my-map" flag: k2 must be formatted as key=value
Usage:
  my-app [flags]

Flags:
  -h, --help                    help for my-app
  -m, --my-map stringToString   a string map (default [])

invalid argument "newtag=k1=v1,k2" for "-m, --my-map" flag: k2 must be formatted as key=value

I’d suggest either flatting the nested tags to small tags or using other symbol other than ,inside the value.

wwctl profile set --yes --tagadd=Feature=standard --tagadd=CpuSpecList=1,33 default
wwctl profile set --yes --tagadd slurmdconf='Feature=standard CpuSpecList=1;33' default
[root@localhost warewulf]# cat /usr/local/etc/warewulf/nodes.conf 
WW_INTERNAL: 45
nodeprofiles:
  default:
    comment: This profile is automatically included for each node
    tags:
      CpuSpecList: 1,33
      Feature: standard
      slurmdconf: Feature=standard CpuSpecList=1;33
nodes:
  n1:
    profiles:
    - default
    network devices:
      eth0:
        onboot: "false"
        device: eth0
  n2:
    profiles:
    - default
    network devices:
      default:
        onboot: "false"

@anderbubble
Copy link
Collaborator Author

@JasonYangShadow I concur. If we actually wanted to fix this, it looks like it'd need to be fixed upstream in cobra. Not that we can't do that; but it seems a bit extensive for now, especially since this can be done by editing nodes.conf directly, or by using wwctl <node|profile> edit.

I'll move this to __future__ for now.

@anderbubble anderbubble removed the stake:ciq CIQ is a stakeholder of this issue label Mar 28, 2024
@anderbubble anderbubble modified the milestones: v4.5.1, __future__ Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants