Skip to content

Commit

Permalink
[v1.24] convert some vars to bool during conditional checks (#170)
Browse files Browse the repository at this point in the history
* convert view_only_mode to bool to ensure conditionals are testing correctly even if the user used a string for the value.

* convert ingress_enabled to bool in case user specified a truthy string

* convert metrics_enabled to bool in case user specified a truthy string
  • Loading branch information
jmazzitelli authored Oct 16, 2020
1 parent 3080c7f commit 6fabf4f
Show file tree
Hide file tree
Showing 20 changed files with 36 additions and 36 deletions.
6 changes: 3 additions & 3 deletions roles/default/kiali-deploy/tasks/kubernetes/k8s-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
loop:
- serviceaccount
- configmap
- "{{ 'role-viewer' if kiali_vars.deployment.view_only_mode == True else 'role' }}"
- "{{ 'role-viewer' if kiali_vars.deployment.view_only_mode|bool == True else 'role' }}"
- rolebinding
- deployment
- service
Expand All @@ -26,7 +26,7 @@
loop_var: process_resource_item
when:
- is_k8s == True
- kiali_vars.deployment.ingress_enabled == True
- kiali_vars.deployment.ingress_enabled|bool == True

- name: Delete Ingress on Kubernetes if disabled
k8s:
Expand All @@ -37,7 +37,7 @@
name: "kiali"
when:
- is_k8s == True
- kiali_vars.deployment.ingress_enabled == False
- kiali_vars.deployment.ingress_enabled|bool == False

- name: Create additional Kiali roles on Kubernetes
include_tasks: process-additional-roles.yml
Expand Down
6 changes: 3 additions & 3 deletions roles/default/kiali-deploy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
msg: "The auth.strategy is 'openshift' which requires a Route, but deployment.ingress_enabled is false. Aborting."
when:
- kiali_vars.auth.strategy == "openshift"
- kiali_vars.deployment.ingress_enabled == False
- kiali_vars.deployment.ingress_enabled|bool == False

- name: Confirm the cluster can access github.com when it needs to determine the last release of Kiali
uri:
Expand Down Expand Up @@ -640,15 +640,15 @@
loop_var: role_namespace
when:
- current_view_only_mode is defined
- current_view_only_mode != kiali_vars.deployment.view_only_mode
- current_view_only_mode|bool != kiali_vars.deployment.view_only_mode|bool
- current_accessible_namespaces is defined
- '"**" not in current_accessible_namespaces'

- name: Delete Kiali cluster roles if view_only_mode is changing since role bindings are immutable
include_tasks: remove-clusterroles.yml
when:
- current_view_only_mode is defined
- current_view_only_mode != kiali_vars.deployment.view_only_mode
- current_view_only_mode|bool != kiali_vars.deployment.view_only_mode|bool
- current_accessible_namespaces is defined
- '"**" in current_accessible_namespaces'

Expand Down
6 changes: 3 additions & 3 deletions roles/default/kiali-deploy/tasks/openshift/os-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- serviceaccount
- configmap
- cabundle
- "{{ 'role-viewer' if kiali_vars.deployment.view_only_mode == True else 'role' }}"
- "{{ 'role-viewer' if kiali_vars.deployment.view_only_mode|bool == True else 'role' }}"
- rolebinding
- deployment
- service
Expand All @@ -27,7 +27,7 @@
loop_var: process_resource_item
when:
- is_openshift == True
- kiali_vars.deployment.ingress_enabled == True
- kiali_vars.deployment.ingress_enabled|bool == True

- name: Delete Route on OpenShift if disabled
k8s:
Expand All @@ -38,7 +38,7 @@
name: "kiali"
when:
- is_openshift == True
- kiali_vars.deployment.ingress_enabled == False
- kiali_vars.deployment.ingress_enabled|bool == False

- name: Create additional Kiali roles on OpenShift
include_tasks: process-additional-roles.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
role_namespace_obj: "{{ lookup('k8s', namespace=role_namespace, kind='Namespace', resource_name=role_namespace, api_version='v1') }}"
include_tasks: process-resource.yml
loop:
- "{{ 'role-viewer' if kiali_vars.deployment.view_only_mode == True else 'role' }}"
- "{{ 'role-viewer' if kiali_vars.deployment.view_only_mode|bool == True else 'role' }}"
- rolebinding
loop_control:
loop_var: process_resource_item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
app: kiali
version: {{ kiali_vars.deployment.version_label }}
annotations:
{% if kiali_vars.server.metrics_enabled == True %}
{% if kiali_vars.server.metrics_enabled|bool == True %}
prometheus.io/scrape: "true"
prometheus.io/port: "{{ kiali_vars.server.metrics_port }}"
{% else %}
Expand Down Expand Up @@ -62,7 +62,7 @@ spec:
ports:
- name: api-port
containerPort: {{ kiali_vars.server.port }}
{% if kiali_vars.server.metrics_enabled == True %}
{% if kiali_vars.server.metrics_enabled|bool == True %}
- name: http-metrics
containerPort: {{ kiali_vars.server.metrics_port }}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ metadata:
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: {{ role_kind }}
name: {{ 'kiali-viewer' if kiali_vars.deployment.view_only_mode == True else 'kiali' }}
name: {{ 'kiali-viewer' if kiali_vars.deployment.view_only_mode|bool == True else 'kiali' }}
subjects:
- kind: ServiceAccount
name: kiali-service-account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ spec:
- name: {{ 'http' if kiali_vars.identity.cert_file == "" else 'tcp' }}
protocol: TCP
port: {{ kiali_vars.server.port }}
{% if kiali_vars.server.metrics_enabled == True %}
{% if kiali_vars.server.metrics_enabled|bool == True %}
- name: http-metrics
protocol: TCP
port: {{ kiali_vars.server.metrics_port }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
app: kiali
version: {{ kiali_vars.deployment.version_label }}
annotations:
{% if kiali_vars.server.metrics_enabled == True %}
{% if kiali_vars.server.metrics_enabled|bool == True %}
prometheus.io/scrape: "true"
prometheus.io/port: "{{ kiali_vars.server.metrics_port }}"
{% else %}
Expand Down Expand Up @@ -62,7 +62,7 @@ spec:
ports:
- name: api-port
containerPort: {{ kiali_vars.server.port }}
{% if kiali_vars.server.metrics_enabled == True %}
{% if kiali_vars.server.metrics_enabled|bool == True %}
- name: http-metrics
containerPort: {{ kiali_vars.server.metrics_port }}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ metadata:
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: {{ role_kind }}
name: {{ 'kiali-viewer' if kiali_vars.deployment.view_only_mode == True else 'kiali' }}
name: {{ 'kiali-viewer' if kiali_vars.deployment.view_only_mode|bool == True else 'kiali' }}
subjects:
- kind: ServiceAccount
name: kiali-service-account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
- name: {{ 'http' if kiali_vars.identity.cert_file == "" else 'tcp' }}
protocol: TCP
port: {{ kiali_vars.server.port }}
{% if kiali_vars.server.metrics_enabled == True %}
{% if kiali_vars.server.metrics_enabled|bool == True %}
- name: http-metrics
protocol: TCP
port: {{ kiali_vars.server.metrics_port }}
Expand Down
6 changes: 3 additions & 3 deletions roles/v1.24/kiali-deploy/tasks/kubernetes/k8s-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
loop:
- serviceaccount
- configmap
- "{{ 'role-viewer' if kiali_vars.deployment.view_only_mode == True else 'role' }}"
- "{{ 'role-viewer' if kiali_vars.deployment.view_only_mode|bool == True else 'role' }}"
- rolebinding
- deployment
- service
Expand All @@ -26,7 +26,7 @@
loop_var: process_resource_item
when:
- is_k8s == True
- kiali_vars.deployment.ingress_enabled == True
- kiali_vars.deployment.ingress_enabled|bool == True

- name: Delete Ingress on Kubernetes if disabled
k8s:
Expand All @@ -37,7 +37,7 @@
name: "kiali"
when:
- is_k8s == True
- kiali_vars.deployment.ingress_enabled == False
- kiali_vars.deployment.ingress_enabled|bool == False

- name: Create additional Kiali roles on Kubernetes
include_tasks: process-additional-roles.yml
Expand Down
6 changes: 3 additions & 3 deletions roles/v1.24/kiali-deploy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
msg: "The auth.strategy is 'openshift' which requires a Route, but deployment.ingress_enabled is false. Aborting."
when:
- kiali_vars.auth.strategy == "openshift"
- kiali_vars.deployment.ingress_enabled == False
- kiali_vars.deployment.ingress_enabled|bool == False

- name: Confirm the cluster can access github.com when it needs to determine the last release of Kiali
uri:
Expand Down Expand Up @@ -640,15 +640,15 @@
loop_var: role_namespace
when:
- current_view_only_mode is defined
- current_view_only_mode != kiali_vars.deployment.view_only_mode
- current_view_only_mode|bool != kiali_vars.deployment.view_only_mode|bool
- current_accessible_namespaces is defined
- '"**" not in current_accessible_namespaces'

- name: Delete Kiali cluster roles if view_only_mode is changing since role bindings are immutable
include_tasks: remove-clusterroles.yml
when:
- current_view_only_mode is defined
- current_view_only_mode != kiali_vars.deployment.view_only_mode
- current_view_only_mode|bool != kiali_vars.deployment.view_only_mode|bool
- current_accessible_namespaces is defined
- '"**" in current_accessible_namespaces'

Expand Down
6 changes: 3 additions & 3 deletions roles/v1.24/kiali-deploy/tasks/openshift/os-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- serviceaccount
- configmap
- cabundle
- "{{ 'role-viewer' if kiali_vars.deployment.view_only_mode == True else 'role' }}"
- "{{ 'role-viewer' if kiali_vars.deployment.view_only_mode|bool == True else 'role' }}"
- rolebinding
- deployment
- service
Expand All @@ -27,7 +27,7 @@
loop_var: process_resource_item
when:
- is_openshift == True
- kiali_vars.deployment.ingress_enabled == True
- kiali_vars.deployment.ingress_enabled|bool == True

- name: Delete Route on OpenShift if disabled
k8s:
Expand All @@ -38,7 +38,7 @@
name: "kiali"
when:
- is_openshift == True
- kiali_vars.deployment.ingress_enabled == False
- kiali_vars.deployment.ingress_enabled|bool == False

- name: Create additional Kiali roles on OpenShift
include_tasks: process-additional-roles.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
role_namespace_obj: "{{ lookup('k8s', namespace=role_namespace, kind='Namespace', resource_name=role_namespace, api_version='v1') }}"
include_tasks: process-resource.yml
loop:
- "{{ 'role-viewer' if kiali_vars.deployment.view_only_mode == True else 'role' }}"
- "{{ 'role-viewer' if kiali_vars.deployment.view_only_mode|bool == True else 'role' }}"
- rolebinding
loop_control:
loop_var: process_resource_item
Expand Down
4 changes: 2 additions & 2 deletions roles/v1.24/kiali-deploy/templates/kubernetes/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
app: kiali
version: {{ kiali_vars.deployment.version_label }}
annotations:
{% if kiali_vars.server.metrics_enabled == True %}
{% if kiali_vars.server.metrics_enabled|bool == True %}
prometheus.io/scrape: "true"
prometheus.io/port: "{{ kiali_vars.server.metrics_port }}"
{% else %}
Expand Down Expand Up @@ -62,7 +62,7 @@ spec:
ports:
- name: api-port
containerPort: {{ kiali_vars.server.port }}
{% if kiali_vars.server.metrics_enabled == True %}
{% if kiali_vars.server.metrics_enabled|bool == True %}
- name: http-metrics
containerPort: {{ kiali_vars.server.metrics_port }}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ metadata:
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: {{ role_kind }}
name: {{ 'kiali-viewer' if kiali_vars.deployment.view_only_mode == True else 'kiali' }}
name: {{ 'kiali-viewer' if kiali_vars.deployment.view_only_mode|bool == True else 'kiali' }}
subjects:
- kind: ServiceAccount
name: kiali-service-account
Expand Down
2 changes: 1 addition & 1 deletion roles/v1.24/kiali-deploy/templates/kubernetes/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ spec:
- name: {{ 'http' if kiali_vars.identity.cert_file == "" else 'tcp' }}
protocol: TCP
port: {{ kiali_vars.server.port }}
{% if kiali_vars.server.metrics_enabled == True %}
{% if kiali_vars.server.metrics_enabled|bool == True %}
- name: http-metrics
protocol: TCP
port: {{ kiali_vars.server.metrics_port }}
Expand Down
4 changes: 2 additions & 2 deletions roles/v1.24/kiali-deploy/templates/openshift/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
app: kiali
version: {{ kiali_vars.deployment.version_label }}
annotations:
{% if kiali_vars.server.metrics_enabled == True %}
{% if kiali_vars.server.metrics_enabled|bool == True %}
prometheus.io/scrape: "true"
prometheus.io/port: "{{ kiali_vars.server.metrics_port }}"
{% else %}
Expand Down Expand Up @@ -62,7 +62,7 @@ spec:
ports:
- name: api-port
containerPort: {{ kiali_vars.server.port }}
{% if kiali_vars.server.metrics_enabled == True %}
{% if kiali_vars.server.metrics_enabled|bool == True %}
- name: http-metrics
containerPort: {{ kiali_vars.server.metrics_port }}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ metadata:
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: {{ role_kind }}
name: {{ 'kiali-viewer' if kiali_vars.deployment.view_only_mode == True else 'kiali' }}
name: {{ 'kiali-viewer' if kiali_vars.deployment.view_only_mode|bool == True else 'kiali' }}
subjects:
- kind: ServiceAccount
name: kiali-service-account
Expand Down
2 changes: 1 addition & 1 deletion roles/v1.24/kiali-deploy/templates/openshift/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
- name: {{ 'http' if kiali_vars.identity.cert_file == "" else 'tcp' }}
protocol: TCP
port: {{ kiali_vars.server.port }}
{% if kiali_vars.server.metrics_enabled == True %}
{% if kiali_vars.server.metrics_enabled|bool == True %}
- name: http-metrics
protocol: TCP
port: {{ kiali_vars.server.metrics_port }}
Expand Down

0 comments on commit 6fabf4f

Please sign in to comment.