Merge pull request #976 from hangyan/hostname-domain-support

Support hostname and domainname
This commit is contained in:
Tomas Kral 2018-04-11 15:58:18 +02:00 committed by GitHub
commit 25f8ba42f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 271 additions and 8 deletions

View File

@ -40,6 +40,7 @@ __Glossary:__
| depends_on | x | x | x | | | | depends_on | x | x | x | | |
| dns | x | x | x | | Not used within Kubernetes. Kubernetes uses a managed DNS server | | dns | x | x | x | | Not used within Kubernetes. Kubernetes uses a managed DNS server |
| dns_search | x | x | x | | See `dns` key | | dns_search | x | x | x | | See `dns` key |
| dommainname | ✓ | ✓ | ✓ | Pod.Spec.SubDomain |
| tmpfs | ✓ | ✓ | ✓ | Pod.Spec.Containers.Volumes.EmptyDir | Creates emptyDirvolume with medium set to Memory & mounts given directory inside container | | tmpfs | ✓ | ✓ | ✓ | Pod.Spec.Containers.Volumes.EmptyDir | Creates emptyDirvolume with medium set to Memory & mounts given directory inside container |
| entrypoint | ✓ | ✓ | ✓ | Pod.Spec.Container.Command | Same as command | | entrypoint | ✓ | ✓ | ✓ | Pod.Spec.Container.Command | Same as command |
| env_file | n | n | ✓ | | | | env_file | n | n | ✓ | | |
@ -50,6 +51,7 @@ __Glossary:__
| extra_hosts | n | n | n | | | | extra_hosts | n | n | n | | |
| group_add | ✓ | ✓ | ✓ | | | | group_add | ✓ | ✓ | ✓ | | |
| healthcheck | - | n | ✓ | | | | healthcheck | - | n | ✓ | | |
| hostname | ✓ | ✓ | ✓ | Pod.Spec.HostName | |
| image | ✓ | ✓ | ✓ | Deployment.Spec.Containers.Image | | | image | ✓ | ✓ | ✓ | Deployment.Spec.Containers.Image | |
| isolation | x | x | x | | Not applicable as this applies to Windows with HyperV support | | isolation | x | x | x | | Not applicable as this applies to Windows with HyperV support |
| labels | ✓ | ✓ | ✓ | Metadata.Annotations | | | labels | ✓ | ✓ | ✓ | Metadata.Annotations | |

View File

@ -69,6 +69,8 @@ type ServiceConfig struct {
Port []Ports `compose:"ports"` Port []Ports `compose:"ports"`
Command []string `compose:"command"` Command []string `compose:"command"`
WorkingDir string `compose:""` WorkingDir string `compose:""`
DomainName string `compose:"domainname"`
HostName string `compose:"hostname"`
Args []string `compose:"args"` Args []string `compose:"args"`
VolList []string `compose:"volumes"` VolList []string `compose:"volumes"`
Network []string `compose:"network"` Network []string `compose:"network"`

View File

@ -53,11 +53,9 @@ func checkUnsupportedKey(composeProject *project.Project) []string {
"DependsOn": false, "DependsOn": false,
"DNS": false, "DNS": false,
"DNSSearch": false, "DNSSearch": false,
"DomainName": false,
"EnvFile": false, "EnvFile": false,
"ExternalLinks": false, "ExternalLinks": false,
"ExtraHosts": false, "ExtraHosts": false,
"Hostname": false,
"Ipc": false, "Ipc": false,
"Logging": false, "Logging": false,
"MacAddress": false, "MacAddress": false,

View File

@ -318,7 +318,7 @@ func TestUnsupportedKeys(t *testing.T) {
}{ }{
"With Networks (service and root level)": { "With Networks (service and root level)": {
projectWithNetworks, projectWithNetworks,
[]string{"root level networks", "root level volumes", "hostname", "networks"}, []string{"root level networks", "root level volumes", "networks"},
}, },
"Empty Networks on Service level": { "Empty Networks on Service level": {
projectWithEmptyNetwork, projectWithEmptyNetwork,

View File

@ -199,6 +199,8 @@ func libComposeToKomposeMapping(composeObject *project.Project) (kobject.Kompose
log.Infof("Container name in service %q has been changed from %q to %q", name, composeServiceConfig.ContainerName, newName) log.Infof("Container name in service %q has been changed from %q to %q", name, composeServiceConfig.ContainerName, newName)
} }
serviceConfig.Command = composeServiceConfig.Entrypoint serviceConfig.Command = composeServiceConfig.Entrypoint
serviceConfig.HostName = composeServiceConfig.Hostname
serviceConfig.DomainName = composeServiceConfig.DomainName
serviceConfig.Args = composeServiceConfig.Command serviceConfig.Args = composeServiceConfig.Command
serviceConfig.Dockerfile = composeServiceConfig.Build.Dockerfile serviceConfig.Dockerfile = composeServiceConfig.Build.Dockerfile
serviceConfig.BuildArgs = composeServiceConfig.Build.Args serviceConfig.BuildArgs = composeServiceConfig.Build.Args

View File

@ -241,6 +241,8 @@ func dockerComposeToKomposeMapping(composeObject *types.Config) (kobject.Kompose
serviceConfig.Command = composeServiceConfig.Entrypoint serviceConfig.Command = composeServiceConfig.Entrypoint
serviceConfig.Args = composeServiceConfig.Command serviceConfig.Args = composeServiceConfig.Command
serviceConfig.Labels = composeServiceConfig.Labels serviceConfig.Labels = composeServiceConfig.Labels
serviceConfig.HostName = composeServiceConfig.Hostname
serviceConfig.DomainName = composeServiceConfig.DomainName
// //
// Deploy keys // Deploy keys

View File

@ -514,6 +514,15 @@ func (k *Kubernetes) UpdateKubernetesObjects(name string, service kobject.Servic
default: default:
return errors.New("Unknown restart policy " + service.Restart + " for service " + name) return errors.New("Unknown restart policy " + service.Restart + " for service " + name)
} }
// Configure hostname/domain_name settings
if service.HostName != "" {
template.Spec.Hostname = service.HostName
}
if service.DomainName != "" {
template.Spec.Subdomain = service.DomainName
}
return nil return nil
} }

View File

@ -261,6 +261,30 @@ cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compos
sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-os-restart-unless-stopped.json" > /tmp/output-os.json sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-os-restart-unless-stopped.json" > /tmp/output-os.json
convert::expect_success_and_warning "$cmd" /tmp/output-os.json convert::expect_success_and_warning "$cmd" /tmp/output-os.json
#####
# Test related to hostname/domainname in docker-compose
# kubernetes test
cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/domain/docker-compose.yaml convert --stdout -j"
sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" "$KOMPOSE_ROOT/script/test/fixtures/domain/output-k8s.json" > /tmp/output-k8s.json
convert::expect_success "$cmd" /tmp/output-k8s.json
cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/domain/docker-compose-v3.yaml convert --stdout -j"
sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" "$KOMPOSE_ROOT/script/test/fixtures/domain/output-k8s.json" > /tmp/output-k8s.json
convert::expect_success "$cmd" /tmp/output-k8s.json
# openshift test
cmd="kompose --provider openshift -f $KOMPOSE_ROOT/script/test/fixtures/domain/docker-compose.yaml convert --stdout -j"
sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" "$KOMPOSE_ROOT/script/test/fixtures/domain/output-os.json" > /tmp/output-os.json
convert::expect_success "$cmd" /tmp/output-os.json
cmd="kompose --provider openshift -f $KOMPOSE_ROOT/script/test/fixtures/domain/docker-compose-v3.yaml convert --stdout -j"
sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" "$KOMPOSE_ROOT/script/test/fixtures/domain/output-os.json" > /tmp/output-os.json
convert::expect_success "$cmd" /tmp/output-os.json
###### ######
# Test key-only environment variable # Test key-only environment variable
export $(cat $KOMPOSE_ROOT/script/test/fixtures/keyonly-envs/envs) export $(cat $KOMPOSE_ROOT/script/test/fixtures/keyonly-envs/envs)
@ -448,9 +472,9 @@ sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/f
convert::expect_success_and_warning "$cmd" "/tmp/output-k8s.json" "Volume mount on the host "\"."\" isn't supported - ignoring path on the host" convert::expect_success_and_warning "$cmd" "/tmp/output-k8s.json" "Volume mount on the host "\"."\" isn't supported - ignoring path on the host"
#Failing test for `--volumes` option #Failing test for `--volumes` option
convert::expect_failure "kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/docker-compose.yaml --volumes foobar" convert::expect_failure "kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/docker-compose.yml --volumes foobar"
# Test related to support docker-compose.yaml beside docker-compose.yml # Test related to support docker-compose.yml beside docker-compose.yml
# Store the original path # Store the original path
CURRENT_DIR=$(pwd) CURRENT_DIR=$(pwd)
# Kubernets test # Kubernets test
@ -543,7 +567,7 @@ convert::expect_success "$cmd" "/tmp/output-k8s.json"
# Test that two files that are different versions fail # Test that two files that are different versions fail
convert::expect_failure "kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/v3/docker-compose.yaml -f $KOMPOSE_ROOT/script/test/fixtures/etherpad/docker-compose.yml" convert::expect_failure "kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/v3/docker-compose.yaml -f $KOMPOSE_ROOT/script/test/fixtures/etherpad/docker-compose.yaml"
# Kubernetes # Kubernetes
cmd="kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/v3/docker-compose.yaml" cmd="kompose convert --stdout -j -f $KOMPOSE_ROOT/script/test/fixtures/v3/docker-compose.yaml"

View File

@ -0,0 +1,6 @@
version: '3'
services:
dns:
image: phensley/docker-dns
hostname: affy
domainname: affy.com

View File

@ -0,0 +1,6 @@
version: 2
services:
dns:
image: phensley/docker-dns
hostname: affy
domainname: affy.com

View File

@ -0,0 +1,78 @@
{
"kind": "List",
"apiVersion": "v1",
"metadata": {},
"items": [
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "dns",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "dns"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
"ports": [
{
"name": "headless",
"port": 55555,
"targetPort": 0
}
],
"selector": {
"io.kompose.service": "dns"
},
"clusterIP": "None"
},
"status": {
"loadBalancer": {}
}
},
{
"kind": "Deployment",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "dns",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "dns"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
"replicas": 1,
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "dns"
}
},
"spec": {
"containers": [
{
"name": "dns",
"image": "phensley/docker-dns",
"resources": {}
}
],
"restartPolicy": "Always",
"hostname": "affy",
"subdomain": "affy.com"
}
},
"strategy": {}
},
"status": {}
}
]
}

View File

@ -0,0 +1,130 @@
{
"kind": "List",
"apiVersion": "v1",
"metadata": {},
"items": [
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "dns",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "dns"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
"ports": [
{
"name": "headless",
"port": 55555,
"targetPort": 0
}
],
"selector": {
"io.kompose.service": "dns"
},
"clusterIP": "None"
},
"status": {
"loadBalancer": {}
}
},
{
"kind": "DeploymentConfig",
"apiVersion": "v1",
"metadata": {
"name": "dns",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "dns"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
"strategy": {
"resources": {}
},
"triggers": [
{
"type": "ConfigChange"
},
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"dns"
],
"from": {
"kind": "ImageStreamTag",
"name": "dns:latest"
}
}
}
],
"replicas": 1,
"test": false,
"selector": {
"io.kompose.service": "dns"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "dns"
}
},
"spec": {
"containers": [
{
"name": "dns",
"image": " ",
"resources": {}
}
],
"restartPolicy": "Always",
"hostname": "affy",
"subdomain": "affy.com"
}
}
},
"status": {}
},
{
"kind": "ImageStream",
"apiVersion": "v1",
"metadata": {
"name": "dns",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "dns"
}
},
"spec": {
"tags": [
{
"name": "latest",
"annotations": null,
"from": {
"kind": "DockerImage",
"name": "phensley/docker-dns"
},
"generation": null,
"importPolicy": {}
}
]
},
"status": {
"dockerImageRepository": ""
}
}
]
}

View File

@ -223,7 +223,9 @@
"tty": true "tty": true
} }
], ],
"restartPolicy": "OnFailure" "restartPolicy": "OnFailure",
"hostname": "foo",
"subdomain": "foo.com"
}, },
"status": {} "status": {}
}, },

View File

@ -223,7 +223,9 @@
"tty": true "tty": true
} }
], ],
"restartPolicy": "OnFailure" "restartPolicy": "OnFailure",
"hostname": "foo",
"subdomain": "foo.com"
}, },
"status": {} "status": {}
}, },