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

Add delete and list command #101

Merged
merged 3 commits into from
Jul 31, 2024
Merged

Add delete and list command #101

merged 3 commits into from
Jul 31, 2024

Conversation

greghaynes
Copy link
Contributor

@greghaynes greghaynes commented Dec 5, 2023

This isnt perfect, but this should handle the 90% case for when users dont want to have to install kind separately.

if err != nil {
return err
}
if err := cluster.Delete(); err != nil {
Copy link
Collaborator

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?

}

func init() {
DeleteCmd.PersistentFlags().StringVar(&buildName, "buildName", "localdev", "Name for build (Prefix for kind cluster name, pod names, etc).")
Copy link
Contributor

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."

@greghaynes greghaynes changed the title Add delete command Add delete and list command Feb 15, 2024
@greghaynes greghaynes force-pushed the delete-command branch 2 times, most recently from 809287b to ee9a96f Compare February 15, 2024 22:59
}

func init() {
ListCmd.PersistentFlags().StringVar(&buildName, "buildName", "localdev", "Name of the kind cluster to be deleted.")
Copy link
Collaborator

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.

Use: "list",
Short: "List idp clusters",
Long: ``,
RunE: delete,
Copy link
Contributor

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

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
}

func delete(cmd *cobra.Command, args []string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

}

func init() {
ListCmd.PersistentFlags().StringVar(&buildName, "build-name", "localdev", "Name of the kind cluster to be deleted.")
Copy link
Contributor

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

return errors.Wrapf(err, "failed to delete cluster %q", buildName)
}

fmt.Printf("Clusters: %v\n", clusters)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a pretty print?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats that?

@greghaynes greghaynes force-pushed the delete-command branch 2 times, most recently from 1c76742 to 9a73bd3 Compare April 25, 2024 00:58
@greghaynes
Copy link
Contributor Author

@nimakaviani @nabuskey Sorry I dropped this - it should be ready for re-review

Comment on lines 28 to 36
zapfs := flag.NewFlagSet("zap", flag.ExitOnError)
opts := zap.Options{
Development: true,
}
opts.BindFlags(zapfs)
DeleteCmd.Flags().AddGoFlagSet(zapfs)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use

func SetLogger() error {
instead?

}

func delete(cmd *cobra.Command, args []string) error {
provider := cluster.NewProvider(cluster.ProviderWithDocker())
Copy link
Collaborator

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

@nimakaviani nimakaviani requested a review from cmoulliard April 30, 2024 00:07
@cmoulliard
Copy link
Contributor

Can you resolve the conflicts (rebase) please ?

Copy link
Contributor

@cmoulliard cmoulliard left a 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 and custom 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)
	}
}

@greghaynes
Copy link
Contributor Author

@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.

@greghaynes
Copy link
Contributor Author

@nabuskey @nimakaviani Can you all re-review this please? thanks

Copy link
Contributor

@nimakaviani nimakaviani left a 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",
Copy link
Contributor

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?

@nimakaviani
Copy link
Contributor

@greghaynes once you resolve the conflict, this should be good to go.

@nabuskey nabuskey requested a review from a team as a code owner July 30, 2024 23:07
@nabuskey nabuskey force-pushed the delete-command branch 2 times, most recently from aeace38 to 868dd4f Compare July 30, 2024 23:56
greghaynes and others added 3 commits July 30, 2024 23:57
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]>
Copy link
Contributor

@nimakaviani nimakaviani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nabuskey nabuskey merged commit af755fd into main Jul 31, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants