Skip to content

Commit

Permalink
Add service for cost-tracking (hobbyfarm#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-sva authored Jan 16, 2025
1 parent 0a401da commit 6502f9f
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 0 deletions.
12 changes: 12 additions & 0 deletions charts/hobbyfarm/templates/cost-service/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: cost-config
data:
config.json: |
{{- if $.Values.cost.trackableResources }}
{{ toJson $.Values.cost.trackableResources | indent 4 }}
{{- else }}
[]
{{- end }}
75 changes: 75 additions & 0 deletions charts/hobbyfarm/templates/cost-service/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: cost-service
namespace: {{ .Release.Namespace }}
spec:
replicas: {{ $.Values.cost.replicas }}
selector:
matchLabels:
component: cost-service
template:
metadata:
labels:
component: cost-service
annotations:
checksum/secret: {{ include (print $.Template.BasePath "/tls-certificates/grpc-secret.yaml") . | sha256sum }}
spec:
serviceAccountName: {{ .Values.cost.serviceAccountName }}
containers:
- name: cost-service
image: {{ $.Values.cost.image }}
command: ["app"]
args:
- "-v=9"
- "-logtostderr"
- --enableReflection={{ .Values.general.enableReflection }}
env:
- name: LOG_LEVEL
value: {{ $.Values.cost.logLevel | quote }}
- name: HF_NAMESPACE
value: {{ .Release.Namespace | quote }}
- name: PORT
value: {{ .Values.cost.apiPort | quote }}
- name: GRPC_PORT
value: "8080"
- name: STATEFULSET_NAME
value: "cost-service"
- name: CONTROLLER_THREAD_COUNT
value: {{ .Values.cost.controllerWorkerThreadCount | quote }}
ports:
- containerPort: {{ .Values.cost.apiPort }}
- containerPort: 8080
volumeMounts:
- name: cost-secret
mountPath: "/etc/ssl/certs/ca.crt"
subPath: ca.crt
readOnly: true
- name: cost-secret
mountPath: "/etc/ssl/certs/tls.key"
subPath: tls.key
readOnly: true
- name: cost-secret
mountPath: "/etc/ssl/certs/tls.crt"
subPath: tls.crt
readOnly: true
- name: webhook-secret
mountPath: "/webhook-secret/ca.crt"
subPath: ca.crt
readOnly: true
- name: config
mountPath: "/etc/cost-config.json"
subPath: config.json
readOnly: true
volumes:
- name: cost-secret
secret:
secretName: hobbyfarm-grpc-secret
optional: false
- name: webhook-secret
secret:
secretName: hobbyfarm-webhook-secret
optional: false
- name: config
configMap:
name: cost-config
54 changes: 54 additions & 0 deletions charts/hobbyfarm/templates/cost-service/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: cost-{{ .Release.Namespace }}
rules:
- apiGroups: ["apiextensions.k8s.io"]
resources: ["customresourcedefinitions"]
verbs: ["*"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: cost-{{ .Release.Namespace }}
subjects:
- kind: ServiceAccount
namespace: {{ .Release.Namespace }}
name: {{ .Values.cost.serviceAccountName }}
roleRef:
kind: ClusterRole
name: cost-{{ .Release.Namespace }}
apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: costsvc
rules:
- apiGroups: [""]
resources: ["*"]
verbs: ["*"]
- apiGroups: ["hobbyfarm.io"]
resources: ["costs"]
verbs: ["*"]
{{- if .Values.cost.trackableResources }}
{{- range .Values.cost.trackableResources }}
- apiGroups: ["{{ .group }}"]
resources: ["{{ .resource }}"]
verbs: ["list", "watch"]
{{- end }}
{{- end }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: costsvc
subjects:
- kind: ServiceAccount
namespace: {{ .Release.Namespace }}
name: {{ .Values.cost.serviceAccountName }}
roleRef:
kind: Role
name: costsvc
apiGroup: rbac.authorization.k8s.io
13 changes: 13 additions & 0 deletions charts/hobbyfarm/templates/cost-service/service-grpc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: cost-service-grpc
namespace: {{ .Release.Namespace }}
spec:
clusterIP: None
selector:
component: cost-service
ports:
- name: grpc
protocol: TCP
port: 8080
12 changes: 12 additions & 0 deletions charts/hobbyfarm/templates/cost-service/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: cost-service
namespace: {{ .Release.Namespace }}
spec:
selector:
component: cost-service
ports:
- name: http
protocol: TCP
port: {{ .Values.cost.apiPort }}
6 changes: 6 additions & 0 deletions charts/hobbyfarm/templates/cost-service/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Values.cost.serviceAccountName }}
namespace: {{ .Release.Namespace }}
8 changes: 8 additions & 0 deletions charts/hobbyfarm/templates/gargantua/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ spec:
name: environment-service
port:
number: {{ $.Values.environment.apiPort }}
# cost-service
- pathType: Prefix
path: "/a/cost"
backend:
service:
name: cost-service
port:
number: {{ $.Values.cost.apiPort }}
# course-service
- pathType: Prefix
path: "/a/course"
Expand Down
10 changes: 10 additions & 0 deletions charts/hobbyfarm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ conversion:
containerPort: 444
servicePort: 443 # needs to remain 443, see https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/#deploy-the-conversion-webhook-servicev2
serviceAccountName: "hobbyfarm-conversion"
cost:
image: hobbyfarm/cost-service:master
replicas: 1
logLevel: "0"
apiPort: 80
serviceAccountName: "hobbyfarm-cost"
trackableResources: # add all non default kubernetes resources for cost tracking
- group: "hobbyfarm.io"
version: "v1"
resource: "virtualmachines"
course:
image: hobbyfarm/course-service:v3.2.5
replicas: 1
Expand Down

0 comments on commit 6502f9f

Please sign in to comment.