Skip to content

Commit

Permalink
fix(nelm): don't skip release if all resources up-to-date but the rel…
Browse files Browse the repository at this point in the history
…ease itself changed

Signed-off-by: Ilya Lesikov <ilya@lesikov.com>
  • Loading branch information
ilya-lesikov committed Apr 4, 2024
1 parent 7dabc56 commit e208e9c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
17 changes: 13 additions & 4 deletions cmd/werf/bundle/apply/apply.go
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/werf/nelm/pkg/resrcpatcher"
"github.com/werf/nelm/pkg/resrcprocssr"
"github.com/werf/nelm/pkg/rls"
"github.com/werf/nelm/pkg/rlsdiff"

Check failure on line 40 in cmd/werf/bundle/apply/apply.go

View workflow job for this annotation

GitHub Actions / check_broken_links

no required module provides package github.com/werf/nelm/pkg/rlsdiff; to add it:

Check failure on line 40 in cmd/werf/bundle/apply/apply.go

View workflow job for this annotation

GitHub Actions / doc_unit / _

no required module provides package github.com/werf/nelm/pkg/rlsdiff; to add it:

Check failure on line 40 in cmd/werf/bundle/apply/apply.go

View workflow job for this annotation

GitHub Actions / doc_integration / _ (ubuntu-latest-16-cores)

no required module provides package github.com/werf/nelm/pkg/rlsdiff; to add it:

Check failure on line 40 in cmd/werf/bundle/apply/apply.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package github.com/werf/nelm/pkg/rlsdiff; to add it:

Check failure on line 40 in cmd/werf/bundle/apply/apply.go

View workflow job for this annotation

GitHub Actions / unit / _

no required module provides package github.com/werf/nelm/pkg/rlsdiff; to add it:

Check failure on line 40 in cmd/werf/bundle/apply/apply.go

View workflow job for this annotation

GitHub Actions / e2e_simple / _

no required module provides package github.com/***/nelm/pkg/rlsdiff; to add it:
"github.com/werf/nelm/pkg/rlshistor"
"github.com/werf/nelm/pkg/track"
"github.com/werf/nelm/pkg/utls"
Expand Down Expand Up @@ -490,11 +491,19 @@ func runApply(ctx context.Context) error {
}
}

if useless, err := plan.Useless(); err != nil {
releaseUpToDate, err := rlsdiff.ReleaseUpToDate(prevRelease, newRel)
if err != nil {
return fmt.Errorf("error checking if release is up to date: %w", err)
}

planUseless, err := plan.Useless()
if err != nil {
return fmt.Errorf("error checking if deploy plan will do nothing useful: %w", err)
} else if useless {
}

if releaseUpToDate && planUseless {
printNotes(ctx, notes)
log.Default.Info(ctx, color.Style{color.Bold, color.Green}.Render("Skipped release")+" %q (namespace: %q): cluster resources already as desired", releaseName, releaseNamespace.Name())
log.Default.Info(ctx, color.Style{color.Bold, color.Green}.Render(fmt.Sprintf("Skipped release %q (namespace: %q): cluster resources already as desired", releaseName, releaseNamespace.Name())))
return nil
}

Expand Down Expand Up @@ -650,7 +659,7 @@ func runApply(ctx context.Context) error {
} else if len(nonCriticalErrs) > 0 {
return utls.Multierrorf("succeeded release %q (namespace: %q), but non-critical errors encountered", nonCriticalErrs, releaseName, releaseNamespace.Name())
} else {
log.Default.Info(ctx, color.Style{color.Bold, color.Green}.Render("Succeeded release")+" %q (namespace: %q)", releaseName, releaseNamespace.Name())
log.Default.Info(ctx, color.Style{color.Bold, color.Green}.Render(fmt.Sprintf("Succeeded release %q (namespace: %q)", releaseName, releaseNamespace.Name())))
return nil
}
})
Expand Down
17 changes: 13 additions & 4 deletions cmd/werf/converge/converge.go
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/werf/nelm/pkg/resrcpatcher"
"github.com/werf/nelm/pkg/resrcprocssr"
"github.com/werf/nelm/pkg/rls"
"github.com/werf/nelm/pkg/rlsdiff"
"github.com/werf/nelm/pkg/rlshistor"
"github.com/werf/nelm/pkg/track"
"github.com/werf/nelm/pkg/utls"
Expand Down Expand Up @@ -755,11 +756,19 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
}
}

if useless, err := plan.Useless(); err != nil {
releaseUpToDate, err := rlsdiff.ReleaseUpToDate(prevRelease, newRel)
if err != nil {
return fmt.Errorf("error checking if release is up to date: %w", err)
}

planUseless, err := plan.Useless()
if err != nil {
return fmt.Errorf("error checking if deploy plan will do nothing useful: %w", err)
} else if useless {
}

if releaseUpToDate && planUseless {
printNotes(ctx, notes)
log.Default.Info(ctx, color.Style{color.Bold, color.Green}.Render("Skipped release")+" %q (namespace: %q): cluster resources already as desired", releaseName, releaseNamespace.Name())
log.Default.Info(ctx, color.Style{color.Bold, color.Green}.Render(fmt.Sprintf("Skipped release %q (namespace: %q): cluster resources already as desired", releaseName, releaseNamespace.Name())))
return nil
}

Expand Down Expand Up @@ -916,7 +925,7 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
} else if len(nonCriticalErrs) > 0 {
return utls.Multierrorf("succeeded release %q (namespace: %q), but non-critical errors encountered", nonCriticalErrs, releaseName, releaseNamespace.Name())
} else {
log.Default.Info(ctx, color.Style{color.Bold, color.Green}.Render("Succeeded release")+" %q (namespace: %q)", releaseName, releaseNamespace.Name())
log.Default.Info(ctx, color.Style{color.Bold, color.Green}.Render(fmt.Sprintf("Succeeded release %q (namespace: %q)", releaseName, releaseNamespace.Name())))
return nil
}
})
Expand Down
26 changes: 24 additions & 2 deletions cmd/werf/plan/plan.go
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"time"

"github.com/gookit/color"
"github.com/samber/lo"
Expand All @@ -30,6 +31,8 @@ import (
"github.com/werf/nelm/pkg/resrcchanglog"
"github.com/werf/nelm/pkg/resrcpatcher"
"github.com/werf/nelm/pkg/resrcprocssr"
"github.com/werf/nelm/pkg/rls"
"github.com/werf/nelm/pkg/rlsdiff"
"github.com/werf/nelm/pkg/rlshistor"
"github.com/werf/werf/cmd/werf/common"
"github.com/werf/werf/pkg/build"
Expand Down Expand Up @@ -552,8 +555,10 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
}

var newRevision int
var firstDeployed time.Time
if prevReleaseFound {
newRevision = prevRelease.Revision() + 1
firstDeployed = prevRelease.FirstDeployed()
} else {
newRevision = 1
}
Expand Down Expand Up @@ -589,6 +594,8 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
return fmt.Errorf("error constructing chart tree: %w", err)
}

notes := chartTree.Notes()

var prevRelGeneralResources []*resrc.GeneralResource
var prevRelFailed bool
if prevReleaseFound {
Expand Down Expand Up @@ -633,8 +640,17 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
return fmt.Errorf("error processing deployable resources: %w", err)
}

log.Default.Info(ctx, "Constructing new release")
newRel, err := rls.NewRelease(releaseName, releaseNamespace.Name(), newRevision, chartTree.ReleaseValues(), chartTree.LegacyChart(), resProcessor.ReleasableHookResources(), resProcessor.ReleasableGeneralResources(), notes, rls.ReleaseOptions{
FirstDeployed: firstDeployed,
Mapper: clientFactory.Mapper(),
})
if err != nil {
return fmt.Errorf("error constructing new release: %w", err)
}

log.Default.Info(ctx, "Calculating planned changes")
createdChanges, recreatedChanges, updatedChanges, appliedChanges, deletedChanges, anyChangesPlanned := resrcchangcalc.CalculatePlannedChanges(
createdChanges, recreatedChanges, updatedChanges, appliedChanges, deletedChanges, planChangesPlanned := resrcchangcalc.CalculatePlannedChanges(
resProcessor.DeployableReleaseNamespaceInfo(),
resProcessor.DeployableStandaloneCRDsInfos(),
resProcessor.DeployableHookResourcesInfos(),
Expand All @@ -643,18 +659,24 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
prevRelFailed,
)

releaseUpToDate, err := rlsdiff.ReleaseUpToDate(prevRelease, newRel)
if err != nil {
return fmt.Errorf("error checking if release is up to date: %w", err)
}

resrcchanglog.LogPlannedChanges(
ctx,
releaseName,
releaseNamespace.Name(),
!releaseUpToDate,
createdChanges,
recreatedChanges,
updatedChanges,
appliedChanges,
deletedChanges,

Check failure on line 676 in cmd/werf/plan/plan.go

View workflow job for this annotation

GitHub Actions / lint / _

too many arguments in call to resrcchanglog.LogPlannedChanges
)

if cmdData.DetailedExitCode && anyChangesPlanned {
if cmdData.DetailedExitCode && (planChangesPlanned || !releaseUpToDate) {
return resrcchangcalc.ErrChangesPlanned
}

Expand Down

0 comments on commit e208e9c

Please sign in to comment.