ploigos / ploigos-software-factory-operator

33 stars 22 forks source link

Disabled components in the PloigosPlatform will still be deployed by the operator due to jmespath edge cases #189

Closed rhn-gps-anbecker closed 3 years ago

rhn-gps-anbecker commented 3 years ago

I was running through the Ploigos Enablement, but the operator was unable to deploy due to issues setting up Quay, even though Quay was disabled in the platform definition. This is because the Ansible json search filter will return all components in a service if any one of them is enabled.

The below playbook shows the issue. The vars are pulled from the platform role defaults/main.yml.

---
- hosts: localhost
  gather_facts: no
  vars:
    ploigosPlatform:
      apiVersion: redhatgov.io/v1alpha1
      kind: PloigosPlatform
      metadata:
        name: ploigosplatform-jenkins
      spec:
       due to the all the operations being OR'd together in the query. 
 ploigosPlatform:
          services:
            continuousIntegration:
              jenkins:
                enabled: true
            sourceControl:
              gitea:
                enabled: true
            containerRegistry:
              nexusContainers:deploy
                enabled: true
              quay:
                enabled: false   # Quay should not appear in managed Services output
    ploigos_platform: "{{ ploigosPlatform['spec']['ploigosPlatform'] }}"
    all_services: "{{ ploigos_platform.services.values() | list | json_query('[].keys(@)[]') }}"
    managed_services: >-
        {{ ploigos_platform.services.values() | list |
          json_query('[?(' + ( all_services | join('||') ) + ').enabled && !*.external_properties].keys(@)[]') }}
  tasks:
    - debug: var=ploigos_platform
    - debug: var=all_services
    - debug: var=managed_services

Example output, displays quay as a managed service even when it is not enabled:

PLAY [localhost] ***************************

TASK [debug] **********************
Friday 02 July 2021  15:53:27 -0400 (0:00:00.016)       0:00:00.016 *********** 
 [started TASK: debug on localhost]
ok: [localhost] => {deploy
    "ploigos_platform": {
        "services": {
            "containerRegistry": {
                "nexusContainers": {
                    "enabled": true
                },
                "quay": {
                    "enabled": false
                }
            },
            "continuousIntegration": {
                "jenkins": {due to the all the operations being OR'd together in the query. 

                    "enabled": true
                }
            },
            "sourceControl": {
                "gitea": {
                    "enabled": true
                }
            }
        }
    }
}

TASK [debug] *********************************
Friday 02 July 2021  15:53:27 -0400 (0:00:00.037)       0:00:00.054 *********** 
 [started TASK: debug on localhost]
ok: [localhost] => {
    "all_services": [
        "jenkins",
        "gitea",
        "nexusContainers",
        "quay"
    ]
}

TASK [debug] ********************
Friday 02 July 2021  15:53:27 -0400 (0:00:00.042)       0:00:00.096 *********** 
 [started TASK: debug on localhost]
ok: [localhost] => {
    "managed_services": [
        "jenkins",
        "gitea",
        "nexusContainers",
        "quay"  # Quay still appears, even though it is still disabled.
    ]
}

PLAY RECAP ******************
localhost                  : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Problem can be worked around by deleting the component from the service definition instead of setting enabled to false. However this work around is not intuitive when using the form-based operator installation method in the OCP UI.

andykrohg commented 3 years ago

Nice catch @rhn-gps-anbecker ! 👍🏼 I just pushed a commit to fix this. Once this build finishes: https://github.com/ploigos/ploigos-software-factory-operator/runs/2975526543 can you delete your ploigos-operator-controller-manager Pod and see if it corrects the behavior?

rhn-gps-anbecker commented 3 years ago

Awesome! Will do, thanks @andykrohg