This repository contains the code to build a Nexus Operator for Red Hat OpenShift Container Platform. It will not run on Kubernetes because it uses the Route object to provide access to Nexus.
The Operator will create a Nexus Server with persistent storage. It will configure Nexus with Red Hat repositories and also set up Nexus as a container registry.
It is implemented on top of the Red Hat Operator SDK - in particular the Ansible Operator.
There is a script build.sh which will download the prerequisite Ansible roles from https://github.com/redhat-gpte-devopsautomation/ansible-operator-roles and install the required roles. The script will then build the container image.
Before running the script make sure to update the location of the container image to a repository you have access to. If you decide to build your own also make sure to update deploy/operator.yaml with the updated container image location.
The installation of the Custom Resource Definition and Cluster Role requires cluster-admin privileges. After that regular users with admin privileges on their projects (which is automatically granted to the user who creates a project) can provision the Nexus Operator in their projects and deploy instances of Nexus using the gogs.gogs.opentlc.com Custom Resource.
Perform the following tasks as cluster-admin:
-
Deploy the Custom Resource Definition:
oc create -f https://raw.githubusercontent.com/wkulhanek/nexus-operator/master/deploy/crds/gpte_v1alpha1_nexus_crd.yaml
-
If you want to enable deployment of the nexus operator for regular users deploy the
nexus-admin-rulesCluster Role (which will be granted automatically to everyone withadminprivileges). You may skip this step if you are deploying a clusterwide operator as a user with cluster-admin privileges:oc create -f https://raw.githubusercontent.com/wkulhanek/nexus-operator/master/deploy/clusterrole_admin.yaml
Perform the following tasks as cluster-admin:
-
Create the Cluster Role for the Operator
oc create -f https://raw.githubusercontent.com/wkulhanek/nexus-operator/master/deploy/clusterrole.yaml
-
Create a project for the operator to run in (different from where the application will be running)
oc new-project gpte-operators --display-name="GPTE Operators" -
Deploy the nexus-operator service account:
oc create -f https://raw.githubusercontent.com/wkulhanek/nexus-operator/master/deploy/service_account.yaml
-
Grant the nexus-operator cluster role to the nexus-operator service account (if your project is not
gpte-operatorschange the project name in the command):oc adm policy add-cluster-role-to-user nexus-operator system:serviceaccount:gpte-operators:nexus-operator
-
And finally create the Nexus Operator:
oc create -f https://raw.githubusercontent.com/wkulhanek/nexus-operator/master/deploy/cluster_operator.yaml
-
Once the Operator pod is running the Operator is ready to start creating Nexus Servers.
A Nexus instance is deployed by creating a Custom Resource based on the Nexus Custom Resource Definition. There is an example of a Nexus CR at https://raw.githubusercontent.com/wkulhanek/nexus-operator/master/deploy/crds/gpte_v1alpha1_nexus_cr.yaml.
The Nexus Operator understands the following settings under it’s spec setting:
-
nexusVolumeSize: The size of the Persistent Volume to be created for the Nexus repositories (e.g. 4Gi) -
nexusSsl: Weather the created route should be a HTTP (false) or HTTPS (true) route.
apiVersion: gpte.opentlc.com/v1alpha1
kind: Nexus
metadata:
name: nexus-repository
spec:
nexusVolumeSize: 10Gi
# Each of the following variables is optional
nexusSsl: True
nexusImageTag: latest
nexusCpuRequest: 1
nexusCpuLimit: 2
nexusMemoryRequest: 2Gi
nexusMemoryLimit: 2Gi-
Write the definition to a file (e.g. nexus-server.yaml) and then create the Nexus instance:
oc create -f ./nexus-server.yaml
-
The operator will create the Nexus instance.
-
Validate that the Nexus pod is running before proceeding.
-
You can validate the existence of your Nexus instance by querying for nexus objects:
oc get nexus
-
Get the Route for the Nexus instance (there will be two routes, one to access the Nexus Web UI and a second route for the Nexus container registry):
oc get route
-
Use the hostname returned in your Web Browser to open the Nexus Web UI. The default user is
adminwith passwordadmin123.
Deleting a Nexus instance and its associated resources is as simple as deleting the nexus object. If you created a Nexus instance called nexus-repository as in the example above it suffices to run the delete command on that resource:
oc delete nexus nexus-repositoryThe Operator adds ownerReference fields to all created objects - which means that deleting the Nexus object also deletes all objects that have been created by the Operator.
In case you wish to uninstall the Nexus Operator make sure that there are no more nexus instances running. Once all Nexus instances have been deleted simply delete the project the operator is running in.
oc delete project nexusThen as cluster-admin delete the ClusterRole and Custom Resource:
oc delete clusterrole nexus-admin-rules
oc delete crd nexus.gpte.opentlc.com