Skip to content

Commit c26b05c

Browse files
feat: limits enforcement in runtime installation (#457)
1 parent db1afc7 commit c26b05c

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

charts/gitops-runtime/templates/hooks/pre-install/rbac.yaml

+45
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,48 @@ metadata:
4141
helm.sh/hook-delete-policy: hook-succeeded,before-hook-creation,hook-failed
4242
helm.sh/hook-weight: "-10"
4343
{{- end }}
44+
45+
{{- if not .Values.installer.skipUsageValidation }}
46+
---
47+
apiVersion: rbac.authorization.k8s.io/v1
48+
kind: ClusterRole
49+
metadata:
50+
name: validate-usage-cr
51+
annotations:
52+
helm.sh/hook: pre-install
53+
helm.sh/hook-delete-policy: hook-succeeded,before-hook-creation,hook-failed
54+
helm.sh/hook-weight: "5"
55+
rules:
56+
- apiGroups:
57+
- ""
58+
resources:
59+
- secrets
60+
verbs:
61+
- get
62+
---
63+
apiVersion: rbac.authorization.k8s.io/v1
64+
kind: ClusterRoleBinding
65+
metadata:
66+
name: validate-usage-crb
67+
annotations:
68+
helm.sh/hook: pre-install
69+
helm.sh/hook-delete-policy: hook-succeeded,before-hook-creation,hook-failed
70+
helm.sh/hook-weight: "5"
71+
roleRef:
72+
apiGroup: rbac.authorization.k8s.io
73+
kind: ClusterRole
74+
name: validate-usage-cr
75+
subjects:
76+
- kind: ServiceAccount
77+
name: validate-usage-sa
78+
namespace: {{ .Release.Namespace }}
79+
---
80+
apiVersion: v1
81+
kind: ServiceAccount
82+
metadata:
83+
name: validate-usage-sa
84+
annotations:
85+
helm.sh/hook: pre-install
86+
helm.sh/hook-delete-policy: hook-succeeded,before-hook-creation,hook-failed
87+
helm.sh/hook-weight: "5"
88+
{{- end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{{- if not .Values.installer.skipUsageValidation }}
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: validate-usage-config
6+
annotations:
7+
helm.sh/hook: pre-install
8+
helm.sh/hook-delete-policy: hook-succeeded,before-hook-creation,hook-failed
9+
helm.sh/hook-weight: "5"
10+
data:
11+
values.yaml: |
12+
{{ .Values | toYaml | indent 4 }}
13+
14+
---
15+
apiVersion: batch/v1
16+
kind: Job
17+
metadata:
18+
name: validate-usage
19+
annotations:
20+
helm.sh/hook: pre-install
21+
helm.sh/hook-delete-policy: hook-succeeded,before-hook-creation
22+
helm.sh/hook-weight: "10"
23+
spec:
24+
backoffLimit: 0
25+
ttlSecondsAfterFinished: 300
26+
template:
27+
spec:
28+
serviceAccountName: validate-usage-sa
29+
restartPolicy: Never
30+
containers:
31+
- name: validate-usage
32+
image: "{{ .Values.installer.image.repository }}:{{ .Values.installer.image.tag | default .Chart.Version }}"
33+
imagePullPolicy: {{ .Values.installer.image.pullPolicy }}
34+
env:
35+
- name: NAMESPACE
36+
valueFrom:
37+
fieldRef:
38+
fieldPath: metadata.namespace
39+
command: ["sh", "-c"]
40+
args:
41+
- |
42+
cf account validate-usage --fail-condition=reached --subject=clusters --values /job_tmp/values.yaml --namespace ${NAMESPACE} --hook --log-level debug
43+
volumeMounts:
44+
- name: validate-usage-volume
45+
mountPath: "/job_tmp"
46+
volumes:
47+
- name: validate-usage-volume
48+
configMap:
49+
name: validate-usage-config
50+
{{- end }}

charts/gitops-runtime/values.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ global:
177177
installer:
178178
# -- if set to true, pre-install hook will *not* run
179179
skipValidation: false
180+
# -- if set to true, pre-install hook will *not* run
181+
skipUsageValidation: false
180182
image:
181183
repository: quay.io/codefresh/gitops-runtime-installer
182184
tag: ""

installer-image/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ FROM debian:12.10-slim
88

99
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
1010

11-
ARG CF_CLI_VERSION=v0.2.6
11+
ARG CF_CLI_VERSION=v0.2.7
1212
ARG TARGETARCH
1313

1414
RUN apt-get update && apt-get install curl jq -y

0 commit comments

Comments
 (0)