Skip to content
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.

Commit

Permalink
feat(forcedUpdates) Allow forced updates
Browse files Browse the repository at this point in the history
Allow forced updates when delete and/or create stages are disabled
  • Loading branch information
carlosjgp committed Jul 5, 2018
1 parent bec6b34 commit ab45b32
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/landscaper/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
}
Expand Down
54 changes: 54 additions & 0 deletions pkg/landscaper/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ab45b32

Please sign in to comment.