-
Notifications
You must be signed in to change notification settings - Fork 63
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
Add delete and list command #101
Conversation
3c96832
to
4506ca9
Compare
pkg/cmd/delete/root.go
Outdated
if err != nil { | ||
return err | ||
} | ||
if err := cluster.Delete(); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we get an error if we call delete on a cluster that doesn't exist? If it does return an error, do we want to check it exists then exit with status 0?
pkg/cmd/delete/root.go
Outdated
} | ||
|
||
func init() { | ||
DeleteCmd.PersistentFlags().StringVar(&buildName, "buildName", "localdev", "Name for build (Prefix for kind cluster name, pod names, etc).") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The text "Name for build (Prefix for kind cluster name, pod names, etc)." is confusing.
I suggest "Name of the kind cluster to be deleted."
809287b
to
ee9a96f
Compare
pkg/cmd/list/root.go
Outdated
} | ||
|
||
func init() { | ||
ListCmd.PersistentFlags().StringVar(&buildName, "buildName", "localdev", "Name of the kind cluster to be deleted.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be build-name
instead of buildName
because we use kebab case everywhere else.
pkg/cmd/list/root.go
Outdated
Use: "list", | ||
Short: "List idp clusters", | ||
Long: ``, | ||
RunE: delete, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function name needs to be changed
pkg/cmd/list/root.go
Outdated
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) | ||
} | ||
|
||
func delete(cmd *cobra.Command, args []string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
pkg/cmd/list/root.go
Outdated
} | ||
|
||
func init() { | ||
ListCmd.PersistentFlags().StringVar(&buildName, "build-name", "localdev", "Name of the kind cluster to be deleted.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why require a build-name
if listingg clusters? also the description needs fixing
pkg/cmd/list/root.go
Outdated
return errors.Wrapf(err, "failed to delete cluster %q", buildName) | ||
} | ||
|
||
fmt.Printf("Clusters: %v\n", clusters) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a pretty print?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats that?
1c76742
to
9a73bd3
Compare
@nimakaviani @nabuskey Sorry I dropped this - it should be ready for re-review |
pkg/cmd/delete/root.go
Outdated
zapfs := flag.NewFlagSet("zap", flag.ExitOnError) | ||
opts := zap.Options{ | ||
Development: true, | ||
} | ||
opts.BindFlags(zapfs) | ||
DeleteCmd.Flags().AddGoFlagSet(zapfs) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use
idpbuilder/pkg/cmd/helpers/logger.go
Line 19 in 8094f56
func SetLogger() error { |
pkg/cmd/delete/root.go
Outdated
} | ||
|
||
func delete(cmd *cobra.Command, args []string) error { | ||
provider := cluster.NewProvider(cluster.ProviderWithDocker()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if we can use DetectNodeProvider() here? Not sure 100% but might be possible. Just in case someone created one with another provider. #182
Can you resolve the conflicts (rebase) please ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please rebase the code due to conflicts
- Use a
printOutPut
function to list the clusters. Ideally the cluster listed should mention in separate columns:core packages
andcustom
packages if available
// Example from list secrets
func printOutput(templatePath string, outWriter io.Writer, data []any, format string) error {
switch format {
case "json":
b, err := json.MarshalIndent(data, "", " ")
if err != nil {
return err
}
b = append(b, []byte("\n")...)
_, err = outWriter.Write(b)
return err
case "yaml":
b, err := yaml.Marshal(data)
if err != nil {
return err
}
_, err = outWriter.Write(b)
return err
case "":
return renderTemplate(templatePath, outWriter, data)
default:
return fmt.Errorf("output format %s is not supported", format)
}
}
32d7949
to
d19749c
Compare
@cmoulliard I moved this to match Kind's upstream behavior - for a 'get clusters' command I'm not sure its necessary to have templates/json/etc. IME its pretty common to simply list the clusters (this is very useful for e.g. shell tooling integration). If we want to add extra formatting dont let me stop anyone from making that an optional argument. |
d31dbcf
to
0c50a02
Compare
@nabuskey @nimakaviani Can you all re-review this please? thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor comment on the naming of the command, otherwise looks good.
) | ||
|
||
var ClustersCmd = &cobra.Command{ | ||
Use: "clusters", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not to be too picky here but looks like the other commands are verbs and this one is a noun. shall we keep it as list
like it used to be? or get
maybe?
@greghaynes once you resolve the conflict, this should be good to go. |
aeace38
to
868dd4f
Compare
Add list command too Remove changes to delete routines Update buildName to build-name Fix rebase miss Fix list to not use build name arg Fix delete cmd function name Bump kubebuilder version Signed-off-by: Greg Haynes <[email protected]> Signed-off-by: Manabu McCloskey <[email protected]>
Signed-off-by: Greg Haynes <[email protected]> Signed-off-by: Manabu McCloskey <[email protected]>
Signed-off-by: Greg Haynes <[email protected]> Signed-off-by: Manabu McCloskey <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This isnt perfect, but this should handle the 90% case for when users dont want to have to install kind separately.