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

Adding changed_whens for role, rolebinding, and scc reconciliation ba… #3517

Merged
merged 3 commits into from Mar 6, 2017

Conversation

ewolinetz
Copy link
Contributor

Copy link
Contributor

@tbielawa tbielawa left a comment

Choose a reason for hiding this comment

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

These changes are required to meet the defined acceptance criteria

policy reconcile-cluster-roles --additive-only=true --confirm
policy reconcile-cluster-roles --additive-only=true --confirm -o name
register: reconcile_cluster_role_result
changed_when: reconcile_cluster_role_result.stdout.length > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing part of the acceptance criteria

  • The changed_when parameter is added to each task such that it is only true when there is output from the task and the return code is 0

For example:

   - name: Reconcile Cluster Roles
      command: >
        {{ openshift.common.client_binary }} adm --config={{ openshift.common.config_base }}/master/admin.kubeconfig
      policy reconcile-cluster-roles --additive-only=true --confirm
      policy reconcile-cluster-roles --additive-only=true --confirm -o name
    register: reconcile_cluster_role_result
    changed_when: 
    - reconcile_cluster_role_result.stdout.length > 0
    - reconcile_cluster_role_result.rc == 0

would be more like what we're looking for

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I must have missed that in the AC, will update

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't the return value impact failed_when not changed_when? I guess I'm not seeing the reasoning for comparing the rc for changed_when in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want to also check the rc for the changed_when because -o name will tell us what objects need a change, not whether or not they did change (per IRC discussion with liggit).

I would agree that we would also want to have a failed_when that examined the rc != 0

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, that makes sense.

when: origin_reconcile_bindings | bool or ent_reconcile_bindings | bool
register: reconcile_bindings_result
change_when: reconcile_bindings_result.stdout.length > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

run_once: true
register: reconcile_jenkens_role_binding_result
changed_when: reconcile_jenkins_role_binding_result.stdout.length > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

same

{{ openshift.common.client_binary }} adm policy reconcile-sccs --confirm --additive-only=true
{{ openshift.common.client_binary }} adm policy reconcile-sccs --confirm --additive-only=true -o name
register: reconcile_scc_result
changed_when: reconcile_scc_result.stdout.length > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

same

@ewolinetz
Copy link
Contributor Author

@tbielawa updated changed_when to also verify that the rc == 0

@tbielawa
Copy link
Contributor

aos-ci-test

@openshift-bot
Copy link

@ewolinetz
Copy link
Contributor Author

reverted failed_when commit

@ewolinetz
Copy link
Contributor Author

aos-ci-test

@openshift-bot
Copy link

@ewolinetz
Copy link
Contributor Author

aos-ci-test

@openshift-bot
Copy link

@tbielawa
Copy link
Contributor

tbielawa commented Mar 2, 2017

I'm running two tests from this branch. A first test to get a base-line for the timing and number of changes. A second test to verify the results from the first. Hopefully should be done in about 25-30 minutes once I examine the ARA report.

@tbielawa
Copy link
Contributor

tbielawa commented Mar 2, 2017

Test run fails for me @ewolinetz

TASK [openshift_cli : Install bash completion for oc tools] ********************
ok: [m01.example.com] => {"changed": false, "msg": "", "rc": 0, "results": ["bash-completion-1:2.1-6.el7.noarch providing bash-completion is already installed"]}

TASK [Reconcile Cluster Roles] *************************************************
fatal: [m01.example.com]: FAILED! => {"failed": true, "msg": "The conditional check 'reconcile_cluster_role_result.stdout.length > 0' failed. The error was: error while evaluating conditional (reconcile_cluster_role_result.stdout.length > 0): 'ansible.vars.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'length'"}

NO MORE HOSTS LEFT *************************************************************

PLAY RECAP *********************************************************************
localhost                  : ok=34   changed=0    unreachable=0    failed=0
m01.example.com            : ok=245  changed=10   unreachable=0    failed=1
n01.example.com            : ok=100  changed=1    unreachable=0    failed=0
n02.example.com            : ok=100  changed=1    unreachable=0    failed=0

