Skip to content

Commit 252cf42

Browse files
Config reorg
1 parent bb7366a commit 252cf42

29 files changed

+141
-168
lines changed

cmd/flags.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,12 @@ import (
2121
var (
2222
metricsBackend string
2323
verbose bool
24-
25-
locationPort int
26-
frontendPort int
27-
routePort int
28-
29-
basePath string
30-
baseDomain string
3124
)
3225

3326
const expvarDepr = "(deprecated, will be removed after 2024-01-01 or in release v1.53.0, whichever is later) "
3427

3528
// used by root command
3629
func addFlags(cmd *cobra.Command) {
3730
cmd.PersistentFlags().StringVarP(&metricsBackend, "metrics", "m", "prometheus", expvarDepr+"Metrics backend (expvar|prometheus). ")
38-
39-
// Add flags to choose ports for services
40-
cmd.PersistentFlags().IntVarP(&locationPort, "location-service-port", "c", 8081, "Port for location service")
41-
cmd.PersistentFlags().IntVarP(&frontendPort, "frontend-service-port", "f", 8080, "Port for frontend service")
42-
cmd.PersistentFlags().IntVarP(&routePort, "route-service-port", "r", 8083, "Port for routing service")
43-
44-
// Flag for serving frontend at custom basepath url
45-
cmd.PersistentFlags().StringVarP(&basePath, "basepath", "b", "", `Basepath for frontend service(default "/")`)
46-
cmd.PersistentFlags().StringVarP(&baseDomain, "basedomain", "B", "", `Base domain for accessing hotrod services`)
47-
4831
cmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enables debug logging")
4932
}

cmd/frontend.go

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
package cmd
1717

1818
import (
19-
"net"
20-
"os"
21-
"strconv"
22-
2319
"github.com/spf13/cobra"
2420
"go.uber.org/zap"
2521

@@ -33,44 +29,13 @@ var frontendCmd = &cobra.Command{
3329
Short: "Starts Frontend service",
3430
Long: `Starts Frontend service.`,
3531
RunE: func(cmd *cobra.Command, args []string) error {
36-
options.FrontendHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(frontendPort))
37-
38-
options.Basepath = basePath
39-
40-
// Resolve services addresses
41-
var locationHost, routeHost string
42-
if baseDomain == "" {
43-
locationHost = "location"
44-
routeHost = "route"
45-
} else {
46-
if baseDomain == "localhost" || net.ParseIP(baseDomain) != nil {
47-
locationHost = baseDomain
48-
routeHost = baseDomain
49-
} else {
50-
locationHost = "location." + baseDomain
51-
routeHost = "route." + baseDomain
52-
}
53-
}
54-
if val := os.Getenv("FRONTEND_LOCATION_ADDR"); val != "" {
55-
options.LocationHostPort = val
56-
} else {
57-
options.LocationHostPort = net.JoinHostPort(locationHost, strconv.Itoa(locationPort))
58-
}
59-
if val := os.Getenv("FRONTEND_ROUTE_ADDR"); val != "" {
60-
options.RouteHostPort = val
61-
} else {
62-
options.RouteHostPort = net.JoinHostPort(routeHost, strconv.Itoa(routePort))
63-
}
64-
6532
zapLogger := logger.With(zap.String("service", "frontend"))
6633
logger := log.NewFactory(zapLogger)
67-
server := frontend.NewServer(options, logger)
34+
server := frontend.NewServer(logger)
6835
return logError(zapLogger, server.Run())
6936
},
7037
}
7138

72-
var options frontend.ConfigOptions
73-
7439
func init() {
7540
RootCmd.AddCommand(frontendCmd)
7641
}

cmd/location.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
package cmd
1717

1818
import (
19-
"net"
20-
"strconv"
21-
2219
"github.com/spf13/cobra"
2320
"go.uber.org/zap"
2421

@@ -34,10 +31,7 @@ var locationCmd = &cobra.Command{
3431
RunE: func(cmd *cobra.Command, args []string) error {
3532
zapLogger := logger.With(zap.String("service", "location"))
3633
logger := log.NewFactory(zapLogger)
37-
server := location.NewServer(
38-
net.JoinHostPort("0.0.0.0", strconv.Itoa(locationPort)),
39-
logger,
40-
)
34+
server := location.NewServer(logger)
4135
return logError(zapLogger, server.Run())
4236
},
4337
}

cmd/root.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,6 @@ func onInitialize() {
7878
default:
7979
logger.Fatal("unsupported metrics backend " + metricsBackend)
8080
}
81-
82-
if locationPort != 8081 {
83-
logger.Info("changing location service port", zap.Int("old", 8081), zap.Int("new", locationPort))
84-
}
85-
86-
if frontendPort != 8080 {
87-
logger.Info("changing frontend service port", zap.Int("old", 8080), zap.Int("new", frontendPort))
88-
}
89-
90-
if routePort != 8083 {
91-
logger.Info("changing route service port", zap.Int("old", 8083), zap.Int("new", routePort))
92-
}
93-
94-
if basePath != "" {
95-
logger.Info("changing basepath for frontend", zap.String("old", "/"), zap.String("new", basePath))
96-
}
9781
}
9882

9983
func logError(logger *zap.Logger, err error) error {

cmd/route.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
package cmd
1717

1818
import (
19-
"net"
20-
"strconv"
21-
2219
"github.com/spf13/cobra"
2320
"go.uber.org/zap"
2421

@@ -34,10 +31,7 @@ var routeCmd = &cobra.Command{
3431
RunE: func(cmd *cobra.Command, args []string) error {
3532
zapLogger := logger.With(zap.String("service", "route"))
3633
logger := log.NewFactory(zapLogger)
37-
server := route.NewServer(
38-
net.JoinHostPort("0.0.0.0", strconv.Itoa(routePort)),
39-
logger,
40-
)
34+
server := route.NewServer(logger)
4135
return logError(zapLogger, server.Run())
4236
},
4337
}

k8s/base/driver.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ spec:
2323
- driver
2424
- --verbose
2525
env:
26+
# baseline reference
2627
- name: SIGNADOT_BASELINE_KIND
2728
value: Deployment
2829
- name: SIGNADOT_BASELINE_NAMESPACE
@@ -31,15 +32,21 @@ spec:
3132
fieldPath: metadata.namespace
3233
- name: SIGNADOT_BASELINE_NAME
3334
value: "driver"
35+
# service dependencies (<NAMESPACE> get replaced at runtime by the app)
3436
- name: SIGNADOT_ROUTESERVER
3537
value: routeserver.signadot.svc:7777
38+
- name: ROUTE_ADDR
39+
value: route.<NAMESPACE>:8083
40+
- name: REDIS_ADDR
41+
value: redis.<NAMESPACE>:6379
42+
- name: KAFKA_BROKER_ADDR
43+
value: kafka-headless.<NAMESPACE>:9092
3644
- name: OTEL_EXPORTER_OTLP_ENDPOINT
37-
value: "http://jaeger:4318"
45+
value: http://jaeger.<NAMESPACE>:4318
3846
image: signadot/hotrod:latest
3947
imagePullPolicy: Always
4048
readinessProbe:
4149
httpGet:
4250
path: /healthz
4351
port: 8082
44-
4552
restartPolicy: Always

k8s/base/frontend.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ spec:
2323
- frontend
2424
- --verbose
2525
env:
26+
# baseline reference
2627
- name: SIGNADOT_BASELINE_KIND
2728
value: Deployment
2829
- name: SIGNADOT_BASELINE_NAMESPACE
@@ -31,8 +32,15 @@ spec:
3132
fieldPath: metadata.namespace
3233
- name: SIGNADOT_BASELINE_NAME
3334
value: "frontend"
35+
# service dependencies (<NAMESPACE> get replaced at runtime by the app)
36+
- name: LOCATION_ADDR
37+
value: location.<NAMESPACE>:8081
38+
- name: REDIS_ADDR
39+
value: redis.<NAMESPACE>:6379
40+
- name: KAFKA_BROKER_ADDR
41+
value: kafka-headless.<NAMESPACE>:9092
3442
- name: OTEL_EXPORTER_OTLP_ENDPOINT
35-
value: "http://jaeger:4318"
43+
value: http://jaeger.<NAMESPACE>:4318
3644
image: signadot/hotrod:latest
3745
imagePullPolicy: Always
3846
ports:

k8s/base/kustomization.yaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
apiVersion: kustomize.config.k8s.io/v1beta1
22
kind: Kustomization
3+
34
resources:
4-
- mysql
5-
- redis
6-
- kafka
7-
- frontend.yaml
8-
- location.yaml
9-
- driver.yaml
10-
- route.yaml
5+
- mysql
6+
- redis
7+
- kafka
8+
- frontend.yaml
9+
- location.yaml
10+
- driver.yaml
11+
- route.yaml
12+
1113
images:
12-
- name: signadot/hotrod
13-
newTag: latest
14+
- name: signadot/hotrod
15+
newTag: latest

k8s/base/location.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,24 @@ spec:
2222
args:
2323
- location
2424
env:
25+
# baseline reference
2526
- name: SIGNADOT_BASELINE_KIND
2627
value: Deployment
2728
- name: SIGNADOT_BASELINE_NAMESPACE
2829
valueFrom:
2930
fieldRef:
3031
fieldPath: metadata.namespace
3132
- name: SIGNADOT_BASELINE_NAME
32-
value: "location"
33-
- name: OTEL_EXPORTER_OTLP_ENDPOINT
34-
value: "http://jaeger:4318"
35-
- name: MYSQL_HOST
36-
value: "mysql"
37-
- name: MYSQL_PORT
38-
value: "3306"
33+
value: location
34+
# service dependencies (<NAMESPACE> get replaced at runtime by the app)
35+
- name: MYSQL_ADDR
36+
value: mysql.<NAMESPACE>:3306
3937
- name: MYSQL_PASS
4038
value: abc
39+
- name: REDIS_ADDR
40+
value: redis.<NAMESPACE>:6379
41+
- name: OTEL_EXPORTER_OTLP_ENDPOINT
42+
value: http://jaeger.<NAMESPACE>:4318
4143
image: signadot/hotrod:latest
4244
imagePullPolicy: Always
4345
ports:

k8s/base/route.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ spec:
2222
args:
2323
- route
2424
env:
25+
# baseline reference
2526
- name: SIGNADOT_BASELINE_KIND
2627
value: Deployment
2728
- name: SIGNADOT_BASELINE_NAMESPACE
@@ -30,8 +31,11 @@ spec:
3031
fieldPath: metadata.namespace
3132
- name: SIGNADOT_BASELINE_NAME
3233
value: "route"
34+
# service dependencies
35+
- name: REDIS_ADDR
36+
value: redis.<NAMESPACE>:6379
3337
- name: OTEL_EXPORTER_OTLP_ENDPOINT
34-
value: "http://jaeger:4318"
38+
value: http://jaeger.<NAMESPACE>:4318
3539
image: signadot/hotrod:latest
3640
imagePullPolicy: Always
3741
ports:

0 commit comments

Comments
 (0)