Skip to content

Commit

Permalink
added seed to labels
Browse files Browse the repository at this point in the history
  • Loading branch information
nmnellis committed Jul 6, 2021
1 parent 275ab3e commit adca01c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 7 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ generate [flags]
--app-error-percent 0.25
```

* Recreating an output - there are times you might want to recreate a users setup. All assets are labeled with a seed value. simply use the seed in your cmd
```shell
# Example namespace
# apiVersion: v1
# kind: Namespace
# metadata:
# name: ns-1
# labels:
# istio-injection: enabled
# seed: "1625582727962871000"

./istio-app-simulator generate \
# use the seed above to regenerate the same output
--seed 1625582727962871000
```


### Fake Service UI
You can reach a UI for the fake service call stack by using kubernetes port forwarding to the tier 1 service in the namespace
```shell
Expand Down
5 changes: 5 additions & 0 deletions pkg/generate/assets/app.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{ $seed := .Seed }}
{{range $namespace,$microservices := .Microservices}}
---
apiVersion: v1
Expand All @@ -6,6 +7,7 @@ metadata:
name: {{$namespace}}
labels:
istio-injection: enabled
seed: "{{ $seed }}"
---
{{range $microservice := $microservices}}
apiVersion: v1
Expand All @@ -16,6 +18,7 @@ metadata:
labels:
app: {{$microservice.Name}}
tier: "{{$microservice.Tier}}"
seed: "{{ $seed }}"
---
apiVersion: v1
kind: Service
Expand All @@ -25,6 +28,7 @@ metadata:
labels:
app: {{$microservice.Name}}
tier: "{{$microservice.Tier}}"
seed: "{{ $seed }}"
spec:
selector:
app: {{$microservice.Name}}
Expand All @@ -44,6 +48,7 @@ metadata:
app: {{$microservice.Name}}
version: {{$version}}
tier: "{{$microservice.Tier}}"
seed: "{{ $seed }}"
spec:
replicas: 1
selector:
Expand Down
3 changes: 3 additions & 0 deletions pkg/generate/assets/gateway.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{{ $seed := .Seed }}
---
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: istio-ingressgateway
namespace: istio-system
labels:
seed: "{{ $seed }}"
spec:
selector:
istio: ingressgateway
Expand Down
3 changes: 3 additions & 0 deletions pkg/generate/assets/serviceentry.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{{ $seed := .Seed }}
{{- range $service := .ExternalServices }}
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: {{ $service }}
namespace: istio-system
labels:
seed: "{{ $seed }}"
spec:
hosts:
- {{ $service }}
Expand Down
3 changes: 3 additions & 0 deletions pkg/generate/assets/virtualservice.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{{ $seed := .Seed }}
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: ingress-gw
namespace: istio-system
labels:
seed: "{{ $seed }}"
spec:
hosts:
- "{{- .Host }}"
Expand Down
1 change: 0 additions & 1 deletion pkg/generate/const.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package generate


const (
maxAmountOfVersions = 3
)
Expand Down
8 changes: 4 additions & 4 deletions pkg/generate/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ func NewAppGenerator(config *Config) *AppGenerator {

func (a *AppGenerator) Generate() error {

seed := a.config.Seed
// if unset, make random
if seed == 0 {
seed = time.Now().UnixNano()
if a.config.Seed == 0 {
a.config.Seed = time.Now().UnixNano()
}

rand.Seed(seed)
rand.Seed(a.config.Seed)
// generate namespaces
// namespace names will be very simple ns1, ns2 etc
var microservices []*Microservice
Expand Down Expand Up @@ -149,6 +148,7 @@ func (a *AppGenerator) render(microservices map[string][]*Microservice) {
Microservices: microservices,
ExternalServices: externalServices,
Host: a.config.Hostname,
Seed: a.config.Seed,
}

gatewayFile, err := os.Create(a.config.OutputDir + "/gateway.yaml")
Expand Down
5 changes: 3 additions & 2 deletions pkg/generate/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ type Backend struct {
}

type TemplateConfig struct {
Microservices map[string][]*Microservice
Microservices map[string][]*Microservice
ExternalServices []string
Host string
Host string
Seed int64
}

type Config struct {
Expand Down

0 comments on commit adca01c

Please sign in to comment.