Commit 4b54fbc1 authored by Christopher Harm's avatar Christopher Harm

Adding delete command and --rebuild flag to reset k8s environment

parent 854a5c14
// Copyright © 2019 NAME HERE <EMAIL ADDRESS>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
import (
"os"
"git.psu.edu/k8s/devtool/environment"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// startCmd represents the start command
var rmCmd = &cobra.Command{
Use: "delete",
Short: "delete the kubernetes environment",
Run: func(command *cobra.Command, args []string) {
delete()
},
}
func init() {
rootCmd.AddCommand(rmCmd)
}
func delete() {
if minikubeProvider() {
color.Blue("Using minikube Kubernetes Provider")
} else if kindProvider() {
color.Blue("Using kind Kubernetes Provider")
} else {
color.Red("Unsupported k8s provider was specified")
os.Exit(-1)
}
color.Blue("Checking Prerequisites.")
prereqsInstalled := checkLocalSetup()
if !prereqsInstalled {
color.Red("Please install the required applications and try again.\n")
return
}
tearDownKubernetes()
}
func tearDownKubernetes() {
color.Blue("Tearing down Kubernetes")
if minikubeProvider() {
environment.RunRequired(true, "minikube", "delete")
} else if kindProvider() {
clusterName := viper.GetString("kind.name")
environment.RunRequired(true, "kind", "delete", "cluster", "--name", clusterName)
}
}
......@@ -36,7 +36,7 @@ import (
// startCmd represents the start command
var startCmd = &cobra.Command{
Use: "start",
Short: "start the minikube environment",
Short: "start the kubernetes environment",
Run: func(command *cobra.Command, args []string) {
start()
},
......@@ -56,6 +56,13 @@ func init() {
panic("invalid arg")
}
startCmd.Flags().Bool("rebuild", false, "Destroy Kubernetes and start again.")
viper.SetDefault("k8s.rebuild", false)
err = viper.BindPFlag("k8s.rebuild", startCmd.Flags().Lookup("rebuild"))
if err != nil {
panic("invalid arg")
}
startCmd.PersistentFlags().IntP("memory", "m", 0, "memory for minikube (default is 8192)")
viper.SetDefault("minikube.memory", 8192)
err = viper.BindPFlag("minikube.memory", startCmd.PersistentFlags().Lookup("memory"))
......@@ -125,6 +132,16 @@ func start() {
environment.RunRequired(true, "helm", "repo", "add", "stable", "https://kubernetes-charts.storage.googleapis.com")
}
if viper.GetBool("k8s.rebuild") {
color.Blue("Tearing down Kubernetes")
if minikubeProvider() {
environment.RunRequired(true, "minikube", "delete")
} else if kindProvider() {
clusterName := viper.GetString("kind.name")
environment.RunRequired(true, "kind", "delete", "cluster", "--name", clusterName)
}
}
if minikubeProvider() {
memory := strconv.Itoa(viper.GetInt("minikube.memory"))
cpu := strconv.Itoa(viper.GetInt("minikube.cpu"))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment