Skip to content
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

feat: add topologySpreadContraints #18

Merged
merged 1 commit into from
Sep 12, 2024
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
4 changes: 2 additions & 2 deletions charts/openbas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ _See [helm uninstall](https://helm.sh/docs/helm/helm_uninstall/) for command doc
## OpenBAS

* [Environment configuration](https://docs.openbas.io/latest/deployment/configuration/#platform)
* [Collectors](https://github.com/OpenBAS-Platform/collectors/tree/main). Review `docker-compose.yaml` with the properly config or check collectors samples on [`collector-examples`](./collector-examples) folder.
* [Injectors](https://github.com/OpenBAS-Platform/injectors/tree/main). Review `docker-compose.yaml` with the properly config or check injectors samples on [`injector-examples`](./injector-examples) folder.
* [Collectors](https://github.com/OpenBAS-Platform/collectors/tree/main). Review `docker-compose.yaml` with the properly config or check collectors samples on [`collector-examples`](./examples/collector) folder.
* [Injectors](https://github.com/OpenBAS-Platform/injectors/tree/main). Review `docker-compose.yaml` with the properly config or check injectors samples on [`injector-examples`](./examples/injector) folder.

## Basic installation and examples

Expand Down
4 changes: 2 additions & 2 deletions charts/openbas/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ _See [helm uninstall](https://helm.sh/docs/helm/helm_uninstall/) for command doc
## OpenBAS

* [Environment configuration](https://docs.openbas.io/latest/deployment/configuration/#platform)
* [Collectors](https://github.com/OpenBAS-Platform/collectors/tree/main). Review `docker-compose.yaml` with the properly config or check collectors samples on [`collector-examples`](./collector-examples) folder.
* [Injectors](https://github.com/OpenBAS-Platform/injectors/tree/main). Review `docker-compose.yaml` with the properly config or check injectors samples on [`injector-examples`](./injector-examples) folder.
* [Collectors](https://github.com/OpenBAS-Platform/collectors/tree/main). Review `docker-compose.yaml` with the properly config or check collectors samples on [`collector-examples`](./examples/collector) folder.
* [Injectors](https://github.com/OpenBAS-Platform/injectors/tree/main). Review `docker-compose.yaml` with the properly config or check injectors samples on [`injector-examples`](./examples/injector) folder.

## Basic installation and examples

Expand Down
38 changes: 38 additions & 0 deletions charts/openbas/ci/ci-common-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ podDisruptionBudget:
autoscaling:
enabled: true

secrets:
OPENBAS_ADMIN_TOKEN: "b1976749-8a53-4f49-bf04-cafa2a3458c1"
OPENBAS_RABBITMQ_PASS: ChangeMe

envFromSecrets:
OPENBAS_ADMIN_TOKEN:
name: openbas-ci-credentials
key: OPENBAS_ADMIN_TOKEN
OPENBAS_TOKEN:
name: openbas-ci-credentials
key: OPENBAS_TOKEN
OPENBAS_RABBITMQ_PASS:
name: openbas-ci-credentials
key: OPENBAS_RABBITMQ_PASS

caldera:
enabled: true

Expand Down Expand Up @@ -109,6 +124,11 @@ caldera:
autoscaling:
enabled: true

topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/os
whenUnsatisfiable: DoNotSchedule

collectors:
- name: atomic-red-team
enabled: true
Expand Down Expand Up @@ -137,6 +157,14 @@ collectors:
COLLECTOR_ID: e668aa07-e1a3-41d8-8748-786be5df9dab
COLLECTOR_NAME: "Atomic Red Team"
COLLECTOR_LOG_LEVEL: error
envFromSecrets:
OPENBAS_TOKEN:
name: openbas-ci-credentials
key: OPENBAS_TOKEN
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/os
whenUnsatisfiable: DoNotSchedule

injectors:
- name: http-query
Expand Down Expand Up @@ -164,6 +192,14 @@ injectors:
INJECTOR_ID: e668aa07-e1a3-41d8-8748-786be5df9dab
INJECTOR_NAME: "HTTP query"
INJECTOR_LOG_LEVEL: error
envFromSecrets:
OPENBAS_TOKEN:
name: openbas-ci-credentials
key: OPENBAS_TOKEN
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/os
whenUnsatisfiable: DoNotSchedule

minio:
fullnameOverride: openbas-ci-minio
Expand All @@ -184,6 +220,8 @@ postgresql:
rabbitmq:
fullnameOverride: openbas-ci-rabbitmq
auth:
existingPasswordSecret: openbas-ci-credentials
existingSecretPasswordKey: OPENBAS_RABBITMQ_PASS
erlangCookie: b25c953e-2193-4b8e-9f3b-9a3a5ba76d75
clustering:
enabled: false
Expand Down
106 changes: 106 additions & 0 deletions charts/openbas/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,109 @@ Create the name of the service account to use
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
#######################
SERVER SECTION
#######################
*/}}

{{/*
Default server component
*/}}
{{- define "openbas.serverComponentLabel" -}}
openbas.component: server
{{- end -}}

{{/*
Generate labels for server component
*/}}
{{- define "openbas.serverLabels" -}}
{{- toYaml (merge ((include "openbas.labels" .) | fromYaml) ((include "openbas.serverComponentLabel" .) | fromYaml)) }}
{{- end }}

{{/*
Generate selectorLabels for server component
*/}}
{{- define "openbas.selectorServerLabels" -}}
{{- toYaml (merge ((include "openbas.selectorLabels" .) | fromYaml) ((include "openbas.serverComponentLabel" .) | fromYaml)) }}
{{- end }}

{{/*
Ref: https://github.com/aws/karpenter-provider-aws/blob/main/charts/karpenter/templates/_helpers.tpl
Patch the label selector on an object
This template will add a labelSelector using matchLabels to the object referenced at _target if there is no labelSelector specified.
The matchLabels are created with the selectorLabels template.
This works because Helm treats dictionaries as mutable objects and allows passing them by reference.
*/}}
{{- define "openbas.patchSelectorServerLabels" -}}
{{- if not (hasKey ._target "labelSelector") }}
{{- $selectorLabels := (include "openbas.selectorServerLabels" .) | fromYaml }}
{{- $_ := set ._target "labelSelector" (dict "matchLabels" $selectorLabels) }}
{{- end }}
{{- end }}

{{/*
Ref: https://github.com/aws/karpenter-provider-aws/blob/main/charts/karpenter/templates/_helpers.tpl
Patch topology spread constraints
This template uses the openbas.selectorLabels template to add a labelSelector to topologySpreadConstraints if one isn't specified.
This works because Helm treats dictionaries as mutable objects and allows passing them by reference.
*/}}
{{- define "openbas.patchTopologySpreadConstraintsServer" -}}
{{- range $constraint := .Values.topologySpreadConstraints }}
{{- include "openbas.patchSelectorServerLabels" (merge (dict "_target" $constraint (include "openbas.selectorServerLabels" $)) $) }}
{{- end }}
{{- end }}
{{/*
#######################
CALDERA SECTION
#######################
*/}}
{{/*
Default caldera component
*/}}
{{- define "openbas.calderaComponentLabel" -}}
openbas.component: caldera
{{- end -}}
{{/*
Generate labels for caldera component
*/}}
{{- define "openbas.calderaLabels" -}}
{{- toYaml (merge ((include "openbas.labels" .) | fromYaml) ((include "openbas.calderaComponentLabel" .) | fromYaml)) }}
{{- end }}
{{/*
Generate selectorLabels for caldera component
*/}}
{{- define "openbas.selectorCalderaLabels" -}}
{{- toYaml (merge ((include "openbas.selectorLabels" .) | fromYaml) ((include "openbas.calderaComponentLabel" .) | fromYaml)) }}
{{- end }}
{{/*
Ref: https://github.com/aws/karpenter-provider-aws/blob/main/charts/karpenter/templates/_helpers.tpl
Patch the label selector on an object
This template will add a labelSelector using matchLabels to the object referenced at _target if there is no labelSelector specified.
The matchLabels are created with the selectorLabels template.
This works because Helm treats dictionaries as mutable objects and allows passing them by reference.
*/}}
{{- define "openbas.patchSelectorCalderaLabels" -}}
{{- if not (hasKey ._target "labelSelector") }}
{{- $selectorLabels := (include "openbas.selectorCalderaLabels" .) | fromYaml }}
{{- $_ := set ._target "labelSelector" (dict "matchLabels" $selectorLabels) }}
{{- end }}
{{- end }}
{{/*
Ref: https://github.com/aws/karpenter-provider-aws/blob/main/charts/karpenter/templates/_helpers.tpl
Patch topology spread constraints
This template uses the openbas.selectorLabels template to add a labelSelector to topologySpreadConstraints if one isn't specified.
This works because Helm treats dictionaries as mutable objects and allows passing them by reference.
*/}}
{{- define "openbas.patchTopologySpreadConstraintsCaldera" -}}
{{- range $constraint := .Values.caldera.topologySpreadConstraints }}
{{- include "openbas.patchSelectorCalderaLabels" (merge (dict "_target" $constraint (include "openbas.selectorCalderaLabels" $)) $) }}
{{- end }}
{{- end }}
3 changes: 1 addition & 2 deletions charts/openbas/templates/caldera/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ kind: ConfigMap
metadata:
name: {{ include "openbas.fullname" . }}-caldera-config
labels:
openbas.component: caldera
{{- include "openbas.labels" . | nindent 4 }}
{{- include "openbas.calderaLabels" . | nindent 4 }}
data:
local.yml: |
{{- .Values.caldera.config | toYaml | nindent 4 }}
14 changes: 8 additions & 6 deletions charts/openbas/templates/caldera/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ kind: Deployment
metadata:
name: {{ include "openbas.fullname" . }}-caldera
labels:
openbas.component: caldera
{{- include "openbas.labels" . | nindent 4 }}
{{- include "openbas.calderaLabels" . | nindent 4 }}
spec:
{{- if not .Values.caldera.autoscaling.enabled }}
replicas: {{ .Values.caldera.replicaCount }}
{{- end }}
selector:
matchLabels:
openbas.component: caldera
{{- include "openbas.selectorLabels" . | nindent 6 }}
{{- include "openbas.selectorCalderaLabels" . | nindent 6 }}
template:
metadata:
annotations:
Expand All @@ -22,8 +20,7 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
openbas.component: caldera
{{- include "openbas.selectorLabels" . | nindent 8 }}
{{- include "openbas.selectorCalderaLabels" . | nindent 8 }}
{{- with .Values.caldera.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -112,4 +109,9 @@ spec:
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.caldera.topologySpreadConstraints }}
{{- $_ := include "openbas.patchTopologySpreadConstraintsCaldera" $ }}
topologySpreadConstraints:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
3 changes: 1 addition & 2 deletions charts/openbas/templates/caldera/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ kind: HorizontalPodAutoscaler
metadata:
name: {{ include "openbas.fullname" . }}-caldera
labels:
openbas.component: caldera
{{- include "openbas.labels" . | nindent 4 }}
{{- include "openbas.calderaLabels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
Expand Down
6 changes: 2 additions & 4 deletions charts/openbas/templates/caldera/networkpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ kind: NetworkPolicy
metadata:
name: {{ include "openbas.fullname" . }}-caldera
labels:
openbas.component: caldera
{{- include "openbas.labels" . | nindent 4 }}
{{- include "openbas.calderaLabels" . | nindent 4 }}
spec:
{{- if and (not .Values.caldera.networkPolicy.policyTypes) (not .Values.caldera.networkPolicy.ingress) (not .Values.caldera.networkPolicy.egress) }}
podSelector: {}
{{- else }}
podSelector:
matchLabels:
openbas.component: caldera
{{- include "openbas.selectorLabels" . | nindent 6 }}
{{- include "openbas.selectorCalderaLabels" . | nindent 6 }}
{{- end }}

{{- if .Values.caldera.networkPolicy.policyTypes }}
Expand Down
6 changes: 2 additions & 4 deletions charts/openbas/templates/caldera/pdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ kind: PodDisruptionBudget
metadata:
name: {{ include "openbas.fullname" . }}-caldera
labels:
openbas.component: caldera
{{- include "openbas.labels" . | nindent 4 }}
{{- include "openbas.calderaLabels" . | nindent 4 }}
spec:
selector:
matchLabels:
openbas.component: caldera
{{- include "openbas.selectorLabels" . | nindent 6 }}
{{- include "openbas.selectorCalderaLabels" . | nindent 6 }}
{{- if .Values.caldera.podDisruptionBudget.minAvailable }}
minAvailable: {{ .Values.caldera.podDisruptionBudget.minAvailable }}
{{- end }}
Expand Down
6 changes: 2 additions & 4 deletions charts/openbas/templates/caldera/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ kind: Service
metadata:
name: {{ include "openbas.fullname" . }}-caldera
labels:
openbas.component: caldera
{{- include "openbas.labels" . | nindent 4 }}
{{- include "openbas.calderaLabels" . | nindent 4 }}
spec:
type: {{ .Values.caldera.service.type }}
ports:
Expand All @@ -13,5 +12,4 @@ spec:
protocol: TCP
name: http
selector:
openbas.component: caldera
{{- include "openbas.selectorLabels" . | nindent 4 }}
{{- include "openbas.selectorCalderaLabels" . | nindent 4 }}
10 changes: 10 additions & 0 deletions charts/openbas/templates/collector/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ spec:
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .topologySpreadConstraints }}
topologySpreadConstraints:
{{- range $constraint := . }}
- labelSelector:
matchLabels:
openbas.collector: {{ $collectorName }}
{{- include "openbas.selectorLabels" $ | nindent 14 }}
{{- toYaml $constraint | nindent 10 }}
{{- end }}
{{- end }}

{{- end }}
{{- end }}
10 changes: 10 additions & 0 deletions charts/openbas/templates/injector/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ spec:
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .topologySpreadConstraints }}
topologySpreadConstraints:
{{- range $constraint := . }}
- labelSelector:
matchLabels:
openbas.injector: {{ $injectorName }}
{{- include "openbas.selectorLabels" $ | nindent 14 }}
{{- toYaml $constraint | nindent 10 }}
{{- end }}
{{- end }}

{{- end }}
{{- end }}
14 changes: 8 additions & 6 deletions charts/openbas/templates/server/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@ kind: Deployment
metadata:
name: {{ include "openbas.fullname" . }}-server
labels:
openbas.component: server
{{- include "openbas.labels" . | nindent 4 }}
{{- include "openbas.serverLabels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
openbas.component: server
{{- include "openbas.selectorLabels" . | nindent 6 }}
{{- include "openbas.selectorServerLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
openbas.component: server
{{- include "openbas.selectorLabels" . | nindent 8 }}
{{- include "openbas.selectorServerLabels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -175,3 +172,8 @@ spec:
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.topologySpreadConstraints }}
{{- $_ := include "openbas.patchTopologySpreadConstraintsServer" $ }}
topologySpreadConstraints:
{{- toYaml . | nindent 8 }}
{{- end }}
3 changes: 1 addition & 2 deletions charts/openbas/templates/server/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ kind: HorizontalPodAutoscaler
metadata:
name: {{ include "openbas.fullname" . }}-server
labels:
openbas.component: server
{{- include "openbas.labels" . | nindent 4 }}
{{- include "openbas.serverLabels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
Expand Down
Loading
Loading