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(application): handle storage details conversion error #525

Conversation

anvial
Copy link
Member

@anvial anvial commented Jul 12, 2024

Description

This PR ensures that the application correctly handles storage conversion errors and retries appropriately until the storage is ready.

  • Added error handling for "cannot convert storage details" in applicationsClient.ReadApplication.
  • Improved retry logic for storage readiness in ReadApplicationWithRetryOnNotFound.

Add a fatal error check to the retry logic around reading an application. Fail if ApplicationsInfo fails in a way other than expected. See a "connection refused" error, which is intermittent, so allow for retry in that case.

Fixes: #520

Type of change

  • Change in tests (one or several tests have been changed)
  • Bug fix (non-breaking change which fixes an issue)

QA steps

Also run reproduction steps from bug.

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

resource "juju_model" "sunbeam" {
  name = var.model

  cloud {
    name   = var.cloud
    region = "localhost"
  }

  config = var.config
}

resource "juju_application" "mysql" {
  name  = "mysql"
  trust = true
  model = juju_model.sunbeam.name

  charm {
    name    = "mysql-k8s"
    channel = "8.0/stable"
    base    = "ubuntu@22.04"
  }

  storage_directives = { database = "1G" }
}

resource "juju_application" "mysql1" {
  name  = "mysql1"
  trust = true
  model = juju_model.sunbeam.name

  charm {
    name    = "mysql-k8s"
    channel = "8.0/stable"
    base    = "ubuntu@22.04"
  }

  storage_directives = { database = "1G" }
}

resource "juju_application" "mysql2" {
  name  = "mysql2"
  trust = true
  model = juju_model.sunbeam.name

  charm {
    name    = "mysql-k8s"
    channel = "8.0/stable"
    base    = "ubuntu@22.04"
  }

  storage_directives = { database = "1G" }
}

resource "juju_application" "mysql3" {
  name  = "mysql3"
  trust = true
  model = juju_model.sunbeam.name

  charm {
    name    = "mysql-k8s"
    channel = "8.0/stable"
    base    = "ubuntu@22.04"
  }

  storage_directives = { database = "1G" }
}

resource "juju_application" "mysql4" {
  name  = "mysql4"
  trust = true
  model = juju_model.sunbeam.name

  charm {
    name    = "mysql-k8s"
    channel = "8.0/stable"
    base    = "ubuntu@22.04"
  }

  storage_directives = { database = "1G" }
}

resource "juju_application" "mysql5" {
  name  = "mysql5"
  trust = true
  model = juju_model.sunbeam.name

  charm {
    name    = "mysql-k8s"
    channel = "8.0/stable"
    base    = "ubuntu@22.04"
  }

  storage_directives = { database = "1G" }
}

resource "juju_application" "mysql6" {
  name  = "mysql6"
  trust = true
  model = juju_model.sunbeam.name

  charm {
    name    = "mysql-k8s"
    channel = "8.0/stable"
    base    = "ubuntu@22.04"
  }

  storage_directives = { database = "1G" }
}

resource "juju_application" "mysql7" {
  name  = "mysql7"
  trust = true
  model = juju_model.sunbeam.name

  charm {
    name    = "mysql-k8s"
    channel = "8.0/stable"
    base    = "ubuntu@22.04"
  }

  storage_directives = { database = "1G" }
}

resource "juju_application" "mysql8" {
  name  = "mysql8"
  trust = true
  model = juju_model.sunbeam.name

  charm {
    name    = "mysql-k8s"
    channel = "8.0/stable"
    base    = "ubuntu@22.04"
  }

  storage_directives = { database = "1G" }
}

variable "model" {
  description = "Name of Juju model to use for deployment"
  default     = "sunbeam"
}

variable "cloud" {
  description = "Name of K8S cloud to use for deployment"
  default     = "microk8s"
}

variable "config" {
  description = "Set configuration on model"
  default     = { "workload-storage" : "microk8s-hostpath" }
}
rm -rf .terraform* && rm -rf terraform*

terraform init -upgrade  && terraform plan && terraform apply -auto-approve -parallelism=3

@anvial anvial requested a review from hmlanigan July 12, 2024 11:44
- Added error handling for "cannot convert storage details"
  in `applicationsClient.ReadApplication`.
- Improved retry logic for storage readiness in `ReadApplicationWithRetryOnNotFound`.

This commit ensures that the application correctly handles storage conversion errors and retries
appropriately until the storage is ready.
@anvial anvial force-pushed the JUJU-6355-panic-runtime-error-invalid-memory-address-or-nil-pointer-dereference-520 branch from 4c85fc2 to 185ce0d Compare July 12, 2024 13:18
@hmlanigan hmlanigan added this to the 0.13.0 milestone Jul 12, 2024
Related to juju#520, panic on nil pointer from ReadApplicationWithRetryOnNotFound.
Add IsFatalError func to retry. Allow for known types or "connection
refused" which is intermittent. Doesn't guarentee that everything works
as expected, but doesn't panic either.
@hmlanigan hmlanigan force-pushed the JUJU-6355-panic-runtime-error-invalid-memory-address-or-nil-pointer-dereference-520 branch from 44a5f6e to 98952a1 Compare July 12, 2024 21:16
Copy link

@cderici cderici left a comment

Choose a reason for hiding this comment

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

LGTM, QA went well, tried with various -parallelism values (including -parallelism=3) and was able to apply the plan each time 👍

@anvial
Copy link
Member Author

anvial commented Jul 15, 2024

Thx, I also double checked... I'll land these changes.

Heather, thx for catching IsFatalError case, I didn't see it on my local machine.

@anvial anvial merged commit ae0e31d into juju:main Jul 15, 2024
26 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.

panic: runtime error: invalid memory address or nil pointer dereference
3 participants