Skip to content

Commit

Permalink
[ansible-lint] Use fqcn for modules (#457)
Browse files Browse the repository at this point in the history
* [ansible-lint] Use fqcn for modules

* command -> ansible.builtin.command
* debug -> ansible.builtin.debug
* file -> ansible.builtin.file
* k8s -> kubernetes.core.k8s
* k8s_info -> kubernetes.core.k8s_info
* set_fact -> ansible.builtin.set_fact
* shell -> ansible.builtin.shell
* template -> ansible.builtin.template


#455

* Add lint testing for stf-run-ci fqcn (#462)

---------

Co-authored-by: Leif Madsen <lmadsen@redhat.com>
  • Loading branch information
elfiesmelfie and leifmadsen authored Sep 14, 2023
1 parent 0d0dbec commit e04c521
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 159 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: CI
on: push

jobs:
linting:
name: Linting
operator-linting:
name: Operator Linting
runs-on: ubuntu-20.04
steps:
- name: Checkout code
Expand All @@ -16,11 +16,28 @@ jobs:
run: ansible-galaxy collection install operator_sdk.util

- name: Install ansible-lint
run: pip install 'ansible-lint < 6.0.0'
run: python -m pip install 'ansible-lint < 6.0.0'

- name: Lint Ansible roles/servicetelemetry/ directory
run: ${HOME}/.local/bin/ansible-lint roles/servicetelemetry

stf-run-ci-linting:
name: stf-run-ci Linting
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install Ansible
run: python -m pip install 'ansible'

- name: Install ansible-lint
run: python -m pip install 'ansible-lint'

- name: Lint Ansible build/stf-run-ci directory
run: ${HOME}/.local/bin/ansible-lint .
working-directory: ./build/stf-run-ci

build-operator-check:
name: Build Operator check
runs-on: ubuntu-20.04
Expand Down
52 changes: 52 additions & 0 deletions build/stf-run-ci/.ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
profile: null
skip_list:
- args
- avoid-implicit
- command-instead-of-module
- command-instead-of-shell
- complexity
- deprecated-bare-vars
- deprecated-local-action
- deprecated-module
- empty-string-compare
- galaxy
- ignore-errors
- inline-env-var
- internal-error
- jinja
- key-order
- latest
- literal-compare
- loop-var-prefix
- meta-incorrect
- meta-no-tags
- meta-runtime
- meta-video-links
- name
- no-changed-when
- no-free-form
- no-handler
- no-jinja-when
- no-log-password
- no-prompting
- no-relative-paths
- no-same-owner
- no-tabs
- only-builtins
- package-latest
- parser-error
- partial-become
- playbook-extension
- risky-file-permissions
- risky-octal
- risky-shell-pipe
- role-name
- run-once
- sanity
- schema
- var-naming
- warning
- yaml

# vimrc: ft=yaml
35 changes: 8 additions & 27 deletions build/stf-run-ci/meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)
role_name: stf_run_ci # if absent directory name hosting role is used instead
namespace: infrawatch

author: InfraWatch
description: Helper CI role for Service Telemetry Framework
company: Red Hat

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
Expand All @@ -14,30 +17,9 @@ galaxy_info:
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)

min_ansible_version: 2.9

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
license: Apache-2.0

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
min_ansible_version: '2.14'

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
Expand All @@ -50,4 +32,3 @@ galaxy_info:
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

18 changes: 9 additions & 9 deletions build/stf-run-ci/tasks/clone_repos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,56 @@
- name: Get Smart Gateway Operator
block:
- name: Try cloning same-named branch or override branch from SGO repository
git:
ansible.builtin.git:
repo: "{{ sgo_repository }}"
dest: working/smart-gateway-operator
version: "{{ sgo_branch | default(branch, true) }}"
force: yes
force: true
rescue:
- name: "Get {{ version_branches.sgo }} upstream branch because specified branch or repository doesn't exist"
git:
ansible.builtin.git:
repo: https://github.com/infrawatch/smart-gateway-operator
dest: working/smart-gateway-operator
version: "{{ version_branches.sgo }}"

- name: Get sg-core
block:
- name: Try cloning same-named branch or override branch from sg-core repository
git:
ansible.builtin.git:
repo: "{{ sg_core_repository }}"
dest: working/sg-core
version: "{{ sg_core_branch | default(branch, true) }}"
rescue:
- name: "Get {{ version_branches.sg_core }} upstream branch because specified branch or repository doesn't exist"
git:
ansible.builtin.git:
repo: https://github.com/infrawatch/sg-core
dest: working/sg-core
version: "{{ version_branches.sg_core }}"

