Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cvila84 committed May 22, 2019
1 parent 8303613 commit b18af10
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
41 changes: 29 additions & 12 deletions cmd/gokube/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ import (
)

const (
MONOCULAR_CHART_VERSION = "1.2.8"
MONOCULAR_APP_VERSION = "1.2.0"
NGINX_INGRESS_CHART_VERSION = "1.1.4"
NGINX_INGRESS_APP_VERSION = "0.23.0"
TPROXY_CHART_VERSION = "1.0.0"
NGINX_INGRESS_APP_VERSION = "0.23.0"
TPROXY_CHART_VERSION = "1.0.0"
DEFAULT_KUBERNETES_VERSION = "v1.10.13"
DEFAULT_MINIKUBE_VERSION = "v1.1.0"
)

var minikubeURL string
Expand Down Expand Up @@ -68,16 +67,24 @@ var ingressController bool
// initCmd represents the init command
var initCmd = &cobra.Command{
Use: "init",
Short: "Initializes gokube. This command downloads dependencies: minikube + helm + kubectl + docker + monocular and creates the virtual machine (minikube)",
Long: "Initializes gokube. This command downloads dependencies: minikube + helm + kubectl + docker + monocular and creates the virtual machine (minikube)",
Short: "Initializes gokube. This command downloads dependencies: minikube + helm + kubectl + docker + stern and creates the virtual machine (minikube)",
Long: "Initializes gokube. This command downloads dependencies: minikube + helm + kubectl + docker + stern and creates the virtual machine (minikube)",
Run: initRun,
}

func init() {
var defaultKubernetesVersion = os.Getenv("KUBERNETES_VERSION")
if len(defaultKubernetesVersion) == 0 {
defaultKubernetesVersion = DEFAULT_KUBERNETES_VERSION
}
var defaultMinikubeVersion = os.Getenv("MINIKUBE_VERSION")
if len(defaultMinikubeVersion) == 0 {
defaultMinikubeVersion = DEFAULT_MINIKUBE_VERSION
}
initCmd.Flags().StringVarP(&minikubeURL, "minikube-url", "", "https://storage.googleapis.com/minikube/releases/%s/minikube-windows-amd64.exe", "The URL to download minikube")
initCmd.Flags().StringVarP(&minikubeVersion, "minikube-version", "", "v1.0.0", "The minikube version")
initCmd.Flags().StringVarP(&minikubeVersion, "minikube-version", "", defaultMinikubeVersion, "The minikube version")
initCmd.Flags().StringVarP(&dockerVersion, "docker-version", "", "18.09.0", "The docker version")
initCmd.Flags().StringVarP(&kubernetesVersion, "kubernetes-version", "", "v1.10.13", "The kubernetes version")
initCmd.Flags().StringVarP(&kubernetesVersion, "kubernetes-version", "", defaultKubernetesVersion, "The kubernetes version")
initCmd.Flags().StringVarP(&kubectlVersion, "kubectl-version", "", "v1.13.5", "The kubectl version")
initCmd.Flags().StringVarP(&helmVersion, "helm-version", "", "v2.13.1", "The helm version")
initCmd.Flags().StringVarP(&helmSprayVersion, "helm-spray-version", "", "v3.3.0", "The helm version")
Expand Down Expand Up @@ -160,7 +167,7 @@ func initRun(cmd *cobra.Command, args []string) {

// Create virtual machine (minikube)
minikube.Start(memory, cpus, disk, transparentProxy, httpProxy, httpsProxy, noProxy, insecureRegistry, kubernetesVersion, imageCache)
// Disbale notification for updates
// Disable notification for updates
minikube.ConfigSet("WantUpdateNotification", "false")
// Enable dashboard
minikube.ConfigSet("dashboard", "true")
Expand Down Expand Up @@ -224,8 +231,18 @@ func initRun(cmd *cobra.Command, args []string) {
}

// Patch kubernetes-dashboard to expose it on nodePort 30000
fmt.Println("Exposing kubernetes dashboard...")
kubectl.Patch("kube-system", "svc", "kubernetes-dashboard", "{\"spec\":{\"type\":\"NodePort\",\"ports\":[{\"port\":80,\"protocol\":\"TCP\",\"targetPort\":9090,\"nodePort\":30000}]}}")
fmt.Print("Exposing kubernetes dashboard...")
for n := 1; n < 12; n++ {
var dashboardService = kubectl.GetObject("kube-system", "svc", "kubernetes-dashboard")
if len(dashboardService) > 0 {
fmt.Println()
kubectl.Patch("kube-system", "svc", "kubernetes-dashboard", "{\"spec\":{\"type\":\"NodePort\",\"ports\":[{\"port\":80,\"protocol\":\"TCP\",\"targetPort\":9090,\"nodePort\":30000}]}}")
break
} else {
fmt.Print(".")
time.Sleep(10 * time.Second)
}
}

fmt.Println("\ngokube has been installed.")
if !imageCache {
Expand Down
2 changes: 1 addition & 1 deletion cmd/gokube/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

const (
GOKUBE_VERSION = "1.6.0"
GOKUBE_VERSION = "1.6.1"
)

// versionCmd represents the version command
Expand Down
9 changes: 9 additions & 0 deletions pkg/kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ const (
URL = "https://storage.googleapis.com/kubernetes-release/release/%s/bin/windows/amd64/kubectl.exe"
)

// GetObject ...
func GetObject(namespace string, resourceType string, resourceName string) string {
output, err := exec.Command("kubectl", "--namespace", namespace, "get", resourceType, resourceName).Output()
if err != nil {
return ""
}
return string(output)
}

// ConfigUseContext ...
func ConfigUseContext(context string) {
cmd := exec.Command("kubectl", "config", "use-context", context)
Expand Down

0 comments on commit b18af10

Please sign in to comment.