Cleanup pod annotation test and only support tailing wildcard.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
@@ -86,8 +86,8 @@ func TestGenerateSandboxContainerSpec(t *testing.T) {
|
||||
testID := "test-id"
|
||||
nsPath := "test-cni"
|
||||
for desc, test := range map[string]struct {
|
||||
configCriService func(*criService)
|
||||
configChange func(*runtime.PodSandboxConfig)
|
||||
podAnnotations []string
|
||||
imageConfigChange func(*imagespec.ImageConfig)
|
||||
specCheck func(*testing.T, *runtimespec.Spec)
|
||||
expectErr bool
|
||||
@@ -158,54 +158,40 @@ func TestGenerateSandboxContainerSpec(t *testing.T) {
|
||||
assert.Contains(t, spec.Process.User.AdditionalGids, uint32(2222))
|
||||
},
|
||||
},
|
||||
// Scenario 1 - containerd config allows "c" and podSpec defines "c" to be passed to OCI
|
||||
"passthroughAnnotations scenario 1": {
|
||||
configCriService: func(c *criService) {
|
||||
c.config.Runtimes = make(map[string]criconfig.Runtime)
|
||||
c.config.Runtimes["runc"] = criconfig.Runtime{
|
||||
PodAnnotations: []string{"c"},
|
||||
}
|
||||
}, //assert.Equal(t, passthroughAnnotations["c"], "d")
|
||||
"a passthrough annotation should be passed as an OCI annotation": {
|
||||
podAnnotations: []string{"c"},
|
||||
specCheck: func(t *testing.T, spec *runtimespec.Spec) {
|
||||
assert.Equal(t, spec.Annotations["c"], "d")
|
||||
},
|
||||
},
|
||||
// Scenario 2 - containerd config allows only "c" but podSpec defines "c" and "d"
|
||||
// Only annotation "c" will be injected in OCI annotations and "d" should be dropped.
|
||||
"passthroughAnnotations scenario 2": {
|
||||
"a non-passthrough annotation should not be passed as an OCI annotation": {
|
||||
configChange: func(c *runtime.PodSandboxConfig) {
|
||||
c.Annotations["d"] = "e"
|
||||
},
|
||||
configCriService: func(c *criService) {
|
||||
c.config.Runtimes = make(map[string]criconfig.Runtime)
|
||||
c.config.Runtimes["runc"] = criconfig.Runtime{
|
||||
PodAnnotations: []string{"c"},
|
||||
}
|
||||
},
|
||||
podAnnotations: []string{"c"},
|
||||
specCheck: func(t *testing.T, spec *runtimespec.Spec) {
|
||||
assert.Equal(t, spec.Annotations["c"], "d")
|
||||
_, ok := spec.Annotations["d"]
|
||||
assert.Equal(t, ok, false)
|
||||
assert.False(t, ok)
|
||||
},
|
||||
},
|
||||
// Scenario 3 - Let's test some wildcard support
|
||||
// podSpec has following annotations
|
||||
"passthroughAnnotations scenario 3": {
|
||||
"passthrough annotations should support wildcard match": {
|
||||
configChange: func(c *runtime.PodSandboxConfig) {
|
||||
c.Annotations["t.f"] = "j"
|
||||
c.Annotations["z.g"] = "o"
|
||||
c.Annotations["z"] = "o"
|
||||
c.Annotations["y.ca"] = "b"
|
||||
c.Annotations["y"] = "b"
|
||||
},
|
||||
configCriService: func(c *criService) {
|
||||
c.config.Runtimes = make(map[string]criconfig.Runtime)
|
||||
c.config.Runtimes["runc"] = criconfig.Runtime{
|
||||
PodAnnotations: []string{"t*", "z.*", "y.c*"},
|
||||
}
|
||||
},
|
||||
podAnnotations: []string{"t*", "z.*", "y.c*"},
|
||||
specCheck: func(t *testing.T, spec *runtimespec.Spec) {
|
||||
assert.Equal(t, spec.Annotations["t.f"], "j")
|
||||
assert.Equal(t, spec.Annotations["z.g"], "o")
|
||||
assert.Equal(t, spec.Annotations["y.ca"], "b")
|
||||
_, ok := spec.Annotations["y"]
|
||||
assert.False(t, ok)
|
||||
_, ok = spec.Annotations["z"]
|
||||
assert.False(t, ok)
|
||||
},
|
||||
},
|
||||
} {
|
||||
@@ -216,15 +202,11 @@ func TestGenerateSandboxContainerSpec(t *testing.T) {
|
||||
test.configChange(config)
|
||||
}
|
||||
|
||||
if test.configCriService != nil {
|
||||
test.configCriService(c)
|
||||
}
|
||||
|
||||
if test.imageConfigChange != nil {
|
||||
test.imageConfigChange(imageConfig)
|
||||
}
|
||||
spec, err := c.generateSandboxContainerSpec(testID, config, imageConfig, nsPath,
|
||||
c.config.Runtimes["runc"].PodAnnotations)
|
||||
test.podAnnotations)
|
||||
if test.expectErr {
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, spec)
|
||||
@@ -412,7 +394,6 @@ options timeout:1
|
||||
c.os.(*ostesting.FakeOS).HostnameFn = func() (string, error) {
|
||||
return realhostname, nil
|
||||
}
|
||||
|
||||
cfg := &runtime.PodSandboxConfig{
|
||||
Hostname: test.hostname,
|
||||
DnsConfig: test.dnsConfig,
|
||||
|
||||
Reference in New Issue
Block a user