Implement to set a domainname

opencontainers/runtime-spec#1156

Signed-off-by: utam0k <k0ma@utam0k.jp>
This commit is contained in:
utam0k
2022-10-04 20:45:50 +09:00
parent 11983894a8
commit d9230602e9
7 changed files with 65 additions and 5 deletions
+5 -2
View File
@@ -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) {