Răsfoiți Sursa

Merge pull request #1619 from porter-dev/nafees/preview-env-improvements

[POR-312] Add support for waitForJob in porter.yaml
abelanger5 4 ani în urmă
părinte
comite
008bd9354e
1 a modificat fișierele cu 27 adăugiri și 0 ștergeri
  1. 27 0
      cli/cmd/apply.go

+ 27 - 0
cli/cmd/apply.go

@@ -132,6 +132,8 @@ type Target struct {
 }
 
 type ApplicationConfig struct {
+	WaitForJob bool
+
 	Build struct {
 		Method     string
 		Context    string
@@ -315,6 +317,26 @@ func (d *Driver) applyApplication(resource *models.Resource, client *api.Client,
 		return nil, err
 	}
 
+	if d.source.Name == "job" && appConfig.WaitForJob {
+		color.New(color.FgYellow).Printf("Waiting for job '%s' to finish\n", resource.Name)
+
+		prevProject := config.Project
+		prevCluster := config.Cluster
+		name = resource.Name
+		namespace = d.target.Namespace
+		config.Project = d.target.Project
+		config.Cluster = d.target.Cluster
+
+		err = waitForJob(nil, client, []string{})
+
+		if err != nil {
+			return nil, err
+		}
+
+		config.Project = prevProject
+		config.Cluster = prevCluster
+	}
+
 	return resource, err
 }
 
@@ -623,6 +645,11 @@ func (d *Driver) getApplicationConfig(resource *models.Resource) (*ApplicationCo
 		return nil, err
 	}
 
+	if _, ok := resource.Config["waitForJob"]; !ok && d.source.Name == "job" {
+		// default to true and wait for the job to finish
+		config.WaitForJob = true
+	}
+
 	return config, nil
 }