Skip to content

Commit

Permalink
Fixes #161,#157,#154: Cluster scoped operator
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo Zanini <[email protected]>
  • Loading branch information
ricardozanini committed Oct 4, 2020
1 parent 377b68a commit 17daa5e
Show file tree
Hide file tree
Showing 19 changed files with 689 additions and 109 deletions.
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,14 @@ If you have any questions please either [open an issue](https://github.com/m88i/

## Quick Install

The installation procedure will create a Namespace named `nexus` and a Nexus 3.x server for you:
The installation procedure will create a Namespace named `operators` and will install every resources needed for the operator to run:

```bash
make install
```

You can then edit or customize the installation as you pleased, just run:

```bash
kubectl edit nexus
```

If you're running on Kubernetes, edit the Nexus resource to add a [valid host for the Ingress](#network-on-kubernetes-114) to work.
You can choose any flavors of Nexus 3.x server from our [`examples`](examples) directory and apply the YAML in any namespace in your cluster.
Use this examples as a starting point to customize the server to meet your requirements.

### Openshift

Expand Down
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Version 0.4.0

- #161 - Nexus Operator is now cluster-scoped, meaning that you can install the operator and the Nexus CRs in separated namespaces. See [Operator Scopes](https://sdk.operatorframework.io/docs/building-operators/golang/operator-scope/) for more information.
2 changes: 1 addition & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func main() {

// Set default manager options
options := manager.Options{
Namespace: namespace,
Namespace: "",
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
}

Expand Down
4 changes: 4 additions & 0 deletions deploy/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: operators
Original file line number Diff line number Diff line change
Expand Up @@ -150,39 +150,7 @@ spec:
mediatype: image/svg+xml
install:
spec:
deployments:
- name: nexus-operator
spec:
replicas: 1
selector:
matchLabels:
name: nexus-operator
strategy: {}
template:
metadata:
labels:
name: nexus-operator
spec:
containers:
- command:
- nexus-operator
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.annotations['olm.targetNamespaces']
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: nexus-operator
image: quay.io/m88i/nexus-operator:0.4.0
imagePullPolicy: Always
name: nexus-operator
resources: {}
serviceAccountName: nexus-operator
permissions:
clusterPermissions:
- rules:
- apiGroups:
- ""
Expand Down Expand Up @@ -283,6 +251,38 @@ spec:
verbs:
- get
serviceAccountName: nexus-operator
deployments:
- name: nexus-operator
spec:
replicas: 1
selector:
matchLabels:
name: nexus-operator
strategy: {}
template:
metadata:
labels:
name: nexus-operator
spec:
containers:
- command:
- nexus-operator
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.annotations['olm.targetNamespaces']
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: nexus-operator
image: quay.io/m88i/nexus-operator:0.4.0
imagePullPolicy: Always
name: nexus-operator
resources: {}
serviceAccountName: nexus-operator
strategy: deployment
installModes:
- supported: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,39 +150,7 @@ spec:
mediatype: image/svg+xml
install:
spec:
deployments:
- name: nexus-operator
spec:
replicas: 1
selector:
matchLabels:
name: nexus-operator
strategy: {}
template:
metadata:
labels:
name: nexus-operator
spec:
containers:
- command:
- nexus-operator
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.annotations['olm.targetNamespaces']
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: nexus-operator
image: quay.io/m88i/nexus-operator:0.4.0
imagePullPolicy: Always
name: nexus-operator
resources: {}
serviceAccountName: nexus-operator
permissions:
clusterPermissions:
- rules:
- apiGroups:
- ""
Expand Down Expand Up @@ -283,13 +251,45 @@ spec:
verbs:
- get
serviceAccountName: nexus-operator
deployments:
- name: nexus-operator
spec:
replicas: 1
selector:
matchLabels:
name: nexus-operator
strategy: {}
template:
metadata:
labels:
name: nexus-operator
spec:
containers:
- command:
- nexus-operator
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.annotations['olm.targetNamespaces']
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: nexus-operator
image: quay.io/m88i/nexus-operator:0.4.0
imagePullPolicy: Always
name: nexus-operator
resources: {}
serviceAccountName: nexus-operator
strategy: deployment
installModes:
- supported: true
type: OwnNamespace
- supported: true
type: SingleNamespace
- supported: false
- supported: true
type: MultiNamespace
- supported: true
type: AllNamespaces
Expand Down
4 changes: 1 addition & 3 deletions deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ spec:
imagePullPolicy: Always
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
value: ""
- name: POD_NAME
valueFrom:
fieldRef:
Expand Down
2 changes: 1 addition & 1 deletion deploy/role.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
kind: ClusterRole
metadata:
creationTimestamp: null
name: nexus-operator
Expand Down
5 changes: 3 additions & 2 deletions deploy/role_binding.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
kind: RoleBinding
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: nexus-operator
subjects:
- kind: ServiceAccount
name: nexus-operator
namespace: ${NAMESPACE}
roleRef:
kind: Role
kind: ClusterRole
name: nexus-operator
apiGroup: rbac.authorization.k8s.io
2 changes: 2 additions & 0 deletions hack/generate-manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ operator-sdk generate csv --apis-dir ./pkg/apis/apps/v1alpha1 --verbose --operat

# our package doesn't have the same name as the operator
rm ./deploy/olm-catalog/nexus-operator/nexus-operator.package.yaml -rf

source ./hack/generate-yaml-installer.sh
35 changes: 35 additions & 0 deletions hack/generate-yaml-installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
# Copyright 2020 Nexus Operator and/or its authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# generating all in one yaml file
sed -i '4 a \ \ namespace: operators' ./deploy/operator.yaml
sed -i '4 a \ \ namespace: operators' ./deploy/service_account.yaml

cat ./deploy/namespace.yaml > nexus-operator.yaml
echo "---" >> nexus-operator.yaml
cat ./deploy/crds/apps.m88i.io_nexus_crd.yaml >> nexus-operator.yaml
echo "---" >> nexus-operator.yaml
cat ./deploy/service_account.yaml >> nexus-operator.yaml
echo "---" >> nexus-operator.yaml
cat ./deploy/role.yaml >> nexus-operator.yaml
echo "---" >> nexus-operator.yaml
cat ./deploy/role_binding.yaml >> nexus-operator.yaml
echo "---" >> nexus-operator.yaml
cat ./deploy/operator.yaml >> nexus-operator.yaml

sed -i '5d' ./deploy/operator.yaml
sed -i '5d' ./deploy/service_account.yaml

sed -i "s/\${NAMESPACE}/operators/g" nexus-operator.yaml
29 changes: 9 additions & 20 deletions hack/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,16 @@
# limitations under the License.


# The git command will fetch the most recent tag across all branches
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
NAMESPACE=nexus
VERSION=$1

echo "[INFO] The repository will be checked out at the latest release"
echo "....... Checkout code at ${LATEST_TAG} ......"
git checkout tags/${LATEST_TAG}
if [ -z ${VERSION} ]; then
echo "Please inform the desired version"
exit(1)
fi

echo "....... Creating namespace ......."
kubectl create namespace ${NAMESPACE}
echo "Downloading latest version"
curl -LO https://github.com/m88i/nexus-operator/releases/download/${VERSION}/nexus-operator.yaml

echo "....... Applying CRDS ......."
kubectl apply -f deploy/crds/apps.m88i.io_nexus_crd.yaml
echo "....... Installing Nexus Operator ......."

echo "....... Applying Rules and Service Account ......."
kubectl apply -f deploy/role.yaml -n ${NAMESPACE}
kubectl apply -f deploy/role_binding.yaml -n ${NAMESPACE}
kubectl apply -f deploy/service_account.yaml -n ${NAMESPACE}

echo "....... Applying Nexus Operator ......."
kubectl apply -f deploy/operator.yaml -n ${NAMESPACE}

echo "....... Creating the Nexus 3.x Server ......."
kubectl apply -f examples/nexus3-centos-no-volume.yaml -n ${NAMESPACE}
kubectl apply -f nexus-operator.yaml
Loading

0 comments on commit 17daa5e

Please sign in to comment.