- name: Get sg-bridge
block:
- name: Try cloning same-named branch or override branch from sg-bridge repository
git:
ansible.builtin.git:
repo: "{{ sg_bridge_repository }}"
dest: working/sg-bridge
version: "{{ sg_bridge_branch | default(branch, true) }}"
rescue:
- name: "Get {{ version_branches.sg_bridge }} upstream branch because specified branch or repository doesn't exist"
git:
ansible.builtin.git:
repo: https://github.com/infrawatch/sg-bridge
dest: working/sg-bridge
version: "{{ version_branches.sg_bridge }}"

- name: Get prometheus-webhook-snmp
block:
- name: Try cloning same-named branch or override branch from prometheus-webhook-snmp repository
git:
ansible.builtin.git:
repo: "{{ prometheus_webhook_snmp_repository }}"
dest: working/prometheus-webhook-snmp
version: "{{ prometheus_webhook_snmp_branch | default(branch, true) }}"
rescue:
- name: "Get {{ version_branches.prometheus_webhook_snmp }} upstream branch because specified branch or repository doesn't exist"
git:
ansible.builtin.git:
repo: https://github.com/infrawatch/prometheus-webhook-snmp
dest: working/prometheus-webhook-snmp
version: "{{ version_branches.prometheus_webhook_snmp }}"
Expand Down
23 changes: 12 additions & 11 deletions build/stf-run-ci/tasks/create_builds.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
- name: Get current BuildConfig for artifact to check if it exists
k8s_info:
kubernetes.core.k8s_info:
api_version: build.openshift.io/v1
kind: BuildConfig
namespace: "{{ namespace }}"
name: "{{ artifact.name }}"
register: build_config_lookup

- name: Get current Builds for artifact to check if it exists
k8s_info:
kubernetes.core.k8s_info:
api_version: build.openshift.io/v1
kind: Build
namespace: "{{ namespace }}"
Expand All @@ -19,33 +19,34 @@
- when: build_config_lookup.resources | length == 0
block:
- name: Create BuildConfig and ImageStream
shell: oc new-build -n "{{ namespace }}" --name {{ artifact.name }} --dockerfile - < {{ artifact.working_build_dir }}/{{ artifact.dockerfile_path }}
ansible.builtin.shell: oc new-build -n "{{ namespace }}" --name {{ artifact.name }} --dockerfile - < {{ artifact.working_build_dir }}/{{ artifact.dockerfile_path }}

- name: Kill first build since it will always fail (triggered on BuildConfig creation)
shell: sleep 10 ; oc delete build {{ artifact.name }}-1 -n "{{ namespace }}"
ansible.builtin.shell: sleep 10 ; oc delete build {{ artifact.name }}-1 -n "{{ namespace }}"

- name: Start local image build
command: oc start-build {{ artifact.name }} -n "{{ namespace }}" --wait --from-dir "{{ artifact.working_build_dir }}"
ansible.builtin.command: oc start-build {{ artifact.name }} -n "{{ namespace }}" --wait --from-dir "{{ artifact.working_build_dir }}"
register: build_results
when: build_lookup.resources | length == 0

- name: Get latest build information for artifact
command: oc get build --selector build={{ artifact.name }} -n "{{ namespace }}" -ojsonpath='{.items[-1:]}'
ansible.builtin.command: oc get build --selector build={{ artifact.name }} -n "{{ namespace }}" -ojsonpath='{.items[-1:]}'
register: build_describe_results

- name: Set build_describe from json results
set_fact:
ansible.builtin.set_fact:
build_describe: "{{ build_describe_results.stdout | from_json }}"

- debug:
- ansible.builtin.debug:
var: build_describe

- debug:
- ansible.builtin.debug:
var: build_describe.status.outputDockerImageReference

- name: Set unique image reference for this artifact
set_fact:
ansible.builtin.set_fact:
"{{ artifact.image_reference_name }}": "{{ build_describe.status.outputDockerImageReference }}"

- debug:
- name: Show the image reference name for the build
ansible.builtin.debug:
var: "{{ artifact.image_reference_name }}"
30 changes: 15 additions & 15 deletions build/stf-run-ci/tasks/create_catalog.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
---
- name: Create service-telemetry-framework-index working directory
file:
ansible.builtin.file:
path: working/service-telemetry-framework-index
state: directory
mode: '0755'

- name: Create info variables from bundle generation output
set_fact:
ansible.builtin.set_fact:
sto_bundle_info: "{{ generate_bundle_sto.stdout }}"
sgo_bundle_info: "{{ generate_bundle_sgo.stdout }}"

