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 issue 346: Do not require permissions on the controller model to deploy an application. #353

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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