forked from LaconicNetwork/kompose
fix: expose container to host only with labels (#1880)
Signed-off-by: ahmed.g <ahmed.g@adjoe.io> Signed-off-by: TessaIO <ahmedgrati1999@gmail.com>
This commit is contained in:
@@ -142,6 +142,7 @@ type ServiceConfig struct {
|
||||
StopGracePeriod string `compose:"stop_grace_period"`
|
||||
Build string `compose:"build"`
|
||||
BuildArgs map[string]*string `compose:"build-args"`
|
||||
ExposeContainerToHost bool `compose:"kompose.controller.port.expose"`
|
||||
ExposeService string `compose:"kompose.service.expose"`
|
||||
ExposeServicePath string `compose:"kompose.service.expose.path"`
|
||||
BuildLabels map[string]string `compose:"build-labels"`
|
||||
|
||||
@@ -759,6 +759,8 @@ func parseKomposeLabels(labels map[string]string, serviceConfig *kobject.Service
|
||||
serviceConfig.ServiceExternalTrafficPolicy = serviceExternalTypeTrafficPolicy
|
||||
case LabelSecurityContextFsGroup:
|
||||
serviceConfig.FsGroup = cast.ToInt64(value)
|
||||
case LabelExposeContainerToHost:
|
||||
serviceConfig.ExposeContainerToHost = cast.ToBool(value)
|
||||
case LabelServiceExpose:
|
||||
serviceConfig.ExposeService = strings.Trim(value, " ,")
|
||||
case LabelNodePortPort:
|
||||
|
||||
@@ -104,6 +104,8 @@ const (
|
||||
LabelHpaMemory = "kompose.hpa.memory"
|
||||
// LabelNameOverride defines the override resource name
|
||||
LabelNameOverride = "kompose.service.name_override"
|
||||
// LabelExposeContainerToHost defines whether to expose container to host or not using hostPort
|
||||
LabelExposeContainerToHost = "kompose.controller.port.expose"
|
||||
)
|
||||
|
||||
// load environment variables from compose file
|
||||
|
||||
@@ -654,10 +654,13 @@ func ConfigPorts(service kobject.ServiceConfig) []api.ContainerPort {
|
||||
}
|
||||
containerPort := api.ContainerPort{
|
||||
ContainerPort: port.ContainerPort,
|
||||
HostIP: port.HostIP,
|
||||
HostPort: port.HostPort,
|
||||
Protocol: api.Protocol(port.Protocol),
|
||||
}
|
||||
|
||||
if service.ExposeContainerToHost {
|
||||
containerPort.HostIP = port.HostIP
|
||||
containerPort.HostPort = port.HostPort
|
||||
}
|
||||
ports = append(ports, containerPort)
|
||||
exist[port.ID()] = true
|
||||
}
|
||||
|
||||
@@ -88,10 +88,11 @@ func newKomposeObject() kobject.KomposeObject {
|
||||
|
||||
func newKomposeObjectHostPortProtocolConfig() kobject.ServiceConfig {
|
||||
return kobject.ServiceConfig{
|
||||
Name: "nginx",
|
||||
ContainerName: "nginx",
|
||||
Image: "nginx",
|
||||
Port: []kobject.Ports{{HostPort: 80, Protocol: string(api.ProtocolTCP), ContainerPort: 80}},
|
||||
Name: "nginx",
|
||||
ContainerName: "nginx",
|
||||
Image: "nginx",
|
||||
Port: []kobject.Ports{{HostPort: 80, Protocol: string(api.ProtocolTCP), ContainerPort: 80}},
|
||||
ExposeContainerToHost: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user