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

fix(storagedirective): fix storage directive validator #538

Merged
merged 2 commits into from
Aug 7, 2024

Conversation

anvial
Copy link
Member

@anvial anvial commented Aug 1, 2024

Description

This fix add the following:

  • 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).

Fixes: #534

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Environment

  • Juju controller version:

  • Terraform version:

QA steps

terraform {
  required_providers {
    juju = {
      source  = "juju/juju"
      version = "0.14.0"
    }
  }
}
provider "juju" {}

resource "juju_model" "tf-test" {
  name = "tf-test"
}

variable "blocksize"{
  type    = string
  default = "101M"
}

variable "filessize"{
  type    = string
  default = "102M"
}

variable "pgstorages" {
  type = map
  default = {
    "files"  = "2G"
  }
}

resource "juju_application" "test-app-storage" {
  model = juju_model.tf-test.name
  name = "test-app-storage"
  charm {
    name = "ubuntu"
    channel = "latest/stable"
    revision = 24
  }

  # storage_directives = var.pgstorages
  storage_directives = {
    files = var.filessize
    block = var.blocksize
  }

  units = 1
}
...

- 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`).
@anvial anvial requested a review from hmlanigan August 1, 2024 15:54
Copy link
Member

@hmlanigan hmlanigan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't completed QA yet, but I have a question.

// If the value of any element is unknown or null, there is nothing to validate.
for _, element := range req.ConfigValue.Elements() {
if element.IsUnknown() || element.IsNull() {
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: Should this be continue instead? What if there is more than one storage directive provided?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we just need to stop validating if we have at least one unknown among variables.

I've updated QA to touch case with multiple vars and and storage directives.
It looks like it's working.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: update the comment at line 33 to describe what is going on so we know if it breaks again. Below describes what I found and why this works.

It's only working because the method is called twice by terraform. I added some logging to see what is going on

Warning: CALLED ValidateMap "{\"block\":<unknown>,\"files\":\"73heather\"}"
Warning: CALLED ValidateMap "{\"block\":\"101M\",\"files\":\"73heather\"}"

The second call has the values filled in. I have no idea why terraform is doing this. If the behavior changes, we won't validate all the values.

@hmlanigan hmlanigan self-requested a review August 5, 2024 20:06
Copy link
Member

@hmlanigan hmlanigan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the comment is appropriately updated, approved.

@anvial
Copy link
Member Author

anvial commented Aug 7, 2024

/usr/bin/sg microk8s -c microk8s kubectl -n kube-system rollout status deployment/coredns
  Waiting for deployment "coredns" rollout to finish: 0 of 1 updated replicas are available...
  error: deployment "coredns" exceeded its progress deadline
  Command microk8s kubectl -n kube-system rollout status deployment/coredns failed with return code 1. Will retry after 10000ms

It looks like the GitHub action fails, not because of the PR. So I'll merge it.

@anvial anvial merged commit 4bcd17c into juju:main Aug 7, 2024
26 of 27 checks passed
@hmlanigan hmlanigan added this to the 0.14.0 milestone Aug 28, 2024
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.

Storage specification doesn't seem to support values coming from variables
2 participants