- name: Get the builder-dockercfg Secret name
command: oc get secret -n {{ namespace }} --field-selector='type==kubernetes.io/dockercfg' -ojsonpath='{.items[?(@.metadata.annotations.kubernetes\.io/service-account\.name=="builder")].metadata.name}'
ansible.builtin.command: oc get secret -n {{ namespace }} --field-selector='type==kubernetes.io/dockercfg' -ojsonpath='{.items[?(@.metadata.annotations.kubernetes\.io/service-account\.name=="builder")].metadata.name}'
register: secret_builder_dockercfg_name

- name: Get contents of builder Secret
k8s_info:
kubernetes.core.k8s_info:
api_version: v1
kind: Secret
name: "{{ secret_builder_dockercfg_name.stdout }}"
namespace: "{{ namespace }}"
register: secret_builder_dockercfg_results

- name: Get builder-dockercfg authentication contents
set_fact:
ansible.builtin.set_fact:
builder_dockercfg_auth_results: "{{ secret_builder_dockercfg_results.resources[0].data['.dockercfg'] | b64decode }}"

- name: Set internal registry authentication
set_fact:
ansible.builtin.set_fact:
internal_registry: "{{ builder_dockercfg_auth_results['image-registry.openshift-image-registry.svc:5000'] | to_json }}"

- when: query('kubernetes.core.k8s', api_version='v1', kind='Secret', resource_name='service-telemetry-framework-index-dockercfg', namespace=namespace) | length == 0
block:
- name: Create config.json to import as Secret
template:
ansible.builtin.template:
variable_start_string: "<<"
variable_end_string: ">>"
src: config-json.j2
dest: working/service-telemetry-framework-index/config.json

- name: Create a Secret for the dockercfg
command: oc create secret generic -n {{ namespace }} service-telemetry-framework-index-dockercfg --from-file=.dockerconfigjson=working/service-telemetry-framework-index/config.json --type=kubernetes.io/dockerconfigjson
ansible.builtin.command: oc create secret generic -n {{ namespace }} service-telemetry-framework-index-dockercfg --from-file=.dockerconfigjson=working/service-telemetry-framework-index/config.json --type=kubernetes.io/dockerconfigjson

- name: Create ImageStream for ose-operator-registry
command: oc import-image -n {{ namespace }} ose-operator-registry:{{ default_operator_registry_image_tag }} --from={{ default_operator_registry_image_base }}:{{ default_operator_registry_image_tag }} --confirm
ansible.builtin.command: oc import-image -n {{ namespace }} ose-operator-registry:{{ default_operator_registry_image_tag }} --from={{ default_operator_registry_image_base }}:{{ default_operator_registry_image_tag }} --confirm
when: query('kubernetes.core.k8s', api_version='v1', kind='ImageStream', resource_name='ose-operator-registry', namespace=namespace) | length == 0

- name: Create ImageStream for service-telemetry-framework-index
command: oc create imagestream -n {{ namespace }} service-telemetry-framework-index
ansible.builtin.command: oc create imagestream -n {{ namespace }} service-telemetry-framework-index
when: query('kubernetes.core.k8s', api_version='v1', kind='ImageStream', resource_name='service-telemetry-framework-index', namespace=namespace) | length == 0

- name: Create BuildConfig for service-telemetry-framework-index
k8s:
kubernetes.core.k8s:
definition:
apiVersion: build.openshift.io/v1
kind: BuildConfig
Expand Down Expand Up @@ -109,7 +109,7 @@
successfulBuildsHistoryLimit: 5

- name: Get builds of service-telemetry-framework-index
k8s_info:
kubernetes.core.k8s_info:
api_version: build.openshift.io/v1
kind: Build
namespace: "{{ namespace }}"
Expand All @@ -120,15 +120,15 @@
- when: index_builds.resources | length == 0
block:
- name: Create index.yaml base for index image
template:
ansible.builtin.template:
src: index-yaml.j2
dest: working/service-telemetry-framework-index/index.yaml

- name: Build service-telemetry-framework-index
command: oc start-build -n "{{ namespace }}" service-telemetry-framework-index --wait --from-dir working/service-telemetry-framework-index
ansible.builtin.command: oc start-build -n "{{ namespace }}" service-telemetry-framework-index --wait --from-dir working/service-telemetry-framework-index

- name: Create CloudOps CatalogSource
k8s:
kubernetes.core.k8s:
definition:
apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
Expand Down
Loading

0 comments on commit e04c521

Please sign in to comment.