Handles non-status errors

This commit is contained in:
Daniel
2019-06-06 14:00:56 +10:00
parent 6aa443838e
commit 42c45c78db
3 changed files with 6 additions and 4 deletions
+3 -2
View File
@@ -74,8 +74,9 @@ func CreateDeployment(clientset *kubernetes.Clientset, namespace string, deploym
func DeploymentExists(clientset *kubernetes.Clientset, namespace string, deploymentName string) (bool, error) {
_, err := clientset.AppsV1().Deployments(namespace).Get(deploymentName, meta.GetOptions{})
if err != nil {
statusErr := err.(*errors.StatusError)
if statusErr.Status().Code == 404 {
// TODO: Only conver to StatusError if the error is in fact a status error
statusError, ok := err.(*errors.StatusError)
if ok == true && statusError.Status().Code == 404 {
return false, nil
}
return false, err
+1
View File
@@ -18,6 +18,7 @@ func main() {
},
}
fmt.Printf(os.Getenv("PLUGIN_SKIP_TLS"))
fmt.Println("kubano v0.0.1 https://github.com/danielgormly/drone-plugin-kube")
err := plugin.Exec()
if err != nil {
log.Fatalf("⛔️ Fatal error: \n%s", err)
+2 -2
View File
@@ -75,11 +75,11 @@ func (p Plugin) Exec() error {
deployment := CreateDeploymentObj(depYaml)
deploymentExists, err := DeploymentExists(clientset, p.KubeConfig.Namespace, deployment.Name)
if deploymentExists {
log.Printf("📦 Found existing deployment. Updating:\n%s\n", depYaml)
log.Printf("📦 Found existing deployment. Updating.\n%s\n", depYaml)
err = UpdateDeployment(clientset, p.KubeConfig.Namespace, deployment)
return err
}
log.Printf("📦 Creating new deployment\n%s\n", depYaml)
log.Printf("📦 Creating new deployment.\n%s\n", depYaml)
err = CreateDeployment(clientset, p.KubeConfig.Namespace, deployment)
return err
}