Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/common/net.go
2500 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package common
6
7
import (
8
"fmt"
9
"net"
10
"strconv"
11
12
"github.com/gitpod-io/gitpod/common-go/baseserver"
13
)
14
15
const (
16
localhost = "127.0.0.1"
17
)
18
19
func LocalhostAddressFromPort(port int) string {
20
return fmt.Sprintf("%v:%v", localhost, port)
21
}
22
23
func LocalhostPrometheusAddr() string {
24
return LocalhostAddressFromPort(baseserver.BuiltinMetricsPort)
25
}
26
27
func LocalhostPprofAddr() string {
28
return LocalhostAddressFromPort(baseserver.BuiltinDebugPort)
29
}
30
31
func ClusterAddress(serviceName string, namespace string, port int) string {
32
return net.JoinHostPort(fmt.Sprintf("%s.%s.svc.cluster.local", serviceName, namespace), strconv.Itoa(port))
33
}
34
35
func ClusterURL(protocol string, serviceName string, namespace string, port int) string {
36
return fmt.Sprintf("%s://%s", protocol, ClusterAddress(serviceName, namespace, port))
37
}
38
39