mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
Implement to set a domainname
opencontainers/runtime-spec#1156 Signed-off-by: utam0k <k0ma@utam0k.jp>
This commit is contained in:
@@ -23,7 +23,7 @@ func Validate(config *configs.Config) error {
|
||||
cgroupsCheck,
|
||||
rootfs,
|
||||
network,
|
||||
hostname,
|
||||
uts,
|
||||
security,
|
||||
namespaces,
|
||||
sysctl,
|
||||
@@ -75,10 +75,13 @@ func network(config *configs.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func hostname(config *configs.Config) error {
|
||||
func uts(config *configs.Config) error {
|
||||
if config.Hostname != "" && !config.Namespaces.Contains(configs.NEWUTS) {
|
||||
return errors.New("unable to set hostname without a private UTS namespace")
|
||||
}
|
||||
if config.Domainname != "" && !config.Namespaces.Contains(configs.NEWUTS) {
|
||||
return errors.New("unable to set domainname without a private UTS namespace")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,25 @@ func TestValidateHostname(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateHostnameWithoutUTSNamespace(t *testing.T) {
|
||||
func TestValidateUTS(t *testing.T) {
|
||||
config := &configs.Config{
|
||||
Rootfs: "/var",
|
||||
Domainname: "runc",
|
||||
Hostname: "runc",
|
||||
Namespaces: configs.Namespaces(
|
||||
[]configs.Namespace{
|
||||
{Type: configs.NEWUTS},
|
||||
},
|
||||
),
|
||||
}
|
||||
|
||||
err := Validate(config)
|
||||
if err != nil {
|
||||
t.Errorf("Expected error to not occur: %+v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateUTSWithoutUTSNamespace(t *testing.T) {
|
||||
config := &configs.Config{
|
||||
Rootfs: "/var",
|
||||
Hostname: "runc",
|
||||
@@ -92,6 +110,16 @@ func TestValidateHostnameWithoutUTSNamespace(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Error("Expected error to occur but it was nil")
|
||||
}
|
||||
|
||||
config = &configs.Config{
|
||||
Rootfs: "/var",
|
||||
Domainname: "runc",
|
||||
}
|
||||
|
||||
err = Validate(config)
|
||||
if err == nil {
|
||||
t.Error("Expected error to occur but it was nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateSecurityWithMaskPaths(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user