mirror of
https://github.com/kubernetes-sigs/kind.git
synced 2025-11-30 23:16:04 +07:00
move commands into pkg/
This commit is contained in:
2
Makefile
2
Makefile
@@ -30,7 +30,7 @@ INSTALL?=install
|
|||||||
INSTALL_DIR?=$(shell hack/build/goinstalldir.sh)
|
INSTALL_DIR?=$(shell hack/build/goinstalldir.sh)
|
||||||
# record the source commit in the binary
|
# record the source commit in the binary
|
||||||
COMMIT?=$(shell git rev-parse HEAD 2>/dev/null)
|
COMMIT?=$(shell git rev-parse HEAD 2>/dev/null)
|
||||||
LD_FLAGS:=-X sigs.k8s.io/kind/cmd/kind/version.GitCommit=$(COMMIT)
|
LD_FLAGS:=-X sigs.k8s.io/kind/pkg/cmd/kind/version.GitCommit=$(COMMIT)
|
||||||
# the output binary name, overridden when cross compiling
|
# the output binary name, overridden when cross compiling
|
||||||
KIND_BINARY_NAME?=kind
|
KIND_BINARY_NAME?=kind
|
||||||
|
|
||||||
|
|||||||
21
cmd/kind/app/main.go
Normal file
21
cmd/kind/app/main.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kind/pkg/cmd/kind"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Main is the kind main(), it will invoke Run(), if an error is returned
|
||||||
|
// it will then call os.Exit
|
||||||
|
func Main() {
|
||||||
|
if err := Run(); err != nil {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run invokes the kind root command, returning the error.
|
||||||
|
// See: sigs.k8s.io/kind/pkg/cmd/kind
|
||||||
|
func Run() error {
|
||||||
|
return kind.NewCommand().Execute()
|
||||||
|
}
|
||||||
9
cmd/kind/main.go
Normal file
9
cmd/kind/main.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sigs.k8s.io/kind/cmd/kind/app"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app.Main()
|
||||||
|
}
|
||||||
4
main.go
4
main.go
@@ -18,9 +18,9 @@ limitations under the License.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sigs.k8s.io/kind/cmd/kind"
|
"sigs.k8s.io/kind/cmd/kind/app"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
kind.Main()
|
app.Main()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ package build
|
|||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"sigs.k8s.io/kind/cmd/kind/build/baseimage"
|
"sigs.k8s.io/kind/pkg/cmd/kind/build/baseimage"
|
||||||
"sigs.k8s.io/kind/cmd/kind/build/nodeimage"
|
"sigs.k8s.io/kind/pkg/cmd/kind/build/nodeimage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCommand returns a new cobra.Command for building
|
// NewCommand returns a new cobra.Command for building
|
||||||
@@ -20,8 +20,8 @@ package completion
|
|||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"sigs.k8s.io/kind/cmd/kind/completion/bash"
|
"sigs.k8s.io/kind/pkg/cmd/kind/completion/bash"
|
||||||
"sigs.k8s.io/kind/cmd/kind/completion/zsh"
|
"sigs.k8s.io/kind/pkg/cmd/kind/completion/zsh"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCommand returns a new cobra.Command for cluster creation
|
// NewCommand returns a new cobra.Command for cluster creation
|
||||||
@@ -20,7 +20,7 @@ package create
|
|||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
createcluster "sigs.k8s.io/kind/cmd/kind/create/cluster"
|
createcluster "sigs.k8s.io/kind/pkg/cmd/kind/create/cluster"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCommand returns a new cobra.Command for cluster creation
|
// NewCommand returns a new cobra.Command for cluster creation
|
||||||
@@ -20,7 +20,7 @@ package delete
|
|||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
deletecluster "sigs.k8s.io/kind/cmd/kind/delete/cluster"
|
deletecluster "sigs.k8s.io/kind/pkg/cmd/kind/delete/cluster"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCommand returns a new cobra.Command for cluster creation
|
// NewCommand returns a new cobra.Command for cluster creation
|
||||||
@@ -20,7 +20,7 @@ package export
|
|||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"sigs.k8s.io/kind/cmd/kind/export/logs"
|
"sigs.k8s.io/kind/pkg/cmd/kind/export/logs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCommand returns a new cobra.Command for export
|
// NewCommand returns a new cobra.Command for export
|
||||||
@@ -20,9 +20,9 @@ package get
|
|||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"sigs.k8s.io/kind/cmd/kind/get/clusters"
|
"sigs.k8s.io/kind/pkg/cmd/kind/get/clusters"
|
||||||
"sigs.k8s.io/kind/cmd/kind/get/kubeconfig"
|
"sigs.k8s.io/kind/pkg/cmd/kind/get/kubeconfig"
|
||||||
"sigs.k8s.io/kind/cmd/kind/get/nodes"
|
"sigs.k8s.io/kind/pkg/cmd/kind/get/nodes"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCommand returns a new cobra.Command for get
|
// NewCommand returns a new cobra.Command for get
|
||||||
@@ -20,8 +20,8 @@ package load
|
|||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
dockerimage "sigs.k8s.io/kind/cmd/kind/load/docker-image"
|
dockerimage "sigs.k8s.io/kind/pkg/cmd/kind/load/docker-image"
|
||||||
imagearchive "sigs.k8s.io/kind/cmd/kind/load/image-archive"
|
imagearchive "sigs.k8s.io/kind/pkg/cmd/kind/load/image-archive"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCommand returns a new cobra.Command for get
|
// NewCommand returns a new cobra.Command for get
|
||||||
@@ -22,14 +22,14 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"sigs.k8s.io/kind/cmd/kind/build"
|
"sigs.k8s.io/kind/pkg/cmd/kind/build"
|
||||||
"sigs.k8s.io/kind/cmd/kind/completion"
|
"sigs.k8s.io/kind/pkg/cmd/kind/completion"
|
||||||
"sigs.k8s.io/kind/cmd/kind/create"
|
"sigs.k8s.io/kind/pkg/cmd/kind/create"
|
||||||
"sigs.k8s.io/kind/cmd/kind/delete"
|
"sigs.k8s.io/kind/pkg/cmd/kind/delete"
|
||||||
"sigs.k8s.io/kind/cmd/kind/export"
|
"sigs.k8s.io/kind/pkg/cmd/kind/export"
|
||||||
"sigs.k8s.io/kind/cmd/kind/get"
|
"sigs.k8s.io/kind/pkg/cmd/kind/get"
|
||||||
"sigs.k8s.io/kind/cmd/kind/load"
|
"sigs.k8s.io/kind/pkg/cmd/kind/load"
|
||||||
"sigs.k8s.io/kind/cmd/kind/version"
|
"sigs.k8s.io/kind/pkg/cmd/kind/version"
|
||||||
"sigs.k8s.io/kind/pkg/errors"
|
"sigs.k8s.io/kind/pkg/errors"
|
||||||
"sigs.k8s.io/kind/pkg/exec"
|
"sigs.k8s.io/kind/pkg/exec"
|
||||||
"sigs.k8s.io/kind/pkg/globals"
|
"sigs.k8s.io/kind/pkg/globals"
|
||||||
@@ -52,7 +52,11 @@ func NewCommand() *cobra.Command {
|
|||||||
Short: "kind is a tool for managing local Kubernetes clusters",
|
Short: "kind is a tool for managing local Kubernetes clusters",
|
||||||
Long: "kind creates and manages local Kubernetes clusters using Docker container 'nodes'",
|
Long: "kind creates and manages local Kubernetes clusters using Docker container 'nodes'",
|
||||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return runE(flags, cmd)
|
err := runE(flags, cmd)
|
||||||
|
if err != nil {
|
||||||
|
logError(err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
},
|
},
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
SilenceErrors: true,
|
SilenceErrors: true,
|
||||||
@@ -115,19 +119,6 @@ func runE(flags *Flags, cmd *cobra.Command) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run runs the `kind` root command
|
|
||||||
func Run() error {
|
|
||||||
return NewCommand().Execute()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main wraps Run and sets the log formatter
|
|
||||||
func Main() {
|
|
||||||
if err := Run(); err != nil {
|
|
||||||
logError(err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// logError logs the error and the root stacktrace if there is one
|
// logError logs the error and the root stacktrace if there is one
|
||||||
func logError(err error) {
|
func logError(err error) {
|
||||||
globals.GetLogger().Errorf("ERROR: %v", err)
|
globals.GetLogger().Errorf("ERROR: %v", err)
|
||||||
Reference in New Issue
Block a user