#! this two-part example is based on the blog post
#! by matthew palmer: https://bit.ly/2QNCWab

#! let's now make it possible to have multiple copies
#! of the app: apple, banana, and orange.
#! to do so, we pull reusable functionality into a
#! set of functions

#@ def/end app_labels(app):
app: #@ app.name

#@ def app_svc_name(app):
#@   return app.name + "-svc"
#@ end

#@ def app_config(app):
---
kind: Pod
apiVersion: v1
metadata:
  name: #@ app.name + "-app"
  labels: #@ app_labels(app)
spec:
  containers:
  - name: app
    image: hashicorp/http-echo
    args:
    - #@ "-listen=:" + str(app.port)
    - #@ "-text=" + app.text

---
kind: Service
apiVersion: v1
metadata:
  name: #@ app_svc_name(app)
spec:
  selector: #@ app_labels(app)
  ports:
  - port: #@ app.port
#@ end
