mirror of
https://github.com/danielgormly/drone-plugin-kube.git
synced 2026-06-04 18:23:48 +08:00
Better error handling
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user