Skip to content
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

Use extra_vars and CostManagement CR to drive data collection. #56

Open
wants to merge 2 commits into
base: master
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ molecule/test-local/.kube/
testing/

# vscode settings
.vscode/
.vscode/

# pyenv ignore
.python-version
1 change: 0 additions & 1 deletion molecule/default/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
ansible_python_interpreter: '{{ ansible_playbook_python }}'
roles:
- setup
- collect

- import_playbook: '{{ playbook_dir }}/asserts.yml'
32 changes: 0 additions & 32 deletions molecule/test-cluster/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,4 @@
delay: 12
retries: 10

- name: Create the cost-mgmt-data.openshift.io/v1alpha1.CostManagementData
k8s:
state: present
namespace: '{{ namespace }}'
definition: '{{ cm_data_cr }}'

- name: debug cost-mgmt data custom resource
ignore_errors: yes
failed_when: false
debug:
var: debug_cr
vars:
debug_cr: '{{ lookup("k8s",
kind=cm_data_cr.kind,
api_version=cm_data_cr.apiVersion,
namespace=namespace,
resource_name=cm_data_cr.metadata.name
)}}'

- name: Wait 2m for reconciliation to complete for collect
k8s_info:
api_version: '{{ cm_data_cr.apiVersion }}'
kind: '{{ cm_data_cr.kind }}'
namespace: '{{ namespace }}'
name: '{{ cm_data_cr.metadata.name }}'
register: cm_data_cr
until:
- "'Successful' in (cm_data_cr |
json_query('resources[].status.conditions[].reason'))"
delay: 12
retries: 10

- import_playbook: '{{ playbook_dir }}/../default/asserts.yml'
211 changes: 47 additions & 164 deletions molecule/test-local/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
src: 'mock_ingress_server.py'
mode: 0666

- name: Converge on setup
- name: Prepare converge on setup
hosts: localhost
connection: local
vars:
Expand All @@ -56,10 +56,6 @@
'crds/cost_mgmt_cr.yaml'])) | from_yaml }}"
cm_crd: "{{ lookup('file', '/'.join([deploy_dir,
'crds/cost_mgmt_crd.yaml'])) | from_yaml }}"
cm_data_crd: "{{ lookup('file', '/'.join([deploy_dir,
'crds/cost_mgmt_data_crd.yaml'])) | from_yaml }}"
cm_data_cr: "{{ lookup('file', '/'.join([molecule_dir,
'crds/cost_mgmt_data_cr.yaml'])) | from_yaml }}"
metering_cr: "{{ lookup('file', '/'.join([molecule_dir,
'crds/metering_cr.yaml'])) | from_yaml }}"
metering_crd: "{{ lookup('file', '/'.join([molecule_dir,
Expand All @@ -78,6 +74,9 @@
'crds/reporting_operator_token.yaml'])) | from_yaml }}"
trusted_ca_config: "{{ lookup('file', '/'.join([molecule_dir,
'crds/trusted_ca_certmap.yaml'])) | from_yaml }}"
authentication_secret: "{{ lookup('file', '/'.join([molecule_dir,
'crds/authentication_secret.yaml'])) | from_yaml }}"

tasks:
- block:
- name: Delete the Operator Deployment
Expand Down Expand Up @@ -131,12 +130,6 @@
namespace: '{{ namespace }}'
definition: '{{ cm_crd }}'

- name: Create the cost-mgmt-data.openshift.io/v1alpha1.CostManagementData crd
k8s:
state: present
namespace: '{{ namespace }}'
definition: '{{ cm_data_crd }}'

- name: Create the trusted cert ConfigMap
k8s:
state: present
Expand Down Expand Up @@ -168,8 +161,8 @@
(cr | json_query('resources[].status.conditions[].reason'))"
- "'Metering has not been configured.' in
(cr | json_query('resources[].status.conditions[].message'))"
delay: 12
retries: 15
delay: 10
retries: 12

rescue:
- name: debug cr
Expand Down Expand Up @@ -201,21 +194,7 @@
ignore_errors: yes
failed_when: false
command: kubectl logs
deployment/{{ definition.metadata.name }} -n {{ namespace }} -c operator
environment:
KUBECONFIG: '{{ lookup("env", "KUBECONFIG") }}'
vars:
definition: "{{ lookup('template',
'/'.join([deploy_dir, 'operator.yaml'])) | from_yaml }}"
register: log

