Skip to content

feat: limits enforcement in runtime installation #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions charts/gitops-runtime/templates/hooks/pre-install/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,48 @@ metadata:
helm.sh/hook-delete-policy: hook-succeeded,before-hook-creation,hook-failed
helm.sh/hook-weight: "-10"
{{- end }}

{{- if not .Values.installer.skipUsageValidation }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: validate-usage-cr
annotations:
helm.sh/hook: pre-install
helm.sh/hook-delete-policy: hook-succeeded,before-hook-creation,hook-failed
helm.sh/hook-weight: "5"
rules:
- apiGroups:
- ""
resources:
- secrets
verbs:
- get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: validate-usage-crb
annotations:
helm.sh/hook: pre-install
helm.sh/hook-delete-policy: hook-succeeded,before-hook-creation,hook-failed
helm.sh/hook-weight: "5"
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: validate-usage-cr
subjects:
- kind: ServiceAccount
name: validate-usage-sa
namespace: {{ .Release.Namespace }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: validate-usage-sa
annotations:
helm.sh/hook: pre-install
helm.sh/hook-delete-policy: hook-succeeded,before-hook-creation,hook-failed
helm.sh/hook-weight: "5"
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{{- if not .Values.installer.skipUsageValidation }}
apiVersion: v1
kind: ConfigMap
metadata:
name: validate-usage-config
annotations:
helm.sh/hook: pre-install
helm.sh/hook-delete-policy: hook-succeeded,before-hook-creation,hook-failed
helm.sh/hook-weight: "5"
data:
values.yaml: |
{{ .Values | toYaml | indent 4 }}

---
apiVersion: batch/v1
kind: Job
metadata:
name: validate-usage
annotations:
helm.sh/hook: pre-install
helm.sh/hook-delete-policy: hook-succeeded,before-hook-creation
helm.sh/hook-weight: "10"
spec:
backoffLimit: 0
ttlSecondsAfterFinished: 300
template:
spec:
serviceAccountName: validate-usage-sa
restartPolicy: Never
containers:
- name: validate-usage
image: "{{ .Values.installer.image.repository }}:{{ .Values.installer.image.tag | default .Chart.Version }}"
imagePullPolicy: {{ .Values.installer.image.pullPolicy }}
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
command: ["sh", "-c"]
args:
- |
cf account validate-usage --fail-condition=reached --subject=clusters --values /job_tmp/values.yaml --namespace ${NAMESPACE} --hook --log-level debug
volumeMounts:
- name: validate-usage-volume
mountPath: "/job_tmp"
volumes:
- name: validate-usage-volume
configMap:
name: validate-usage-config
{{- end }}
2 changes: 2 additions & 0 deletions charts/gitops-runtime/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ global:
installer:
# -- if set to true, pre-install hook will *not* run
skipValidation: false
# -- if set to true, pre-install hook will *not* run
skipUsageValidation: false
image:
repository: quay.io/codefresh/gitops-runtime-installer
tag: ""
Expand Down
2 changes: 1 addition & 1 deletion installer-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM debian:12.10-slim

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

ARG CF_CLI_VERSION=v0.2.6
ARG CF_CLI_VERSION=v0.2.7
ARG TARGETARCH

RUN apt-get update && apt-get install curl jq -y
Expand Down