1
0
Fork 0
forked from infra/ansible

communishift: Disable project playbook

Signed-off-by: David Kirwan <davidkirwanirl@gmail.com>
This commit is contained in:
David Kirwan 2026-05-06 19:57:55 +01:00
commit e4321ec9c3
Signed by untrusted user: dkirwan
GPG key ID: A5893AB6474AC37D
7 changed files with 653 additions and 36 deletions

View file

@ -1,7 +1,13 @@
---
# Communishift project disable / shutdown path (inventory + per-project eligibility).
# Uses communishift_projects and each entry's do_not_delete to skip exempt namespaces.
# Currently logs intent; scale-to-zero in the role is still commented out.
# Uses communishift_projects from inventory (e.g. inventory/group_vars/all) and each
# entry's do_not_delete to skip exempt namespaces.
#
# Default: report only (no API scale). To apply scale-to-zero on eligible namespaces:
# ansible-playbook .../communishift_disable_project.yml --tags communishift_disable_project \
# -e communishift_disable_shutdown=true
#
# Run with an inventory that merges group_vars/all so communishift_projects is defined.
#
# Run disable tasks only:
# ansible-playbook .../communishift_disable_project.yml --tags communishift_disable_project
@ -15,9 +21,21 @@
- "/srv/private/ansible/vars.yml"
- /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml
pre_tasks:
- name: Require communishift_projects from inventory
ansible.builtin.assert:
that:
- communishift_projects is defined
- communishift_projects is mapping
fail_msg: >
communishift_projects is missing. Run with an inventory that loads
inventory/group_vars/all (e.g. ansible-playbook -i path/to/inventory ...).
tags:
- always
tasks:
- name: Communishift project shutdown (eligible projects)
include_role:
ansible.builtin.include_role:
name: communishift
tasks_from: cleanup-administration-shutdown-services
apply:

View file

