|
| 1 | +# Running the operator in OpenShift with external dependencies |
| 2 | + |
| 3 | +**NOTE**: This article [makes some assumptions](assumptions.md), make sure they |
| 4 | +are correct or adapt the steps accordingly. |
| 5 | + |
| 6 | +If you've already [run the operator in OpenShift](custom-image.md) before, |
| 7 | +you'll be familiar with the process of running custom cinder-operator code |
| 8 | +by building and deploying a custom image. |
| 9 | + |
| 10 | +Let's see what we have to do to run our operator in OpenShift when we need to |
| 11 | +compile and build containers with external dependencies. |
| 12 | + |
| 13 | +This short guide builds on the knowledge provided in [guide to running the |
| 14 | +operator in OpenShift](custom-image.md) to explain external dependencies usage. |
| 15 | + |
| 16 | +The steps will be the same, the only difference is that some additional steps |
| 17 | +are necessary between the [Preparation](custom-image.md#preparation) and the |
| 18 | +[Image build](custom-image.md#image-build) steps to indicate the new |
| 19 | +references. |
| 20 | + |
| 21 | +To avoid repeating things again, this text assumes familiarity with the |
| 22 | + concepts presented in the [running locally with external |
| 23 | +dependencies](local-dependencies.md) article. |
| 24 | + |
| 25 | +All the cases described in running the operator locally with external |
| 26 | +dependencies where the dependency was expressed as github repositories will |
| 27 | +work fine when building the containers, so we don't need to do anything |
| 28 | +special. |
| 29 | + |
| 30 | +The difference comes when using local paths to reference the external |
| 31 | +dependencies, because those are outside of the root directory of the |
| 32 | +`Dockerfile` and therefore won't be present in the building container. |
| 33 | + |
| 34 | +The solution is to use bind mounts. |
| 35 | + |
| 36 | +### Unmerged local simple reference |
| 37 | + |
| 38 | +Assuming the same example as running things locally we would do: |
| 39 | + |
| 40 | +``` |
| 41 | +cd ~/cinder-operator |
| 42 | +mkdir -p tmp/lib-common |
| 43 | +sudo mount --bind `realpath ../lib-common` `realpath tmp/lib-common` |
| 44 | +
|
| 45 | +go work edit -replace github.com/openstack-k8s-operators/lib-common/modules/common=tmp/lib-common/modules/common |
| 46 | +go work edit -replace github.com/openstack-k8s-operators/lib-common/modules/database=tmp/lib-common/modules/database |
| 47 | +go work edit -replace github.com/openstack-k8s-operators/lib-common/modules/storage=tmp/lib-common/modules/storage |
| 48 | +``` |
| 49 | + |
| 50 | +Alternatively we can replace the last 3 commands with a single command: |
| 51 | + |
| 52 | +``` |
| 53 | +hack/setdeps.py lib-common=tmp/lib-common |
| 54 | +``` |
| 55 | + |
| 56 | +Then we can just continue with [building the |
| 57 | +image](custom-image.md#image-build) like we would normally do with the exception |
| 58 | +of having to add `GOWORK=` as well: |
| 59 | + |
| 60 | +``` |
| 61 | +GOWORK= make docker-build |
| 62 | +``` |
| 63 | + |
| 64 | +### Circular references |
| 65 | + |
| 66 | +In the circular references case when using local paths it's a bit more |
| 67 | +complicated than the local run case, because the bind mount created from the |
| 68 | +cinder-operator to the openstack-operator is not preserved when we bind mount |
| 69 | +the cinder-operator from the openstack-operator, so we need to link it again. |
| 70 | + |
| 71 | +We'll assume we have the dependency between cinder-operator and |
| 72 | +openstack-operator and that our local repositories have the code we want to |
| 73 | +use. |
| 74 | + |
| 75 | +``` |
| 76 | +cd ~/cinder-operator |
| 77 | +mkdir -p tmp/openstack-operator |
| 78 | +sudo mount --bind `realpath ../openstack-operator` `realpath tmp/openstack-operator` |
| 79 | +
|
| 80 | +go work edit -replace github.com/openstack-k8s-operators/openstack-operator/apis=tmp/openstack-operator |
| 81 | +
|
| 82 | +
|
| 83 | +cd ~/openstack-operator |
| 84 | +mkdir -p tmp/cinder-operator |
| 85 | +sudo mount --bind `realpath ../cinder-operator` `realpath tmp/cinder-operator` |
| 86 | +sudo mount --bind `realpath ./` `realpath tmp/cinder-operator/tmp/openstack-operator` |
| 87 | +
|
| 88 | +go work edit -replace github.com/openstack-k8s-operators/cinder-operator/api=tmp/cinder-operator/api |
| 89 | +``` |
| 90 | + |
| 91 | +Now we can continue with the [Image build steps](custom-image.md#image-build), |
| 92 | +again adding `GOWORK=` to the `docker-build`. |
0 commit comments