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

Cannot skip commissioning when manually adding machine #75

Open
gnuoy opened this issue May 20, 2024 · 3 comments
Open

Cannot skip commissioning when manually adding machine #75

gnuoy opened this issue May 20, 2024 · 3 comments
Labels
bug Something isn't working triaged Triaged to be addressed in a given cycle

Comments

@gnuoy
Copy link
Contributor

gnuoy commented May 20, 2024

<tl;dr> If omitempty is used with a boolean option then go-querystring drops it if it is set to false.
Which leads to: "commissioning = false" => commissioning option dropped => maas runs commissioning </tl;dr>

When adding a machine manually via the CLI it is possible to skip commissioning by setting

maas admin machines create ... commission=false

This is not possible via the gomaasclient due to the way MachineParams are defined ( https://github.com/maas/gomaasclient/blob/master/entity/machine.go#L223 ) .

If commission is not explicitly set in a request to the maas api then maas does the default which is to run a commission. Which leads to the following:

If commission is unset:

	_, err = c.Machines.Create(
		&entity.MachineParams{
			Hostname:      "test01",
                        ...
		}

Maas will run a commission as this is the default behaviour

If commission is set to True:

	_, err = c.Machines.Create(
		&entity.MachineParams{
			Hostname:      "test01",
                        Commission:    true,
                        ...
		}

Maas will run a commission as explicitly requested

If commission is set to False:

	_, err = c.Machines.Create(
		&entity.MachineParams{
			Hostname:      "test01",
                        Commission:    false,
                        ...
		}

Maas will run a commission because when the machine params are processes the commission option is dropped (https://github.com/maas/gomaasclient/blob/master/client/machines.go#L37) because it is set to false and that option has omitempty set. omitempty omits the value if "...values are false, 0, any nil pointer or interface value, any array slice, map, or string of length zero, and any type (such as time.Time) that returns true for IsZero()."

@gnuoy
Copy link
Contributor Author

gnuoy commented May 20, 2024

A workaround is to disable automatic commissioning globally with:

maas admin maas set-config name=enlist_commissioning value=false

@troyanov
Copy link
Member

Hi @gnuoy

Indeed, this is a valid bug.

import (
	"fmt"
	"github.com/google/go-querystring/query"
)

type Options struct {
        // Faulty behaviour with `omitempty`
	//Commission bool `url:"commission,omitempty"`
	Commission bool `url:"commission"`
}

func main() {
	opt := Options{false}
	v, _ := query.Values(opt)
        // Will print nothing instead of `commission=false` if `omitempty` is specified
	fmt.Print(v.Encode())
}

@troyanov troyanov added bug Something isn't working triaged Triaged to be addressed in a given cycle labels May 20, 2024
@gnuoy
Copy link
Contributor Author

gnuoy commented May 20, 2024

Thanks for the quick triage @troyanov ! fwiw I think the issue is going to affect any setting that:

  1. Is a bool
  2. Uses omitempty (I think all of them do at the moment)
  3. maas interprets the absence of the setting as true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triaged Triaged to be addressed in a given cycle
Projects
None yet
Development

No branches or pull requests

2 participants