@ -1,35 +1,116 @@
---
- name: Check if this project should be deleted
- name: Set Communishift shutdown context for this project
ansible.builtin.set_fact:
should_not_delete: "{{ item.value.do_not_delete | default(false) }}"
communishift_namespace: "{{ item.value.name }}"
communishift_protected: "{{ item.value.do_not_delete | default(false) | bool }}"
- name: Debug
debug:
msg: "Project {{ item.value.name }} marked for shutdown"
when: "not should_not_delete"
- name: Skip shutdown for protected Communishift project
ansible.builtin.debug:
msg: "Skipping {{ communishift_namespace }} (do_not_delete is true)"
when: communishift_protected | bool
- name: Report eligible project (dry run, no API scale)
ansible.builtin.debug:
msg: >-
Would scale workloads to 0 in {{ communishift_namespace }}
(use -e communishift_disable_shutdown=true to apply).
when:
- not (communishift_protected | bool)
- not (communishift_disable_shutdown | default(false) | bool)
- name: Scale down workloads in eligible Communishift namespace
when:
- not (communishift_protected | bool)
- communishift_disable_shutdown | default(false) | bool
block:
- name: List Deployments
kubernetes.core.k8s_info:
api_key: "{{ communishift_ocp_api_token }}"
host: "{{ communishift_ocp_api_host }}"
api_version: apps/v1
kind: Deployment
namespace: "{{ communishift_namespace }}"
register: communishift_deployments
#- name: Loop over each project and scale its deployments to 0
# block:
# - name: Get list of deployments in the current project
# kubernetes.core.k8s_info:
# kind: Deployment
# api_version: apps/v1
# namespace: "{{ item }}"
# register: deployment_list
# loop: "{{ projects_list }}"
#
# - name: Scale each deployment to 0 replicas
# kubernetes.core.k8s_scale:
# api_version: apps/v1
# kind: Deployment
# name: "{{ dep.metadata.name }}"
# namespace: "{{ item.item }}" # item.item is the project from the outer loop
# replicas: 0
# wait: true # Optional: wait for scale to complete
# loop: "{{ deployment_list.results | selectattr('resources', 'defined') | map(attribute='resources') | flatten }}"
# loop_control:
# loop_var: dep
# when: deployment_list.results is defined and deployment_list.results | length > 0
# when: projects_list is defined and projects_list | length > 0
- name: Scale Deployments to zero
kubernetes.core.k8s_scale:
api_key: "{{ communishift_ocp_api_token }}"
host: "{{ communishift_ocp_api_host }}"
api_version: apps/v1
kind: Deployment
name: "{{ scale_target.metadata.name }}"
namespace: "{{ communishift_namespace }}"
replicas: 0
wait: true
loop: "{{ communishift_deployments.resources | default([]) }}"
loop_control:
loop_var: scale_target
- name: List DeploymentConfigs
kubernetes.core.k8s_info:
api_key: "{{ communishift_ocp_api_token }}"
host: "{{ communishift_ocp_api_host }}"
api_version: apps.openshift.io/v1
kind: DeploymentConfig
namespace: "{{ communishift_namespace }}"
register: communishift_deploymentconfigs
- name: Scale DeploymentConfigs to zero
kubernetes.core.k8s_scale:
api_key: "{{ communishift_ocp_api_token }}"
host: "{{ communishift_ocp_api_host }}"
api_version: apps.openshift.io/v1
kind: DeploymentConfig
name: "{{ scale_target.metadata.name }}"
namespace: "{{ communishift_namespace }}"
replicas: 0
wait: true
loop: "{{ communishift_deploymentconfigs.resources | default([]) }}"
loop_control:
loop_var: scale_target
- name: List StatefulSets
kubernetes.core.k8s_info:
api_key: "{{ communishift_ocp_api_token }}"
host: "{{ communishift_ocp_api_host }}"
api_version: apps/v1
kind: StatefulSet
namespace: "{{ communishift_namespace }}"
register: communishift_statefulsets
- name: Scale StatefulSets to zero
kubernetes.core.k8s_scale:
api_key: "{{ communishift_ocp_api_token }}"
host: "{{ communishift_ocp_api_host }}"
api_version: apps/v1
kind: StatefulSet
name: "{{ scale_target.metadata.name }}"
namespace: "{{ communishift_namespace }}"
replicas: 0
wait: true
loop: "{{ communishift_statefulsets.resources | default([]) }}"
loop_control:
loop_var: scale_target
- name: List DaemonSets
kubernetes.core.k8s_info:
api_key: "{{ communishift_ocp_api_token }}"
host: "{{ communishift_ocp_api_host }}"
api_version: apps/v1
kind: DaemonSet
namespace: "{{ communishift_namespace }}"
register: communishift_daemonsets
- name: Scale DaemonSets to zero
kubernetes.core.k8s_scale:
api_key: "{{ communishift_ocp_api_token }}"
host: "{{ communishift_ocp_api_host }}"
api_version: apps/v1
kind: DaemonSet
name: "{{ scale_target.metadata.name }}"
namespace: "{{ communishift_namespace }}"
replicas: 0
wait: true
loop: "{{ communishift_daemonsets.resources | default([]) }}"
loop_control:
loop_var: scale_target

View file

@ -0,0 +1,28 @@
---
- name: Generate the zabbix-values.yaml from template
ansible.builtin.template:
src: "values.yaml.j2"
dest: "/root/ocp4/openshift-apps/zabbix-proxy/zabbix-values.yaml"
mode: "0770"
- name: Git clone the Zabbix Helm Chart
ansible.builtin.git:
repo: "https://codeberg.org/fedora/forgejo-helm.git"
dest: /tmp/zabbix-kubernetes-helm
- name: Build Helm chart dependencies
ansible.builtin.command:
cmd: helm dependency update
chdir: /tmp/zabbix-kubernetes-helm/
changed_when: true
- name: Deploy Forgejo chart from local path
kubernetes.core.helm:
name: zabbix
create_namespace: true
chart_ref: /tmp/zabbix-kubernetes-helm/
release_name: zabbix
release_namespace: zabbix
values_files:
- "/root/ocp4/openshift-apps/zabbix-proxy/zabbix-values.yaml"

View file

