Skip to content

Commit

Permalink
fix(v2): dont save service annotations in release secret
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 Apr 22, 2024
1 parent 7a4daaf commit 27d6c4d
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 33 deletions.
42 changes: 29 additions & 13 deletions cmd/werf/bundle/apply/apply.go
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"regexp"
"sort"
"strings"
"time"

"github.com/google/uuid"
Expand Down Expand Up @@ -228,10 +229,6 @@ func runApply(ctx context.Context) error {
lockManager = m
}

if *commonCmdData.Environment != "" {
userExtraAnnotations["project.werf.io/env"] = *commonCmdData.Environment
}

secretsManager := secrets_manager.NewSecretsManager(secrets_manager.SecretsManagerOptions{DisableSecretsDecryption: *commonCmdData.IgnoreSecretKey})

bundle, err := chart_extender.NewBundle(ctx, bundleTmpDir, helm_v3.Settings, helmRegistryClient, secretsManager, chart_extender.BundleOptions{
Expand Down Expand Up @@ -283,8 +280,26 @@ func runApply(ctx context.Context) error {
saveDeployGraph := deployGraphPath != ""
saveRollbackGraphPath := rollbackGraphPath != ""
networkParallelism := common.GetNetworkParallelism(&commonCmdData)
extraAnnotations := bundle.ExtraAnnotationsAndLabelsPostRenderer.ExtraAnnotations
extraAnnotations["werf.io/version"] = werf.Version

serviceAnnotations := map[string]string{
"werf.io/version": werf.Version,
}

if *commonCmdData.Environment != "" {
serviceAnnotations["project.werf.io/env"] = *commonCmdData.Environment
}

var extraAnnotations map[string]string
for key, value := range bundle.ExtraAnnotationsAndLabelsPostRenderer.ExtraAnnotations {
if strings.HasPrefix(key, "project.werf.io/") ||
strings.Contains(key, "ci.werf.io/") ||
key == "werf.io/release-channel" {
serviceAnnotations[key] = value
} else {
extraAnnotations[key] = value
}
}

extraLabels := bundle.ExtraAnnotationsAndLabelsPostRenderer.ExtraLabels

clientFactory, err := kubeclnt.NewClientFactory()
Expand Down Expand Up @@ -400,13 +415,13 @@ func runApply(ctx context.Context) error {
resrcpatcher.NewExtraMetadataPatcher(extraAnnotations, extraLabels),
},
DeployableStandaloneCRDsPatchers: []resrcpatcher.ResourcePatcher{
resrcpatcher.NewExtraMetadataPatcher(extraAnnotations, extraLabels),
resrcpatcher.NewExtraMetadataPatcher(lo.Assign(extraAnnotations, serviceAnnotations), extraLabels),
},
DeployableHookResourcePatchers: []resrcpatcher.ResourcePatcher{
resrcpatcher.NewExtraMetadataPatcher(extraAnnotations, extraLabels),
resrcpatcher.NewExtraMetadataPatcher(lo.Assign(extraAnnotations, serviceAnnotations), extraLabels),
},
DeployableGeneralResourcePatchers: []resrcpatcher.ResourcePatcher{
resrcpatcher.NewExtraMetadataPatcher(extraAnnotations, extraLabels),
resrcpatcher.NewExtraMetadataPatcher(lo.Assign(extraAnnotations, serviceAnnotations), extraLabels),
},
},
)
Expand Down Expand Up @@ -623,6 +638,7 @@ func runApply(ctx context.Context) error {
history,
clientFactory,
extraAnnotations,
serviceAnnotations,
extraLabels,
trackReadinessTimeout,
trackReadinessTimeout,
Expand Down Expand Up @@ -743,7 +759,7 @@ func runRollbackPlan(
failedRevision int,
history *rlshistor.History,
clientFactory *kubeclnt.ClientFactory,
extraAnnotations, extraLabels map[string]string,
extraAnnotations, serviceAnnotations, extraLabels map[string]string,
trackReadinessTimeout, trackCreationTimeout, trackDeletionTimeout time.Duration,
saveRollbackGraph bool,
rollbackGraphPath string,
Expand Down Expand Up @@ -773,13 +789,13 @@ func runRollbackPlan(
resrcpatcher.NewExtraMetadataPatcher(extraAnnotations, extraLabels),
},
DeployableStandaloneCRDsPatchers: []resrcpatcher.ResourcePatcher{
resrcpatcher.NewExtraMetadataPatcher(extraAnnotations, extraLabels),
resrcpatcher.NewExtraMetadataPatcher(lo.Assign(extraAnnotations, serviceAnnotations), extraLabels),
},
DeployableHookResourcePatchers: []resrcpatcher.ResourcePatcher{
resrcpatcher.NewExtraMetadataPatcher(extraAnnotations, extraLabels),
resrcpatcher.NewExtraMetadataPatcher(lo.Assign(extraAnnotations, serviceAnnotations), extraLabels),
},
DeployableGeneralResourcePatchers: []resrcpatcher.ResourcePatcher{
resrcpatcher.NewExtraMetadataPatcher(extraAnnotations, extraLabels),
resrcpatcher.NewExtraMetadataPatcher(lo.Assign(extraAnnotations, serviceAnnotations), extraLabels),
},
},
)
Expand Down
34 changes: 23 additions & 11 deletions cmd/werf/converge/converge.go
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"regexp"
"sort"
"strings"
"time"

"github.com/gookit/color"
Expand Down Expand Up @@ -411,9 +412,25 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
return err
}

