Skip to content

Commit cc930d2

Browse files
Merge pull request #7 from fetch-rewards/feature/configurable-helm-chart
Feature/configurable helm chart
2 parents b09b778 + b35a1af commit cc930d2

File tree

12 files changed

+195
-219
lines changed

12 files changed

+195
-219
lines changed

charts/streamlit-chart/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.1.0
18+
version: 0.2.0
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to

charts/streamlit-chart/templates/launch-configmap.yaml renamed to charts/streamlit-chart/templates/launch-script-configmap.yaml

File renamed without changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: streamlit-operator-config
5+
namespace: streamlit
6+
data:
7+
config.yaml: |
8+
baseDnsRecord: {{ .Values.baseDnsRecord }}
9+
ingressAnnotations:
10+
{{- range $key, $value := .Values.ingressAnnotations }}
11+
{{ $key }} : {{ tpl $value $ }}
12+
{{- end }}

charts/streamlit-chart/templates/operator-deployment.yaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ spec:
2323
- name: GIT_SYNC_REPO
2424
value: https://github.com/fetch-rewards/streamlit-operator.git
2525
- name: GIT_SYNC_BRANCH
26-
value: feature/docker
26+
value: feature/configurable-helm-chart
2727
- name: GIT_SYNC_ROOT
2828
value: /tmp/code
2929
- name: GIT_SYNC_DEST
@@ -36,13 +36,25 @@ spec:
3636
containers:
3737
- name: streamlit-operator
3838
image: python:3.8.5
39+
env:
40+
- name: BASE_DNS_RECORD
41+
value: {{ required "Must provide a base dns to host your Streamlit apps" .Values.baseDnsRecord }}
3942
ports:
4043
- containerPort: 80
4144
volumeMounts:
4245
- name: code
4346
mountPath: /app
47+
- name: config
48+
mountPath: "/config"
49+
readOnly: true
4450
workingDir: /app/repo/
4551
command: ["/app/repo/src/start.sh"]
4652
volumes:
4753
- name: code
48-
emptyDir: { }
54+
emptyDir: { }
55+
- name: config
56+
configMap:
57+
name: streamlit-operator-config
58+
items:
59+
- key: config.yaml
60+
path: config.yaml

charts/streamlit-chart/values.yaml

Lines changed: 4 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,4 @@
1-
# Default values for streamlit-chart.
2-
# This is a YAML-formatted file.
3-
# Declare variables to be passed into your templates.
4-
5-
# replicaCount: 1
6-
7-
# image:
8-
# repository: nginx
9-
# pullPolicy: IfNotPresent
10-
# # Overrides the image tag whose default is the chart appVersion.
11-
# tag: ""
12-
13-
# imagePullSecrets: []
14-
# nameOverride: ""
15-
# fullnameOverride: ""
16-
17-
# serviceAccount:
18-
# # Specifies whether a service account should be created
19-
# create: true
20-
# # Annotations to add to the service account
21-
# annotations: {}
22-
# # The name of the service account to use.
23-
# # If not set and create is true, a name is generated using the fullname template
24-
# name: ""
25-
26-
# podAnnotations: {}
27-
28-
# podSecurityContext: {}
29-
# # fsGroup: 2000
30-
31-
# securityContext: {}
32-
# # capabilities:
33-
# # drop:
34-
# # - ALL
35-
# # readOnlyRootFilesystem: true
36-
# # runAsNonRoot: true
37-
# # runAsUser: 1000
38-
39-
# service:
40-
# type: ClusterIP
41-
# port: 80
42-
43-
# ingress:
44-
# enabled: false
45-
# className: ""
46-
# annotations: {}
47-
# # kubernetes.io/ingress.class: nginx
48-
# # kubernetes.io/tls-acme: "true"
49-
# hosts:
50-
# - host: chart-example.local
51-
# paths:
52-
# - path: /
53-
# pathType: ImplementationSpecific
54-
# tls: []
55-
# # - secretName: chart-example-tls
56-
# # hosts:
57-
# # - chart-example.local
58-
59-
# resources: {}
60-
# # We usually recommend not to specify default resources and to leave this as a conscious
61-
# # choice for the user. This also increases chances charts run on environments with little
62-
# # resources, such as Minikube. If you do want to specify resources, uncomment the following
63-
# # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
64-
# # limits:
65-
# # cpu: 100m
66-
# # memory: 128Mi
67-
# # requests:
68-
# # cpu: 100m
69-
# # memory: 128Mi
70-
71-
# autoscaling:
72-
# enabled: false
73-
# minReplicas: 1
74-
# maxReplicas: 100
75-
# targetCPUUtilizationPercentage: 80
76-
# # targetMemoryUtilizationPercentage: 80
77-
78-
# nodeSelector: {}
79-
80-
# tolerations: []
81-
82-
# affinity: {}
1+
#baseDnsRecord: "this-is-a-test"
2+
#ingressAnnotations:
3+
# annotation1: "value1"
4+
# annotation2: "value2"

src/main.py

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,20 @@
1-
import os
21
import kopf
32
import kubernetes
4-
import yaml
53

6-
7-
def template_deployment(name, repo, branch, code_dir):
8-
path = os.path.join(os.path.dirname(__file__), "templates", 'deployment.yaml')
9-
tmpl = open(path, 'rt').read()
10-
deployment_text = tmpl.format(
11-
name=name,
12-
repo=repo,
13-
branch=branch,
14-
code_dir=code_dir
15-
)
16-
deployment_data = yaml.safe_load(deployment_text)
17-
return deployment_data
4+
from src.templating import template_deployment, template_service, template_ingress
5+
import os
6+
import yaml
7+
import logging
188

199

20-
def template_service(name):
21-
path = os.path.join(os.path.dirname(__file__), "templates", 'service.yaml')
22-
tmpl = open(path, 'rt').read()
23-
service_text = tmpl.format(
24-
name=name,
25-
)
26-
service_data = yaml.safe_load(service_text)
27-
return service_data
10+
global config
2811

12+
@kopf.on.startup()
13+
def configure(settings: kopf.OperatorSettings, **_):
14+
global config
15+
config = yaml.safe_load(open("/config/config.yaml"))
16+
logging.info(f"Loaded config: {config}")
2917

30-
def template_ingress(name):
31-
path = os.path.join(os.path.dirname(__file__), "templates", 'ingress.yaml')
32-
tmpl = open(path, 'rt').read()
33-
ingress_text = tmpl.format(
34-
name=name,
35-
)
36-
ingress_data = yaml.safe_load(ingress_text)
37-
return ingress_data
3818

3919

4020
@kopf.on.create('streamlit-apps')
@@ -63,7 +43,7 @@ def create_fn(spec, name, namespace, logger, **kwargs):
6343
kopf.adopt(service_data)
6444

6545
# Template the ingress
66-
ingress_data = template_ingress(name)
46+
ingress_data = template_ingress(name, config["baseDnsRecord"], config["ingressAnnotations"])
6747
kopf.adopt(ingress_data)
6848

6949
api = kubernetes.client.CoreV1Api()

src/start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33

44
pip install -r ./src/requirements.txt
5-
python -m kopf run ./src/main.py
5+
python -m kopf run --namespace=streamlit ./src/main.py

src/templates/deployment.yaml

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/templates/ingress.yaml

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/templates/service.yaml

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)