mirror of
https://github.com/danielgormly/drone-plugin-kube.git
synced 2026-06-14 14:02:32 +08:00
Handles non-status errors
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user