Browse Source
Enable reserved variable name checks and fix violations (#12463 )
* Enable reserved variable name checks and fix violations
Updated .ansible-lint configuration to skip only var-naming[pattern]
and var-naming[no-role-prefix] instead of skipping the entire var-naming rule.
This enables the check for reserved variable names.
Renamed variables that used reserved names to avoid conflicts.
Updated all references in tasks, variables, and templates.
Signed-off-by: Ali Afsharzadeh <afsharzadeh8@gmail.com>
* Rename namespace variable inside tasks instead of deleting it
Signed-off-by: Ali Afsharzadeh <afsharzadeh8@gmail.com>
* Change hosts variable to vm_hosts
Signed-off-by: Ali Afsharzadeh <afsharzadeh8@gmail.com>
* Use k8s_namespace instead of dashboard_namespace in dashboard.yml.j2 template
Signed-off-by: Ali Afsharzadeh <afsharzadeh8@gmail.com>
---------
Signed-off-by: Ali Afsharzadeh <afsharzadeh8@gmail.com>
pull/12489/head
Ali Afsharzadeh
1 month ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with
19 additions and
17 deletions
.ansible-lint
roles/kubernetes-apps/ansible/tasks/main.yml
roles/kubernetes-apps/ansible/templates/dashboard.yml.j2
roles/kubernetes-apps/defaults/main.yml
roles/kubernetes-apps/vars/main.yml
roles/network_plugin/multus/tasks/main.yml
tests/cloud_playbooks/roles/packet-ci/tasks/main.yml
@ -12,10 +12,12 @@ skip_list:
# (Disabled in June 2021)
- 'role-name'
# [var-naming] "defaults/main.yml" File defines variable 'apiVersion' that violates variable naming standards
# [var-naming]
# In Kubespray we use variables that use camelCase to match their k8s counterparts
# (Disabled in June 2021)
- 'var-naming'
- 'var-naming[pattern]'
# Variables names from within roles in kubespray don't need role name as a prefix
- 'var-naming[no-role-prefix]'
# [fqcn-builtins]
# Roles in kubespray don't need fully qualified collection names
@ -95,7 +95,7 @@
delegate_to : "{{ groups['kube_control_plane'][0] }}"
run_once : true
vars:
namespace : "{{ netcheck_namespace }}"
k8s_ namespace: "{{ netcheck_namespace }}"
when : deploy_netchecker
tags:
- netchecker
@ -117,7 +117,7 @@
delegate_to : "{{ groups['kube_control_plane'][0] }}"
run_once : true
vars:
namespace : "{{ dashboard_namespace }}"
k8s_ namespace: "{{ dashboard_namespace }}"
when : dashboard_enabled
tags:
- dashboard
@ -17,14 +17,14 @@
#
# Example usage: kubectl create -f <this_file>
{% if namespace != 'kube-system' %}
{% if k8s_ namespace != 'kube-system' %}
---
apiVersion: v1
kind: Namespace
metadata:
name: {{ namespace }}
name: {{ k8s_ namespace }}
labels:
name: {{ namespace }}
name: {{ k8s_ namespace }}
{% endif %}
---
# ------------------- Dashboard Secrets ------------------- #
@ -118,7 +118,7 @@ roleRef:
subjects:
- kind: ServiceAccount
name: kubernetes-dashboard
namespace: {{ namespace }}
namespace: {{ k8s_ namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
@ -132,7 +132,7 @@ roleRef:
subjects:
- kind: ServiceAccount
name: kubernetes-dashboard
namespace: {{ namespace }}
namespace: {{ k8s_ namespace }}
---
# ------------------- Dashboard Deployment ------------------- #
@ -173,7 +173,7 @@ spec:
- containerPort: 8443
protocol: TCP
args:
- --namespace={{ namespace }}
- --namespace={{ k8s_ namespace }}
{% if dashboard_use_custom_certs %}
- --tls-key-file={{ dashboard_tls_key_file }}
- --tls-cert-file={{ dashboard_tls_cert_file }}
@ -1,2 +1,2 @@
---
namespace : kube-system
k8s_ namespace: kube-system
@ -1,2 +1,2 @@
---
kubectl_apply_stdin : "{{ kubectl }} apply -f - -n {{ namespace }}"
kubectl_apply_stdin : "{{ kubectl }} apply -f - -n {{ k8s_ namespace }}"
@ -27,8 +27,8 @@
- {name: multus-daemonset-crio, file: multus-daemonset-crio.yml, type: daemonset, engine : crio }
register : multus_manifest_2
vars:
query : "*|[?container_manager=='{{ container_manager }}']|[0].inventory_hostname"
vars_from_node : "{{ hostvars | json_query(query) }}"
host_ query: "*|[?container_manager=='{{ container_manager }}']|[0].inventory_hostname"
vars_from_node : "{{ hostvars | json_query(host_ query) }}"
delegate_to : "{{ groups['kube_control_plane'][0] }}"
when:
- item.engine in container_manager_types
@ -32,14 +32,14 @@
ips : "{{ vmis.resources | map(attribute='status.interfaces.0.ipAddress') }}"
names : "{{ vmis.resources | map(attribute='metadata.annotations.inventory_name') }}"
_groups : "{{ (vmis.resources | map(attribute='metadata.annotations.ansible_groups') | map('split', ','))}}"
hosts : "{{ ips | zip(_groups, names)
vm_ hosts: "{{ ips | zip(_groups, names)
| map('zip', ['ansible_host', 'ansible_groups', 'inventory_name'])
| map('map', 'reverse') | map('community.general.dict') }}"
loop : "{{ hosts | map(attribute='ansible_groups') | flatten | unique }}"
loop : "{{ vm_ hosts | map(attribute='ansible_groups') | flatten | unique }}"
set_fact:
ci_inventory : "{{ ci_inventory|d({}) | combine({
item : {
'hosts' : hosts | selectattr('ansible_groups', 'contains', item)
'hosts' : vm_ hosts | selectattr('ansible_groups', 'contains', item)
| rekey_on_member('inventory_name')
}
})