Skip to content

Commit

Permalink
chore(examples): update vote and vote-helm examples
Browse files Browse the repository at this point in the history
This fixes an issue with hostname conflicts and also cleans them up
a bit, and a small general update to how they flow.
  • Loading branch information
edvald authored and thsig committed Jan 18, 2021
1 parent 4e168fc commit c9650fa
Show file tree
Hide file tree
Showing 32 changed files with 12,506 additions and 8,128 deletions.
4 changes: 0 additions & 4 deletions docs/guides/using-helm-charts.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@ values:
image:
repository: api-image
tag: ${modules.api-image.version}
ingress:
enabled: true
paths: [/]
hosts: [api.local.app.garden]
```

Here, the `base-chart` module contains the actual Helm chart and templates. Note the `skipDeploy` flag, which we set
Expand Down
35 changes: 19 additions & 16 deletions examples/vote-helm/api-image/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ def get_redis():
g.redis = Redis(host="redis-master", db=0, socket_timeout=5)
return g.redis

@app.route("/vote/", methods=['POST','GET'])
def vote():
voter_id = hex(random.getrandbits(64))[2:-1]
@app.route("/api", methods=['GET'])
def hello():
return app.response_class(
response="Hello, I am the api service",
status=200,
)

@app.route("/api/vote", methods=['POST','GET'])
def vote():
app.logger.info("received request")

voter_id = hex(random.getrandbits(64))[2:-1]
vote = None

if request.method == 'POST':
Expand All @@ -33,20 +39,17 @@ def vote():

redis.rpush('votes', data)
print("Registered vote")
response = app.response_class(
response=json.dumps(data),
status=200,
mimetype='application/json'
return app.response_class(
response=json.dumps(data),
status=200,
mimetype='application/json'
)
else:
return app.response_class(
response=json.dumps({}),
status=404,
mimetype='application/json'
)
return response

response = app.response_class(
response=json.dumps({}),
status=404,
mimetype='application/json'
)
return response


if __name__ == "__main__":
app.run(host='0.0.0.0', port=80, debug=True, threaded=True)
5 changes: 5 additions & 0 deletions examples/vote-helm/api-image/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ name: api-image
tests:
- name: unit
args: [echo, ok]
- name: integ
args: [python, /app/test.py]
timeout: 60
dependencies:
- api
1 change: 1 addition & 0 deletions examples/vote-helm/api-image/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Flask
Redis
gunicorn
flask-cors
requests
14 changes: 14 additions & 0 deletions examples/vote-helm/api-image/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import requests
import unittest

class IntegTest(unittest.TestCase):
def test_post(self):
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Access-Control-Allow-Origin': '*',
}
response = requests.post("http://api/api/vote", headers=headers, data="vote=a")
self.assertEqual(response.status_code, 200)

if __name__ == '__main__':
unittest.main()
3 changes: 2 additions & 1 deletion examples/vote-helm/api/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ values:
ingress:
enabled: true
paths: [/]
hosts: [api.local.app.garden]
hosts: ["api.${var.baseHostname}"]
healthCheckPath: /api
8 changes: 8 additions & 0 deletions examples/vote-helm/base-chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,13 @@ spec:
- name: http
containerPort: 80
protocol: TCP
{{- if .Values.healthCheckPath }}
readinessProbe:
httpGet:
path: {{ .Values.healthCheckPath }}
port: http
{{- end }}
env:
{{- toYaml .Values.env | nindent 12 }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
6 changes: 4 additions & 2 deletions examples/vote-helm/base-chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ service:
type: ClusterIP

servicePort: 80
healthCheckPath:

env: []

ingress:
enabled: false
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
paths: []
hosts:
- chart-example.local
hosts: []
tls: []
# - secretName: chart-example-tls
# hosts:
Expand Down
9 changes: 7 additions & 2 deletions examples/vote-helm/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ kind: Project
name: vote-helm
environments:
- name: local
variables:
baseHostname: ${project.name}.local.app.garden
- name: testing
defaultNamespace: testing-${local.env.CIRCLE_BUILD_NUM || local.username}
defaultNamespace: testing-${var.userId}
variables:
baseHostname: ${project.name}-testing-${var.userId}.dev-1.sys.garden
providers:
- name: local-kubernetes
environments: [local]
- name: kubernetes
environments: [testing]
context: gke_garden-dev-200012_europe-west1-b_garden-dev-1
defaultHostname: ${environment.namespace}.dev-1.sys.garden
buildMode: cluster-docker
variables:
userId: ${local.env.CIRCLE_BUILD_NUM || local.username}
2 changes: 1 addition & 1 deletion examples/vote-helm/result/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ values:
ingress:
enabled: true
paths: [/]
hosts: [result-helm.local.app.garden]
hosts: ["result-helm.${var.baseHostname}"]
tests:
- name: integ
args: [echo, ok]
Expand Down
2 changes: 1 addition & 1 deletion examples/vote-helm/vote-image/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
presets: [
'@vue/app',
'@vue/cli-plugin-babel/preset',
],
};
Loading

0 comments on commit c9650fa

Please sign in to comment.