Skip to content

Commit 1b29383

Browse files
committed
Docs: External dependencies
This patch introduces a couple of guides on how to do dependencies in the cinder-operator to explain simple and circular references for both running the operator locally and building the operator.
1 parent 167ffbc commit 1b29383

File tree

3 files changed

+417
-0
lines changed

3 files changed

+417
-0
lines changed

CONTRIBUTING.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ section](README.md#getting-started):
7070

7171
- [Run operator locally](docs/dev/local.md)
7272
- [Run operator in OpenShift using a custom image](docs/dev/custom-image.md)
73+
- [Running locally with external dependencies](docs/dev/local-dependencies.md)
74+
- [Running in OpenShift with external
75+
dependencies](docs/dev/custom-image-dependencies.md)
76+
77+
There is a script called `hack/checkout_pr.sh` that is helpful when we want to
78+
test an existing PR that has dependencies. Check the [Testing PR section in the
79+
hack documentation](hack/README.md#testing-prs) for additional information.
7380

7481
### Pull Requests
7582

@@ -91,6 +98,38 @@ instead using a merge strategy instead. This means that we can have both
9198
single commit and as multi-commit PRs, and both have their places. It's all
9299
about how and when to split changes.
93100

101+
#### Dependency Management
102+
103+
When submitting a PR that has dependencies in other repositories these
104+
dependencies should be stated in the PR or the commits using the `Depends-On:`
105+
tag.
106+
107+
There are 4 ways to state a dependency with another projects PR:
108+
- `Depends-On: lib-common=88`
109+
- `Depends-On: lib-common#88`
110+
- `Depends-On: openstack-k8s-operators/lib-common#88`
111+
- `Depends-On: https://github.com/openstack-k8s-operators/lib-common/88`
112+
113+
Multiple `Depends-On:` tags are supported.
114+
115+
For the time being these tags are only useful when using the
116+
`hack/checkout_pr.sh` or `hack/showdeps.py` scripts.
117+
118+
A good example of using these tags is the `extraVol` series of PRs. There are
119+
PRs in 4 projects: lib-common, cinder-operator, glance-operator, and the
120+
openstack-operator.
121+
122+
The operators all require the lib-common PR, but then there are 2 circular
123+
requirements. One is between the cinder-operator and the openstack-operator,
124+
and the other is between the glance-operator and the openstack-operator.
125+
126+
These are the PRs for reference:
127+
128+
- https://github.com/openstack-k8s-operators/lib-common/pull/88
129+
- https://github.com/openstack-k8s-operators/cinder-operator/pull/65
130+
- https://github.com/openstack-k8s-operators/glance-operator/pull/75
131+
- https://github.com/openstack-k8s-operators/openstack-operator/pull/38
132+
94133
#### Structural split of changes
95134

96135
The general rule for how to split code changes into commits is that we should
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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

Comments
 (0)