refactor: simplify port string
This commit is contained in:
@@ -261,6 +261,10 @@ type PortMap struct {
|
|||||||
Scheme string `json:"scheme"`
|
Scheme string `json:"scheme"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p PortMap) String() string {
|
||||||
|
return fmt.Sprintf("%s-%d-%d", p.Scheme, p.HostPort, p.ContainerPort)
|
||||||
|
}
|
||||||
|
|
||||||
func (p PortMap) IsAllowedHttp() bool {
|
func (p PortMap) IsAllowedHttp() bool {
|
||||||
return p.Scheme == "http" || p.ContainerPort == 80
|
return p.Scheme == "http" || p.ContainerPort == 80
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -460,7 +460,7 @@ func templateKubernetesDeployment(input Deployment) (appsv1.Deployment, error) {
|
|||||||
protocol = "UDP"
|
protocol = "UDP"
|
||||||
}
|
}
|
||||||
deployment.Spec.Template.Spec.Containers[0].Ports = append(deployment.Spec.Template.Spec.Containers[0].Ports, corev1.ContainerPort{
|
deployment.Spec.Template.Spec.Containers[0].Ports = append(deployment.Spec.Template.Spec.Containers[0].Ports, corev1.ContainerPort{
|
||||||
Name: fmt.Sprintf("%s-%d-%d", portMap.Scheme, portMap.HostPort, portMap.ContainerPort),
|
Name: portMap.String(),
|
||||||
ContainerPort: portMap.ContainerPort,
|
ContainerPort: portMap.ContainerPort,
|
||||||
Protocol: corev1.Protocol(protocol),
|
Protocol: corev1.Protocol(protocol),
|
||||||
})
|
})
|
||||||
@@ -557,7 +557,7 @@ func templateKubernetesIngressRoute(input IngressRoute) traefikv1alpha1.IngressR
|
|||||||
"dokku.com/managed": "true",
|
"dokku.com/managed": "true",
|
||||||
}
|
}
|
||||||
|
|
||||||
port := fmt.Sprintf("%s-%d-%d", input.PortMap.Scheme, input.PortMap.HostPort, input.PortMap.ContainerPort)
|
port := input.PortMap.String()
|
||||||
ingressRoute := traefikv1alpha1.IngressRoute{
|
ingressRoute := traefikv1alpha1.IngressRoute{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: fmt.Sprintf("%s-%s", input.ServiceName, port),
|
Name: fmt.Sprintf("%s-%s", input.ServiceName, port),
|
||||||
@@ -811,9 +811,9 @@ func templateKubernetesService(input Service) corev1.Service {
|
|||||||
protocol = "UDP"
|
protocol = "UDP"
|
||||||
}
|
}
|
||||||
service.Spec.Ports = append(service.Spec.Ports, corev1.ServicePort{
|
service.Spec.Ports = append(service.Spec.Ports, corev1.ServicePort{
|
||||||
Name: fmt.Sprintf("%s-%d-%d", portMap.Scheme, portMap.HostPort, portMap.ContainerPort),
|
Name: portMap.String(),
|
||||||
Port: portMap.HostPort,
|
Port: portMap.HostPort,
|
||||||
TargetPort: intstr.FromString(fmt.Sprintf("%s-%d-%d", portMap.Scheme, portMap.HostPort, portMap.ContainerPort)),
|
TargetPort: intstr.FromString(portMap.String()),
|
||||||
Protocol: corev1.Protocol(protocol),
|
Protocol: corev1.Protocol(protocol),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user