Skip to content

Commit

Permalink
Merge pull request #2 from nmnellis/resources
Browse files Browse the repository at this point in the history
added resources
  • Loading branch information
nmnellis authored Jul 6, 2021
2 parents d2bb7aa + da65232 commit 2a44f86
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 17 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ generate [flags]
--chance-version int Percent chance that a given application will have multiple versions v1/v2/v3 (0-100) (default 10)
-h, --help help for generate
--hostname string Hostname to use for gateway and virtualService (default "*")
--limits-cpu string Kubernetes container CPU limit
--limits-memory string Kubernetes container memory limit
-n, --namespaces int Number of namespaces to generate applications for (default 1)
-o, --output-dir string Output directory where assets will be generated (default "out")
--requests-cpu string Kubernetes container CPU request (default "100m")
--requests-memory string Kubernetes container memory request (default "100Mi")
--seed int Override random seed with static one (for deterministic outputs)
-t, --tiers int Length of the application call stack per namespace (how many applications deep) (default 3)
```
Expand Down
9 changes: 9 additions & 0 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,13 @@ func init() {
"Percent chance that a given application will make a call to an external service (0-100)")
generateCmd.Flags().StringVarP(&cfg.OutputDir, "output-dir", "o", "out",
"Output directory where assets will be generated")

generateCmd.Flags().StringVar(&cfg.MemoryRequest, "requests-memory", "100Mi",
"Kubernetes container memory request")
generateCmd.Flags().StringVar(&cfg.MemoryLimit, "limits-memory", "",
"Kubernetes container memory limit")
generateCmd.Flags().StringVar(&cfg.CPULimit, "limits-cpu", "",
"Kubernetes container CPU limit")
generateCmd.Flags().StringVar(&cfg.CPURequest, "requests-cpu", "100m",
"Kubernetes container CPU request")
}
4 changes: 4 additions & 0 deletions docs/generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ generate [flags]
--chance-version int Percent chance that a given application will have multiple versions v1/v2/v3 (0-100) (default 10)
-h, --help help for generate
--hostname string Hostname to use for gateway and virtualService (default "*")
--limits-cpu string Kubernetes container CPU limit
--limits-memory string Kubernetes container memory limit
-n, --namespaces int Number of namespaces to generate applications for (default 1)
-o, --output-dir string Output directory where assets will be generated (default "out")
--requests-cpu string Kubernetes container CPU request (default "100m")
--requests-memory string Kubernetes container memory request (default "100Mi")
--seed int Override random seed with static one (for deterministic outputs)
-t, --tiers int Length of the application call stack per namespace (how many applications deep) (default 3)
```
Expand Down
31 changes: 26 additions & 5 deletions pkg/generate/assets/app.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ $seed := .Seed }}
{{ $config := .Config }}
{{range $namespace,$microservices := .Microservices}}
---
apiVersion: v1
Expand All @@ -7,7 +7,7 @@ metadata:
name: {{$namespace}}
labels:
istio-injection: enabled
seed: "{{ $seed }}"
seed: "{{ $config.Seed }}"
---
{{range $microservice := $microservices}}
apiVersion: v1
Expand All @@ -18,7 +18,7 @@ metadata:
labels:
app: {{$microservice.Name}}
tier: "{{$microservice.Tier}}"
seed: "{{ $seed }}"
seed: "{{ $config.Seed }}"
---
apiVersion: v1
kind: Service
Expand All @@ -28,7 +28,7 @@ metadata:
labels:
app: {{$microservice.Name}}
tier: "{{$microservice.Tier}}"
seed: "{{ $seed }}"
seed: "{{ $config.Seed }}"
spec:
selector:
app: {{$microservice.Name}}
Expand All @@ -48,7 +48,7 @@ metadata:
app: {{$microservice.Name}}
version: {{$version}}
tier: "{{$microservice.Tier}}"
seed: "{{ $seed }}"
seed: "{{ $config.Seed }}"
spec:
replicas: 1
selector:
Expand Down Expand Up @@ -83,6 +83,27 @@ spec:
- name: "EXTERNAL_SERVICE_URIS"
value: "{{ genExternalServices $microservice.ExternalServices }}"
{{- end }}
{{- if or $config.MemoryRequest $config.MemoryLimit $config.CPURequest $config.CPULimit }}
resources:
{{- if or $config.MemoryLimit $config.CPULimit }}
limits:
{{- if $config.MemoryLimit }}
memory: {{ $config.MemoryLimit }}
{{- end }}
{{- if $config.CPULimit }}
cpu: {{ $config.CPULimit }}
{{- end }}
{{- end }}
{{- if or $config.MemoryRequest $config.CPURequest }}
requests:
{{- if $config.MemoryRequest }}
memory: {{ $config.MemoryRequest }}
{{- end }}
{{- if $config.CPURequest }}
cpu: {{ $config.CPURequest }}
{{- end }}
{{- end }}
{{- end }}
---
{{- end }}
{{- end }}
Expand Down
6 changes: 3 additions & 3 deletions pkg/generate/assets/gateway.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{{ $seed := .Seed }}
{{ $config := .Config }}
---
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: istio-ingressgateway
namespace: istio-system
labels:
seed: "{{ $seed }}"
seed: "{{ $config.Seed }}"
spec:
selector:
istio: ingressgateway
Expand All @@ -16,5 +16,5 @@ spec:
name: http
protocol: HTTP
hosts:
- "{{- .Host }}"
- "{{- $config.Hostname }}"
---
4 changes: 2 additions & 2 deletions pkg/generate/assets/serviceentry.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{{ $seed := .Seed }}
{{ $config := .Config }}
{{- range $service := .ExternalServices }}
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: {{ $service }}
namespace: istio-system
labels:
seed: "{{ $seed }}"
seed: "{{ $config.Seed }}"
spec:
hosts:
- {{ $service }}
Expand Down
6 changes: 3 additions & 3 deletions pkg/generate/assets/virtualservice.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{{ $seed := .Seed }}
{{ $config := .Config }}
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: ingress-gw
namespace: istio-system
labels:
seed: "{{ $seed }}"
seed: "{{ $config.Seed }}"
spec:
hosts:
- "{{- .Host }}"
- "{{- $config.Hostname }}"
gateways:
- istio-ingressgateway
http:
Expand Down
3 changes: 1 addition & 2 deletions pkg/generate/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ func (a *AppGenerator) render(microservices map[string][]*Microservice) error {
templateConfig := &TemplateConfig{
Microservices: microservices,
ExternalServices: externalServices,
Host: a.config.Hostname,
Seed: a.config.Seed,
Config: a.config,
}

gatewayFile, err := os.Create(a.config.OutputDir + "/gateway.yaml")
Expand Down
7 changes: 5 additions & 2 deletions pkg/generate/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ type Backend struct {
type TemplateConfig struct {
Microservices map[string][]*Microservice
ExternalServices []string
Host string
Seed int64
Config *Config
}

type Config struct {
Expand All @@ -45,4 +44,8 @@ type Config struct {
ChanceToCallExternalService int
OutputDir string
Hostname string
MemoryLimit string
CPULimit string
MemoryRequest string
CPURequest string
}

0 comments on commit 2a44f86

Please sign in to comment.