From f4241284dcbe0198c94d22a0daf26aff8c4b94f6 Mon Sep 17 00:00:00 2001 From: Heather Lanigan Date: Mon, 4 Dec 2023 16:01:57 -0500 Subject: [PATCH 1/2] A better way to find the controller version. The old way failed when a juju user without permissions for the controller model used a plan to deploy an application. It also created an additional connection and client, which with the new method are not needed. Leaving the controller version off the application client is not a problem as a new client is created for all terraform plans/applies. It will be found new each time. --- go.mod | 2 +- internal/juju/applications.go | 33 ++++++++------------------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/go.mod b/go.mod index cc80021a..fb19df95 100644 --- a/go.mod +++ b/go.mod @@ -24,6 +24,7 @@ require ( github.com/juju/names/v4 v4.0.0 github.com/juju/retry v1.0.0 github.com/juju/utils/v3 v3.0.2 + github.com/juju/version/v2 v2.0.0 github.com/rs/zerolog v1.31.0 github.com/stretchr/testify v1.8.4 ) @@ -137,7 +138,6 @@ require ( github.com/juju/schema v1.0.1 // indirect github.com/juju/txn/v2 v2.1.1 // indirect github.com/juju/usso v1.0.1 // indirect - github.com/juju/version/v2 v2.0.0 // indirect github.com/juju/webbrowser v1.0.0 // indirect github.com/juju/worker/v3 v3.4.0 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect diff --git a/internal/juju/applications.go b/internal/juju/applications.go index 15a0190c..f02570a9 100644 --- a/internal/juju/applications.go +++ b/internal/juju/applications.go @@ -29,7 +29,6 @@ import ( apicharms "github.com/juju/juju/api/client/charms" apiclient "github.com/juju/juju/api/client/client" apimodelconfig "github.com/juju/juju/api/client/modelconfig" - "github.com/juju/juju/api/client/modelmanager" apiresources "github.com/juju/juju/api/client/resources" apicommoncharm "github.com/juju/juju/api/common/charm" "github.com/juju/juju/cmd/juju/application/utils" @@ -39,9 +38,10 @@ import ( "github.com/juju/juju/core/series" "github.com/juju/juju/environs/config" "github.com/juju/juju/rpc/params" - "github.com/juju/juju/version" + jujuversion "github.com/juju/juju/version" "github.com/juju/names/v4" "github.com/juju/retry" + "github.com/juju/version/v2" ) var ApplicationNotFoundError = &applicationNotFoundError{} @@ -57,6 +57,7 @@ func (ae *applicationNotFoundError) Error() string { type applicationsClient struct { SharedClient + controllerVersion version.Number } // ConfigEntry is an auxiliar struct to keep information about @@ -192,6 +193,9 @@ func (c applicationsClient) CreateApplication(ctx context.Context, input *Create } defer func() { _ = conn.Close() }() + // Version needed for operating system selection. + c.controllerVersion, _ = conn.ServerVersion() + charmsAPIClient := apicharms.NewClient(conn) applicationAPIClient := apiapplication.NewClient(conn) modelconfigAPIClient := apimodelconfig.NewClient(conn) @@ -393,32 +397,11 @@ func (c applicationsClient) CreateApplication(ctx context.Context, input *Create // uses juju 2.9.45 code. However the supported workload series list is // different between juju 2 and juju 3. Handle that here. func (c applicationsClient) supportedWorkloadSeries(imageStream string) (set.Strings, error) { - conn, err := c.GetConnection(nil) - if err != nil { - return nil, err - } - defer func() { _ = conn.Close() }() - - modelManagerAPIClient := modelmanager.NewClient(conn) - - uuid, err := c.ModelUUID("controller") - if err != nil { - return nil, err - } - - info, err := modelManagerAPIClient.ModelInfo([]names.ModelTag{names.NewModelTag(uuid)}) - if err != nil { - return nil, err - } - if info[0].Error != nil { - return nil, info[0].Error - } - supportedSeries, err := series.WorkloadSeries(time.Now(), "", imageStream) if err != nil { return nil, err } - if info[0].Result.AgentVersion.Major > 2 { + if c.controllerVersion.Major > 2 { unsupported := set.NewStrings("bionic", "trusty", "windows", "xenial", "centos7", "precise") supportedSeries = supportedSeries.Difference(unsupported) } @@ -485,7 +468,7 @@ func (c applicationsClient) seriesToUse(modelconfigAPIClient *apimodelconfig.Cli } // Note: This DefaultSupportedLTS is specific to juju 2.9.45 - lts := version.DefaultSupportedLTS() + lts := jujuversion.DefaultSupportedLTS() // Select an actually supported series return charm.SeriesForCharm(lts, supportedSeries.Values()) From e97c75d6bafb8d2e9e83113784567ebf266e61b0 Mon Sep 17 00:00:00 2001 From: Heather Lanigan Date: Mon, 4 Dec 2023 16:18:19 -0500 Subject: [PATCH 2/2] Fix test. Postgresql charm in the default channel supports 22.04 only. Specify the lastest/stable channel to find other versions of ubuntu. --- internal/provider/resource_offer_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/provider/resource_offer_test.go b/internal/provider/resource_offer_test.go index a496b902..f479218e 100644 --- a/internal/provider/resource_offer_test.go +++ b/internal/provider/resource_offer_test.go @@ -149,6 +149,7 @@ resource "juju_application" "this" { charm { name = "postgresql" + channel = "latest/stable" %s } }