From ab45b32c017a4c12002d36b65bda78236ac5bf12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Juan=20G=C3=B3mez=20Pe=C3=B1alver?= Date: Thu, 5 Jul 2018 11:44:03 +0100 Subject: [PATCH] feat(forcedUpdates) Allow forced updates Allow forced updates when delete and/or create stages are disabled --- pkg/landscaper/executor.go | 10 +++--- pkg/landscaper/executor_test.go | 54 +++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/pkg/landscaper/executor.go b/pkg/landscaper/executor.go index 05abb42..a97968a 100644 --- a/pkg/landscaper/executor.go +++ b/pkg/landscaper/executor.go @@ -84,8 +84,9 @@ func (e *executor) Apply(desired, current Components) error { logrus.WithFields(logrus.Fields{"create": len(create), "update": len(update), "delete": len(delete)}).Info("Apply desired state") - if e.stageEnabled("delete") { - for _, cmp := range delete { + for _, cmp := range delete { + _, cmpForcedUpdate := needForcedUpdate[cmp.Name] + if e.stageEnabled("delete") || (e.stageEnabled("update") && cmpForcedUpdate) { logrus.Infof("Delete: %s", cmp.Name) if err := e.DeleteComponent(cmp); err != nil { logrus.WithFields(logrus.Fields{"error": err, "component": cmp}).Error("DeleteComponent failed") @@ -106,8 +107,9 @@ func (e *executor) Apply(desired, current Components) error { } } - if e.stageEnabled("create") { - for _, cmp := range create { + for _, cmp := range create { + _, cmpForcedUpdate := needForcedUpdate[cmp.Name] + if e.stageEnabled("create") || (e.stageEnabled("update") && cmpForcedUpdate) { if err := logDifferences(logrus.Infof, "Create: "+cmp.Name, nil, cmp); err != nil { return err } diff --git a/pkg/landscaper/executor_test.go b/pkg/landscaper/executor_test.go index d8bbc1e..271f966 100644 --- a/pkg/landscaper/executor_test.go +++ b/pkg/landscaper/executor_test.go @@ -92,6 +92,60 @@ func TestExecutorApply(t *testing.T) { } +func TestExecutorApplyWithForcedUpdatesAndDeleteCreateDisable(t *testing.T) { + chartPath := "/opt/store/whatever/path/" + + nu := newTestComponent("new-one") + nu.Namespace = "recognizable-new-one" + rem := newTestComponent("busted-one") + up := newTestComponent("updated-one") + updiff := newTestComponent("updated-one") + updiff.Configuration["FlushSize"] = 4 + updiff.SecretNames = SecretNames{"newSecret": "somethingNew"} + + updiff.SecretValues = SecretValues{ + "newSecret": []byte("somethingNew"), + } + + des := Components{nu.Name: nu, updiff.Name: updiff} + cur := Components{rem.Name: rem, up.Name: up} + + helmMock := &HelmclientMock{ + installRelease: func(chStr string, namespace string, opts ...helm.InstallOption) (*services.InstallReleaseResponse, error) { + t.Logf("installRelease %#v %#v %#v", chStr, namespace, opts) + require.Equal(t, namespace, "recognizable-new-one") // the name is hidden in the opts we cannot inspect + return nil, nil + }, + deleteRelease: func(rlsName string, opts ...helm.DeleteOption) (*services.UninstallReleaseResponse, error) { + t.Logf("deleteRelease %#v", rlsName) + require.Equal(t, rlsName, "busted-one") + return nil, nil + }, + updateRelease: func(rlsName string, chStr string, opts ...helm.UpdateOption) (*services.UpdateReleaseResponse, error) { + t.Logf("updateRelease %#v %#v %#v", rlsName, chStr, opts) + require.Equal(t, rlsName, "updated-one") + return nil, nil + }} + chartLoadMock := MockChartLoader(func(chartRef string) (*chart.Chart, string, error) { + t.Logf("MockChartLoader %#v", chartRef) + return nil, chartPath, nil + }) + secretsMock := SecretsProviderMock{ + write: func(componentName, namespace string, values SecretValues) error { + return nil + }, + delete: func(componentName, namespace string) error { + return nil + }, + } + + createDeleteDisabled := []string{"create", "delete"} + + err := NewExecutor(helmMock, chartLoadMock, secretsMock, false, false, waitTimeout, createDeleteDisabled).Apply(des, cur) + require.NoError(t, err) + +} + func TestExecutorCreate(t *testing.T) { chartPath := "/opt/store/whatever/path/" nameSpace := "spacename"