Skip to content

Commit

Permalink
fix #1 : wrong upstream names in multi-namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
kitt1987 committed Sep 20, 2022
1 parent ffe856c commit 3fa64ee
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@

/_output
/.vscode
/.gitpod.yml
/.gitpod.yml
*.dot
11 changes: 7 additions & 4 deletions pkg/manifest/k8s.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package manifest

import (
"fmt"
"io"
"math/rand"
"strconv"
Expand Down Expand Up @@ -215,7 +216,7 @@ func GenForK8s(g graph.Directed, opts *Options) {
toService = opts.NewService(to)
versionMap[to.ID()] = toService
}
fromService.Upstream = append(fromService.Upstream, toService.App)
fromService.Upstream = append(fromService.Upstream, fmt.Sprintf("%s.%s", toService.App, toService.Namespace))
}
}

Expand All @@ -224,20 +225,22 @@ func GenForK8s(g graph.Directed, opts *Options) {

const GatewayApp = "gateway"
gatewayOutput := opts.OutputForVersions(1)[0]
if err := deploymentTmpl.Execute(gatewayOutput, versionMap[serviceMap[GatewayApp][0]]); err != nil {
gatewaySvc := versionMap[serviceMap[GatewayApp][0]]
if err := deploymentTmpl.Execute(gatewayOutput, gatewaySvc); err != nil {
panic(err)
}
if err := serviceTmpl.Execute(gatewayOutput, versionMap[serviceMap[GatewayApp][0]]); err != nil {
if err := serviceTmpl.Execute(gatewayOutput, gatewaySvc); err != nil {
panic(err)
}
trafficGen := opts.NewService(nil)
trafficGen.Name = "traffic-generator"
trafficGen.Namespace = gatewaySvc.Namespace
trafficGen.App = trafficGen.Name
trafficGen.Version = "v1"
trafficGen.NumVersions = 1
trafficGen.NumReplicas = 1
trafficGen.Image = "docker.io/warmmetal/ms-demo-traffic:latest"
trafficGen.Upstream = []string{versionMap[1].App}
trafficGen.Upstream = []string{GatewayApp}
trafficGen.PayloadSize = -1
trafficGen.Address = ""
if err := deploymentTmpl.Execute(gatewayOutput, trafficGen); err != nil {
Expand Down
26 changes: 13 additions & 13 deletions pkg/manifest/k8s_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ package manifest
const deployTemplate = `apiVersion: apps/v1
kind: Deployment
metadata:
name: {{.Name}}
namespace: {{.Namespace}}
name: "{{.Name}}"
namespace: "{{.Namespace}}"
labels:
app: {{.App}}
version: {{.Version}}
app: "{{.App}}"
version: "{{.Version}}"
origin: msdgen
spec:
replicas: {{.NumReplicas}}
selector:
matchLabels:
app: {{.App}}
version: {{.Version}}
app: "{{.App}}"
version: "{{.Version}}"
template:
metadata:
labels:
app: {{.App}}
version: {{.Version}}
app: "{{.App}}"
version: "{{.Version}}"
origin: msdgen
spec:
containers:
Expand Down Expand Up @@ -61,14 +61,14 @@ spec:
const serviceTemplate = `apiVersion: v1
kind: Service
metadata:
name: {{.App}}
namespace: {{.Namespace}}
name: "{{.App}}"
namespace: "{{.Namespace}}"
labels:
app: {{.App}}
origin: msdgen
app: "{{.App}}"
origin: "msdgen"
spec:
selector:
app: {{.App}}
app: "{{.App}}"
ports:
- protocol: TCP
port: 80
Expand Down

0 comments on commit 3fa64ee

Please sign in to comment.