- debug: var=log.stdout_lines

- name: get ansible logs
ignore_errors: yes
failed_when: false
command: kubectl logs
deployment/{{ definition.metadata.name }} -n {{ namespace }} -c ansible
deployment/{{ definition.metadata.name }} -n {{ namespace }}
environment:
KUBECONFIG: '{{ lookup("env", "KUBECONFIG") }}'
vars:
Expand Down Expand Up @@ -268,6 +247,12 @@
command: docker ps -aqf "ancestor=cost-mgmt.openshift.io/cost-mgmt-operator:testing"
register: container_id

- name: Create the authentication Secret
k8s:
state: present
namespace: '{{ namespace }}'
definition: '{{ authentication_secret }}'

- name: Create the metering namespace
k8s:
api_version: v1
Expand Down Expand Up @@ -335,68 +320,13 @@
debug:
var: reporting_token

- name: Create the cost-mgmt.openshift.io/v1alpha1.CostManagement crd
k8s:
state: present
namespace: '{{ namespace }}'
definition: '{{ cm_crd }}'

- name: Create the cost-mgmt-data.openshift.io/v1alpha1.CostManagementData crd
k8s:
state: present
namespace: '{{ namespace }}'
definition: '{{ cm_data_crd }}'

- name: Create the cost-mgmt.openshift.io/v1alpha1.CostManagement
k8s:
state: present
namespace: '{{ namespace }}'
definition: '{{ cm_cr }}'

- name: Wait 2m for reconciliation to complete for setup
k8s_info:
api_version: '{{ cm_cr.apiVersion }}'
kind: '{{ cm_cr.kind }}'
namespace: '{{ namespace }}'
name: '{{ cm_cr.metadata.name }}'
register: cr
until:
- "'Successful' in (cr |
json_query('resources[].status.conditions[].reason'))"
delay: 12
retries: 10

rescue:
- name: debug cr
ignore_errors: yes
failed_when: false
debug:
var: debug_cr
vars:
debug_cr: '{{ lookup("k8s",
kind=cm_data_cr.kind,
api_version=cm_data_cr.apiVersion,
namespace=namespace,
resource_name=cm_data_cr.metadata.name
)}}'

- name: debug cost-mgmt lookup
ignore_errors: yes
failed_when: false
debug:
var: deploy
vars:
deploy: '{{ lookup("k8s",
kind="Deployment",
api_version="apps/v1",
namespace=namespace
)}}'

- name: get operator logs
ignore_errors: yes
failed_when: false
command: kubectl logs
deployment/{{ definition.metadata.name }} -n {{ namespace }} -c operator
deployment/{{ definition.metadata.name }} -n {{ namespace }}
environment:
KUBECONFIG: '{{ lookup("env", "KUBECONFIG") }}'
vars:
Expand All @@ -406,23 +336,6 @@

- debug: var=log.stdout_lines

- name: get ansible logs
ignore_errors: yes
failed_when: false
command: kubectl logs
deployment/{{ definition.metadata.name }} -n {{ namespace }} -c ansible
environment:
KUBECONFIG: '{{ lookup("env", "KUBECONFIG") }}'
vars:
definition: "{{ lookup('template',
'/'.join([deploy_dir, 'operator.yaml'])) | from_yaml }}"
register: log

- debug: var=log.stdout_lines

- fail:
msg: "Failed on action: converge"

- name: Start server on Operator container
hosts: k8s
tasks:
Expand Down Expand Up @@ -483,57 +396,44 @@
- name: start server
command: docker exec -i "{{ containerName }}" bash -c 'cd /tmp/www; nohup python3 mock_ingress_server.py </dev/null >/dev/null 2>&1 &'

