Initial commit.
This commit is contained in:
33
internal/tools/kubectl.go
Normal file
33
internal/tools/kubectl.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// Kubectl provides a thin wrapper around the kubectl command-line tool
|
||||
type Kubectl struct {
|
||||
kubeconfigPath string
|
||||
}
|
||||
|
||||
// NewKubectl creates a new Kubectl wrapper
|
||||
func NewKubectl(kubeconfigPath string) *Kubectl {
|
||||
return &Kubectl{
|
||||
kubeconfigPath: kubeconfigPath,
|
||||
}
|
||||
}
|
||||
|
||||
// DeploymentExists checks if a deployment exists in the specified namespace
|
||||
func (k *Kubectl) DeploymentExists(name, namespace string) bool {
|
||||
args := []string{
|
||||
"get", "deployment", name,
|
||||
"-n", namespace,
|
||||
}
|
||||
|
||||
if k.kubeconfigPath != "" {
|
||||
args = append([]string{"--kubeconfig", k.kubeconfigPath}, args...)
|
||||
}
|
||||
|
||||
cmd := exec.Command("kubectl", args...)
|
||||
err := cmd.Run()
|
||||
return err == nil
|
||||
}
|
||||
Reference in New Issue
Block a user