feat: follow-up compose 'ports' support: use ingress mode by default (closes #81)

This commit is contained in:
Pasha Sviderski
2025-07-21 16:56:52 +10:00
parent fea7edcbc5
commit 6fb07db4b2
4 changed files with 45 additions and 39 deletions
+1 -18
View File
@@ -34,23 +34,6 @@ type PortSpec struct {
Mode string
}
func (p *PortSpec) isHTTP() bool {
return p.Protocol == ProtocolHTTP || p.Protocol == ProtocolHTTPS
}
// AdjustUncloudMode makes adjustments for uncloud compatibility
func (p *PortSpec) AdjustUncloudMode() {
if p.Protocol == "" {
p.Protocol = "tcp"
}
if p.Mode == "" {
p.Mode = PortModeIngress
}
if p.Mode == PortModeIngress && !p.isHTTP() && p.PublishedPort != 0 {
p.Mode = PortModeHost
}
}
func (p *PortSpec) Validate() error {
if p.ContainerPort == 0 {
return fmt.Errorf("container port must be non-zero")
@@ -73,7 +56,7 @@ func (p *PortSpec) Validate() error {
return fmt.Errorf("host IP cannot be specified in %s mode", PortModeIngress)
}
if p.Hostname != "" {
if !p.isHTTP() {
if p.Protocol != ProtocolHTTP && p.Protocol != ProtocolHTTPS {
return fmt.Errorf("hostname is only valid with '%s' or '%s' protocols", ProtocolHTTP, ProtocolHTTPS)
}
if err := validateHostname(p.Hostname); err != nil {