Skip to content

Commit

Permalink
cleanup commands
Browse files Browse the repository at this point in the history
Signed-off-by: Manabu McCloskey <[email protected]>
  • Loading branch information
nabuskey committed Jul 31, 2024
1 parent af755fd commit 33f73f2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 66 deletions.
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ require (
github.com/go-logr/logr v1.4.1
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v61 v61.0.0
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.9.0
gotest.tools/v3 v3.5.1
k8s.io/api v0.29.1
k8s.io/apiextensions-apiserver v0.29.1
k8s.io/apimachinery v0.29.1
Expand Down Expand Up @@ -49,7 +47,6 @@ require (
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-fed/httpsig v1.1.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
Expand Down Expand Up @@ -84,6 +81,7 @@ require (
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
Expand All @@ -96,8 +94,6 @@ require (
github.com/stretchr/objx v0.5.2 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/mod v0.14.0 // indirect
Expand All @@ -117,6 +113,7 @@ require (
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
k8s.io/component-base v0.29.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
Expand Down
25 changes: 9 additions & 16 deletions pkg/cmd/delete/root.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,44 @@
package delete

import (
"flag"
"fmt"

"github.com/cnoe-io/idpbuilder/pkg/cmd/helpers"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/kind/pkg/cluster"
)

var (
// Flags
buildName string
name string
)

var DeleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete an IDP cluster",
Long: ``,
RunE: delete,
RunE: deleteE,
PreRunE: preDeleteE,
}

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

zapfs := flag.NewFlagSet("zap", flag.ExitOnError)
opts := zap.Options{
Development: true,
}
opts.BindFlags(zapfs)
DeleteCmd.Flags().AddGoFlagSet(zapfs)
DeleteCmd.PersistentFlags().StringVar(&name, "name", "localdev", "Name of the kind cluster to be deleted.")
}

func preDeleteE(cmd *cobra.Command, args []string) error {
return helpers.SetLogger()
}

func delete(cmd *cobra.Command, args []string) error {
func deleteE(cmd *cobra.Command, args []string) error {
logger := helpers.CmdLogger
logger.Info("deleting cluster", "clusterName", name)
detectOpt, err := cluster.DetectNodeProvider()
if err != nil {
return err
}
provider := cluster.NewProvider(detectOpt)
if err := provider.Delete(buildName, ""); err != nil {
return errors.Wrapf(err, "failed to delete cluster %q", buildName)
if err := provider.Delete(name, ""); err != nil {
return fmt.Errorf("failed to delete cluster %s: %w", name, err)
}
return nil
}
34 changes: 34 additions & 0 deletions pkg/cmd/get/clusters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package get

import (
"fmt"

"github.com/cnoe-io/idpbuilder/pkg/cmd/helpers"
"github.com/spf13/cobra"
"sigs.k8s.io/kind/pkg/cluster"
)

var ClustersCmd = &cobra.Command{
Use: "clusters",
Short: "Get idp clusters",
Long: ``,
RunE: list,
PreRunE: preClustersE,
}

func preClustersE(cmd *cobra.Command, args []string) error {
return helpers.SetLogger()
}

func list(cmd *cobra.Command, args []string) error {
provider := cluster.NewProvider(cluster.ProviderWithDocker())
clusters, err := provider.List()
if err != nil {
return fmt.Errorf("failed to list clusters: %w", err)
}

for _, c := range clusters {
fmt.Println(c)
}
return nil
}
43 changes: 0 additions & 43 deletions pkg/cmd/get/clusters/clusters.go

This file was deleted.

3 changes: 1 addition & 2 deletions pkg/cmd/get/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package get
import (
"fmt"

"github.com/cnoe-io/idpbuilder/pkg/cmd/get/clusters"
"github.com/spf13/cobra"
)

Expand All @@ -20,7 +19,7 @@ var (
)

func init() {
GetCmd.AddCommand(clusters.ClustersCmd)
GetCmd.AddCommand(ClustersCmd)
GetCmd.AddCommand(SecretsCmd)
GetCmd.PersistentFlags().StringSliceVarP(&packages, "packages", "p", []string{}, "names of packages.")
GetCmd.PersistentFlags().StringVarP(&outputFormat, "output", "o", "", "Output format. json or yaml.")
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/helpers/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
var (
LogLevel string
LogLevelMsg = "Set the log verbosity. Supported values are: debug, info, warn, and error."
CmdLogger logr.Logger
)

func SetLogger() error {
Expand All @@ -29,6 +30,7 @@ func SetLogger() error {

klog.SetLogger(klogger)
ctrl.SetLogger(logger)
CmdLogger = logger
return nil
}

Expand Down

0 comments on commit 33f73f2

Please sign in to comment.