Better error handling

This commit is contained in:
Daniel
2019-05-29 12:32:42 +10:00
parent 144da236dc
commit 5265201a0e
2 changed files with 10 additions and 10 deletions
+1 -1
View File
@@ -20,6 +20,6 @@ func main() {
fmt.Printf(os.Getenv("PLUGIN_SKIP_TLS"))
err := plugin.Exec()
if err != nil {
log.Fatalf("Fatal error: \n%s", err)
log.Fatalf("⛔️ Fatal error: \n%s", err)
}
}
+9 -9
View File
@@ -1,7 +1,7 @@
package main
import (
"fmt"
"errors"
"io/ioutil"
"log"
"os"
@@ -30,19 +30,19 @@ type (
// Exec -- Runs plugin
func (p Plugin) Exec() error {
if p.KubeConfig.Server == "" {
log.Fatal("PLUGIN_SERVER is not defined")
return errors.New("PLUGIN_SERVER is not defined")
}
if p.KubeConfig.Token == "" {
log.Fatal("PLUGIN_TOKEN is not defined")
return errors.New("PLUGIN_TOKEN is not defined")
}
if p.KubeConfig.Ca == "" {
log.Fatal("PLUGIN_CA is not defined")
return errors.New("PLUGIN_CA is not defined")
}
if p.KubeConfig.Namespace == "" {
p.KubeConfig.Namespace = "default"
}
if p.Template == "" {
log.Fatal("PLUGIN_TEMPLATE, or template must be defined")
return errors.New("PLUGIN_TEMPLATE, or template must be defined")
}
// Make map of environment variables set by Drone
ctx := make(map[string]string)
@@ -58,20 +58,20 @@ func (p Plugin) Exec() error {
// Grab template from filesystem
raw, err := ioutil.ReadFile(p.Template)
if err != nil {
log.Print("Error reading template file:")
log.Print("⛔️ Error reading template file:")
return err
}
// Parse template
depYaml, err := raymond.Render(string(raw), ctx)
fmt.Printf("Updating deployment template: \n%s", depYaml)
log.Printf("📦 Updating deployment template: \n%s", depYaml)
if err != nil {
panic(err)
return err
}
// Connect to Kubernetes
clientset, err := p.CreateKubeClient()
if err != nil {
log.Fatal(err.Error())
return err
}
deployment := CreateDeploymentObj(depYaml)
err = UpdateDeployment(clientset, p.KubeConfig.Namespace, deployment)