Merge pull request #5510 from andreaskaris/kustomize-env-var-max-length

Skip KUSTOMIZE_PLUGIN_CONFIG_* env variables when too large
This commit is contained in:
Kubernetes Prow Robot
2024-02-21 09:35:01 -08:00
committed by GitHub
2 changed files with 123 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ import (
"strings"
"github.com/google/shlex"
"k8s.io/klog"
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
"sigs.k8s.io/kustomize/api/resmap"
@@ -21,6 +22,7 @@ import (
const (
tmpConfigFilePrefix = "kust-plugin-config-"
maxArgStringLength = 131071
)
// ExecPlugin record the name and args of an executable
@@ -185,8 +187,19 @@ func (p *ExecPlugin) invokePlugin(input []byte) ([]byte, error) {
func (p *ExecPlugin) getEnv() []string {
env := os.Environ()
env = append(env,
"KUSTOMIZE_PLUGIN_CONFIG_STRING="+string(p.cfg),
"KUSTOMIZE_PLUGIN_CONFIG_ROOT="+p.h.Loader().Root())
pluginConfigString := "KUSTOMIZE_PLUGIN_CONFIG_STRING=" + string(p.cfg)
if len(pluginConfigString) <= maxArgStringLength {
env = append(env, pluginConfigString)
} else {
klog.Warningf("KUSTOMIZE_PLUGIN_CONFIG_STRING exceeds hard limit of %d characters, the environment variable "+
"will be omitted", maxArgStringLength)
}
pluginConfigRoot := "KUSTOMIZE_PLUGIN_CONFIG_ROOT=" + p.h.Loader().Root()
if len(pluginConfigRoot) <= maxArgStringLength {
env = append(env, pluginConfigRoot)
} else {
klog.Warningf("KUSTOMIZE_PLUGIN_CONFIG_ROOT exceeds hard limit of %d characters, the environment variable "+
"will be omitted", maxArgStringLength)
}
return env
}