From 93f551d7fd43aa765d35bf4a749ca9d462ed4cf8 Mon Sep 17 00:00:00 2001 From: Brendan Melville Date: Thu, 3 Dec 2015 17:15:56 -0500 Subject: [PATCH] Resource errors should result in a failed deployment with good errors. --- manager/manager/manager.go | 19 +++++++++++++++++++ manager/manager/manager_test.go | 3 --- resourcifier/configurator/configurator.go | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/manager/manager/manager.go b/manager/manager/manager.go index 53e14a089..69c0041a0 100644 --- a/manager/manager/manager.go +++ b/manager/manager/manager.go @@ -125,6 +125,14 @@ func (m *manager) CreateDeployment(t *common.Template) (*common.Deployment, erro return nil, err } } else { + // May be errors in the resources themselves. + errs := getResourceErrors(actualConfig) + if len(errs) > 0 { + e := fmt.Errorf("Found resource errors during deployment: %v", errs) + m.repository.SetDeploymentState(t.Name, failState(e)) + return nil, e + } + m.repository.SetDeploymentState(t.Name, &common.DeploymentState{Status: common.DeployedStatus}) } @@ -301,3 +309,14 @@ func failState(e error) *common.DeploymentState { Errors: []string{e.Error()}, } } + +func getResourceErrors(c *common.Configuration) []string { + var errs []string + for _, r := range c.Resources { + if r.State.Status == common.Failed { + errs = append(errs, r.State.Errors...) + } + } + + return errs +} diff --git a/manager/manager/manager_test.go b/manager/manager/manager_test.go index eeed183a7..c93153cff 100644 --- a/manager/manager/manager_test.go +++ b/manager/manager/manager_test.go @@ -455,9 +455,6 @@ func TestDeleteDeploymentForget(t *testing.T) { if err != nil { t.Fatalf("DeleteDeployment failed with %v", err) } - if d.State.Status != common.DeletedStatus { - t.Fatalf("Expected DeletedStatus on deleted deployment") - } // Make sure the resources were deleted through deployer. if len(testDeployer.Deleted) > 0 { diff --git a/resourcifier/configurator/configurator.go b/resourcifier/configurator/configurator.go index fb826f86a..9efd61fd3 100644 --- a/resourcifier/configurator/configurator.go +++ b/resourcifier/configurator/configurator.go @@ -175,7 +175,7 @@ func (a *Configurator) configureResource(resource *common.Resource, o operation) } else { e := fmt.Errorf("kubetcl failed for resource: %v: %v: %v", resource.Name, err, combined.String()) resource.State = failState(e) - return "", e + return combined.String(), e } }