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

Application creation not successful until storages for all apps in the batch are completed #539

Open
hemanthnakkina opened this issue Aug 5, 2024 · 1 comment
Assignees
Labels
area/application hint/main going on main branch kind/bug indicates a bug in the project state/in-progress currently being worked on

Comments

@hemanthnakkina
Copy link
Contributor

Description

Deployed a terraform plan with a mix of application resources that requires storage and does not require storage.
When terraform plan is applied, the "Creation complete" for application resource that does not require storage only printed after storages are created for all the applications.

The expectation is to complete the application resources that does not require storage with no dependency on storages of other applications and start creation of new resources that exist in plan.

This is observed on juju 3.5.3 + microk8s v1.28.10 cloud

Urgency

Casually reporting

Terraform Juju Provider version

0.13.0

Terraform version

1.9.3

Juju version

3.5.3

Terraform Configuration(s)

terraform {
  required_providers {
    juju = {
      source  = "juju/juju"
      version = "= 0.13.0"
    }
  }
}

provider "juju" {}

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

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

  credential = var.credential
  config     = var.config
}

# 1 storage resource
resource "juju_application" "mysql" {
  model = juju_model.sunbeam.name
  name  = "mysql"

  charm {
    name     = "mysql-k8s"
    channel  = "8.0/stable"
    revision = null
  }

  config             = var.mysql-config
  storage_directives = var.mysql-storage
  units              = 1
  trust              = false
}

resource "juju_application" "mysql-router" {
  name  = "keystone-mysql-router"
  model = juju_model.sunbeam.name

  charm {
    name    = "mysql-router-k8s"
    channel = "8.0/stable"
  }

  units = 1
  trust = false
}

resource "juju_integration" "mysql-router-to-mysql" {
  model = juju_model.sunbeam.name

  application {
    name     = juju_application.mysql-router.name
    endpoint = "backend-database"
  }

  application {
    name     = juju_application.mysql.name
    endpoint = "database"
  }
}

# 2 storage resources
resource "juju_application" "keystone" {
  model = juju_model.sunbeam.name
  name  = "keystone"

  charm {
    name     = "keystone-k8s"
    channel  = "2024.1/edge"
  }

  config             = {}
  storage_directives = {}
  units              = 1
  trust              = false
}

resource "juju_integration" "service-to-mysql-router" {
  model = juju_model.sunbeam.name

  application {
    name     = juju_application.keystone.name
    endpoint = "database"
  }

  application {
    name     = juju_application.mysql-router.name
    endpoint = "database"
  }
}

# 4 storage resources
resource "juju_application" "vault" {
  model = juju_model.sunbeam.name
  name  = "vault"

  charm {
    name     = "vault-k8s"
    channel  = "1.15/edge"
    revision = 61
  }

  config             = var.vault-config
  storage_directives = var.vault-storage
  units              = 1
  trust              = false
}

# No storage resources
resource "juju_application" "bind" {
  name  = "bind"
  model = juju_model.sunbeam.name

  charm {
    name     = "designate-bind-k8s"
    channel  = "9/stable"
    revision = null
  }

  config = {}
  units  = 1
}


variable "model" {
  description = "Name of Juju model to use for deployment"
  type        = string
  default     = "openstack"
}

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

# https://github.com/juju/terraform-provider-juju/issues/147
variable "credential" {
  description = "Name of credential to use for deployment"
  type        = string
  default     = "microk8s"
}

variable "config" {
  description = "Set configuration on model"
  type        = map(string)
  default     = {}
}

variable "mysql-config" {
  description = "Operator configs for MySQL deployment"
  type        = map(string)
  default = {
    "profile-limit-memory" = 3456
  }
}

variable "mysql-storage" {
  description = "Storage directives for MySQL deployment"
  type        = map(string)
  default     = {}
}

variable "vault-config" {
  description = "Operator config for Vault deployment"
  type        = map(string)
  default     = {}
}

variable "vault-storage" {
  description = "Operator storage directives for Vault deployment"
  type        = map(string)
  default     = {}
}

Reproduce / Test

terraform init
terraform apply -auto-approve | ts '[%Y-%m-%d %H:%M:%.S]'

Debug/Panic Output

Logs attached

Notes & References

I have run the terraform plan with modified terraform-juju-provider on main. The modifications are just printouts which should be reflected in debug log. Attached print.patch.txt that contains the changes.

Attached console and debug logs for terraform apply command and hostpath-provisioner logs which provisions storage for juju+microkk8s.

tfapplyconsoleout.log
tfapplydebug.log
hostpath-provisioner.log
prints.patch.txt

From tfapplyconsoleout.log, bind application (no storage requirement) creation is started at 2024-08-05 03:02:20.786997 and completed at 2024-08-05 03:04:30.837884, that took 2 min 10 seconds for provider to consider it complete. On my observation the app is created in juju with active/idle status in 1 min.

From tfapplydebug.log, it shows bind is waiting for storage vault-raft-3 but that particular storage is required for vault application but not bind application
2024-08-05T03:02:30.370Z [DEBUG] provider.terraform-provider-juju_v0.13.0: waiting for application "bind": @caller=github.com/juju/terraform-provider-juju/internal/juju/client.go:235 @module=juju.client err="retrying: storage label \"vault-raft-3\" missing detail" timestamp=2024-08-05T03:02:30.370Z

@hemanthnakkina
Copy link
Contributor Author

#535 can be related

@Aflynn50 Aflynn50 added kind/bug indicates a bug in the project area/application hint/main going on main branch labels Aug 8, 2024
@hmlanigan hmlanigan assigned hmlanigan and unassigned anvial Aug 26, 2024
@hmlanigan hmlanigan added the state/in-progress currently being worked on label Aug 26, 2024
jujubot added a commit that referenced this issue Aug 29, 2024
#557

## Description

FullStatus was called without a filter. The storage returned in the structure was assumed to be for the application being read. In reality it was for all application's in the model. Unfortunately piecing which storage is for which application is non-trivial as the data is embedded deep in the structure on a unit level.

Instead call FullStatus 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.

Fixes: #535, #539, #550

## Type of change

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

## QA steps

```tf
terraform {
 required_providers {
 juju = {
 version = ">0.12.0"
 source = "juju/juju"
 }
 }
}

provider "juju" {
}

resource "juju_model" "one" {
 name = "testing"
}

resource "juju_application" "test" {
 model = juju_model.one.name
 charm {
 name = "juju-qa-test"
 }
}

resource "juju_application" "githubrunner" {
 name = "github-runner"
 model = juju_model.one.name

 charm {
 name = "github-runner"
 channel = "latest/stable"
 base = "[email protected]"
 }
 units = 1

 storage_directives = {
 runner = "2G"
 }
}
```

```
# output from the below should include storage_directive and storage
$ terraform state show juju_application.githubrunner

# output from below should not include any mention of storage
$ terraform state show juju_application.test
```

## Additional notes

JUJU-6599
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/application hint/main going on main branch kind/bug indicates a bug in the project state/in-progress currently being worked on
Projects
None yet
Development

No branches or pull requests

4 participants