Maybe try with reconcile_cluster_role_result.stdout != '' ?

EDIT removed .length from my suggestion

Copy link
Contributor

@tbielawa tbielawa left a comment

Choose a reason for hiding this comment

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

Upgrade test fails on invalid when test statements.

@@ -192,7 +192,7 @@
when: origin_reconcile_bindings | bool or ent_reconcile_bindings | bool
register: reconcile_bindings_result
changed_when:
- reconcile_bindings_result.stdout.length > 0
- reconcile_bindings_result.stdout != ''
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a bit, but I think the default filter might be better here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or maybe even just dropping the == ''...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we would need some way to verify whether or not the output is empty which means that there weren't any roles to update. I'm not sure using default or dropping the comparison would allow us to still accomplish this...

Copy link
Contributor

Choose a reason for hiding this comment

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

@ewolinetz I meant something like this:

changed_when:
- reconcile_bindings_results.stdout

Then empty string would evaluate to False

or if it is possible that stdout is not present:

changed_when:
- reconcile_bindings_result.stdout | default(false, boolean=true)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack, that's pretty cool; i didn't realize that we could do that. So it would be something like

changed_when:
- not reconcile_bindings_results.stdout

However I think this makes the check non-obvious for people that don't realize you can do that. It would probably be better if we had a way to test like

changed_when:
- not reconcile_bindings_result.stdout | empty

Copy link
Contributor

Choose a reason for hiding this comment

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

  • There are many different ways to shave this yack write these when conditions
  • I don't care which one we use but we need to make a decision
  • I personally prefer the last one @detiber posted, it handles a lot of edge cases
changed_when:
- reconcile_bindings_result.stdout | default(false, boolean=true)

If stdout is empty for some reason then the default is false. Otherwise the result is true.

  • stdout == ''Nothing changeddefault filter says no input value, so this is false
  • stdout != ''Something changed changeddefault filter says input value present, so this is true

@detiber @ewolinetz if that translation is correct ^, let's just do that and move on with this the way @detiber wrote it up.

@tbielawa
Copy link
Contributor

tbielawa commented Mar 2, 2017

We talked about this on IRC, just noting it here for transparency:

TASK [Reconcile Jenkins Pipeline Role Bindings] ********************************
fatal: [m01.example.com]: FAILED! => {"failed": true, "msg": "The conditional check 'reconcile_jenkins_role_binding_result.stdout != ''' failed. The error was: error while evaluating conditional (reconcile_jenkins
_role_binding_result.stdout != ''): 'reconcile_jenkins_role_binding_result' is undefined"}

@tbielawa
Copy link
Contributor

tbielawa commented Mar 2, 2017

Restesting w/ updates

@ewolinetz
Copy link
Contributor Author

aos-ci-test

@tbielawa
Copy link
Contributor

tbielawa commented Mar 2, 2017

Tests are quite satisfying.

change-result-comparisons

Those 9 result rows were (in order) ran against the following branches

  • This PR
  • This PR
  • Master Branch
  • Master Branch
  • This PR
  • This PR
  • Master Branch
  • Master Branch
  • This PR

Examining the changed tasks in the PR vs. Master branch results side-by-side we can see that the tasks we fixed in this PR no longer appear as changing in the PR branch

tasks-changing-comparison

Confirming this PR reduces changed by 5 vs the master branch @ openshift-ansible-3.5.3-1-466-g68aa6f2.

👍

@openshift-bot
Copy link

@ewolinetz
Copy link
Contributor Author

ewolinetz commented Mar 6, 2017

I didn't get a chance to work on a test plugin for checking std{out,err}; so we can merge this now and i'll take it on as tech debt/a nice to have

@ewolinetz ewolinetz merged commit f017f5a into openshift:master Mar 6, 2017
@ewolinetz ewolinetz deleted the idempotency_role_bindings branch July 26, 2017 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants