Add ability to install porter plugins
This PR implements the ability to allow users to configure plugins they need in agent-config resource.
Current workflow:
It creates a new agent config controller to manage the lifecycle of the plugin installation. The controller dispatch jobs to the porter agent to install plugins onto a persistent volume through a pvc (temporary persistent volume claim) managed by the agent config controller. Once the installation is done, the controller sets labels, including all installed plugins and the agent config name, on the persistent volume. Then the controller will create a new pvc. The new pvc will use the hash of all the plugins information as its name and the plain text version of all the plugin information as its label.
When a new agent action is created, it will query using the plugin hash derived from its agent config and mount a plugin pvc using that name.
If no existing plugin pvc exits, the agent action will wait for the pvc to be created before kubernetes schedules it.
When a plugin volumes is no longer needed, the current approach is to allow k8s GC to do the work for us. All the operator is doing when a agent config is deleted is to make sure to remove itself from the pvc's and pv's OwnerReferences value. Once no other resource is referencing a volume, GC will know to delete it permanently.
To make sure we are not deleting any volumes that still could being used, when a volume is being reused by multiple agent config, the controller will make sure to add all agent config into the owner reference before marking the agent config status has complete.
Couple issues that may need to be worked out before this feature is complete:
- [ ] - Since currently, the operator doesn't have the capability to clean up pods after each job has been finished, the above cleanup workflow for plugin volumes only removes the deleted agent config from the plugin volume's owner reference list. we need to validate that when all the pods are deleted, the plugin volumes will be deleted too. https://github.com/getporter/operator/issues/54
- [ ] - Another issue that the current code has not solved is how to install multiple porter plugins with one agent job. From my discovery, porter currently does not seem to allow installation for multiple plugins with one command. https://github.com/getporter/operator/issues/123
- [ ] - We probably should set default plugin configuration in both the installer bundle and the controller code. If someone were to delete the default agent config defined by the installer bundle, the controller can still set a default kubernetes pluin in the code
- [ ] - We need to add integration tests for delete behavior
- [ ] - This feature is also missing document. For example, where all the default values for plugin configs are set https://github.com/getporter/operator/issues/122
Codecov Report
Merging #108 (f733fe2) into main (4c2faac) will decrease coverage by
2.71%. The diff coverage is68.45%.
@@ Coverage Diff @@
## main #108 +/- ##
==========================================
- Coverage 78.30% 75.58% -2.72%
==========================================
Files 12 13 +1
Lines 1014 1536 +522
==========================================
+ Hits 794 1161 +367
- Misses 138 242 +104
- Partials 82 133 +51
| Flag | Coverage Δ | |
|---|---|---|
| unit-tests | 75.58% <68.45%> (-2.72%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Impacted Files | Coverage Δ | |
|---|---|---|
| api/v1/agentaction_types.go | 44.44% <0.00%> (-22.23%) |
:arrow_down: |
| controllers/porter_resource.go | 77.61% <ø> (ø) |
|
| api/v1/agentconfig_types.go | 58.97% <54.28%> (-14.36%) |
:arrow_down: |
| controllers/agentconfig_controller.go | 71.04% <71.04%> (ø) |
|
| controllers/agentaction_controller.go | 83.29% <84.61%> (+2.38%) |
:arrow_up: |
:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more
BTW I have codecov turned on mostly for our own information. It's not a requirement to hit a certain percentage and it's okay if a feature reduces coverage (which is easy to do since we don't test exception handling).