Skip to content

Commit

Permalink
Added Update command (#171)
Browse files Browse the repository at this point in the history
Added update command.
Refactored terraform init.
Enabled zone list that allows you to specify node pool zones in the cluster config.
Refactored ASM mesh install scripts to take advantage of the Fleets mesh api and use connect gw.

Co-authored-by: Nick Eberts <[email protected]>
  • Loading branch information
knee-berts and knee-berts authored Oct 10, 2022
1 parent 333ceec commit b2904a8
Show file tree
Hide file tree
Showing 31 changed files with 331 additions and 578 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,5 @@ cli/*.yaml

# Ignore users' kubeconfigs
*kubeconfig*

.idea/
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ time="2022-02-04T21:58:00Z" level=info msg="✔️ Kubeconfig generated: &{Kind:
time="2022-02-04T21:58:00Z" level=info msg="☸️ Verifying Kubernetes API access for all clusters..."
time="2022-02-04T21:58:00Z" level=info msg="🌎 5 Namespaces found in cluster=gke_gpt-e2etest-020422-214428_us-central1_gke-central"
```

## Update

If you want to update your environment change the config file and run the update command. This is a great way to add or remove clusters.
```bash
./gkekitctl update --config <config file name>
```

## Clean up

```bash
Expand Down
26 changes: 6 additions & 20 deletions cli/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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
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,
Expand All @@ -17,7 +17,6 @@ package cmd

import (
"gkekitctl/pkg/analytics"
"gkekitctl/pkg/anthos"
"gkekitctl/pkg/config"
"gkekitctl/pkg/lifecycle"

Expand All @@ -44,23 +43,23 @@ var createCmd = &cobra.Command{

config.GenerateTfvars(conf)
log.Info("👟 Started configuring TF State...")
tfStateBucket, err := config.CheckTfStateType(conf)
err := config.CheckTfStateType(conf)
if err != nil {
log.Errorf("🚨 Failed checking TF state type: %s", err)
} else {
log.Info("✅ TF state configured successfully.")
}

if conf.VpcConfig.VpcType == "shared" {
lifecycle.InitTF("shared_vpc", tfStateBucket[1])
lifecycle.InitTF("shared_vpc")
lifecycle.ApplyTF("shared_vpc")
}
lifecycle.InitTF("cluster_build", tfStateBucket[0])
lifecycle.InitTF("cluster_build")
lifecycle.ApplyTF("cluster_build")

// Authenticate Kubernetes client-go to all clusters
log.Info("☸️ Generating Kubeconfig...")
kc, err := anthos.GenerateKubeConfig(conf)
kc, err := lifecycle.GenerateKubeConfig(conf)
if err != nil {
log.Errorf("🚨 Failed to generate kube config: %s", err)
} else {
Expand All @@ -69,25 +68,12 @@ var createCmd = &cobra.Command{

// Verify access to Kubernetes API on all clusters
log.Info("☸️ Verifying Kubernetes API access for all clusters...")
err = anthos.ListNamespaces(kc)
err = lifecycle.ListNamespaces(kc)
if err != nil {
log.Errorf("🚨 Failed API access check on clusters: %s", err)
} else {
log.Info("✅ Clusters API access check passed.")
}

// Init ACM (either ConfigSync or ConfigSync plus PolicyController)
if conf.ConfigSync {
err := anthos.InitACM(conf, kc)
if err != nil {
log.Errorf("🚨 Failed to initialize ACM: %s", err)
} else {
log.Info("✅ ConfigSync setup successfully.")
}
}
if err == nil {
log.Info("✅ Clusters API access check passed.")
}
},
}

Expand Down
50 changes: 50 additions & 0 deletions cli/cmd/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright © 2020 Google Inc.
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 (
"gkekitctl/pkg/config"
"gkekitctl/pkg/lifecycle"

log "github.com/sirupsen/logrus"

"github.com/spf13/cobra"
)

// createCmd represents the create command
var updateCmd = &cobra.Command{
Use: "update",
Short: "update your gke toolkit environment",
Example: `gkekitctl update --config <file.yaml>`,
Run: func(cmd *cobra.Command, args []string) {
log.Info("👟 Started config validation...")
conf := config.InitConf(cfgFile)
log.Info("👟 Started generating TFVars...")

config.GenerateTfvars(conf)

if conf.VpcConfig.VpcType == "shared" {
lifecycle.InitTF("shared_vpc")
lifecycle.ApplyTF("shared_vpc")
}
lifecycle.InitTF("cluster_build")
lifecycle.ApplyTF("cluster_build")
},
}

func init() {
rootCmd.AddCommand(updateCmd)
}
44 changes: 22 additions & 22 deletions cli/pkg/analytics/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,27 @@ import (

// This is an Analytics-only object representing 1 GKE cluster created with gkekitctl.
type Cluster struct {
ClusterId string `json:"clusterId"`
CreateId string `json:"createId"`
Version string `json:"version"`
GitCommit string `json:"gitCommit"`
Timestamp string `json:"timestamp"`
OS string `json:"os"`
TerraformState string `json:"terraformState"`
Region string `json:"region"`
EnablePreemptibleNodepool bool `json:"enablePreemptibleNodepool"`
DefaultNodepoolOS string `json:"defaultNodepoolOS"`
PrivateEndpoint bool `json:"privateEndpoint"`
EnableConfigSync bool `json:"enableConfigSync"`
EnablePolicyController bool `json:"enablePolicyController"`
AnthosServiceMesh bool `json:"anthosServiceMesh"`
MultiClusterGateway bool `json:"multiClusterGateway"`
VPCType string `json:"vpcType"`
ClusterIndex int `json:"clusterIndex"`
ClusterType string `json:"clusterType"`
ClusterMachineType string `json:"clusterMachineType"`
ClusterRegion string `json:"clusterRegion"`
ClusterZone string `json:"clusterZone"`
ClusterId string `json:"clusterId"`
CreateId string `json:"createId"`
Version string `json:"version"`
GitCommit string `json:"gitCommit"`
Timestamp string `json:"timestamp"`
OS string `json:"os"`
TerraformState string `json:"terraformState"`
Region string `json:"region"`
EnablePreemptibleNodepool bool `json:"enablePreemptibleNodepool"`
DefaultNodepoolOS string `json:"defaultNodepoolOS"`
PrivateEndpoint bool `json:"privateEndpoint"`
EnableConfigSync bool `json:"enableConfigSync"`
EnablePolicyController bool `json:"enablePolicyController"`
AnthosServiceMesh bool `json:"anthosServiceMesh"`
MultiClusterGateway bool `json:"multiClusterGateway"`
VPCType string `json:"vpcType"`
ClusterIndex int `json:"clusterIndex"`
ClusterType string `json:"clusterType"`
ClusterMachineType string `json:"clusterMachineType"`
ClusterRegion string `json:"clusterRegion"`
ClusterZones []string `json:"[clusterZone]"`
}

func SendAnalytics(conf *config.Config, version string, gitCommit string) {
Expand Down Expand Up @@ -101,7 +101,7 @@ func SendAnalytics(conf *config.Config, version string, gitCommit string) {
ClusterType: cluster.ClusterType,
ClusterMachineType: cluster.MachineType,
ClusterRegion: cluster.Region,
ClusterZone: cluster.Zone,
ClusterZones: cluster.Zones,
}
// Encode as JSON
json, err := json.Marshal(sendObject)
Expand Down
162 changes: 0 additions & 162 deletions cli/pkg/anthos/configsync.go

This file was deleted.

7 changes: 7 additions & 0 deletions cli/pkg/cli_init/cluster_build/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module "cluster_build" {
project_id = var.project_id
governance_project_id = var.governance_project_id
region = var.region
zones = var.zones
shared_vpc = var.shared_vpc
vpc_name = var.vpc_name
ip_range_pods_name = var.ip_range_pods_name
Expand Down Expand Up @@ -48,6 +49,12 @@ variable "region" {
default = "us-central1"
}

variable "zones" {
type = list(string)
description = "The zones used in your nodepool"
default = ["us-central1-b"]
}

variable "shared_vpc" {
type = bool
description = "boolean value for determining whether to create Standalone VPC or use a preexisting Shared VPC"
Expand Down
2 changes: 1 addition & 1 deletion cli/pkg/cli_init/samples/default-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ clustersConfig:
- clusterName: "gke-central"
machineType: "e2-standard-4"
region: "us-central1"
zone: "us-central1-a"
zones: ["us-central1-a"]
subnetName: "us-central1"
Loading

0 comments on commit b2904a8

Please sign in to comment.