Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New deployment structure #471

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
VERSION="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
sed -i "s~OPERATOR_VERSION :=.*~OPERATOR_VERSION := ${VERSION}~" Makefile
sed -i "s~newTag:.*~newTag: ${VERSION}~" config/manager/kustomization.yaml
sed -i "s~activemq-artemis-operator:.*~activemq-artemis-operator:${VERSION}~" deploy/operator.yaml
sed -i "s~activemq-artemis-operator:.*~activemq-artemis-operator:${VERSION}~" deploy/resources/operator.yaml
sed -i "s~Version = \"${CURRENT_VERSION}\"~Version = \"${VERSION}\"~" version/version.go
sed -i "s~PriorVersion =.*~PriorVersion = \"${CURRENT_VERSION}\"~" version/version.go
git commit --all --message "Update version to ${VERSION}" || echo "nothing to commit"
Expand Down
27 changes: 16 additions & 11 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,21 @@ var (
brokerReconciler *ActiveMQArtemisReconciler
securityReconciler *ActiveMQArtemisSecurityReconciler

crdRes = []string{
"../deploy/resources/crd_artemis.yaml",
"../deploy/resources/crd_artemis_security.yaml",
"../deploy/resources/crd_artemis_address.yaml",
"../deploy/resources/crd_artemis_scaledown.yaml",
}

oprRes = []string{
"../deploy/service_account.yaml",
"../deploy/role.yaml",
"../deploy/role_binding.yaml",
"../deploy/election_role.yaml",
"../deploy/election_role_binding.yaml",
"../deploy/operator_config.yaml",
"../deploy/operator.yaml",
"../deploy/resources/service_account.yaml",
"../deploy/resources/namespace_role.yaml",
"../deploy/resources/namespace_role_binding.yaml",
"../deploy/resources/election_role.yaml",
"../deploy/resources/election_role_binding.yaml",
"../deploy/resources/operator_config.yaml",
"../deploy/resources/operator.yaml",
}
managerChannel chan struct{}

Expand Down Expand Up @@ -356,9 +363,8 @@ func setUpRealOperator() {
setUpK8sClient()

logf.Log.Info("Installing CRDs")
crds := []string{"../deploy/crds"}
options := envtest.CRDInstallOptions{
Paths: crds,
Paths: crdRes,
ErrorIfPathMissing: false,
}
_, err = envtest.InstallCRDs(restConfig, options)
Expand Down Expand Up @@ -403,9 +409,8 @@ func uninstallOperator(deleteCrds bool) error {
if deleteCrds {
//uninstall CRDs
logf.Log.Info("Uninstalling CRDs")
crds := []string{"../deploy/crds"}
options := envtest.CRDInstallOptions{
Paths: crds,
Paths: crdRes,
ErrorIfPathMissing: false,
}
return envtest.UninstallCRDs(restConfig, options)
Expand Down
103 changes: 50 additions & 53 deletions deploy/README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,72 @@
# What are these yaml files
## Manual deployment of Artemis Operator
Resource files specified in this directory are necessary for manual deployment of Artemis Operator.
You have an option to deploy Artemis Operator managing only resources in its own deployed namespace, or you can make it
manage all resources across multiple namespaces if you have cluster wide admin access.
For single namespace usage you should move files `cluster_role` and `cluster_role_binding` out of `resources` directory or you can see deployment permission issues.
For cluster-wide Operator management of artemis components you would need to update `WATCH_NAMESPACE` value.
We numbered files for cases, when they need to be manually applied one by one.

The yaml files in this directory are resource files necessary to manually deploy an operator.
They are generated from the *generate-deploy* make target.
## Operator watching single namespace

## Note ##
Deploy whole `resources` folder, except 2 files. Move out of that folder `cluster_role` and `cluster_role_binding` files.

If you have changed the CRD definitions or any other config resources, you need to regenerate these yamls
by run the following command from the project root.

```
make generate-deploy
```shell
mv deploy/resources/*_cluster_role*yaml .
kubectl create -f deploy/resources # -n <namespace>
```

# How to use the yamls in this dir to deploy an operator
Alternatively you can use script to deploy it for you
```shell
./deploy/install_opr.sh
```

## To deploy an operator watching single namespace (operator's namespace)
## Operator watching all namespaces

Assuming the target namespace is current namespace (if not use kubectl's -n option to specify the target namespace)
Change value of **WATCH_NAMESPACE** environment variable in `operator.yaml` file to `"*"` or empty string (see example).
You should be fine with deploying whole `resources` folder as is, for cluster wide Artemis Operator deployment.

1. Deploy all the crds
```yaml
- name: WATCH_NAMESPACE
value: "*"
```
kubectl create -f ./crds

```shell
kubectl create -f deploy/resources # -n <namespace>
```

2. Deploy operator
And change the subjects `<namespace>` to match your target namespace in `cluster_role_binding.yaml` file using command:
```shell
sed -i 's/namespace: .*/namespace: <namespace>/' resources/cluster_role_binding.yaml
```

You need to deploy all the yamls from this dir except *cluster_role.yaml* and *cluster_role_binding.yaml*:
Alternatively you can use script to deploy it for you
```shell
./deploy/cluster_wide_install_opr.sh
```
kubectl create -f ./deploy/service_account.yaml
kubectl create -f ./deploy/role.yaml
kubectl create -f ./deploy/role_binding.yaml
kubectl create -f ./deploy/election_role.yaml
kubectl create -f ./deploy/election_role_binding.yaml
kubectl create -f ./deploy/operator_config.yaml
kubectl create -f ./deploy/operator.yaml

## Undeploy Operator

To undeploy deployed Operator using these deploy yaml files, just execute following command:
```shell
kubectl delete -f deploy/resources # -n <namespace>
```

## To deploy an operator watching all namespace
Or use simple script
```shell
./deploy/undeploy_all.sh
```

The steps are similar to those for single namespace operators except that you replace the *role.yaml* and *role_binding.yaml* with *cluster_role.yaml* and *cluster_role_binding.yaml* respectively.
### What are these yaml files in deploy folder

**Note**
Before deploy, you should edit operator.yaml and change the **WATCH_NAMESPACE** env var value to be empty string
and also change the subjects namespace to match your target namespace in cluster_role_binding.yaml
as illustrated in following
These yaml files serve for manual deployment of Artemis Operator.
They are generated from the *generate-deploy* make target located in
[ActiveMQ Artemis Cloud](https://github.com/artemiscloud/activemq-artemis-operator) project.

```yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: activemq-artemis-manager-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: activemq-artemis-activemq-artemis-operator
subjects:
- kind: ServiceAccount
name: activemq-artemis-controller-manager
namespace: <<This must match your operator's target namespace>>
```
#### Note ####

After making the above changes deploy the operator as follows
(Assuming the target namespace is current namespace. You can use kubectl's -n option to specify otherwise)
If you make any changes to the CRD definitions or any other config resources, you need to regenerate these YAML files
by run the following command from the project root.

```
kubectl create -f ./deploy/crds
kubectl create -f ./deploy/service_account.yaml
kubectl create -f ./deploy/cluster_role.yaml
kubectl create -f ./deploy/cluster_role_binding.yaml
kubectl create -f ./deploy/election_role.yaml
kubectl create -f ./deploy/election_role_binding.yaml
kubectl create -f ./deploy/operator_config.yaml
kubectl create -f ./deploy/operator.yaml
make generate-deploy
```
9 changes: 6 additions & 3 deletions deploy/cluster_wide_install_opr.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
#!/bin/bash

echo "Deploying cluster-wide operator"
echo "Deploying cluster-wide Operator"

read -p "Enter namespaces to watch (empty for all namespaces): " WATCH_NAMESPACE
if [ -z ${WATCH_NAMESPACE} ]; then
WATCH_NAMESPACE="*"
fi

DEPLOY_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
DEPLOY_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )/resources"

if oc version; then
KUBE_CLI=oc
else
KUBE_CLI=kubectl
fi

$KUBE_CLI create -f $DEPLOY_PATH/crds
$KUBE_CLI create -f $DEPLOY_PATH/crd_artemis.yaml
$KUBE_CLI create -f $DEPLOY_PATH/crd_artemis_security.yaml
$KUBE_CLI create -f $DEPLOY_PATH/crd_artemis_address.yaml
$KUBE_CLI create -f $DEPLOY_PATH/crd_artemis_scaledown.yaml
$KUBE_CLI create -f $DEPLOY_PATH/service_account.yaml
$KUBE_CLI create -f $DEPLOY_PATH/cluster_role.yaml
SERVICE_ACCOUNT_NS="$(kubectl get -f $DEPLOY_PATH/service_account.yaml -o jsonpath='{.metadata.namespace}')"
Expand Down
15 changes: 9 additions & 6 deletions deploy/install_opr.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
#!/bin/bash

echo "Deploying operator to watch single namespace"
echo "Deploying single watch namespace Operator"

DEPLOY_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
DEPLOY_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )/resources"

if oc version; then
KUBE_CLI=oc
else
KUBE_CLI=kubectl
fi

$KUBE_CLI create -f $DEPLOY_PATH/crds
$KUBE_CLI create -f $DEPLOY_PATH/crd_artemis.yaml
$KUBE_CLI create -f $DEPLOY_PATH/crd_artemis_security.yaml
$KUBE_CLI create -f $DEPLOY_PATH/crd_artemis_address.yaml
$KUBE_CLI create -f $DEPLOY_PATH/crd_artemis_scaledown.yaml
$KUBE_CLI create -f $DEPLOY_PATH/service_account.yaml
$KUBE_CLI create -f $DEPLOY_PATH/role.yaml
$KUBE_CLI create -f $DEPLOY_PATH/role_binding.yaml
$KUBE_CLI create -f $DEPLOY_PATH/namespace_role.yaml
$KUBE_CLI create -f $DEPLOY_PATH/namespace_role_binding.yaml
$KUBE_CLI create -f $DEPLOY_PATH/election_role.yaml
$KUBE_CLI create -f $DEPLOY_PATH/election_role_binding.yaml
$KUBE_CLI create -f $DEPLOY_PATH/operator_config.yaml
$KUBE_CLI create -f $DEPLOY_PATH/operator.yaml
$KUBE_CLI create -f $DEPLOY_PATH/operator.yaml
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 7 additions & 4 deletions deploy/undeploy_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@

echo "Undeploy everything..."

DEPLOY_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
DEPLOY_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )/resources"

if oc version; then
KUBE_CLI=oc
else
KUBE_CLI=kubectl
fi

$KUBE_CLI delete -f $DEPLOY_PATH/crds
$KUBE_CLI delete -f $DEPLOY_PATH/crd_artemis.yaml
$KUBE_CLI delete -f $DEPLOY_PATH/crd_artemis_security.yaml
$KUBE_CLI delete -f $DEPLOY_PATH/crd_artemis_address.yaml
$KUBE_CLI delete -f $DEPLOY_PATH/crd_artemis_scaledown.yaml
$KUBE_CLI delete -f $DEPLOY_PATH/service_account.yaml
$KUBE_CLI delete -f $DEPLOY_PATH/role.yaml
$KUBE_CLI delete -f $DEPLOY_PATH/role_binding.yaml
$KUBE_CLI delete -f $DEPLOY_PATH/cluster_role.yaml
$KUBE_CLI delete -f $DEPLOY_PATH/namespace_role.yaml
$KUBE_CLI delete -f $DEPLOY_PATH/cluster_role_binding.yaml
$KUBE_CLI delete -f $DEPLOY_PATH/namespace_role_binding.yaml
$KUBE_CLI delete -f $DEPLOY_PATH/election_role.yaml
$KUBE_CLI delete -f $DEPLOY_PATH/election_role_binding.yaml
$KUBE_CLI delete -f $DEPLOY_PATH/operator_config.yaml
Expand Down
10 changes: 5 additions & 5 deletions docs/getting-started/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace.

## Deploying the operator

For more deployment details see [manual deployment readme](https://github.com/artemiscloud/activemq-artemis-operator/blob/main/deploy/README.md).
Create the namespace activemq-artemis-operator and save it for all subsequent kubectl commands
```shell
kubectl create namespace activemq-artemis-operator
Expand All @@ -46,17 +47,16 @@ kubectl config set-context --current --namespace activemq-artemis-operator
To deploy the operator in the current namespace activemq-artemis-operator simply run

```shell
./deploy/install_opr.sh
kubectl create -f deploy/resources
```
or if you have built your own image, change the image defined in deploy/operator.yaml before deploy the operator.
or if you have built your own image, change the image defined in deploy/resources/110_operator.yaml before deploy the operator.

The operator will be deployed into the current namespace and watches the same namespace.

To watch all namespace, change the **WATCH_NAMESPACE** environment variable defined in deploy/operator.yaml to be empty string before deploy the operator.
To watch all namespace, change the **WATCH_NAMESPACE** environment variable defined in deploy/resources/110_operator.yaml to be "*" or empty string before deployment of the operator.

```shell
cd deploy
./deploy/cluster_wide_install_opr.sh
kubectl create -f deploy/resources
```

At this point you should see the activemq-artemis-operator starting up and if you check the
Expand Down
6 changes: 3 additions & 3 deletions docs/help/operator.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ metadata:
You can also edit the operator deployment using the Kubernetes dashboard or the Kubernetes command-line tool, for example

```shell script
$ sed 's/--zap-log-level=debug/--zap-log-level=error/' deploy/operator.yaml | kubectl apply -f -
$ sed 's/--zap-log-level=debug/--zap-log-level=error/' deploy/resources/operator.yaml | kubectl apply -f -
```

However if you install the operator from OperatorHub you don't have control over the resources which are deployed by olm
Expand Down Expand Up @@ -255,7 +255,7 @@ Deploy the scaledown controller CRD.
$ kubectl create -f deploy/crds/broker_activemqartemisscaledown_crd.yaml
```

In the deploy directory of the Operator archive that you downloaded and extracted, open the operator.yaml file. Ensure that the value of the spec.containers.image property is set to the latest Operator image for ActiveMQ Artemis , as shown below.
In the deploy directory of the Operator archive that you downloaded and extracted, open the resources/operator.yaml file. Ensure that the value of the spec.containers.image property is set to the latest Operator image for ActiveMQ Artemis , as shown below.
```yaml
spec:
template:
Expand All @@ -267,7 +267,7 @@ spec:
Deploy the Operator.

```shell script
$ kubectl create -f deploy/operator.yaml
$ kubectl create -f deploy/resources/operator.yaml
```

In your Kubernetes project, the Operator starts in a new Pod.
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/using_operator.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Deploy all the Custom Resource Definitions (CRDs) that the Operator supports:
Deploy the Operator:

```shell script
$ kubectl create -f deploy/operator.yaml --namespace myproject
$ kubectl create -f deploy/resources/operator.yaml --namespace myproject
deployment.apps/activemq-artemis-operator created
```
You might need to wait a few moments for the Operator to fully start. You can verify the Operator status by running the command and looking at the output:
Expand Down
Loading