generated from canonical/is-charms-template-repo
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Share k8s worker and control-plane charms (#11)
* Share k8s worker and control-plane charms * linting issues * adjust path to working charm directory * Adjust integration tests to new directory structure * Apply linting fix * If the charm is reconciled, and an update status hook runs, we should catch ReconcilerErrors * Add tag-prefix argument to publish-to-edge job * prepare for workers joining the cluster * Use tokens interface to share clustering credentials to workers * charm names are in charmcraft.yaml, not metadata.yaml * Review comment * Update peers relation definition in charmcraft.yaml * worker charm needs git package to build * Successfully ran integration tests locally * LXD profile for kubernetes-workers * Unit base charm tests with is_worker flag parameterized * Rename interface used to cluster workers * Wait for microcluster before joining nodes * Adjust k8s override-prime for rebuild-ability * Flip the heirarchy so that k8s is the inner charm
- Loading branch information
Showing
39 changed files
with
378 additions
and
370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Contributing | ||
|
||
## Structure of the charms | ||
|
||
The `k8s` and `k8s-worker` charms are noticeably tucked into one-another. | ||
|
||
``` | ||
└── worker | ||
├── charmcraft.yaml | ||
├── requirements.txt | ||
└── k8s | ||
├── charmcraft.yaml | ||
├── lib | ||
│ └── charms/... | ||
├── requirements.txt | ||
└── src | ||
└── charm.py | ||
``` | ||
|
||
While unfamiliar to some charm developers, this lets both charms share the exact same `src` folder. This is accomplished by using the `parts.charm.charm-entrypoint` value in the `worker` directory set to `k8s/src/charm.py`. | ||
|
||
### What's unique | ||
|
||
The unique parts of the charm are what are in each charm's top-level directory: | ||
|
||
``` | ||
charmcraft.yaml | ||
config.yaml | ||
actions.yaml | ||
metadata.yaml | ||
requirements.yaml | ||
``` | ||
|
||
In order to exclude the `k8s` exclusive components from the `k8s-worker` charm, charmcraft will read the `worker/.jujuignore` file to determine what to leave out of the final charm. | ||
|
||
### What's not | ||
|
||
The shared portions of each charm are within `worker/k8s` (except for the above mentioned exclusions). This includes shared libraries from `worker/k8s/lib`, shared source from `worker/k8s/src`, shared python dependencies from `worker/k8s/requirements.txt` | ||
|
||
### How to distinguish which charm code should engage | ||
|
||
The charm can distinguish whether it's a `control-plane` or `worker` unit by using `self.is_worker` or `self.is_control_plane` by querying its metadata. | ||
|
||
### Why two charms? | ||
|
||
Much of the charm's behavior will be identical. They will employ many of the same relations, many of the same resources, configure the same snap, and use many of the same configuration options. One might therefore assume the two should be 1 charm. History with Charmed Kubernetes has proven that having 2 charms split between control-plane and worker has advantages when a relation is split across `requires` and `provides`. | ||
|
||
### Why not use a charm library? | ||
|
||
Sharing code between a charm library is a really reasonable idea, there are limitations that a charm library presents: | ||
* limited to a single file | ||
* PRs where the library changes doesn't reflect in the secondary charm | ||
* updating a second charm isn't immediate | ||
- must upload to charmhub, then download into the secondary charms | ||
|
||
### How to use two charms in the same code base: | ||
|
||
In cases where the charms should diverge the behavior, use a runtime switch to make the decision | ||
|
||
```python | ||
if self.is_control_plane: | ||
# do control-plane only thing | ||
... | ||
# do more common things | ||
... | ||
if self.is_worker: | ||
# do worker only thing | ||
... | ||
``` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.