-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(application): deploy applications with custom resources #493
feat(application): deploy applications with custom resources #493
Conversation
3083ece
to
1dd730a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution. It's a good start.
To proceed, please read and follow the process defined: https://github.com/juju/terraform-provider-juju/wiki/Developing#planning--design
Please also include description of what happens during the following scenarios.
- deploy
- refresh
- the resource element is removed from the plan
- what happens if the file isn't an image location?
- what happens if the value is changed from an int to a file?
- what happens if the value is changed from a file to an int?
Hello @hmlanigan,
|
60c62dd
to
59c5c91
Compare
This is counter to current juju behavior. Today juju will upgrade the resources with the charm if a new resource is available, provided that the resource is not an attached local file (but not an ici-image). This behavior would have to be explicitly implemented if we want it. It'd require a juju change. Resources can never be detached by juju.
A charm revision may be in more than one channel. The last I knew resources are associated with a channel only today, not a charm revision.
Juju will not allow a charm with resources to be deployed without one unless the process errors. If no resource is specified, juju deploy will find the resources in charm hub and use those.
What is contained in this repository?
We will only be allowing revision number and oci-image information be used. We will not support custom files to be uploaded.
What will only work for versions of juju where DeployFromRepostory isn't used in older versions of juju.
This is dependent on the charms behavior.
The wording here is tricky. This will only work for oci-image resources. Once you have a file resource using a local upload you can never go back to the revisions numbers. However we will not be supporting local upload of a file resource with terraform.
How hard is it to always provide a link to an image rather than handling the data in a file? e.g.
|
cc90a12
to
2b8c852
Compare
The review comments are addressed. The resources are updated to latest revision associated with the charm channel upon channel updates. As summarized below, only image resources could be provided as custom resource inputs. Image information could be written directly in a string format or provided in a json or yaml file. This PR both works with deployFromRepository and legacyDeploy methods, so older Juju versions are supported.
|
2b8c852
to
4acc5b8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm part way through my review. However I've run out of time to complete it, this is what I have now. I had to spend some time refreshing my knowledge of how juju handles resources, it's a complex bit of code.
I see no need to add the json or yaml file option for oci-images as they can be directly listed in the plan as a URL. It also muddies the water around uploading file resources which we do not intend to support.
9d89021
to
12f19e7
Compare
1 similar comment
2106a84
to
749290a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are my current comments, though I haven't completed the review yet.
Mostly polish and nitpicks with 2 main questions/concerns. One is about not using the juju api resource client directly and the other is related to the validator logic. More detail with the lines.
Some of the changes are to make the code more consistent with already existing code style.
P.S I'm trying out using https://conventionalcomments.org
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QA went well with both k8s and machine charms and their resources.
Hello Heather, I have addressed some of the comments but some of them are still open. I will continue on Monday. Regarding with the validator, I appreciate for your comments. I tried to improve the logic. I will also add the test cases for each scenario. |
1bd1220
to
af21bc2
Compare
In the previous commits, a new sample TF plan was added to show the usage of custom resources. This commits reverts this change by adding combining the placement and resource usage example in the same existing TF plan. Signed-off-by: gatici <[email protected]>
ProviderStableVersion is changed while performing some local tests mistakenly. This change is reverted with this commit. Signed-off-by: gatici <[email protected]>
Empty lines are required between different types of imports and these are added within this commit. Signed-off-by: gatici <[email protected]>
Resolving the merge conflicts with main branch as another merged PRs created some conflicts. Signed-off-by: gatici <[email protected]>
This commit reorganizes the resourceKeyMarkdownDescription by simplifying the explanation. Signed-off-by: gatici <[email protected]>
This PR adds new functions to upload OCI images and handle upload requests. In the initial commit, all these functions were added to the `applications.go` file which reduces the readability of code. This commit puts all the functions which are used to process OCI image resources in a separate file named `resources.go' to reduce the complexity and increase the readilibity. docs(application): Application documentation is updated by adding custom resource usage in the existing sample TF plan. Application optional TF plan parameters are updated by changing the description of `resources` map. test(resources): A few tests are added for the functions in the resources.go. This tests will be expanded in the next commits. Signed-off-by: gatici <[email protected]>
We would like to indicate that default revision number from the CharmHub should be used by providing an invalid revision number. Formerly "0" was used but this is now fixed by replacing it with "-1" in this commit. Signed-off-by: gatici <[email protected]>
ResourceKey schema is validated using a custom PlanValidator named StringIsResourceKeyValidator to to ensure that the string is an int or OCI image information as a URL. This will allow for failure during the planning phase if the values are not as expected. Signed-off-by: gatici <[email protected]>
…nd processResources functions This commit renames the arguments in two functions as existing arguments does not identify the correct resource types withing this change.: - func processResources: - resources -> resourcesToUse Argument "resources" are too generic and it is renamed to resourcesToUse. - In addPendingResources: - resourcesToBeAdded -> charmResources resourcesToBeAdded indicates the resources which are available in the charm.Hence charmResources are used to indicate this map. - resourcesRevisions -> resourcesToUse resourceRevisions does not cover the OCI resources, however this map could include resource revisions from CharmHub and custom OCI images. Signed-off-by: gatici <[email protected]>
…adibility In ReadApplication method, rename resourceRevisions to usedResources chore: Delete unnecassary configuration files which are planned to used provider testing Signed-off-by: gatici <[email protected]>
The mistalenly disabled lines are enabled. Signed-off-by: gatici <[email protected]>
Signed-off-by: gatici <[email protected]>
The PR was parked for a long time and provider stable version is updated in the main branch during this time period. We need to use the same provider version. Signed-off-by: gatici <[email protected]>
from Charmhub if a resource revision is provided If a revision is provided and application channel is updated, provided revision number is used in the application. docs(resources): Update the ResourceKey description in the Markdown file chore: Improve the implementation of isInt method Signed-off-by: gatici <[email protected]>
…epository URL format Images are provided in allowed URL pattern and it is validated using regex format. Juju APIs can not resolve the image provided in digest format so this format is not allowed. Signed-off-by: gatici <[email protected]>
Debug mode is set to True during development and mistakenly committed. This change is reverted. Signed-off-by: gatici <[email protected]>
docs: Fixing typos and wrong content in method docstrings chore: Updating and adding license header files feat(resource): Remove new added ResourceHttpClient and use existing Juju resourcesAPIClient. To use Juju resourcesAPIClient some additional Charm info required and helper methods are added to under resources.go. chore: Unnecessary spaces are removed. fix: Comments are addressed in validator resourcekey file to increase the readability. Signed-off-by: gatici <[email protected]>
…o increase readibility Signed-off-by: gatici <[email protected]>
Format the definition to fix the awkwardly reading and make it compatible with Spec: https://docs.google.com/document/d/1i236ntmw-qXyqifmEtk_rcszWXcXSUhXkeJ6ByKXIeE/edit. Signed-off-by: gatici <[email protected]>
refactor: StringIsResourceKeyValidator ValidateMap function is refactored to increase the readibility. Signed-off-by: gatici <[email protected]>
fix(resources): Fix the helper methods to get the base or series if none of them explicitly provided. Signed-off-by: gatici <[email protected]>
and legacyDeploy methods feat: Use ResourceAPIClient.Upload to upload the custom resources for the applications which are deployed with deployFromRepository method tests: Use grafana-k8s charm to validate the custom resource usage in the integration tests Signed-off-by: gatici <[email protected]>
tests: add more unit tests for addPendingResource and UploadPendingResource methods fix: solve inregratation test and linting issues Signed-off-by: gatici <[email protected]>
0a004b1
to
a8acb4c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! merging now.
/merge |
The failing integration tests are timing out for taking too long. There will shortly be a PR to help with this. |
Description
This PR provides to use custom (OCI image) charm resources with applications. The application resource could be a charm revision or a custom OCI image which needs to be pulled from a repository. The following "juju_application" resource definition becomes valid within this PR. This PR both works with all the Juju versions which are supported by Juju Terraform provider. (Tested with Juju 2.9.x and 3.4.x versions)
Design Spec: https://docs.google.com/document/d/1i236ntmw-qXyqifmEtk_rcszWXcXSUhXkeJ6ByKXIeE/edit
Fixes: #460
Type of change
Environment
The following steps are performed to prepare the environment.
Install Microk8s:
Install Juju:
Install Terraform:
Create
terraformrc
file with following contents. Write the path ofterraform.d/plugins
directory if it is in a different path.QA steps
Manual QA steps should be done to test this PR.
Create a folder to store the Terraform files for testing.
mkdir testing
cd testing
Create a
main.tf
file with following contents:Create a
terraform.tf
file with following contents:Create a
terraform.tfvars
file with following contents:Create a
variables.tf
file with following contents:Fetch the PR and run following commads to install it.
Create a juju model:
Initialise the provider:
Run Terraform plan by providing a var-file:
Deploy the application:
Check the pod to see the attached image.
Additional notes
Test with changing the resources part with different image versions.
Using a revision as string: