Skip to content

Commit

Permalink
fix(deploy): stable resource sorting in Helm release manifests
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Lesikov <ilya@lesikov.com>
  • Loading branch information
ilya-lesikov committed May 20, 2024
1 parent 26095c9 commit 333ac86
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 81 deletions.
39 changes: 0 additions & 39 deletions cmd/werf/bundle/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"os"
"path/filepath"
"sort"
"strings"

"github.com/google/uuid"
Expand All @@ -29,7 +28,6 @@ import (
helmcommon "github.com/werf/nelm/pkg/common"
"github.com/werf/nelm/pkg/kubeclnt"
"github.com/werf/nelm/pkg/resrc"
"github.com/werf/nelm/pkg/resrcid"
"github.com/werf/nelm/pkg/resrcpatcher"
"github.com/werf/nelm/pkg/resrcprocssr"
"github.com/werf/nelm/pkg/rlshistor"
Expand Down Expand Up @@ -427,9 +425,6 @@ func runRender(ctx context.Context) error {

if cmdData.IncludeCRDs {
crds := resProcessor.DeployableStandaloneCRDs()
sort.SliceStable(crds, func(i, j int) bool {
return sortResources(crds[i].ResourceID, crds[j].ResourceID)
})

for _, res := range crds {
if err := renderResource(res.Unstructured(), res.FilePath(), output); err != nil {
Expand All @@ -439,9 +434,6 @@ func runRender(ctx context.Context) error {
}

hooks := resProcessor.DeployableHookResources()
sort.SliceStable(hooks, func(i, j int) bool {
return sortResources(hooks[i].ResourceID, hooks[j].ResourceID)
})

for _, res := range hooks {
if err := renderResource(res.Unstructured(), res.FilePath(), output); err != nil {
Expand All @@ -450,9 +442,6 @@ func runRender(ctx context.Context) error {
}

resources := resProcessor.DeployableGeneralResources()
sort.SliceStable(resources, func(i, j int) bool {
return sortResources(resources[i].ResourceID, resources[j].ResourceID)
})

for _, res := range resources {
if err := renderResource(res.Unstructured(), res.FilePath(), output); err != nil {
Expand Down Expand Up @@ -482,31 +471,3 @@ func renderResource(unstruct *unstructured.Unstructured, path string, output io.

return nil
}

func sortResources(id1, id2 *resrcid.ResourceID) bool {
kind1 := id1.GroupVersionKind().Kind
kind2 := id2.GroupVersionKind().Kind
if kind1 != kind2 {
return kind1 < kind2
}

group1 := id1.GroupVersionKind().Group
group2 := id2.GroupVersionKind().Group
if group1 != group2 {
return group1 < group2
}

version1 := id1.GroupVersionKind().Version
version2 := id2.GroupVersionKind().Version
if version1 != version2 {
return version1 < version2
}

namespace1 := id1.Namespace()
namespace2 := id2.Namespace()
if namespace1 != namespace2 {
return namespace1 < namespace2
}

return id1.Name() < id2.Name()
}
39 changes: 0 additions & 39 deletions cmd/werf/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"os"
"path/filepath"
"sort"
"strings"

"github.com/samber/lo"
Expand All @@ -30,7 +29,6 @@ import (
helmcommon "github.com/werf/nelm/pkg/common"
"github.com/werf/nelm/pkg/kubeclnt"
"github.com/werf/nelm/pkg/resrc"
"github.com/werf/nelm/pkg/resrcid"
"github.com/werf/nelm/pkg/resrcpatcher"
"github.com/werf/nelm/pkg/resrcprocssr"
"github.com/werf/nelm/pkg/rlshistor"
Expand Down Expand Up @@ -660,9 +658,6 @@ func runRender(ctx context.Context, imagesToProcess build.ImagesToProcess) error

if cmdData.IncludeCRDs {
crds := resProcessor.DeployableStandaloneCRDs()
sort.SliceStable(crds, func(i, j int) bool {
return sortResources(crds[i].ResourceID, crds[j].ResourceID)
})

for _, res := range crds {
if len(showFiles) > 0 && !lo.Contains(showFiles, res.FilePath()) {
Expand All @@ -676,9 +671,6 @@ func runRender(ctx context.Context, imagesToProcess build.ImagesToProcess) error
}

hooks := resProcessor.DeployableHookResources()
sort.SliceStable(hooks, func(i, j int) bool {
return sortResources(hooks[i].ResourceID, hooks[j].ResourceID)
})

for _, res := range hooks {
if len(showFiles) > 0 && !lo.Contains(showFiles, res.FilePath()) {
Expand All @@ -691,9 +683,6 @@ func runRender(ctx context.Context, imagesToProcess build.ImagesToProcess) error
}

resources := resProcessor.DeployableGeneralResources()
sort.SliceStable(resources, func(i, j int) bool {
return sortResources(resources[i].ResourceID, resources[j].ResourceID)
})

for _, res := range resources {
if len(showFiles) > 0 && !lo.Contains(showFiles, res.FilePath()) {
Expand Down Expand Up @@ -727,31 +716,3 @@ func renderResource(unstruct *unstructured.Unstructured, path string, output io.

return nil
}

func sortResources(id1, id2 *resrcid.ResourceID) bool {
kind1 := id1.GroupVersionKind().Kind
kind2 := id2.GroupVersionKind().Kind
if kind1 != kind2 {
return kind1 < kind2
}

group1 := id1.GroupVersionKind().Group
group2 := id2.GroupVersionKind().Group
if group1 != group2 {
return group1 < group2
}

version1 := id1.GroupVersionKind().Version
version2 := id2.GroupVersionKind().Version
if version1 != version2 {
return version1 < version2
}

namespace1 := id1.Namespace()
namespace2 := id2.Namespace()
if namespace1 != namespace2 {
return namespace1 < namespace2
}

return id1.Name() < id2.Name()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ require (
github.com/werf/kubedog v0.12.4-0.20240329141850-9e5c458d11bb
github.com/werf/lockgate v0.1.1
github.com/werf/logboek v0.6.1
github.com/werf/nelm v0.0.0-20240424054659-3d5d8049b7d0
github.com/werf/nelm v0.0.0-20240520162550-9b66793c0b60
go.opentelemetry.io/otel v1.24.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1400,8 +1400,8 @@ github.com/werf/lockgate v0.1.1 h1:S400JFYjtWfE4i4LY9FA8zx0fMdfui9DPrBiTciCrx4=
github.com/werf/lockgate v0.1.1/go.mod h1:0yIFSLq9ausy6ejNxF5uUBf/Ib6daMAfXuCaTMZJzIE=
github.com/werf/logboek v0.6.1 h1:oEe6FkmlKg0z0n80oZjLplj6sXcBeLleCkjfOOZEL2g=
github.com/werf/logboek v0.6.1/go.mod h1:Gez5J4bxekyr6MxTmIJyId1F61rpO+0/V4vjCIEIZmk=
github.com/werf/nelm v0.0.0-20240424054659-3d5d8049b7d0 h1:4urlXMNqH3eD+Q9RDYPGpErtyiX9NGeThr32OtPuUvc=
github.com/werf/nelm v0.0.0-20240424054659-3d5d8049b7d0/go.mod h1:F+YVw4fjmuRImzDKacWxDZoC1G1enwpeSfvonAPgyLY=
github.com/werf/nelm v0.0.0-20240520162550-9b66793c0b60 h1:JVU0X4AtF7W7+B5TqRzSLrcKbTKdaGLO4qCsimBEqEI=
github.com/werf/nelm v0.0.0-20240520162550-9b66793c0b60/go.mod h1:F+YVw4fjmuRImzDKacWxDZoC1G1enwpeSfvonAPgyLY=
github.com/xanzy/go-gitlab v0.31.0/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug=
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
Expand Down

0 comments on commit 333ac86

Please sign in to comment.