Skip to content

Commit

Permalink
Merge pull request #533 from t-fine/master
Browse files Browse the repository at this point in the history
Updating nginx-operator example service
  • Loading branch information
t-fine authored May 13, 2022
2 parents 84c7c70 + 4497244 commit 21f77d2
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 39 deletions.
41 changes: 22 additions & 19 deletions edge/services/nginx-operator/CreateService.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,16 @@ The above command will give you an empty ansible operator. At the very least you
```bash
wget https://raw.githubusercontent.com/open-horizon/examples/master/edge/services/nginx-operator/ansible-role-files/deployment.j2 && mv deployment.j2 roles/myoperator/templates/
wget https://raw.githubusercontent.com/open-horizon/examples/master/edge/services/nginx-operator/ansible-role-files/service.j2 && mv service.j2 roles/myoperator/templates/
wget https://raw.githubusercontent.com/open-horizon/examples/master/edge/services/nginx-operator/ansible-role-files/route.j2 && mv route.j2 roles/myoperator/templates/
wget https://raw.githubusercontent.com/open-horizon/examples/master/edge/services/nginx-operator/ansible-role-files/main.yml && mv main.yml roles/myoperator/tasks/
```

3. Build the operator image (use ppc64le for power arch):
3. **FOR OCP EDGE CLUSTERS ONLY:** Obtain the `route`, and modified task file and move them into the `my-operator` roles directory:
```bash
operator-sdk build docker.io/$DOCKER_HUB_ID/my.operator_amd64:1.0.0
docker push docker.io/$DOCKER_HUB_ID/my.operator_amd64:1.0.0
```

4. In the `deploy/operator.yaml` file replace `"REPLACE_IMAGE"` with the operator image name you build and pushed in the previous step (use ppc64le for power arch):
```bash
image: "<docker-hub-id>/my.operator_amd64:1.0.0"
wget https://raw.githubusercontent.com/open-horizon/examples/master/edge/services/nginx-operator/ansible-role-files/route.j2 && mv route.j2 roles/myoperator/templates/
wget https://raw.githubusercontent.com/open-horizon/examples/master/edge/services/nginx-operator/ansible-role-files/main-route.yml && mv main.yml roles/myoperator/tasks/main.yml
```

5. By default the operator does not have the permission to create routes, however, with the following command you can add the lines needed to the `deploy/role.yaml` file so the operator can expose the `nginx` service with a route:
4. **FOR OCP EDGE CLUSTERS ONLY:** By default the operator does not have the permission to create routes, however, with the following command you can add the lines needed to the `deploy/role.yaml` file so the operator can expose the `nginx` service with a route:
```bash
echo "- apiGroups:
- route.openshift.io
Expand All @@ -107,7 +101,18 @@ The above command will give you an empty ansible operator. At the very least you
- delete" >> deploy/role.yaml
```

6. Apply the required resources to run the operator
5. Build the operator image (use ppc64le for power arch):
```bash
operator-sdk build docker.io/$DOCKER_HUB_ID/my.operator_amd64:1.0.0
docker push docker.io/$DOCKER_HUB_ID/my.operator_amd64:1.0.0
```

6. In the `deploy/operator.yaml` file replace `"REPLACE_IMAGE"` with the operator image name you build and pushed in the previous step (use ppc64le for power arch):
```bash
image: "<docker-hub-id>/my.operator_amd64:1.0.0"
```

7. Apply the required resources to run the operator
```bash
kubectl apply -f deploy/crds/my.operator.com_myoperators_crd.yaml
kubectl apply -f deploy/service_account.yaml
Expand All @@ -117,7 +122,7 @@ The above command will give you an empty ansible operator. At the very least you
kubectl apply -f deploy/crds/my.operator.com_v1alpha1_myoperator_cr.yaml
```

7. Ensure the operator pod and the deployed service pod are running:
8. Ensure the operator pod and the deployed service pod are running:
```bash
kubectl get pods
```
Expand All @@ -129,7 +134,7 @@ If everything deployed correctly you should see an output similar to the followi
my-operator-55c6f56c47-b6p7c 1/1 Running 0 48s
```

8. Check that the service is up:
9. Check that the service is up:
```bash
kubectl get service
```
Expand All @@ -142,7 +147,7 @@ If everything deployed correctly you should see an output similar to the followi

If you are using an **OCP edge cluster** you will need to `curl` the service using the exposed `route`.

9. Get the exposed route name:
10. Get the exposed route name:
```bash
kubectl get route -n openhorizon-agent
```
Expand All @@ -153,7 +158,7 @@ If the route was exposed correctly you should see an output similar to the follo
nginx-route nginx-route-openhorizon-agent.apps.apollo5.cp.fyre.ibm.com nginx 8080 None
```

10. `curl` the service to test if it is functioning correctly:
11. `curl` the service to test if it is functioning correctly:
**OCP edge cluster** substitute the above `HOST/PORT` value:
```bash
curl nginx-route-openhorizon-agent.apps.apollo5.cp.fyre.ibm.com
Expand Down Expand Up @@ -193,23 +198,21 @@ If the service is running you should see following `Welcome to nginx!` output:
</html>
```

