Skip to content

itewk/nexus-operator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nexus Operator

Overview

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.

Building the 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.

Installation

Common Installation Steps

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:

  1. Deploy the Custom Resource Definition:

    oc create -f https://raw.githubusercontent.com/wkulhanek/nexus-operator/master/deploy/crds/gpte_v1alpha1_nexus_crd.yaml
  2. If you want to enable deployment of the nexus operator for regular users deploy the nexus-admin-rules Cluster Role (which will be granted automatically to everyone with admin privileges). 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

Clusterwide Installation

Perform the following tasks as cluster-admin:

  1. Create the Cluster Role for the Operator

    oc create -f https://raw.githubusercontent.com/wkulhanek/nexus-operator/master/deploy/clusterrole.yaml
  2. 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"
  3. Deploy the nexus-operator service account:

    oc create -f https://raw.githubusercontent.com/wkulhanek/nexus-operator/master/deploy/service_account.yaml
  4. Grant the nexus-operator cluster role to the nexus-operator service account (if your project is not gpte-operators change the project name in the command):

    oc adm policy add-cluster-role-to-user nexus-operator system:serviceaccount:gpte-operators:nexus-operator
  5. And finally create the Nexus Operator:

    oc create -f https://raw.githubusercontent.com/wkulhanek/nexus-operator/master/deploy/cluster_operator.yaml
  6. Once the Operator pod is running the Operator is ready to start creating Nexus Servers.

Deploying a Nexus instance using the Operator

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.

Example
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
  1. Write the definition to a file (e.g. nexus-server.yaml) and then create the Nexus instance:

    oc create -f ./nexus-server.yaml
  2. The operator will create the Nexus instance.

  3. Validate that the Nexus pod is running before proceeding.

  4. You can validate the existence of your Nexus instance by querying for nexus objects:

    oc get nexus
  5. 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
  6. Use the hostname returned in your Web Browser to open the Nexus Web UI. The default user is admin with password admin123.

Deleting a Nexus instance

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-repository

The 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.

Uninstalling the Nexus 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 nexus

Then as cluster-admin delete the ClusterRole and Custom Resource:

oc delete clusterrole nexus-admin-rules
oc delete crd nexus.gpte.opentlc.com

About

Nexus Operator Source Code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Shell 75.0%
  • Dockerfile 25.0%