Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit b9c06fd

Browse files
authored
Merge pull request #1112 from Random-Liu/cherrypick-#1102-release-1.0
Cherrypick #1102 release 1.0
2 parents 15a3862 + c29999c commit b9c06fd

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

integration/pod_hostname_test.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func TestPodHostname(t *testing.T) {
3434
for name, test := range map[string]struct {
3535
opts []PodSandboxOpts
3636
expectedHostname string
37+
expectErr bool
3738
}{
3839
"regular pod with custom hostname": {
3940
opts: []PodSandboxOpts{
@@ -47,12 +48,12 @@ func TestPodHostname(t *testing.T) {
4748
},
4849
expectedHostname: hostname,
4950
},
50-
"host network pod with custom hostname": {
51+
"host network pod with custom hostname should fail": {
5152
opts: []PodSandboxOpts{
5253
WithHostNetwork,
5354
WithPodHostname("test-hostname"),
5455
},
55-
expectedHostname: "test-hostname",
56+
expectErr: true,
5657
},
5758
} {
5859
t.Run(name, func(t *testing.T) {
@@ -64,11 +65,21 @@ func TestPodHostname(t *testing.T) {
6465
t.Log("Create a sandbox with hostname")
6566
sbConfig := PodSandboxConfig("sandbox", "hostname", opts...)
6667
sb, err := runtimeService.RunPodSandbox(sbConfig)
67-
require.NoError(t, err)
68-
defer func() {
69-
assert.NoError(t, runtimeService.StopPodSandbox(sb))
70-
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
71-
}()
68+
if err != nil {
69+
if !test.expectErr {
70+
t.Fatalf("Unexpected RunPodSandbox error: %v", err)
71+
}
72+
return
73+
} else {
74+
// Make sure the sandbox is cleaned up.
75+
defer func() {
76+
assert.NoError(t, runtimeService.StopPodSandbox(sb))
77+
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
78+
}()
79+
if test.expectErr {
80+
t.Fatalf("Expected RunPodSandbox to return error")
81+
}
82+
}
7283

7384
const (
7485
testImage = "busybox"

pkg/server/sandbox_run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ func (c *criService) generateSandboxContainerSpec(id string, config *runtime.Pod
384384
nsOptions := securityContext.GetNamespaceOptions()
385385
if nsOptions.GetNetwork() == runtime.NamespaceMode_NODE {
386386
g.RemoveLinuxNamespace(string(runtimespec.NetworkNamespace)) // nolint: errcheck
387+
g.RemoveLinuxNamespace(string(runtimespec.UTSNamespace)) // nolint: errcheck
387388
} else {
388389
//TODO(Abhi): May be move this to containerd spec opts (WithLinuxSpaceOption)
389390
g.AddOrReplaceLinuxNamespace(string(runtimespec.NetworkNamespace), nsPath) // nolint: errcheck

pkg/server/sandbox_run_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ func TestGenerateSandboxContainerSpec(t *testing.T) {
9595
Type: runtimespec.NetworkNamespace,
9696
Path: nsPath,
9797
})
98+
assert.Contains(t, spec.Linux.Namespaces, runtimespec.LinuxNamespace{
99+
Type: runtimespec.UTSNamespace,
100+
})
98101
assert.Contains(t, spec.Linux.Namespaces, runtimespec.LinuxNamespace{
99102
Type: runtimespec.PIDNamespace,
100103
})
@@ -119,6 +122,9 @@ func TestGenerateSandboxContainerSpec(t *testing.T) {
119122
assert.NotContains(t, spec.Linux.Namespaces, runtimespec.LinuxNamespace{
120123
Type: runtimespec.NetworkNamespace,
121124
})
125+
assert.NotContains(t, spec.Linux.Namespaces, runtimespec.LinuxNamespace{
126+
Type: runtimespec.UTSNamespace,
127+
})
122128
assert.NotContains(t, spec.Linux.Namespaces, runtimespec.LinuxNamespace{
123129
Type: runtimespec.PIDNamespace,
124130
})

0 commit comments

Comments
 (0)