-
Notifications
You must be signed in to change notification settings - Fork 49
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
Invalid config could cause runtime error #190
Comments
Related Change #722621Subject: Ensure map is initialized before assignment This change will close this issue when merged. ApprovalsCode-Review
! None
Verified
+1 Zuul
Workflow
! None Last Updated: 2020-05-04 18:30:05 CDT |
Per the flightplan call: we will fix this quickly but create a new issue to hand subcommand-level validation of config options |
Summarizing this issue history and answering all comments and disagreements.
The second option is more preferable in my point of view and here is why:
The last question - what should we throw in this case - error or warning? I think it should be just printable warning because it's not a critical problem if clusterTypes is missing for cluster which defined in kubeconfig, we can try to create new one automatically right in place. However, error option also works. To make this approach work, we have to add to Config struct an additional object where to store load/init issues. Later, on post-validation level using EnsureComplete function, we can check whether some problems occurred during load process by getting information from appropriate field of Config struct. Nevertheless, we have to take the first steps to fix the problem now, so the first solution seems proper to me before we can proceed in implementation of next steps. I'd ask you to review once again my patchset [7], taking into account my explanations. All comments and opinions are greatly appreciated. Thank you. [1] https://github.com/airshipit/airshipctl/blob/master/cmd/root.go#L55 |
Describe the bug
Invalid config could cause runtime error. Since some variables in the code are named as is config, there is a possibility that values will be assigned to nil pointers. It could cause runtime error (e.g. in the case of uninitialized maps).
Steps To Reproduce
Modify clusterType variable name to any other. Run airshipctl version command. The following error will occur:
`airshipctl version
panic: assignment to entry in nil map
goroutine 1 [running]:
opendev.org/airship/airshipctl/pkg/config.(*Config).reconcileClusters(0xc0004ad280, 0xc0004ad280, 0x0)
/root/airshipctl/pkg/config/config.go:184 +0x69c
opendev.org/airship/airshipctl/pkg/config.(*Config).reconcileConfig(0xc0004ad280, 0xc000437140, 0x19)
/root/airshipctl/pkg/config/config.go:118 +0x2f
opendev.org/airship/airshipctl/pkg/config.(*Config).LoadConfig(0xc0004ad280, 0xc0004370c0, 0x15, 0xc000437140, 0x19, 0xc0000c0ff0, 0xc000010020)
/root/airshipctl/pkg/config/config.go:50 +0xa5
opendev.org/airship/airshipctl/pkg/environment.(*AirshipCTLSettings).InitConfig(0xc000719710)
/root/airshipctl/pkg/environment/settings.go:71 +0x8f
opendev.org/airship/airshipctl/cmd.NewRootCmd.func1(0xc0002d1900, 0x3332ec0, 0x0, 0x0)
/root/airshipctl/cmd/root.go:55 +0x90
github.com/spf13/cobra.(*Command).execute(0xc0002d1900, 0x3332ec0, 0x0, 0x0, 0xc0002d1900, 0x3332ec0)
/root/go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:810 +0x210
github.com/spf13/cobra.(*Command).ExecuteC(0xc0002d1680, 0xc000010018, 0xc0002d1680, 0xc000719710)
/root/go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:914 +0x2fb
github.com/spf13/cobra.(*Command).Execute(...)
/root/go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:864
main.main()
/root/airshipctl/main.go:31 +0xc1`
Expected behavior
runtime error should not be observed
Environment
24 CPUs, 64GB RAM, bare metal
The text was updated successfully, but these errors were encountered: