mirror of
https://github.com/docker/compose.git
synced 2025-07-21 12:44:54 +02:00
Revert "Prefix kube resource with compose project name to avoid name clashes between projects. "
This reverts commit 6b61902a23763fd51d6a5e864cc568b33058b06e. Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
This commit is contained in:
parent
caec924532
commit
211a1d5d2d
@ -45,7 +45,7 @@ func MapToKubernetesObjects(project *types.Project) (map[string]runtime.Object,
|
|||||||
for _, service := range project.Services {
|
for _, service := range project.Services {
|
||||||
svcObject := mapToService(project, service)
|
svcObject := mapToService(project, service)
|
||||||
if svcObject != nil {
|
if svcObject != nil {
|
||||||
objects[fmt.Sprintf("%s-service.yaml", getProjectServiceName(project, service))] = svcObject
|
objects[fmt.Sprintf("%s-service.yaml", service.Name)] = svcObject
|
||||||
} else {
|
} else {
|
||||||
log.Println("Missing port mapping from service config.")
|
log.Println("Missing port mapping from service config.")
|
||||||
}
|
}
|
||||||
@ -55,13 +55,13 @@ func MapToKubernetesObjects(project *types.Project) (map[string]runtime.Object,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
objects[fmt.Sprintf("%s-daemonset.yaml", getProjectServiceName(project, service))] = daemonset
|
objects[fmt.Sprintf("%s-daemonset.yaml", service.Name)] = daemonset
|
||||||
} else {
|
} else {
|
||||||
deployment, err := mapToDeployment(project, service)
|
deployment, err := mapToDeployment(project, service)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
objects[fmt.Sprintf("%s-deployment.yaml", getProjectServiceName(project, service))] = deployment
|
objects[fmt.Sprintf("%s-deployment.yaml", service.Name)] = deployment
|
||||||
}
|
}
|
||||||
for _, vol := range service.Volumes {
|
for _, vol := range service.Volumes {
|
||||||
if vol.Type == "volume" {
|
if vol.Type == "volume" {
|
||||||
@ -98,7 +98,7 @@ func mapToService(project *types.Project, service types.ServiceConfig) *core.Ser
|
|||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
},
|
},
|
||||||
ObjectMeta: meta.ObjectMeta{
|
ObjectMeta: meta.ObjectMeta{
|
||||||
Name: getProjectServiceName(project, service),
|
Name: service.Name,
|
||||||
},
|
},
|
||||||
Spec: core.ServiceSpec{
|
Spec: core.ServiceSpec{
|
||||||
ClusterIP: clusterIP,
|
ClusterIP: clusterIP,
|
||||||
@ -126,7 +126,7 @@ func mapToDeployment(project *types.Project, service types.ServiceConfig) (*apps
|
|||||||
APIVersion: "apps/v1",
|
APIVersion: "apps/v1",
|
||||||
},
|
},
|
||||||
ObjectMeta: meta.ObjectMeta{
|
ObjectMeta: meta.ObjectMeta{
|
||||||
Name: getProjectServiceName(project, service),
|
Name: service.Name,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
},
|
},
|
||||||
Spec: apps.DeploymentSpec{
|
Spec: apps.DeploymentSpec{
|
||||||
@ -138,10 +138,6 @@ func mapToDeployment(project *types.Project, service types.ServiceConfig) (*apps
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getProjectServiceName(project *types.Project, service types.ServiceConfig) string {
|
|
||||||
return fmt.Sprintf("%s-%s", project.Name, service.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func selectorLabels(projectName string, serviceName string) map[string]string {
|
func selectorLabels(projectName string, serviceName string) map[string]string {
|
||||||
return map[string]string{
|
return map[string]string{
|
||||||
compose.ProjectTag: projectName,
|
compose.ProjectTag: projectName,
|
||||||
@ -158,7 +154,7 @@ func mapToDaemonset(project *types.Project, service types.ServiceConfig) (*apps.
|
|||||||
|
|
||||||
return &apps.DaemonSet{
|
return &apps.DaemonSet{
|
||||||
ObjectMeta: meta.ObjectMeta{
|
ObjectMeta: meta.ObjectMeta{
|
||||||
Name: getProjectServiceName(project, service),
|
Name: service.Name,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
},
|
},
|
||||||
Spec: apps.DaemonSetSpec{
|
Spec: apps.DaemonSetSpec{
|
||||||
|
@ -29,7 +29,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestServiceWithExposedPort(t *testing.T) {
|
func TestServiceWithExposedPort(t *testing.T) {
|
||||||
model, err := loadYAML("myproject", `
|
model, err := loadYAML(`
|
||||||
services:
|
services:
|
||||||
nginx:
|
nginx:
|
||||||
image: nginx
|
image: nginx
|
||||||
@ -45,10 +45,10 @@ services:
|
|||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
},
|
},
|
||||||
ObjectMeta: meta.ObjectMeta{
|
ObjectMeta: meta.ObjectMeta{
|
||||||
Name: "myproject-nginx",
|
Name: "nginx",
|
||||||
},
|
},
|
||||||
Spec: core.ServiceSpec{
|
Spec: core.ServiceSpec{
|
||||||
Selector: map[string]string{"com.docker.compose.service": "nginx", "com.docker.compose.project": "myproject"},
|
Selector: map[string]string{"com.docker.compose.service": "nginx", "com.docker.compose.project": ""},
|
||||||
Ports: []core.ServicePort{
|
Ports: []core.ServicePort{
|
||||||
{
|
{
|
||||||
Name: "80-tcp",
|
Name: "80-tcp",
|
||||||
@ -62,7 +62,7 @@ services:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestServiceWithoutExposedPort(t *testing.T) {
|
func TestServiceWithoutExposedPort(t *testing.T) {
|
||||||
model, err := loadYAML("myproject", `
|
model, err := loadYAML(`
|
||||||
services:
|
services:
|
||||||
nginx:
|
nginx:
|
||||||
image: nginx
|
image: nginx
|
||||||
@ -76,10 +76,10 @@ services:
|
|||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
},
|
},
|
||||||
ObjectMeta: meta.ObjectMeta{
|
ObjectMeta: meta.ObjectMeta{
|
||||||
Name: "myproject-nginx",
|
Name: "nginx",
|
||||||
},
|
},
|
||||||
Spec: core.ServiceSpec{
|
Spec: core.ServiceSpec{
|
||||||
Selector: map[string]string{"com.docker.compose.service": "nginx", "com.docker.compose.project": "myproject"},
|
Selector: map[string]string{"com.docker.compose.service": "nginx", "com.docker.compose.project": ""},
|
||||||
ClusterIP: "None",
|
ClusterIP: "None",
|
||||||
Ports: []core.ServicePort{},
|
Ports: []core.ServicePort{},
|
||||||
Type: core.ServiceTypeClusterIP,
|
Type: core.ServiceTypeClusterIP,
|
||||||
|
@ -31,7 +31,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
func loadYAML(projectName string, yaml string) (*types.Project, error) {
|
func loadYAML(yaml string) (*types.Project, error) {
|
||||||
dict, err := loader.ParseYAML([]byte(yaml))
|
dict, err := loader.ParseYAML([]byte(yaml))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -51,12 +51,7 @@ func loadYAML(projectName string, yaml string) (*types.Project, error) {
|
|||||||
ConfigFiles: configs,
|
ConfigFiles: configs,
|
||||||
Environment: nil,
|
Environment: nil,
|
||||||
}
|
}
|
||||||
project, err := loader.Load(config)
|
return loader.Load(config)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
project.Name = projectName
|
|
||||||
return project, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func podTemplate(t *testing.T, yaml string) apiv1.PodTemplateSpec {
|
func podTemplate(t *testing.T, yaml string) apiv1.PodTemplateSpec {
|
||||||
@ -66,7 +61,7 @@ func podTemplate(t *testing.T, yaml string) apiv1.PodTemplateSpec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func podTemplateWithError(yaml string) (apiv1.PodTemplateSpec, error) {
|
func podTemplateWithError(yaml string) (apiv1.PodTemplateSpec, error) {
|
||||||
model, err := loadYAML("myproject", yaml)
|
model, err := loadYAML(yaml)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return apiv1.PodTemplateSpec{}, err
|
return apiv1.PodTemplateSpec{}, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user