Skip to content

Commit

Permalink
Merge pull request #353 from hmlanigan/fix-issue-346
Browse files Browse the repository at this point in the history
Fix issue 346: Do not require permissions on the controller model to deploy an application.
  • Loading branch information
hmlanigan committed Dec 6, 2023
2 parents 6f261d5 + e97c75d commit 4eaafbd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand Down
33 changes: 8 additions & 25 deletions internal/juju/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{}
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions internal/provider/resource_offer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ resource "juju_application" "this" {
charm {
name = "postgresql"
channel = "latest/stable"
%s
}
}
Expand Down

0 comments on commit 4eaafbd

Please sign in to comment.