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

Implement endpoint bindings for applications (#400) #418

Merged
merged 8 commits into from
Mar 13, 2024

Conversation

gboutry
Copy link
Contributor

@gboutry gboutry commented Feb 29, 2024

Description

The goal is to enable binding endpoints to specific spaces. This features will used in sunbeam when deploying with MAAS.

Fixes: #400

Type of change

<What type of a change is this? Please keep one or more relevant lines from below and delete the others.>

  • Change existing resource
  • Logic changes in resources (the API interaction with Juju has been changed)
  • Change in tests (one or several tests have been changed)
  • Requires a documentation update
  • Maintenance work (repository related, like Github actions, or revving the Go version, etc.)

Environment

  • Juju controller version: 3.4

  • Terraform version: 1.6

QA steps

Manual QA steps should be done to test this PR.

  • You need to have the spaces management and public associated to the model
lxc network create management-br ipv4.address=10.150.40.1/24 ipv4.nat=true ipv6.address=none ipv6.nat=false
lxc network create public-br ipv4.address=10.170.80.1/24 ipv4.nat=true ipv6.address=none ipv6.nat=false
juju add-model my-model
juju add-space management 10.150.40.0/24
juju add-space public 10.170.80.0/24
provider juju {}

data "juju_model" "resource" {
  name = "my-model"
}

resource "juju_application" "zk" {
  name  = "zookeeper"
  model = data.juju_model.resource.name

  constraints = "arch=amd64 spaces=management,public"
  charm {
    name    = "zookeeper"
    channel = "3/stable"
    base    = "[email protected]"
  }

  endpoint_bindings = [
    {
      space = "public"
    },
    {
      endpoint = "zookeeper"
      space    = "management"
    }
  ]
}

Additional notes

<Please add relevant notes & information, links to mattermost chats, other related issues/PRs, anything to help understand and QA the PR.>
Some tests were added, with a note about changing space setup when #336 is implemented.
Current integration tests have been updated to add 2 lxd bridges as support for the tests.
Tests need TEST_PUBLIC_BR and TEST_MANAGEMENT_BR containing the cidrs to be run, otherwise, they are skipped.

On behavior:
Specifying a space without an endpoint will make the space the default space (in term of bindings, not touching model configs)

Constraints are in QA/tests to make sure LXD brings the instance with right networking configuration.

@hmlanigan hmlanigan added this to the 0.11.0 milestone Feb 29, 2024
@gboutry gboutry force-pushed the feat/endpoint-bindings branch from 1da73fc to 1b01c51 Compare February 29, 2024 17:07
@gboutry
Copy link
Contributor Author

gboutry commented Feb 29, 2024

Force push is adding sudo in front of the 2 lxd commands creating the networks

@hmlanigan hmlanigan self-requested a review March 1, 2024 17:18
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.

Thank you for the PR, it'll be a nice addition to the provider functionality.

Here are my initial comments. I haven't had the chance to run initial QA yet. Over all looks good.

I've updated the GitHub action tests, so that the 2.9 tests will work for lxd now. Please rebase as described here: https://github.com/juju/terraform-provider-juju?tab=readme-ov-file#staying-in-sync

internal/provider/resource_application.go Outdated Show resolved Hide resolved
internal/provider/resource_application.go Show resolved Hide resolved
internal/provider/resource_application.go Outdated Show resolved Hide resolved
internal/juju/applications.go Outdated Show resolved Hide resolved
internal/juju/applications.go Show resolved Hide resolved
gboutry added 2 commits March 4, 2024 10:59
Add the attributes `endpoint_bindings` to the application resource. This
endpoint is a set nested attribute.

Usage:
```tf
endpoint_bindings = [
  {
    "space"    = "my_space1",
  },
  {
    "endpoint" = "my_endpoint"
    "space"    = "my_space2"
  }
]
```
Fix typos, newlines and unused return.
Fix docs not regenerated when going from nested list attribute to nested
set attribute.
@gboutry gboutry force-pushed the feat/endpoint-bindings branch from 392610d to 725cb6a Compare March 4, 2024 10:05
@gboutry
Copy link
Contributor Author

gboutry commented Mar 4, 2024

Force push is rebasing on main + adding a new commit on top of the previous ones

@gboutry gboutry force-pushed the feat/endpoint-bindings branch from 725cb6a to bc44232 Compare March 4, 2024 10:09
gboutry added 2 commits March 5, 2024 16:39
Add notice to remove validation in client side until bug lp#2055868 is
resolved.

Use model's default space to compare what's a default or not from an
application.
@gboutry
Copy link
Contributor Author

gboutry commented Mar 7, 2024

While testing for import state, I've had multiple times the failure:

=== RUN   TestAcc_ResourceApplication_EndpointBindings
    resource_application_test.go:293: Step 2/2 error running import: ImportStateVerify attributes not equivalent. Difference is shown below. The - symbol indicates attributes missing after import.
        
          map[string]string{
        - 	"placement": "",
        + 	"placement": "0",
          }
--- FAIL: TestAcc_ResourceApplication_EndpointBindings (32.63s)

@hmlanigan
Copy link
Member

@gboutry the placement issue you've seen in test is a known issue. there is also one with ordering of the placement values I might have a fix for.

gboutry added 2 commits March 7, 2024 23:26
Make sure case where default space is not defined, alpha is used as
default space.
When endpoint_bindings definition is removed from an application,
interpret it as intent and go back to default space.
@gboutry gboutry requested a review from hmlanigan March 12, 2024 08:15
@hmlanigan
Copy link
Member

@gboutry I've been locally running QA on this change and found a small nit. With an application configured in a plan as such

resource "juju_application" "application_two" {
  model = data.juju_model.testmodel.name
  charm {
    name = "ubuntu"
  }
  endpoint_bindings = [
  ]
}

The first run of terraform init && terraform plan && terraform apply is good and deploys the application. However subsequent runs without changing the plan get:

Terraform will perform the following actions:

  # juju_application.application_two will be updated in-place
  ~ resource "juju_application" "application_two" {
      + endpoint_bindings = []
        id                = "six:ubuntu"
        name              = "ubuntu"
      + principal         = (known after apply)
        # (5 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

However there is no change to make. Looks good other than this.

@gboutry
Copy link
Contributor Author

gboutry commented Mar 12, 2024

Thanks for your review @hmlanigan, I fixed this issue.

I ran manual QA steps + whole acceptance test suite on this new commit.

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.

LGTM. I'm sure many people will be happy with this update. Thank you!

@hmlanigan hmlanigan merged commit a5b3bc0 into juju:main Mar 13, 2024
17 of 23 checks passed
@gboutry gboutry deleted the feat/endpoint-bindings branch March 14, 2024 06:48
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.

Add application space support
2 participants