aa624ce27c
This commit provides the Go code and scripts for the Bootstrap container for GCP. The Bootstrap container (bootstrap_capg) for Google Cloud is designed to accept three commands: create, delete and help. - create - will create an Ephemeral GKE cluster in Google Cloud - delete - will delete the Ephemeral GKE cluster from the Google Cloud - help - Stdout the help text for using this container. Please, refer to the bootstrap_capg/README.md for further details. Change-Id: Ifad7c7a7fede0230029716c9e093449f5886e859
79 lines
1.8 KiB
Go
79 lines
1.8 KiB
Go
/*
|
|
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
|
|
|
|
https://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 main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"os"
|
|
|
|
"opendev.org/airship/images/bootstrap_capg/config"
|
|
)
|
|
|
|
const (
|
|
createCmd = "create"
|
|
deleteCmd = "delete"
|
|
helpCmd = "help"
|
|
)
|
|
|
|
func main() {
|
|
var configPath string
|
|
|
|
flag.StringVar(&configPath, "c", "", "Path for the Google Cloud bootstrap configuration (yaml) file")
|
|
flag.Parse()
|
|
|
|
if configPath == "" {
|
|
volMount := os.Getenv("BOOTSTRAP_VOLUME")
|
|
_, dstMount := config.GetVolumeMountPoints(volMount)
|
|
gcpConfigPath := dstMount + "/" + os.Getenv("BOOTSTRAP_CONFIG")
|
|
configPath = gcpConfigPath
|
|
}
|
|
|
|
configYAML := &config.GcpConfig{}
|
|
err := config.ReadYAMLFile(configPath, configYAML)
|
|
if err != nil {
|
|
log.Printf("Failed to load Google Cloud Bootstrap config file")
|
|
os.Exit(1)
|
|
}
|
|
|
|
err = config.ValidateConfigFile(configYAML)
|
|
if err != nil {
|
|
os.Exit(2)
|
|
}
|
|
|
|
command := os.Getenv("BOOTSTRAP_COMMAND")
|
|
switch {
|
|
case command == createCmd:
|
|
err = config.CreateGKECluster(configYAML)
|
|
if err != nil {
|
|
os.Exit(5)
|
|
}
|
|
case command == deleteCmd:
|
|
err = config.DeleteGKECluster(configYAML)
|
|
if err != nil {
|
|
os.Exit(6)
|
|
}
|
|
case command == helpCmd:
|
|
err = config.HelpGKECluster()
|
|
if err != nil {
|
|
os.Exit(7)
|
|
}
|
|
default:
|
|
log.Printf("The --command parameter value shall be 'create', 'delete' or 'help'")
|
|
os.Exit(8)
|
|
}
|
|
os.Exit(0)
|
|
}
|