mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
fix: performance recession when propagating namespace to helm (#5971)
* fix: performance recession when propagating namespace to helm * fix: handle passing namespace downstream more elegant * Revert "fix: handle passing namespace downstream more elegant" This reverts commit976a7cf2aa. * Revert "fix: performance recession when propagating namespace to helm" This reverts commitc7612d1dba. * fix: use annotation to identify helm chart generated resources * fix: deduplicate code * fix: missing import in NamespaceTransformer.go * ci: allow manual trigger of pipeline in fork * Revert "ci: allow manual trigger of pipeline in fork" This reverts commit8948788fe2. * fix: test cases * chore: fix code comment was on wrong line * chore: fix code comment was on wrong line pt2
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
"sigs.k8s.io/kustomize/api/resmap"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||
@@ -302,6 +303,9 @@ func (p *plugin) Generate() (rm resmap.ResMap, err error) {
|
||||
|
||||
rm, resMapErr := p.h.ResmapFactory().NewResMapFromBytes(stdout)
|
||||
if resMapErr == nil {
|
||||
if err := p.markHelmGeneratedResources(rm); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rm, nil
|
||||
}
|
||||
// try to remove the contents before first "---" because
|
||||
@@ -317,6 +321,9 @@ func (p *plugin) Generate() (rm resmap.ResMap, err error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not parse rnode slice into resource map: %w", err)
|
||||
}
|
||||
if err := p.markHelmGeneratedResources(rm); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rm, nil
|
||||
}
|
||||
return nil, fmt.Errorf("could not parse bytes into resource map: %w", resMapErr)
|
||||
@@ -359,6 +366,15 @@ func (p *plugin) chartExistsLocally() (string, bool) {
|
||||
return path, s.IsDir()
|
||||
}
|
||||
|
||||
func (p *plugin) markHelmGeneratedResources(rm resmap.ResMap) error {
|
||||
for _, r := range rm.Resources() {
|
||||
if err := r.RNode.PipeE(kyaml.SetAnnotation(konfig.HelmGeneratedAnnotation, "true")); err != nil {
|
||||
return fmt.Errorf("failed to set helm annotation: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkHelmVersion will return an error if the helm version is not V3
|
||||
func (p *plugin) checkHelmVersion() error {
|
||||
stdout, err := p.runHelmCommand([]string{"version", "-c", "--short"})
|
||||
|
||||
@@ -191,7 +191,6 @@ type: Opaque
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
annotations: {}
|
||||
labels:
|
||||
app: moria-minecraft
|
||||
chart: minecraft-3.1.3
|
||||
@@ -211,7 +210,6 @@ spec:
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
annotations: {}
|
||||
labels:
|
||||
app: moria-minecraft
|
||||
chart: minecraft-3.1.3
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filters/namespace"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
"sigs.k8s.io/kustomize/api/resmap"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||
@@ -56,11 +57,9 @@ func (p *plugin) Transform(m resmap.ResMap) error {
|
||||
// Don't mutate empty objects?
|
||||
continue
|
||||
}
|
||||
if origin, err := r.GetOrigin(); err == nil && origin != nil {
|
||||
if origin.ConfiguredBy.Kind == "HelmChartInflationGenerator" {
|
||||
// Don't apply namespace on Helm generated manifest. Helm should take care of it.
|
||||
continue
|
||||
}
|
||||
if annotations := r.GetAnnotations(konfig.HelmGeneratedAnnotation); annotations[konfig.HelmGeneratedAnnotation] == "true" {
|
||||
// Don't apply namespace on Helm generated manifest. Helm should take care of it.
|
||||
continue
|
||||
}
|
||||
r.StorePreviousId()
|
||||
if err := r.ApplyFilter(namespace.Filter{
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
"sigs.k8s.io/kustomize/api/provider"
|
||||
"sigs.k8s.io/kustomize/api/resmap"
|
||||
"sigs.k8s.io/kustomize/api/resource"
|
||||
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||
kyaml "sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
@@ -779,15 +779,12 @@ kind: Service
|
||||
metadata:
|
||||
name: svc
|
||||
namespace: helm-ns
|
||||
annotations:
|
||||
this-should-be-keept: "true"
|
||||
`))
|
||||
require.NoError(t, err)
|
||||
r := rm.Resources()[0]
|
||||
origin := &resource.Origin{
|
||||
ConfiguredBy: kyaml.ResourceIdentifier{
|
||||
TypeMeta: kyaml.TypeMeta{APIVersion: "builtin", Kind: "HelmChartInflationGenerator"},
|
||||
},
|
||||
}
|
||||
require.NoError(t, r.SetOrigin(origin))
|
||||
require.NoError(t, r.RNode.PipeE(kyaml.SetAnnotation(konfig.HelmGeneratedAnnotation, "true")))
|
||||
|
||||
rm, err = th.RunTransformerFromResMap(`
|
||||
apiVersion: builtin
|
||||
@@ -801,6 +798,8 @@ metadata:
|
||||
th.AssertActualEqualsExpectedNoIdAnnotations(rm, `apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
annotations:
|
||||
this-should-be-keept: "true"
|
||||
name: svc
|
||||
namespace: helm-ns
|
||||
`)
|
||||
|
||||
Reference in New Issue
Block a user