-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 729ada9
Showing
17 changed files
with
1,586 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
.vscode | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
FROM golang:alpine AS builder | ||
|
||
ENV GO111MODULE=on \ | ||
CGO_ENABLED=0 \ | ||
GOOS=linux \ | ||
GOARCH=amd64 | ||
|
||
WORKDIR /build | ||
|
||
# Download go dependencies | ||
COPY go.mod . | ||
COPY go.sum . | ||
RUN go mod download | ||
|
||
# Copy into the container | ||
COPY . . | ||
|
||
# Build the application | ||
RUN go build -o kubernetes-toolkit . | ||
|
||
# Build final image using nothing but the binary | ||
FROM alpine:3.17.2 | ||
|
||
COPY --from=builder /build/kubernetes-toolkit / | ||
|
||
# Command to run | ||
ENTRYPOINT ["/kubernetes-toolkit"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 kubefirst | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
XC_OS="linux darwin" | ||
XC_ARCH="amd64 arm64" | ||
XC_PARALLEL="2" | ||
BIN="bin/" | ||
SRC=$(shell find . -name "*.go") | ||
|
||
ifeq (, $(shell which gox)) | ||
$(warning "could not find gox in $(PATH), run: go get github.com/mitchellh/gox") | ||
endif | ||
|
||
.PHONY: all build | ||
|
||
default: all | ||
|
||
all: build | ||
|
||
build: | ||
gox \ | ||
-os=$(XC_OS) \ | ||
-arch=$(XC_ARCH) \ | ||
-parallel=$(XC_PARALLEL) \ | ||
-output=$(BIN)/{{.Dir}}_{{.OS}}_{{.Arch}} \ | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# kubernetes-toolkit | ||
|
||
An application used to help facilitate operations within a Kubernetes clusters. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// rootCmd represents the base command when called without any subcommands | ||
var rootCmd = &cobra.Command{ | ||
Use: "kubernetes-toolkit", | ||
Short: "A brief description of your application", | ||
Long: `A longer description that spans multiple lines and likely contains | ||
examples and usage of using your application. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
// Uncomment the following line if your bare application | ||
// has an action associated with it: | ||
// Run: func(cmd *cobra.Command, args []string) { }, | ||
} | ||
|
||
// Execute adds all child commands to the root command and sets flags appropriately. | ||
// This is called by main.main(). It only needs to happen once to the rootCmd. | ||
func Execute() { | ||
err := rootCmd.Execute() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
// Here you will define your flags and configuration settings. | ||
// Cobra supports persistent flags, which, if defined here, | ||
// will be global for your application. | ||
|
||
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.kubernetes-toolkit.yaml)") | ||
|
||
// Cobra also supports local flags, which will only run | ||
// when this action is called directly. | ||
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
Copyright © 2023 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/kubefirst/kubernetes-toolkit/internal/kubernetes" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type WaitForCmdOptions struct { | ||
Namespace string | ||
Label string | ||
Timeout int64 | ||
KubeInClusterConfig bool | ||
} | ||
|
||
var waitForCmdOptions *WaitForCmdOptions = &WaitForCmdOptions{} | ||
|
||
// waitForCmd represents the waitFor command | ||
var waitForCmd = &cobra.Command{ | ||
Use: "wait-for", | ||
Short: "Wait on something in Kubernetes to be ready", | ||
Long: `Wait on a resource in Kubernetes to reach a ready state`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("waitFor called") | ||
}, | ||
} | ||
|
||
// waitForDeploymentCmd represents the waitForDeploymentCmd command | ||
var waitForDeploymentCmd = &cobra.Command{ | ||
Use: "deployment", | ||
Short: "Wait for a Deployment to be ready", | ||
Long: `Wait for a Deployment to be ready`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println(waitForCmdOptions) | ||
label := strings.Split(waitForCmdOptions.Label, "=") | ||
if len(label) != 2 { | ||
log.Fatalf("please check the provided label: %s", waitForCmdOptions.Label) | ||
} | ||
|
||
_, clientset, _ := kubernetes.CreateKubeConfig(waitForCmdOptions.KubeInClusterConfig) | ||
deployment, err := kubernetes.ReturnDeploymentObject(&clientset, label[0], label[1], waitForCmdOptions.Namespace, waitForCmdOptions.Timeout) | ||
if err != nil { | ||
log.Fatalf("error retrieving deployment object: %s", err) | ||
} | ||
_, err = kubernetes.WaitForDeploymentReady(&clientset, deployment, waitForCmdOptions.Timeout) | ||
if err != nil { | ||
log.Fatalf("error waiting for deployment object: %s", err) | ||
} | ||
}, | ||
} | ||
|
||
// waitForPodCmd represents the waitForPodCmd command | ||
var waitForPodCmd = &cobra.Command{ | ||
Use: "pod", | ||
Short: "Wait for a Pod to be ready", | ||
Long: `Wait for a Pod to be ready`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
label := strings.Split(waitForCmdOptions.Label, "=") | ||
if len(label) != 2 { | ||
log.Fatalf("please check the provided label: %s", waitForCmdOptions.Label) | ||
} | ||
|
||
_, clientset, _ := kubernetes.CreateKubeConfig(waitForCmdOptions.KubeInClusterConfig) | ||
pod, err := kubernetes.ReturnPodObject(&clientset, label[0], label[1], waitForCmdOptions.Namespace, waitForCmdOptions.Timeout) | ||
if err != nil { | ||
log.Fatalf("error retrieving pod object: %s", err) | ||
} | ||
_, err = kubernetes.WaitForPodReady(&clientset, pod, waitForCmdOptions.Timeout) | ||
if err != nil { | ||
log.Fatalf("error waiting for pod object: %s", err) | ||
} | ||
}, | ||
} | ||
|
||
// waitForStatefulSetCmd represents the waitForStatefulSetCmd command | ||
var waitForStatefulSetCmd = &cobra.Command{ | ||
Use: "statefulset", | ||
Short: "Wait for a StatefulSet to be ready", | ||
Long: `Wait for a StatefulSet to be ready`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
label := strings.Split(waitForCmdOptions.Label, "=") | ||
if len(label) != 2 { | ||
log.Fatalf("please check the provided label: %s", waitForCmdOptions.Label) | ||
} | ||
|
||
_, clientset, _ := kubernetes.CreateKubeConfig(waitForCmdOptions.KubeInClusterConfig) | ||
sts, err := kubernetes.ReturnStatefulSetObject(&clientset, label[0], label[1], waitForCmdOptions.Namespace, waitForCmdOptions.Timeout) | ||
if err != nil { | ||
log.Fatalf("error retrieving statefulset object: %s", err) | ||
} | ||
_, err = kubernetes.WaitForStatefulSetReady(&clientset, sts, waitForCmdOptions.Timeout, false) | ||
if err != nil { | ||
log.Fatalf("error waiting for statefulset object: %s", err) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(waitForCmd) | ||
waitForCmd.AddCommand(waitForDeploymentCmd) | ||
waitForCmd.AddCommand(waitForPodCmd) | ||
waitForCmd.AddCommand(waitForStatefulSetCmd) | ||
|
||
// Required flags | ||
var attach []*cobra.Command | ||
attach = append(attach, waitForDeploymentCmd, waitForPodCmd, waitForStatefulSetCmd) | ||
|
||
for _, command := range attach { | ||
command.Flags().StringVar(&waitForCmdOptions.Namespace, "namespace", waitForCmdOptions.Namespace, "Namespace containing the resource (required)") | ||
err := command.MarkFlagRequired("namespace") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
command.Flags().StringVar(&waitForCmdOptions.Label, "label", waitForCmdOptions.Label, "Label to select the resource in the form key=value (required)") | ||
err = command.MarkFlagRequired("label") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
command.Flags().Int64Var(&waitForCmdOptions.Timeout, "timeout-seconds", 60, "Timeout seconds - 60 (default)") | ||
command.Flags().BoolVar(&waitForCmdOptions.KubeInClusterConfig, "use-kubeconfig-in-cluster", true, "Kube config type - in-cluster (default), set to false to use local") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module github.com/kubefirst/kubernetes-toolkit | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/briandowns/spinner v1.22.0 | ||
github.com/sirupsen/logrus v1.9.0 | ||
github.com/spf13/afero v1.9.5 | ||
github.com/spf13/cobra v1.6.1 | ||
golang.org/x/term v0.5.0 | ||
k8s.io/api v0.26.3 | ||
k8s.io/apimachinery v0.26.3 | ||
k8s.io/client-go v0.26.3 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/emicklei/go-restful/v3 v3.9.0 // indirect | ||
github.com/fatih/color v1.7.0 // indirect | ||
github.com/go-logr/logr v1.2.3 // indirect | ||
github.com/go-openapi/jsonpointer v0.19.5 // indirect | ||
github.com/go-openapi/jsonreference v0.20.0 // indirect | ||
github.com/go-openapi/swag v0.19.14 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/google/gnostic v0.5.7-v3refs // indirect | ||
github.com/google/go-cmp v0.5.9 // indirect | ||
github.com/google/gofuzz v1.1.0 // indirect | ||
github.com/imdario/mergo v0.3.6 // indirect | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/mailru/easyjson v0.7.6 // indirect | ||
github.com/mattn/go-colorable v0.1.12 // indirect | ||
github.com/mattn/go-isatty v0.0.14 // indirect | ||
github.com/moby/spdystream v0.2.0 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
golang.org/x/net v0.7.0 // indirect | ||
golang.org/x/oauth2 v0.3.0 // indirect | ||
golang.org/x/sys v0.5.0 // indirect | ||
golang.org/x/text v0.7.0 // indirect | ||
golang.org/x/time v0.3.0 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/protobuf v1.28.1 // indirect | ||
gopkg.in/inf.v0 v0.9.1 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
k8s.io/klog/v2 v2.80.1 // indirect | ||
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect | ||
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect | ||
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect | ||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect | ||
sigs.k8s.io/yaml v1.3.0 // indirect | ||
) |
Oops, something went wrong.