@ -0,0 +1,11 @@
---
- name: Generate the zabbix-proxy-namespace.yaml from template
ansible.builtin.template:
src: "zabbix-proxy-namespace.yaml.j2"
dest: "/root/ocp4/openshift-apps/zabbix-proxy/zabbix-proxy-namespace.yaml"
mode: "0770"
- name: Deploy the zabbix-proxy-namespace.yaml config
kubernetes.core.k8s:
state: present
src: "/root/ocp4/openshift-apps/zabbix-proxy/zabbix-proxy-namespace.yaml"

View file

@ -0,0 +1,8 @@
---
- name: Ensures /root/ocp4/openshift-apps/zabbix-proxy/ dir exists
ansible.builtin.file:
path: "/root/ocp4/openshift-apps/zabbix-proxy/"
state: directory
- include_tasks: create-zabbix-proxy-namespace.yaml
- include_tasks: call-helm.yaml

View file

@ -0,0 +1,5 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: "dist-git"

View file

@ -0,0 +1,466 @@
## nameOverride -- Override name of app
nameOverride: ""
## fullnameOverride -- Override the full qualified app name
fullnameOverride: ""
## kubeStateMetrics.enabled -- If true, deploys the kube-state-metrics deployment
kubeStateMetrics:
enabled: true
## Service account for Kubernetes API
rbac:
## rbac.create Specifies whether the RBAC resources should be created
create: true
additionalRulesForClusterRole: []
## - apiGroups: [ "" ]
## resources:
## - nodes/proxy
## verbs: [ "get", "list", "watch" ]
serviceAccount:
## serviceAccount.create Specifies whether a service account should be created
create: true
## serviceAccount.name The name of the service account to use. If not set name is generated using the fullname template
name: ""
## **Zabbix proxy** configurations
zabbixProxy:
## Enable use of **Zabbix proxy**
enabled: true
securityContext:
runAsNonRoot: false # Must be false because agent often needs root for host access
# runAsUser: 0 # Explicit root if needed (default is often root)
# fsGroup: 0 # Optional
# Container-level securityContext
containerSecurityContext:
allowPrivilegeEscalation: false # Satisfies one violation (safe to set false)
privileged: false # Ensure not privileged (chart probably doesn't set it)
capabilities:
drop:
- ALL # Drop all extra caps (helps restricted)
seccompProfile:
type: RuntimeDefault # Or "Localhost" if you have a profile
# runAsNonRoot: false # Usually pod-level overrides, but can duplicate
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container
resources: {}
image:
## Zabbix proxy Docker image name
repository: zabbix/zabbix-proxy-sqlite3
## Tag of Docker image of Zabbix proxy
tag: alpine-7.0.17
pullPolicy: IfNotPresent
## List of dockerconfig secrets names to use when pulling images. Secrets must be manually created in the namespace.
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
## https://kubernetes.io/docs/concepts/containers/images/#using-a-private-registry
pullSecrets: []
env:
## The variable allows to switch Zabbix proxy mode. By default, value is 0 - active proxy. Allowed values are 0 and 1.
- name: ZBX_PROXYMODE
value: 0
## Zabbix proxy hostname
- name: ZBX_HOSTNAME
value: openshift-cluster-proxy
## Zabbix server host
## If ProxyMode is set to active mode:
## IP address or DNS name of Zabbix server to get configuration data from and send data to.
## If ProxyMode is set to passive mode:
## List of comma delimited IP addresses, optionally in CIDR notation, or DNS names of Zabbix server. Incoming connections will be accepted only from the addresses listed here. If IPv6 support is enabled then '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' are treated equally and '::/0' will allow any IPv4 or IPv6 address. '0.0.0.0/0' can be used to allow any IPv4 address.
## Example: Server=127.0.0.1,192.168.1.0/24,::1,2001:db8::/32,zabbix.example.com
## Note that since version 6.0 the variable ZBX_SERVER_PORT is not supported anymore. Instead, add a colon (:) followed by the port number to the end of ZBX_SERVER_HOST value.
- name: ZBX_SERVER_HOST
value: "zabbix01.stg.rdu3.fedoraproject.org:10051"
## Security settings
#- name: ZBX_TLSCONNECT
# value: "psk"
- name: ZBX_TLSACCEPT
value: "unencrypted,psk"
- name: ZBX_TLSPSKIDENTITY
value: "Fedora"
## The variable is used to specify debug level. By default, value is 3
- name: ZBX_DEBUGLEVEL
value: 3
## Cache size
- name: ZBX_CACHESIZE
value: 128M
## This variable is specified amount of pre-forked instances of Java pollers. By default, value is 0. If zabbixJavaGateway enable value is 5.
- name: ZBX_STARTJAVAPOLLERS
value: 0
## How often the proxy retrieves configuration data from Zabbix server in seconds. Active proxy parameter. Ignored for passive proxies.
- name: ZBX_PROXYCONFIGFREQUENCY
value: 10
## List can be extended with other environment variables listed here: https://github.com/zabbix/zabbix-docker/tree/7.0/Dockerfiles/proxy-sqlite3#other-variables
## For example:
## The variable is list of comma separated loadable Zabbix modules.
## - name: ZBX_LOADMODULE
## value : dummy1.so,dummy2.so
## The startupProbe, livenessProbe, readinessProbe variables
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
livenessProbe:
enabled: true
tcpSocket:
port: zabbix-proxy
initialDelaySeconds: 10
timeoutSeconds: 3
failureThreshold: 3
periodSeconds: 10
successThreshold: 1
readinessProbe:
enabled: false
tcpSocket:
port: zabbix-proxy
initialDelaySeconds: 10
timeoutSeconds: 3
failureThreshold: 3
periodSeconds: 10
successThreshold: 1
startupProbe:
enabled: true
tcpSocket:
port: zabbix-proxy
initialDelaySeconds: 30
timeoutSeconds: 3
failureThreshold: 5
periodSeconds: 10
successThreshold: 1
service:
annotations: {}
labels: {}
## Type of service for Zabbix proxy
type: ClusterIP
## Port to expose service
port: 10051
## Port of application pod
targetPort: 10051
## Zabbix proxy Ingress externalIPs with optional path
## Ref: https://kubernetes.io/docs/user-guide/services/#external-ips
## Must be provided if ProxyMode is set to passive mode
externalIPs: []
## Loadbalancer IP
## Only use if service.type is "LoadBalancer"
loadBalancerIP: ""
loadBalancerSourceRanges: []
## Node selector for Zabbix proxy
nodeSelector: {}
## Tolerations configuration for Zabbix proxy
tolerations: {}
## Affinity configuration for Zabbix proxy
affinity: {}
persistentVolume:
## If true, Zabbix proxy will create/use a Persistent Volume Claim
##
enabled: true
## Zabbix proxy data Persistent Volume access modes
## Must match those of existing PV or dynamic provisioner
## Ref: http://kubernetes.io/docs/user-guide/persistent-volumes/
##
accessModes:
- ReadWriteOnce
## Zabbix proxy data Persistent Volume Claim annotations
##
annotations: {}
## Zabbix proxy data Persistent Volume existing claim name
## Requires zabbixProxy.persistentVolume.enabled: true
## If defined, PVC must be created manually before volume will be bound
existingClaim: "zabbix-zabbix-helm-chart-proxy"
## Zabbix proxy data Persistent Volume mount root path
##
mountPath: /data
## Zabbix proxy data Persistent Volume size
##
size: 2Gi
## Zabbix proxy data Persistent Volume Storage Class
## If defined, storageClassName: <storageClass>
## If set to "-", storageClassName: "", which disables dynamic provisioning
## If undefined (the default) or set to null, no storageClassName spec is
## set, choosing the default provisioner. (gp2 on AWS, standard on
## GKE, AWS & OpenStack)
##
storageClass: "ocs-storagecluster-ceph-rbd"
## Zabbix proxy data Persistent Volume Binding Mode
## If defined, volumeBindingMode: <volumeBindingMode>
## If undefined (the default) or set to null, no volumeBindingMode spec is
## set, choosing the default mode.
##
volumeBindingMode: ""
## Subdirectory of Zabbix proxy data Persistent Volume to mount
## Useful if the volume's root directory is not empty
##
subPath: ""
## **Zabbix agent** configurations
zabbixAgent:
## Enable use of Zabbix agent
enabled: true
## Set resource requests/limits for Zabbix agents
resources: {}
## requests:
## cpu: 100m
## memory: 54Mi
## limits:
## cpu: 100m
## memory: 54Mi
securityContext:
runAsNonRoot: true # Must be false because agent often needs root for host access
# runAsUser: 0 # Explicit root if needed (default is often root)
# fsGroup: 0 # Optional
# fsGroup: 65534
# runAsGroup: 65534
# runAsNonRoot: true
# runAsUser: 65534
containerSecurityContext:
allowPrivilegeEscalation: false # Satisfies one violation (safe to set false)
privileged: false # Ensure not privileged (chart probably doesn't set it)
capabilities:
drop:
- ALL # Drop all extra caps (helps restricted)
seccompProfile:
type: RuntimeDefault # Or "Localhost" if you have a profile
# runAsNonRoot: false # Usually pod-level overrides, but can duplicate
## capabilities:
## add:
## - SYS_TIME
## Expose the service to the host network
hostNetwork: true
# Specify dns configuration options for agent containers e.g ndots
## ref: https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-dns-config
dnsConfig: {}
# options:
# - name: ndots
# value: "1"
## Share the host process ID namespace
hostPID: true
## If true, agent pods mounts host / at /host/root
##
hostRootFsMount: true
extraHostVolumeMounts: []
## - name: <mountName>
## hostPath: <hostPath>
## mountPath: <mountPath>
## readOnly: true|false
## mountPropagation: None|HostToContainer|Bidirectional
image:
## Zabbix agent Docker image name
repository: zabbix/zabbix-agent2
## Tag of Docker image of Zabbix agent
tag: alpine-7.0.17
pullPolicy: IfNotPresent
## List of dockerconfig secrets names to use when pulling images. Secrets must be manually created in the namespace.
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
## https://kubernetes.io/docs/concepts/containers/images/#using-a-private-registry
pullSecrets: []
env:
## Zabbix server host
- name: ZBX_SERVER_HOST
value: zabbix01.stg.rdu3.fedoraproject.org
## Zabbix server port
- name: ZBX_SERVER_PORT
value: 10051
## This variable is boolean (true or false) and enables or disables feature of passive checks. By default, value is true
- name: ZBX_PASSIVE_ALLOW
value: true
## This variable is boolean (true or false) and enables or disables feature of active checks
- name: ZBX_ACTIVE_ALLOW
value: false
## The variable is used to specify debug level, from 0 to 5
- name: ZBX_DEBUGLEVEL
value: 3
## The variable is used to specify timeout for processing checks. By default, value is 4.
- name: ZBX_TIMEOUT
value: 4
## List can be extended with other environment variables listed here: https://github.com/zabbix/zabbix-docker/tree/7.0/Dockerfiles/agent2/alpine#other-variables
## For example:
## The variable is comma separated list of allowed Zabbix server or proxy hosts for connections to Zabbix agent 2 container. You may specify port of Zabbix server or Zabbix proxy in such syntax: zabbix-server:10061,zabbix-proxy:10072
## - name: ZBX_ACTIVESERVERS
## value: ''
## The variable is comma separated list of allowed Zabbix server or proxy hosts for connections to Zabbix agent 2 container.
## - name: ZBX_PASSIVESERVERS
## value: 0.0.0.0/0
## The variable is list of comma separated loadable Zabbix modules. It works with volume /var/lib/zabbix/modules.
## - name: ZBX_LOADMODULE
## value: ''
## The startupProbe, livenessProbe, readinessProbe variables
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
livenessProbe:
enabled: true
tcpSocket:
port: zabbix-agent
initialDelaySeconds: 10
timeoutSeconds: 3
failureThreshold: 3
periodSeconds: 10
successThreshold: 1
readinessProbe:
enabled: false
tcpSocket:
port: zabbix-agent
initialDelaySeconds: 10
timeoutSeconds: 3
failureThreshold: 3
periodSeconds: 10
successThreshold: 1
startupProbe:
enabled: true
tcpSocket:
port: zabbix-agent
initialDelaySeconds: 10
periodSeconds: 5
timeoutSeconds: 3
failureThreshold: 5
## Node selector for Agent. Only supports Linux.
nodeSelector:
kubernetes.io/os: linux
## Tolerations configuration
tolerations:
- effect: NoSchedule
key: node-role.kubernetes.io/control-plane
## Affinity configuration
affinity: {}
serviceAccount:
## Specifies whether a ServiceAccount should be created
create: true
## The name of the ServiceAccount to use.
## If not set and create is true, a name is generated using the fullname template
name: ""
annotations: {}
imagePullSecrets: []
automountServiceAccountToken: false
service:
type: ClusterIP
port: 10050
targetPort: 10050
nodePort: 10050
portName: zabbix-agent
listenOnAllInterfaces: true
annotations:
agent.zabbix/monitor: "true"
rbac:
## If true, create & use RBAC resources
##
create: true
## If true, create & use Pod Security Policy resources
## https://kubernetes.io/docs/concepts/policy/pod-security-policy/
## PodSecurityPolicies disabled by default because they are deprecated in Kubernetes 1.21 and will be removed in Kubernetes 1.25.
## If you are using PodSecurityPolicies you can enable the previous behaviour by setting `rbac.pspEnabled: true`
pspEnabled: false
pspAnnotations: {}
## **Zabbix Java Gateway** configurations
zabbixJavaGateway:
## Enable use of **Zabbix Java Gateway**
enabled: false
containerSecurityContext: {}
## Resource management for Pods and Containers.
## More details: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers
resources: {}
image:
## Zabbix Java Gateway Docker image name.
repository: zabbix/zabbix-java-gateway
## Tag of Docker image of Zabbix Java Gateway Docker
tag: alpine-7.0.17
pullPolicy: IfNotPresent
## List of dockerconfig secrets names to use when pulling images. Secrets must be manually created in the namespace.
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
## https://kubernetes.io/docs/concepts/containers/images/#using-a-private-registry
pullSecrets: []
env:
## This variable is specified amount of pollers. By default, value is 5
- name: ZBX_START_POLLERS
value: 5
## This variable is used to specify timeout for outgoing connections. By default, value is 3
- name: ZBX_TIMEOUT
value: 3
## This variable is used to specify log level. By default, value is info. Possible values: trace, debug, info, warn, error, all, off
- name: ZBX_DEBUGLEVEL
value: info
## List can be extended with other environment variables listed here: https://github.com/zabbix/zabbix-docker/tree/7.0/Dockerfiles/java-gateway/alpine
## The startupProbe, livenessProbe, readinessProbe variables
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
livenessProbe:
enabled: true
tcpSocket:
port: zabbix-jmx
initialDelaySeconds: 10
timeoutSeconds: 3
failureThreshold: 3
periodSeconds: 10
successThreshold: 1
readinessProbe:
enabled: false
tcpSocket:
port: zabbix-jmx
initialDelaySeconds: 10
timeoutSeconds: 3
failureThreshold: 3
periodSeconds: 10
successThreshold: 1
startupProbe:
enabled: true
tcpSocket:
port: zabbix-jmx
initialDelaySeconds: 30
timeoutSeconds: 3
failureThreshold: 5
periodSeconds: 10
successThreshold: 1
service:
annotations: {}
labels: {}
## Type of service for Zabbix Java Gateway
type: ClusterIP
## Port to expose service
port: 10052
externalIPs: []
## Loadbalancer IP
## Only use if service.type is "LoadBalancer"
loadBalancerIP: ""
loadBalancerSourceRanges: []
loadBalancerClass: ""
sessionAffinity: None
## Node selector for Zabbix Java Gateway
nodeSelector: {}
## Tolerations configurations for Zabbix Java Gateway
tolerations: {}
## Affinity configurations for Zabbix Java Gateway
affinity: {}