Skip to content

fix(module): will not deploy virtualization if moduleconfig is not valid #1134

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 15 additions & 2 deletions hooks/module_config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ModuleConfigValidateHook(Hook):
def __init__(self, module_name: str):
self.module_name = module_name
self.queue = f"/modules/{self.module_name}/{self.SNAPSHOT_MODULE_CONFIG}"
self.path = "virtualization.internal.isReady"

def generate_config(self) -> dict:
"""executeHookOnEvent is empty because we need only execute at module start."""
Expand Down Expand Up @@ -86,16 +87,28 @@ def r(ctx: hook.Context):
.get("filterResult", {})
.get("cidrs", [])
]
self.check_overlaps_cidrs(cidrs)

try:
self.check_overlaps_cidrs(cidrs)
except ValueError as e:
print(f"ERROR: {e}")

self.set_value(self.path, ctx.values, False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it ends up here if there are no "cidrs" in ModuleConfig?
It seems there should be another check to set isReady=False if "cidrs" are empty.


node_addresses: list[IPv4Address] = [
ip_address(addr["address"])
for snap in ctx.snapshots.get(self.SNAPSHOT_NODES, [])
for addr in (snap.get("filterResult", {}).get("addresses") or [])
if addr.get("type") in {"InternalIP", "ExternalIP"}
]
self.check_node_addresses_overlap(cidrs, node_addresses)

try:
self.check_node_addresses_overlap(cidrs, node_addresses)
except ValueError as e:
print(f"ERROR: {e}")
self.set_value(self.path, ctx.values, False)

self.set_value(self.path, ctx.values, True)
return r


Expand Down
3 changes: 3 additions & 0 deletions openapi/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,6 @@ properties:
properties:
nodeCount:
type: integer
isReady:
type: boolean
default: false
2 changes: 2 additions & 0 deletions templates/admission-policy.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
{{- $kubeVersion := .Values.global.discovery.kubernetesVersion }}
{{- $apiVersion := "" }}
{{- if semverCompare ">=1.30.0" $kubeVersion }}
Expand Down Expand Up @@ -69,3 +70,4 @@ spec:
namespaceSelector: {}
objectSelector: {}
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/cdi/cdi-apiserver/vpa.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
{{- if (.Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
---
apiVersion: autoscaling.k8s.io/v1
Expand All @@ -24,3 +25,4 @@ spec:
cpu: 100m
memory: 150Mi
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/cdi/cdi-deployment/rbac-for-us.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand All @@ -12,3 +13,4 @@ roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: d8:rbac-proxy
{{- end }}
2 changes: 2 additions & 0 deletions templates/cdi/cdi-deployment/vpa.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
{{- if (.Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
---
apiVersion: autoscaling.k8s.io/v1
Expand All @@ -24,3 +25,4 @@ spec:
cpu: 100m
memory: 150Mi
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/cdi/cdi-operator/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{{- if .Values.virtualization.internal.isReady }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: cdi-operator-leader-election-helper
namespace: d8-{{ .Chart.Name }}
{{- include "helm_lib_module_labels" (list .) | nindent 2 }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/cdi/cdi-operator/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ cpu: 10m
memory: 150Mi
{{- end }}

{{- if .Values.virtualization.internal.isReady }}
{{- if (.Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
---
apiVersion: autoscaling.k8s.io/v1
Expand Down Expand Up @@ -123,3 +124,4 @@ spec:
serviceAccountName: cdi-operator
volumes:
{{- include "kube_api_rewriter.kubeconfig_volume" . | nindent 6 }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/cdi/cdi-operator/rbac-for-us.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down Expand Up @@ -595,3 +596,4 @@ roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: d8:rbac-proxy
{{- end }}
2 changes: 2 additions & 0 deletions templates/cdi/config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
{{- $nodeSelectorSystem := index (include "helm_lib_node_selector" (tuple . "system") | fromYaml) "nodeSelector" | default (dict) | toJson }}
{{- $nodeSelectorMaster := index (include "helm_lib_node_selector" (tuple . "master") | fromYaml) "nodeSelector" | default (dict) | toJson }}
{{- $tolerationsSystem := index (include "helm_lib_tolerations" (tuple . "system") | fromYaml) "tolerations" | default (list) | toJson }}
Expand Down Expand Up @@ -156,3 +157,4 @@ spec:
workload:
nodeSelector:
kubernetes.io/os: linux
{{- end }}
2 changes: 2 additions & 0 deletions templates/cdi/service-monitor.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
{{- if (.Values.global.enabledModules | has "operator-prometheus-crd") }}
---
apiVersion: monitoring.coreos.com/v1
Expand Down Expand Up @@ -36,3 +37,4 @@ spec:
matchLabels:
prometheus.cdi.internal.virtualization.deckhouse.io: "true"
{{- end }}
{{- end }}
4 changes: 3 additions & 1 deletion templates/certificate.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
{{- if eq (include "helm_lib_module_https_mode" .) "CertManager" }}
---
apiVersion: cert-manager.io/v1
Expand All @@ -15,4 +16,5 @@ spec:
issuerRef:
name: {{ include "helm_lib_module_https_cert_manager_cluster_issuer_name" . }}
kind: ClusterIssuer
{{- end }}
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/custom-certificate.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{{- if .Values.virtualization.internal.isReady }}
{{- include "helm_lib_module_https_copy_custom_certificate" (list . "d8-virtualization" "ingress-tls") -}}
{{- end }}
2 changes: 2 additions & 0 deletions templates/dvcr/ nodegroupconfiguration.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
{{- if ne (dig "dvcr" "serviceIP" "" .Values.virtualization.internal) "" }}
---
{{- $ca := printf "%s" .Values.virtualization.internal.dvcr.cert.ca }}
Expand Down Expand Up @@ -54,3 +55,4 @@ spec:
endpoint = ["https://{{ $endpoint }}"]
EOF
{{- end }}
{{- end }}
4 changes: 3 additions & 1 deletion templates/dvcr/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
apiVersion: v1
kind: ConfigMap
metadata:
Expand Down Expand Up @@ -26,4 +27,5 @@ data:
storagedriver:
enabled: true
interval: 10s
threshold: 3
threshold: 3
{{- end }}
2 changes: 2 additions & 0 deletions templates/dvcr/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
cpu: 50m
memory: 150Mi
{{- end }}
{{- if .Values.virtualization.internal.isReady }}
{{- if (.Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
---
apiVersion: autoscaling.k8s.io/v1
Expand Down Expand Up @@ -108,3 +109,4 @@ spec:
{{- include "helm_lib_tolerations" (tuple . "system") | nindent 6 }}
{{- include "helm_lib_module_pod_security_context_run_as_user_deckhouse_with_writable_fs" . | nindent 6 }}
serviceAccountName: dvcr
{{- end }}
2 changes: 2 additions & 0 deletions templates/dvcr/pvc.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
{{- if eq .Values.virtualization.dvcr.storage.type "PersistentVolumeClaim" }}
{{- $storageClassName := dig "storageClassName" "" .Values.virtualization.dvcr.storage.persistentVolumeClaim }}
kind: PersistentVolumeClaim
Expand All @@ -16,3 +17,4 @@ spec:
storageClassName: {{ $storageClassName }}
{{- end }}
{{- end }}
{{- end }}
4 changes: 3 additions & 1 deletion templates/dvcr/rbac-for-us.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
---
apiVersion: v1
kind: ServiceAccount
Expand All @@ -20,4 +21,5 @@ subjects:
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: d8:rbac-proxy
name: d8:rbac-proxy
{{- end }}
2 changes: 2 additions & 0 deletions templates/dvcr/secret.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
{{- if ne (dig "dvcr" "serviceIP" "" .Values.virtualization.internal) "" }}
---
apiVersion: v1
Expand Down Expand Up @@ -54,3 +55,4 @@ data:
s3SecretKey: {{ .Values.virtualization.dvcr.storage.objectStorage.s3.secretKey | quote }}
{{- end }}
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/dvcr/service-monitor.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
{{- if (.Values.global.enabledModules | has "operator-prometheus-crd") }}
---
apiVersion: monitoring.coreos.com/v1
Expand All @@ -24,3 +25,4 @@ spec:
app: "dvcr"

{{- end }}
{{- end }}
3 changes: 2 additions & 1 deletion templates/dvcr/svc.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
apiVersion: v1
kind: Service
metadata:
Expand All @@ -17,4 +18,4 @@ spec:
targetPort: https-metrics
selector:
app: dvcr
{{- end }}
2 changes: 2 additions & 0 deletions templates/kube-api-rewriter/cm-kubeconfig-local.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
---
apiVersion: v1
kind: ConfigMap
Expand All @@ -18,3 +19,4 @@ data:
cluster: kube-api-rewriter
name: kube-api-rewriter
current-context: kube-api-rewriter
{{- end }}
2 changes: 2 additions & 0 deletions templates/kubevirt/service-monitor.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
{{- if (.Values.global.enabledModules | has "operator-prometheus-crd") }}
---
apiVersion: monitoring.coreos.com/v1
Expand Down Expand Up @@ -233,3 +234,4 @@ spec:
prometheus.kubevirt.internal.virtualization.deckhouse.io: "true"

{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/kubevirt/virt-api/vpa.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
{{- if (.Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
---
apiVersion: autoscaling.k8s.io/v1
Expand All @@ -24,3 +25,4 @@ spec:
cpu: 20m
memory: 250Mi
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/kubevirt/virt-controller/rbac-for-us.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand All @@ -12,3 +13,4 @@ roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: d8:rbac-proxy
{{- end }}
2 changes: 2 additions & 0 deletions templates/kubevirt/virt-controller/vpa.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
{{- if (.Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
---
apiVersion: autoscaling.k8s.io/v1
Expand All @@ -24,3 +25,4 @@ spec:
cpu: 20m
memory: 400Mi
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/kubevirt/virt-handler/rbac-for-us.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand All @@ -12,3 +13,4 @@ roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: d8:rbac-proxy
{{- end }}
2 changes: 2 additions & 0 deletions templates/kubevirt/virt-handler/vpa.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
{{- if (.Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
---
apiVersion: autoscaling.k8s.io/v1
Expand All @@ -24,3 +25,4 @@ spec:
cpu: 20m
memory: 400Mi
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/kubevirt/virt-operator/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
cpu: 10m
memory: 150Mi
{{- end }}
{{- if .Values.virtualization.internal.isReady }}
{{- if (.Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
---
apiVersion: autoscaling.k8s.io/v1
Expand Down Expand Up @@ -163,3 +164,4 @@ spec:
name: profile-data
{{- include "kube_api_rewriter.kubeconfig_volume" . | nindent 6 }}

{{- end }}
2 changes: 2 additions & 0 deletions templates/kubevirt/virt-operator/rbac-for-us.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
---
apiVersion: v1
kind: ServiceAccount
Expand Down Expand Up @@ -1228,3 +1229,4 @@ subjects:
- kind: ServiceAccount
name: kubevirt-operator
namespace: d8-{{ .Chart.Name }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/monitoring.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
{{- include "helm_lib_grafana_dashboard_definitions" . }}
{{- include "helm_lib_prometheus_rules" (list . "d8-virtualization") }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/namespace.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
---
apiVersion: v1
kind: Namespace
Expand All @@ -6,3 +7,4 @@ metadata:
name: d8-{{ .Chart.Name }}
---
{{- include "helm_lib_kube_rbac_proxy_ca_certificate" (list . (printf "d8-%s" .Chart.Name)) }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/nodegroupconfiguration-aio-max-nr.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
apiVersion: deckhouse.io/v1alpha1
kind: NodeGroupConfiguration
metadata:
Expand Down Expand Up @@ -54,3 +55,4 @@ spec:
else
exit 0
fi
{{- end }}
2 changes: 2 additions & 0 deletions templates/nodegroupconfiguration-redos.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
apiVersion: deckhouse.io/v1alpha1
kind: NodeGroupConfiguration
metadata:
Expand Down Expand Up @@ -72,3 +73,4 @@ spec:
else
exit 0
fi
{{- end }}
2 changes: 2 additions & 0 deletions templates/pre-delete-hook/job.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
apiVersion: batch/v1
kind: Job
metadata:
Expand Down Expand Up @@ -51,3 +52,4 @@ spec:
memory: 150Mi
{{- include "helm_lib_tolerations" (tuple . "any-node") | nindent 6 }}
{{- include "helm_lib_module_pod_security_context_run_as_user_deckhouse" . | nindent 6 }}
{{- end }}
2 changes: 2 additions & 0 deletions templates/pre-delete-hook/rbac-for-us.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.virtualization.internal.isReady }}
---
apiVersion: v1
kind: ServiceAccount
Expand Down Expand Up @@ -42,3 +43,4 @@ subjects:
- kind: ServiceAccount
name: virtualization-pre-delete-hook
namespace: d8-{{ .Chart.Name }}
{{- end }}
Loading
Loading