11. Delete the resources to stop your operator pod and service
12. Delete the resources to stop your operator pod and service
```bash
kubectl delete crd myoperators.my.operator.com
kubectl delete deployment my-operator
kubectl delete service my-operator-metrics
kubectl delete serviceaccount my-operator
kubectl delete rolebinding my-operator
kubectl delete role my-operator
kubectl delete route nginx-route
```

**Note:** if any pods are stuck in the `Terminating` state after running the previous commands you can force delete them with the following command:
```bash
kubectl -n <namespace> delete pods --grace-period=0 --force <pod_name(s)>
```

12. Create a tar archive that contains the files inside the operators `deploy/` directory:
13. Create a tar archive that contains the files inside the operators `deploy/` directory:
```
tar -zcvf operator.tar.gz deploy/*
```
Expand Down
2 changes: 1 addition & 1 deletion edge/services/nginx-operator/PatternRegister.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

1. Register your edge node with Horizon to use the `nginx-operator` pattern:
```bash
hzn register -p IBM/pattern-nginx.operator-amd64 -u $HZN_EXCHANGE_USER_AUTH
hzn register -p IBM/pattern-ibm.nginx-operator-amd64 -u $HZN_EXCHANGE_USER_AUTH
```
- **Note**: using the `-s` flag with the `hzn register` command will cause Horizon to wait until agreements are formed and the service is running on your edge node to exit, or alert you of any errors encountered during the registration process.

Expand Down
16 changes: 8 additions & 8 deletions edge/services/nginx-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ In the following steps you will deploy the `nginx-operator` to your edge cluster
```json
{
"properties": [
{ "name": "openhorizon.example", "value": "nginx-operator" }
{ "name": "openhorizon.example", "value": "operator" }
],
"constraints": [
]
Expand Down Expand Up @@ -104,28 +104,28 @@ In the following steps you will deploy the `nginx-operator` to your edge cluster
```json
{
"mycluster/policy-hello-operator": {
"mycluster/policy-ibm.nginx-operator_1.0.1": {
"owner": "root/root",
"label": "nginx-operator Deployment Policy",
"label": "ibm.nginx-operator Deployment Policy",
"description": "A super-simple sample Horizon Deployment Policy",
"service": {
"name": "nginx-operator",
"name": "ibm.nginx-operator",
"org": "IBM",
"arch": "*",
"serviceVersions": [
{
"version": "1.0.0",
"version": "1.0.1",
"priority": {},
"upgradePolicy": {}
}
],
"nodeHealth": {}
},
"constraints": [
"openhorizon.example == nginx-operator"
"openhorizon.example == operator"
],
"created": "2020-11-05T19:18:17.722Z[UTC]",
"lastUpdated": "2020-11-05T19:18:17.722Z[UTC]"
"created": "2022-05-12T23:17:04.919499Z[UTC]",
"lastUpdated": "2022-05-12T23:17:04.919489Z[UTC]"
}
}
```
Expand Down
17 changes: 17 additions & 0 deletions edge/services/nginx-operator/ansible-role-files/main-route.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
# tasks file for nginx operator

- name: Create the Operator Deployment
k8s:
state: present
definition: "{{lookup('template', 'deployment.j2') | from_yaml}}"

- name: Create the Operator Service
k8s:
state: present
definition: "{{lookup('template', 'service.j2') | from_yaml}}"

- name: Create the Operator Route
k8s:
state: present
definition: "{{lookup('template', 'route.j2') | from_yaml}}"
5 changes: 0 additions & 5 deletions edge/services/nginx-operator/ansible-role-files/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,3 @@
k8s:
state: present
definition: "{{lookup('template', 'service.j2') | from_yaml}}"

- name: Create the Operator Route
k8s:
state: present
definition: "{{lookup('template', 'route.j2') | from_yaml}}"
2 changes: 1 addition & 1 deletion edge/services/nginx-operator/ansible-role-files/route.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: v1
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: nginx-route
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"properties": [
],
"constraints": [
"openhorizon.example == nginx-operator"
"openhorizon.example == operator"
],
"userInput": [
]
Expand Down
6 changes: 3 additions & 3 deletions edge/services/nginx-operator/horizon/hzn.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"HZN_ORG_ID": "IBM",
"MetadataVars": {
"DOCKER_IMAGE_BASE": "",
"SERVICE_NAME": "nginx-operator",
"SERVICE_VERSION": "1.0.0"
"DOCKER_IMAGE_BASE": "openhorizon/ibm.nginx-operator",
"SERVICE_NAME": "ibm.nginx-operator",
"SERVICE_VERSION": "1.0.1"
}
}
2 changes: 1 addition & 1 deletion edge/services/nginx-operator/horizon/node.policy.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"properties": [
{ "name": "openhorizon.example", "value": "nginx-operator" }
{ "name": "openhorizon.example", "value": "operator" }
],
"constraints": [
]
Expand Down
Binary file modified edge/services/nginx-operator/operator.tar.gz
Binary file not shown.

0 comments on commit 21f77d2

Please sign in to comment.