Include default envs from containerd.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
parent
ec6dd37691
commit
877c1cadc1
@ -406,10 +406,17 @@ type generator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newCustomGenerator(g generate.Generator) generator {
|
func newCustomGenerator(g generate.Generator) generator {
|
||||||
return generator{
|
cg := generator{
|
||||||
Generator: g,
|
Generator: g,
|
||||||
envCache: make(map[string]int),
|
envCache: make(map[string]int),
|
||||||
}
|
}
|
||||||
|
if g.Config != nil && g.Config.Process != nil {
|
||||||
|
for i, env := range g.Config.Process.Env {
|
||||||
|
kv := strings.SplitN(env, "=", 2)
|
||||||
|
cg.envCache[kv[0]] = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cg
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddProcessEnv overrides the original AddProcessEnv. It uses
|
// AddProcessEnv overrides the original AddProcessEnv. It uses
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
runcoptions "github.com/containerd/containerd/runtime/v2/runc/options"
|
runcoptions "github.com/containerd/containerd/runtime/v2/runc/options"
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
imagedigest "github.com/opencontainers/go-digest"
|
imagedigest "github.com/opencontainers/go-digest"
|
||||||
|
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
|
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
|
||||||
@ -324,6 +325,7 @@ func TestRestrictOOMScoreAdj(t *testing.T) {
|
|||||||
|
|
||||||
func TestCustomGenerator(t *testing.T) {
|
func TestCustomGenerator(t *testing.T) {
|
||||||
for desc, test := range map[string]struct {
|
for desc, test := range map[string]struct {
|
||||||
|
existing []string
|
||||||
kv [][2]string
|
kv [][2]string
|
||||||
expected []string
|
expected []string
|
||||||
expectNil bool
|
expectNil bool
|
||||||
@ -356,16 +358,44 @@ func TestCustomGenerator(t *testing.T) {
|
|||||||
{"k3", "v3"},
|
{"k3", "v3"},
|
||||||
{"k3", "v4"},
|
{"k3", "v4"},
|
||||||
{"k1", "v5"},
|
{"k1", "v5"},
|
||||||
|
{"k4", "v6"},
|
||||||
},
|
},
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"k1=v5",
|
"k1=v5",
|
||||||
"k2=v2",
|
"k2=v2",
|
||||||
"k3=v4",
|
"k3=v4",
|
||||||
|
"k4=v6",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"existing env": {
|
||||||
|
existing: []string{
|
||||||
|
"k1=v1",
|
||||||
|
"k2=v2",
|
||||||
|
"k3=v3",
|
||||||
|
},
|
||||||
|
kv: [][2]string{
|
||||||
|
{"k3", "v4"},
|
||||||
|
{"k2", "v5"},
|
||||||
|
{"k4", "v6"},
|
||||||
|
},
|
||||||
|
expected: []string{
|
||||||
|
"k1=v1",
|
||||||
|
"k2=v5",
|
||||||
|
"k3=v4",
|
||||||
|
"k4=v6",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Logf("TestCase %q", desc)
|
t.Logf("TestCase %q", desc)
|
||||||
g := newSpecGenerator(nil)
|
var spec *runtimespec.Spec
|
||||||
|
if len(test.existing) > 0 {
|
||||||
|
spec = &runtimespec.Spec{
|
||||||
|
Process: &runtimespec.Process{
|
||||||
|
Env: test.existing,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g := newSpecGenerator(spec)
|
||||||
for _, kv := range test.kv {
|
for _, kv := range test.kv {
|
||||||
g.AddProcessEnv(kv[0], kv[1])
|
g.AddProcessEnv(kv[0], kv[1])
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user