mirror of
https://github.com/ko-build/ko.git
synced 2024-12-03 08:35:34 +02:00
add kubectl check for ko delete, apply, and create (#120)
This commit is contained in:
parent
b7e1a7fdbc
commit
2e28671384
@ -64,6 +64,11 @@ func addApply(topLevel *cobra.Command) {
|
|||||||
cat config.yaml | ko apply -f -`,
|
cat config.yaml | ko apply -f -`,
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
if !isKubectlAvailable() {
|
||||||
|
log.Print("error: kubectl is not available. kubectl must be installed to use ko apply.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
builder, err := makeBuilder(bo)
|
builder, err := makeBuilder(bo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error creating builder: %v", err)
|
log.Fatalf("error creating builder: %v", err)
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,3 +33,11 @@ func AddKubeCommands(topLevel *cobra.Command) {
|
|||||||
addRun(topLevel)
|
addRun(topLevel)
|
||||||
addCompletion(topLevel)
|
addCompletion(topLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if kubectl is installed
|
||||||
|
func isKubectlAvailable() bool {
|
||||||
|
if _, err := exec.LookPath("kubectl"); err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
@ -64,6 +64,11 @@ func addCreate(topLevel *cobra.Command) {
|
|||||||
cat config.yaml | ko create -f -`,
|
cat config.yaml | ko create -f -`,
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
if !isKubectlAvailable() {
|
||||||
|
log.Print("error: kubectl is not available. kubectl must be installed to use ko create.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
builder, err := makeBuilder(bo)
|
builder, err := makeBuilder(bo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error creating builder: %v", err)
|
log.Fatalf("error creating builder: %v", err)
|
||||||
|
@ -15,10 +15,11 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// runCmd is suitable for use with cobra.Command's Run field.
|
// runCmd is suitable for use with cobra.Command's Run field.
|
||||||
@ -28,6 +29,11 @@ type runCmd func(*cobra.Command, []string)
|
|||||||
// through to a binary named command.
|
// through to a binary named command.
|
||||||
func passthru(command string) runCmd {
|
func passthru(command string) runCmd {
|
||||||
return func(_ *cobra.Command, _ []string) {
|
return func(_ *cobra.Command, _ []string) {
|
||||||
|
if !isKubectlAvailable() {
|
||||||
|
log.Print("error: kubectl is not available. kubectl must be installed to use ko delete.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Start building a command line invocation by passing
|
// Start building a command line invocation by passing
|
||||||
// through our arguments to command's CLI.
|
// through our arguments to command's CLI.
|
||||||
cmd := exec.Command(command, os.Args[1:]...)
|
cmd := exec.Command(command, os.Args[1:]...)
|
||||||
|
Loading…
Reference in New Issue
Block a user