Skip to content

Commit

Permalink
Added new features when creating a kubernetes cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro JNM <[email protected]>
  • Loading branch information
alejandrojnm committed Aug 14, 2020
1 parent 90daeee commit fb51ae8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cmd/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func init() {
kubernetesCreateCmd.Flags().StringVarP(&targetNodesSize, "size", "s", "g2.medium", "the size of nodes to create.")
kubernetesCreateCmd.Flags().IntVarP(&numTargetNodes, "nodes", "n", 3, "the number of nodes to create (the master also acts as a node).")
kubernetesCreateCmd.Flags().StringVarP(&kubernetesVersion, "version", "v", "latest", "the k3s version to use on the cluster. Defaults to the latest.")
kubernetesCreateCmd.Flags().StringVarP(&applications, "applications", "a", "", "optional, use names shown by running `civo kubernetes applications ls`")
kubernetesCreateCmd.Flags().StringVarP(&removeapplications, "remove-applications", "r", "", "optional, remove default application names shown by running `civo kubernetes applications ls`")
kubernetesCreateCmd.Flags().BoolVarP(&waitKubernetes, "wait", "w", false, "a simple flag (e.g. --wait) that will cause the CLI to spin and wait for the cluster to be ACTIVE")
kubernetesCreateCmd.Flags().BoolVarP(&saveConfigKubernetes, "save", "", false, "save the config")
kubernetesCreateCmd.Flags().BoolVarP(&switchConfigKubernetes, "switch", "", false, "switch context to newly-created cluster")
Expand Down
24 changes: 23 additions & 1 deletion cmd/kubernetes_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"strconv"
"strings"
"time"

"github.com/briandowns/spinner"
Expand All @@ -15,7 +16,7 @@ import (

var numTargetNodes int
var waitKubernetes, saveConfigKubernetes, switchConfigKubernetes bool
var kubernetesVersion, targetNodesSize, clusterName string
var kubernetesVersion, targetNodesSize, clusterName, applications, removeapplications, installApplications string

var kubernetesCreateCmd = &cobra.Command{
Use: "create",
Expand Down Expand Up @@ -57,6 +58,27 @@ var kubernetesCreateCmd = &cobra.Command{
configKubernetes.KubernetesVersion = kubernetesVersion
}

if applications != "" {
installApplications = applications
}

if removeapplications != "" {
var rmApp []string
for _, v := range strings.Split(removeapplications, ",") {
rmApp = append(rmApp, fmt.Sprintf("-%s", v))
}
if installApplications != "" {
installApplications = fmt.Sprintf("%s,%s", installApplications, strings.Join(rmApp, ","))
} else {
installApplications = fmt.Sprintf("%s", strings.Join(rmApp, ","))
}

}

if installApplications != "" {
configKubernetes.Applications = installApplications
}

kubernetesCluster, err := client.NewKubernetesClusters(configKubernetes)
if err != nil {
utility.Error("Creating a Kubernetes cluster failed with %s", err)
Expand Down

0 comments on commit fb51ae8

Please sign in to comment.