userExtraAnnotations, err := common.GetUserExtraAnnotations(&commonCmdData)
if err != nil {
serviceAnnotations := map[string]string{
"werf.io/version": werf.Version,
"project.werf.io/name": werfConfig.Meta.Project,
"project.werf.io/env": *commonCmdData.Environment,
}

var userExtraAnnotations map[string]string
if annos, err := common.GetUserExtraAnnotations(&commonCmdData); err != nil {
return err
} else {
for key, value := range annos {
if strings.HasPrefix(key, "project.werf.io/") ||
strings.Contains(key, "ci.werf.io/") ||
key == "werf.io/release-channel" {
serviceAnnotations[key] = value
} else {
userExtraAnnotations[key] = value
}
}
}

userExtraLabels, err := common.GetUserExtraLabels(&commonCmdData)
Expand Down Expand Up @@ -513,11 +530,6 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
saveDeployGraph := deployGraphPath != ""
saveRollbackGraphPath := rollbackGraphPath != ""
networkParallelism := common.GetNetworkParallelism(&commonCmdData)
serviceAnnotations := map[string]string{
"werf.io/version": werf.Version,
"project.werf.io/name": werfConfig.Meta.Project,
"project.werf.io/env": *commonCmdData.Environment,
}

clientFactory, err := kubeclnt.NewClientFactory()
if err != nil {
Expand Down Expand Up @@ -636,10 +648,10 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
resrcprocssr.DeployableResourcesProcessorOptions{
NetworkParallelism: networkParallelism,
ReleasableHookResourcePatchers: []resrcpatcher.ResourcePatcher{
resrcpatcher.NewExtraMetadataPatcher(lo.Assign(userExtraAnnotations, serviceAnnotations), userExtraLabels),
resrcpatcher.NewExtraMetadataPatcher(userExtraAnnotations, userExtraLabels),
},
ReleasableGeneralResourcePatchers: []resrcpatcher.ResourcePatcher{
resrcpatcher.NewExtraMetadataPatcher(lo.Assign(userExtraAnnotations, serviceAnnotations), userExtraLabels),
resrcpatcher.NewExtraMetadataPatcher(userExtraAnnotations, userExtraLabels),
},
DeployableStandaloneCRDsPatchers: []resrcpatcher.ResourcePatcher{
resrcpatcher.NewExtraMetadataPatcher(lo.Assign(userExtraAnnotations, serviceAnnotations), userExtraLabels),
Expand Down Expand Up @@ -1010,10 +1022,10 @@ func runRollbackPlan(
resrcprocssr.DeployableResourcesProcessorOptions{
NetworkParallelism: networkParallelism,
ReleasableHookResourcePatchers: []resrcpatcher.ResourcePatcher{
resrcpatcher.NewExtraMetadataPatcher(lo.Assign(userExtraAnnotations, serviceAnnotations), userExtraLabels),
resrcpatcher.NewExtraMetadataPatcher(userExtraAnnotations, userExtraLabels),
},
ReleasableGeneralResourcePatchers: []resrcpatcher.ResourcePatcher{
resrcpatcher.NewExtraMetadataPatcher(lo.Assign(userExtraAnnotations, serviceAnnotations), userExtraLabels),
resrcpatcher.NewExtraMetadataPatcher(userExtraAnnotations, userExtraLabels),
},
DeployableStandaloneCRDsPatchers: []resrcpatcher.ResourcePatcher{
resrcpatcher.NewExtraMetadataPatcher(lo.Assign(userExtraAnnotations, serviceAnnotations), userExtraLabels),
Expand Down
30 changes: 21 additions & 9 deletions cmd/werf/plan/plan.go
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"path/filepath"
"strings"
"time"

"github.com/gookit/color"
Expand Down Expand Up @@ -394,9 +395,25 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
return err
}

userExtraAnnotations, err := common.GetUserExtraAnnotations(&commonCmdData)
if err != nil {
serviceAnnotations := map[string]string{
"werf.io/version": werf.Version,
"project.werf.io/name": werfConfig.Meta.Project,
"project.werf.io/env": *commonCmdData.Environment,
}

var userExtraAnnotations map[string]string
if annos, err := common.GetUserExtraAnnotations(&commonCmdData); err != nil {
return err
} else {
for key, value := range annos {
if strings.HasPrefix(key, "project.werf.io/") ||
strings.Contains(key, "ci.werf.io/") ||
key == "werf.io/release-channel" {
serviceAnnotations[key] = value
} else {
userExtraAnnotations[key] = value
}
}
}

userExtraLabels, err := common.GetUserExtraLabels(&commonCmdData)
Expand Down Expand Up @@ -480,11 +497,6 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken

if true {
networkParallelism := common.GetNetworkParallelism(&commonCmdData)
serviceAnnotations := map[string]string{
"werf.io/version": werf.Version,
"project.werf.io/name": werfConfig.Meta.Project,
"project.werf.io/env": *commonCmdData.Environment,
}

clientFactory, err := kubeclnt.NewClientFactory()
if err != nil {
Expand Down Expand Up @@ -593,10 +605,10 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
resrcprocssr.DeployableResourcesProcessorOptions{
NetworkParallelism: networkParallelism,
ReleasableHookResourcePatchers: []resrcpatcher.ResourcePatcher{
resrcpatcher.NewExtraMetadataPatcher(lo.Assign(userExtraAnnotations, serviceAnnotations), userExtraLabels),
resrcpatcher.NewExtraMetadataPatcher(userExtraAnnotations, userExtraLabels),
},
ReleasableGeneralResourcePatchers: []resrcpatcher.ResourcePatcher{
resrcpatcher.NewExtraMetadataPatcher(lo.Assign(userExtraAnnotations, serviceAnnotations), userExtraLabels),
resrcpatcher.NewExtraMetadataPatcher(userExtraAnnotations, userExtraLabels),
},
DeployableStandaloneCRDsPatchers: []resrcpatcher.ResourcePatcher{
resrcpatcher.NewExtraMetadataPatcher(lo.Assign(userExtraAnnotations, serviceAnnotations), userExtraLabels),
Expand Down

0 comments on commit 27d6c4d

Please sign in to comment.