- name: Converge for collect
- name: Converge for setup
hosts: localhost
connection: local
vars:
ansible_python_interpreter: '{{ ansible_playbook_python }}'
deploy_dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/deploy"
molecule_dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/molecule"
cm_data_cr: "{{ lookup('file', '/'.join([deploy_dir,
'crds/cost_mgmt_data_cr.yaml'])) | from_yaml }}"
authentication_secret: "{{ lookup('file', '/'.join([molecule_dir,
'crds/authentication_secret.yaml'])) | from_yaml }}"
REPLACE_IMAGE: cost-mgmt.openshift.io/cost-mgmt-operator:testing
cm_cr: "{{ lookup('file', '/'.join([molecule_dir,
'crds/cost_mgmt_cr.yaml'])) | from_yaml }}"
cm_crd: "{{ lookup('file', '/'.join([deploy_dir,
'crds/cost_mgmt_crd.yaml'])) | from_yaml }}"
tasks:
- block:
- name: Create the authentication Secret
k8s:
state: present
namespace: '{{ namespace }}'
definition: '{{ authentication_secret }}'

- name: Create the cost-mgmt-data.openshift.io/v1alpha1.CostManagementData
k8s:
state: present
namespace: '{{ namespace }}'
definition: '{{ cm_data_cr }}'

- name: debug cost-mgmt data custom resource
ignore_errors: yes
failed_when: false
debug:
var: debug_cr
vars:
debug_cr: '{{ lookup("k8s",
kind=cm_data_cr.kind,
api_version=cm_data_cr.apiVersion,
namespace=namespace,
resource_name=cm_data_cr.metadata.name
)}}'

- name: Wait 2m for reconciliation to complete for collect
k8s_info:
api_version: '{{ cm_data_cr.apiVersion }}'
kind: '{{ cm_data_cr.kind }}'
namespace: '{{ namespace }}'
name: '{{ cm_data_cr.metadata.name }}'
register: cm_data_cr
until:
- "'Successful' in (cm_data_cr |
json_query('resources[].status.conditions[].reason'))"
delay: 12
retries: 10
- name: Create the cost-mgmt.openshift.io/v1alpha1.CostManagement crd
k8s:
state: present
namespace: '{{ namespace }}'
definition: '{{ cm_crd }}'

- name: Create the cost-mgmt.openshift.io/v1alpha1.CostManagement
k8s:
state: present
namespace: '{{ namespace }}'
definition: '{{ cm_cr }}'

- name: Wait 5m for reconciliation to complete for setup
k8s_info:
api_version: '{{ cm_cr.apiVersion }}'
kind: '{{ cm_cr.kind }}'
namespace: '{{ namespace }}'
name: '{{ cm_cr.metadata.name }}'
register: cr
until:
- "'Successful' in (cr |
json_query('resources[].status.conditions[].reason'))"
delay: 20
retries: 15

rescue:
- name: debug cr
Expand All @@ -543,10 +443,10 @@
var: debug_cr
vars:
debug_cr: '{{ lookup("k8s",
kind=cm_data_cr.kind,
api_version=cm_data_cr.apiVersion,
kind=cm_cr.kind,
api_version=cm_cr.apiVersion,
namespace=namespace,
resource_name=cm_data_cr.metadata.name
resource_name=cm_cr.metadata.name
)}}'

- name: debug cost-mgmt lookup
Expand All @@ -565,21 +465,7 @@
ignore_errors: yes
failed_when: false
command: kubectl logs
deployment/{{ definition.metadata.name }} -n {{ namespace }} -c operator
environment:
KUBECONFIG: '{{ lookup("env", "KUBECONFIG") }}'
vars:
definition: "{{ lookup('template',
'/'.join([deploy_dir, 'operator.yaml'])) | from_yaml }}"
register: log

- debug: var=log.stdout_lines

- name: get ansible logs
ignore_errors: yes
failed_when: false
command: kubectl logs
deployment/{{ definition.metadata.name }} -n {{ namespace }} -c ansible
deployment/{{ definition.metadata.name }} -n {{ namespace }}
environment:
KUBECONFIG: '{{ lookup("env", "KUBECONFIG") }}'
vars:
Expand All @@ -589,9 +475,6 @@

- debug: var=log.stdout_lines

- fail:
msg: "Failed on action: converge"

- name: Copy tar.gz to k8s from Operator
hosts: k8s
tasks:
Expand Down
27 changes: 0 additions & 27 deletions roles/collect/defaults/main.yml

This file was deleted.

Loading