Skip to content
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

Merge main jaas resources #585

Merged
merged 39 commits into from
Sep 23, 2024

Conversation

kian99
Copy link
Contributor

@kian99 kian99 commented Sep 20, 2024

Description

This PR merges main into jaas-resources and fixes conflicts.

Type of change

  • Other (merge main into feature branch)

cderici and others added 30 commits September 23, 2024 10:10
…e definition

This commit updates the `juju_application` resource example in the `resource.tf` file,
specifying the correct charm storage definition. This change ensures the example aligns
with the latest usage patterns and configurations for deploying applications with storage.
Bumps [github.com/hashicorp/terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework) from 1.9.0 to 1.10.0.
- [Release notes](https://github.com/hashicorp/terraform-plugin-framework/releases)
- [Changelog](https://github.com/hashicorp/terraform-plugin-framework/blob/main/CHANGELOG.md)
- [Commits](hashicorp/terraform-plugin-framework@v1.9.0...v1.10.0)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/terraform-plugin-framework
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
- Add validation logic to check for unknown or null values in the map elements.
- Parse and validate storage directives using `juju/storage` package
  (use `jujustorage` name instead `storage`).
Bumps github.com/hashicorp/terraform-plugin-framework-validators from 0.12.0 to 0.13.0.
- [Release notes](https://github.com/hashicorp/terraform-plugin-framework-validators/releases)
- [Commits]
  (hashicorp/terraform-plugin-framework-validators@v0.12.0...v0.13.0)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/terraform-plugin-framework-validators
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [github.com/juju/cmd/v3](https://github.com/juju/cmd) from 3.0.14 to 3.0.16.
- [Release notes](https://github.com/juju/cmd/releases)
- [Commits](juju/cmd@v3.0.14...v3.0.16)

---
updated-dependencies:
- dependency-name: github.com/juju/cmd/v3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Charms we need to test with microk8s do not support 2.9, thus test
against 3.1 for legacy code paths. Juju 3.1. requires the strictly
confined microk8s snap.

Update lxd to 5.21 channel while here.
Swap for a newer version of terraform when testing: 1.9 for 1.8. Where
we test with multiple versions, only use the latest 3.
- This commit defines ResourceHttpClient to upload custom OCI resources to Juju controller.
- `addPendingResources` function is modified to upload custom resources.
- Application is deployed using custom resources.

docs(application): Application markdown file is modified to update `resources`
description of application definition in the TF plan.

IMPORTANT: Application input resources are changed from map[string]int
to resources map[string]string.

Signed-off-by: gatici <[email protected]>
This commit updates the application resources after the application is
deployed using a custom OCI resource when TF plan resources are updated.

tests(resource): UploadPendingResource mock base method is generated.

Signed-off-by: gatici <[email protected]>
…ource

If the application is deployed with specified resources such
as revision numbers from CharmHub or an OCI image,
then the resources are removed from the TF plan, the default
resources from the CharmHub is used.

test(resources): Adding tests for new functions that added
for custom resource upload

docs(application): Updating application resources map
description in the application markdown file

Signed-off-by: gatici <[email protected]>
… revision

upon channel updates

If the charm channel is updated and revision or custom image is not
specified in the TF plan, a resource revision should be attached
according the updated channel.
Formerly, this functionality is not implemented properly.
This commit implements this.

revert: Unncessary resource files added for testing are removed.

chore: Some libraries are updated in go.mod and go.sum.
Linting issues are fixed.

docs(resources): Documentation is updated for `resources` key
to include added functionality.

Signed-off-by: gatici <[email protected]>
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]>
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]>
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]>
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]>
gatici and others added 9 commits September 23, 2024 10:22
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]>
Fixes: juju#466

Juju does not distinguish between null constraints and empty-string
constraints. However, null is not considered by terraform to be a
computed value, whereas the empty string is.

Since the constraints schema marks constraints as a computed field, this
means if we insert null into state it will be considered uncomputed & on
the next apply terraform will attempt to compute the constraints by
setting them.

This leads to bugs since subordinate applications cannot have
constraints applied.

Since we know that subordinate applications cannot have constraints, on
Create or Read we can easily 'compute' the constraints ourselves as "".
The cla check verifies that someone contributing to a Canonical project has
signed the Canonical CLA agreement
Call full status with a filter of the application name when Reading,
this ensures that the returned storage is for the current application
only.

Updated an application acceptance test to ensure storage isn't written
for applications without storage.
Check the pointer before using it. First reported in juju#549 which has been
unreproducible. Added a debug message if it can be reproduced other
places to get a better understanding.
- Don't use postgres charms that require storage when running offer tests.
@kian99 kian99 force-pushed the merge-main-jaas-resources branch from defa535 to d2413c8 Compare September 23, 2024 08:23
@kian99 kian99 requested a review from hmlanigan September 23, 2024 08:25
@kian99
Copy link
Contributor Author

kian99 commented Sep 23, 2024

@hmlanigan The conventional commit check is failing. I'm trying to merge main into jaas-resources and I don't want to modify existing commits. Can you override that check to still merge this PR if you are okay with the changes?

@hmlanigan
Copy link
Member

Merging with conventional commits failing, it's on a dependabot PR which was done before this check was added.

@hmlanigan hmlanigan merged commit 7e97049 into juju:jaas-resources Sep 23, 2024
26 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants