Wolfgang Kulhanek
2019-06-14 716ac9fbd8aa75e516076f113154a4cbb24410dc
Finished implementing Nexus Operator Workload (remove workload, readme).
3 files modified
56 ■■■■■ changed files
ansible/roles/ocp4-workload-nexus-operator/readme.adoc 44 ●●●●● patch | view | raw | blame | history
ansible/roles/ocp4-workload-nexus-operator/tasks/remove_workload.yml 10 ●●●● patch | view | raw | blame | history
ansible/roles/ocp4-workload-nexus-operator/templates/operator.j2 2 ●●● patch | view | raw | blame | history
ansible/roles/ocp4-workload-nexus-operator/readme.adoc
@@ -1,13 +1,13 @@
= ocp-workload-user-quota-operator - Enable the User Quota Operator on OCP4
= ocp4-workload-nexus-operator - Deploy a Nexus Operator and Shared Nexus on OCP4
== Role overview
* This role enables the User Quota Operator on an OpenShift 4 Cluster. It consists of the following playbooks:
* This role enables the Nexus Operator on an OpenShift 4 Cluster. It consists of the following playbooks:
** Playbook: link:./tasks/pre_workload.yml[pre_workload.yml] - Sets up an
 environment for the workload deployment.
*** Debug task will print out: `pre_workload Tasks completed successfully.`
** Playbook: link:./tasks/workload.yml[workload.yml] - Used to enable the User Quota Operator
** Playbook: link:./tasks/workload.yml[workload.yml] - Used to deploy the Nexus Operator and then deploy a shared Nexus instance
*** Debug task will print out: `workload Tasks completed successfully.`
** Playbook: link:./tasks/post_workload.yml[post_workload.yml] - Used to
@@ -17,7 +17,7 @@
** Playbook: link:./tasks/remove_workload.yml[remove_workload.yml] - Used to
 delete the workload
*** This role removes the user quota operator from OCP 4. It also removes all created cluster resource quotas
*** This role removes the shared Nexus and Nexus operator from OCP 4. This role does *not* remove the project - there may be other items in it.
*** Debug task will print out: `remove_workload Tasks completed successfully.`
== Review the defaults variable file
@@ -27,33 +27,25 @@
* A variable *silent=True* can be passed to suppress debug messages.
* You can modify any of these default values by adding `-e "variable_name=variable_value"` to the command line
== UserQuota Custom Resource
== Nexus Custom Resource
The operator uses a custom resource *UserQuota.gpte.opentlc.com/v1alpha1* to set the quota for all users in the cluster. This object is shaped after the *ClusterResourceQuota*. Everything under *.spec.quota* will be applied to the .spec.quota of the ClusterResourceQuota to be created.
The operator sets up the UserQuota listed below. It should be called `default` and can be edited after deployment. Any edit will apply the quota to all users within the operator reconciliation period which is set to 5 seconds.
Deleting the UserQuota object `default` will delete all ClusterResourceQuota objects that have been created because of the existence of the UserQuota object.
The operator uses a custom resource *Nexus.gpte.opentlc.com/v1alpha1* to set the quota for all users in the cluster. Variables are in defaults/main.yaml and can be overwritten by setting them globally.
[source,yaml]
----
apiVersion: gpte.opentlc.com/v1alpha1
kind: UserQuota
kind: Nexus
metadata:
  name: default
  name: "{{ _nexus_name }}"
  namespace: "{{ _nexus_operator_project }}"
spec:
  quota:
    hard:
      configmaps: "10"
      limits.cpu: "10"
      limits.memory: 20Gi
      persistentvolumeclaims: "20"
      pods: "20"
      requests.cpu: "5"
      requests.memory: 6Gi
      requests.storage: 50Gi
      secrets: "150"
      services: "30"
  nexusVolumeSize: "{{ _nexus_volume_size }}"
  nexusSsl: "{{ _nexus_ssl }}"
  nexusImageTag: "{{ _nexus_image_tag }}"
  nexusCpuRequest: "{{ _nexus_cpu_request }}"
  nexusCpuLimit: "{{ _nexus_cpu_limit }}"
  nexusMemoryRequest: "{{ _nexus_memory_request }}"
  nexusMemoryLimit: "{{ _nexus_memory_limit }}"
----
=== Deploy a Workload with the `ocp-workload` playbook [Mostly for testing]
@@ -61,7 +53,7 @@
----
TARGET_HOST="bastion.na311.openshift.opentlc.com"
OCP_USERNAME="shacharb-redhat.com"
WORKLOAD="ocp-workload-user-quota-operator"
WORKLOAD="ocp4-workload-nexus-operator"
GUID=1001
# a TARGET_HOST is specified in the command line, without using an inventory file
@@ -80,7 +72,7 @@
----
TARGET_HOST="bastion.na311.openshift.opentlc.com"
OCP_USERNAME="ankay-redhat.com"
WORKLOAD="ocp-workload-user-quota-operator"
WORKLOAD="ocp4-workload-nexus-operator"
GUID=1002
# a TARGET_HOST is specified in the command line, without using an inventory file
ansible/roles/ocp4-workload-nexus-operator/tasks/remove_workload.yml
@@ -1,16 +1,17 @@
---
# Implement your Workload removal tasks here
- name: Delete the UserQuota (which deletes all ClusterResourceQuotas)
- name: Delete Nexus
  k8s:
    state: absent
    definition: "{{ lookup('template', './templates/user_quota.j2' ) | from_yaml }}"
    definition: "{{ lookup('template', './templates/opentlc-nexus.j2' ) | from_yaml }}"
- name: Wait 15 seconds (the Operator reconciles every 5 seconds)
- name: Wait 15 seconds for the Nexus to disappear
  wait_for: timeout=15
  delegate_to: localhost
- name: Delete OpenShift Objects for User Quota Operator
# Delete all objects except the project (there may be other stuff in it)
- name: Delete OpenShift Objects for Nexus Operator (including the OPENTLC Nexus)
  k8s:
    state: absent
    definition: "{{ lookup('template', item ) | from_yaml }}"
@@ -20,7 +21,6 @@
  - ./templates/role.j2
  - ./templates/service_account.j2
  - ./templates/crd.j2
  - ./templates/project.j2
# Leave this as the last task in the playbook.
- name: remove_workload tasks complete
ansible/roles/ocp4-workload-nexus-operator/templates/operator.j2
@@ -40,7 +40,7 @@
                fieldRef:
                  fieldPath: metadata.name
            - name: OPERATOR_NAME
              value: "userquota-operator"
              value: "nexus-operator"
      volumes:
        - name: runner
          emptyDir: {}