Skip to content

Commit

Permalink
Update charm/v9 dependency and remove juju version shims
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyworld committed Mar 25, 2021
1 parent d4fa180 commit b001fb3
Show file tree
Hide file tree
Showing 22 changed files with 29 additions and 63 deletions.
2 changes: 1 addition & 1 deletion api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ func (c *Client) UploadCharm(curl *charm.URL, content io.ReadSeeker) (*charm.URL
}

func (c *Client) validateCharmVersion(ch charm.Charm) error {
minver := jujuversion.ToVersion2(ch.Meta().MinJujuVersion)
minver := ch.Meta().MinJujuVersion
if minver != version.Zero {
agentver, err := c.AgentVersion()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func testMinVer(client *api.Client, t minverTest, c *gc.C) {
curl := charm.MustParseURL(
fmt.Sprintf("local:quantal/%s-%d", charmArchive.Meta().Name, charmArchive.Revision()),
)
charmArchive.Meta().MinJujuVersion = jujuversion.ToVersion1(charmMinVer)
charmArchive.Meta().MinJujuVersion = charmMinVer

_, err := client.AddLocalCharm(curl, charmArchive, t.force)

Expand Down
2 changes: 1 addition & 1 deletion api/common/charms/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/juju/errors"
"github.com/juju/systems"
"github.com/juju/systems/channel"
"github.com/juju/version"
"github.com/juju/version/v2"

"github.com/juju/juju/api/base"
"github.com/juju/juju/apiserver/params"
Expand Down
2 changes: 1 addition & 1 deletion api/common/charms/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/juju/charm/v9/resource"
"github.com/juju/systems"
"github.com/juju/systems/channel"
"github.com/juju/version"
"github.com/juju/version/v2"
gc "gopkg.in/check.v1"

basemocks "github.com/juju/juju/api/base/mocks"
Expand Down
2 changes: 1 addition & 1 deletion apiserver/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"github.com/gorilla/handlers"
"github.com/juju/errors"
"github.com/juju/version"
"github.com/juju/version/v2"

agenttools "github.com/juju/juju/agent/tools"
"github.com/juju/juju/apiserver/common/apihttp"
Expand Down
2 changes: 1 addition & 1 deletion apiserver/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"strings"

jc "github.com/juju/testing/checkers"
"github.com/juju/version"
"github.com/juju/version/v2"
gc "gopkg.in/check.v1"

agenttools "github.com/juju/juju/agent/tools"
Expand Down
6 changes: 2 additions & 4 deletions apiserver/facades/client/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,7 @@ func caasPrecheck(
}

// For older charms, operator-storage model config is mandatory.
minver := ch.Meta().MinJujuVersion
if k8s.RequireOperatorStorage(jujuversion.ToVersion2(minver)) {
if k8s.RequireOperatorStorage(ch.Meta().MinJujuVersion) {
storageClassName, _ := cfg.AllAttrs()[k8sconstants.OperatorStorageKey].(string)
if storageClassName == "" {
return errors.New(
Expand Down Expand Up @@ -486,8 +485,7 @@ func deployApplication(
return errors.Trace(err)
}

minver := ch.Meta().MinJujuVersion
if err := jujuversion.CheckJujuMinVersion(jujuversion.ToVersion2(minver), jujuversion.Current); err != nil {
if err := jujuversion.CheckJujuMinVersion(ch.Meta().MinJujuVersion, jujuversion.Current); err != nil {
return errors.Trace(err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ func (s *ApplicationSuite) TestDeployCAASModelCharmNeedsNoOperatorStorage(c *gc.
s.PatchValue(&jujuversion.Current, version.MustParse("2.8-beta1"))
s.backend.charm = &mockCharm{
meta: &charm.Meta{
MinJujuVersion: jujuversion.ToVersion1(version.MustParse("2.8.0")),
MinJujuVersion: version.MustParse("2.8.0"),
},
}

Expand Down
3 changes: 1 addition & 2 deletions apiserver/facades/client/application/charmstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ func AddCharmWithAuthorizationAndRepo(st State, args params.AddCharmWithAuthoriz
type versionValidator struct{}

func (versionValidator) Validate(meta *charm.Meta) error {
minver := meta.MinJujuVersion
return jujuversion.CheckJujuMinVersion(jujuversion.ToVersion2(minver), jujuversion.Current)
return jujuversion.CheckJujuMinVersion(meta.MinJujuVersion, jujuversion.Current)
}

type charmStateShim struct {
Expand Down
3 changes: 1 addition & 2 deletions apiserver/facades/client/charms/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ func (a *API) addCharmWithAuthorization(args params.AddCharmWithAuth) (params.Ch
type versionValidator struct{}

func (versionValidator) Validate(meta *charm.Meta) error {
minver := meta.MinJujuVersion
return jujuversion.CheckJujuMinVersion(jujuversion.ToVersion2(minver), jujuversion.Current)
return jujuversion.CheckJujuMinVersion(meta.MinJujuVersion, jujuversion.Current)
}

// CharmArchive is the data that needs to be stored for a charm archive in
Expand Down
3 changes: 3 additions & 0 deletions apiserver/facades/client/machinemanager/upgrade_series.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
package machinemanager

import (
"context"
"fmt"

"github.com/juju/charm/v9"
"github.com/juju/collections/set"
"github.com/juju/errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ func (a *API) OperatorProvisioningInfo(args params.Entities) (params.OperatorPro
result.Results[i].Error = apiservererrors.ServerError(err)
continue
}
minVer := ch.Meta().MinJujuVersion
needStorage := provider.RequireOperatorStorage(version.ToVersion2(minVer))
needStorage := provider.RequireOperatorStorage(ch.Meta().MinJujuVersion)
logger.Debugf("application %s has min-juju-version=%v, so charm storage is %v",
appName.String(), ch.Meta().MinJujuVersion, needStorage)
result.Results[i] = oneProvisioningInfo(needStorage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (s *CAASProvisionerSuite) TestOperatorProvisioningInfoNoStorage(c *gc.C) {
s.st.operatorRepo = "somerepo"
minVers := version.MustParse("2.8.0")
s.st.app = &mockApplication{
charm: &mockCharm{meta: &charm.Meta{MinJujuVersion: jujuversion.ToVersion1(minVers)}},
charm: &mockCharm{meta: &charm.Meta{MinJujuVersion: minVers}},
}
result, err := s.api.OperatorProvisioningInfo(params.Entities{Entities: []params.Entity{{"application-gitlab"}}})
c.Assert(err, jc.ErrorIsNil)
Expand All @@ -199,7 +199,7 @@ func (s *CAASProvisionerSuite) TestOperatorProvisioningInfoNoStoragePool(c *gc.C
s.st.operatorRepo = "somerepo"
minVers := version.MustParse("2.7.0")
s.st.app = &mockApplication{
charm: &mockCharm{meta: &charm.Meta{MinJujuVersion: jujuversion.ToVersion1(minVers)}},
charm: &mockCharm{meta: &charm.Meta{MinJujuVersion: minVers}},
}
result, err := s.api.OperatorProvisioningInfo(params.Entities{Entities: []params.Entity{{"application-gitlab"}}})
c.Assert(err, jc.ErrorIsNil)
Expand Down
4 changes: 2 additions & 2 deletions caas/ecs/environ.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
jujuclock "github.com/juju/clock"
"github.com/juju/errors"
"github.com/juju/names/v4"
"github.com/juju/version"
"github.com/juju/version/v2"

"github.com/juju/juju/caas"
"github.com/juju/juju/core/annotations"
"github.com/juju/juju/core/application"
"github.com/juju/juju/core/watcher"
"github.com/juju/juju/environs"
cloudspec "github.com/juju/juju/environs/cloudspec"
"github.com/juju/juju/environs/cloudspec"
"github.com/juju/juju/environs/config"
envcontext "github.com/juju/juju/environs/context"
)
Expand Down
4 changes: 2 additions & 2 deletions caas/kubernetes/provider/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
gc "gopkg.in/check.v1"

"github.com/juju/juju/caas"
k8scloud "github.com/juju/juju/caas/kubernetes/cloud"
k8s "github.com/juju/juju/caas/kubernetes"
k8scloud "github.com/juju/juju/caas/kubernetes/cloud"
"github.com/juju/juju/caas/kubernetes/provider"
"github.com/juju/juju/cloud"
jujucloud "github.com/juju/juju/cloud"
Expand Down Expand Up @@ -168,7 +168,7 @@ func (s *cloudSuite) TestFinalizeCloudMicrok8sAlreadyStorage(c *gc.C) {
c.Assert(cloud, jc.DeepEquals, jujucloud.Cloud{
Name: k8s.K8sCloudMicrok8s,
Type: jujucloud.CloudTypeKubernetes,
AuthTypes: k8scloud.SupportedAuthTypes(),,
AuthTypes: k8scloud.SupportedAuthTypes(),
CACertificates: []string{""},
Endpoint: "http://1.1.1.1:8080",
HostCloudRegion: fmt.Sprintf("%s/%s", k8s.K8sCloudMicrok8s, k8s.Microk8sRegion),
Expand Down
2 changes: 1 addition & 1 deletion core/charm/strategies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/juju/charm/v9"
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
"github.com/juju/version"
"github.com/juju/version/v2"
gc "gopkg.in/check.v1"
)

Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a
github.com/juju/blobstore/v2 v2.0.0-20210302045357-edd2b24570b7
github.com/juju/bundlechanges/v5 v5.0.0-20210224113052-f5fb3bbb6c25
github.com/juju/charm/v9 v9.0.0-20210309091641-7e600f16b30f
github.com/juju/charm/v9 v9.0.0-20210324234318-1204b46e47ee
github.com/juju/charmrepo/v7 v7.0.0-20210309083437-272762c450b9
github.com/juju/clock v0.0.0-20190205081909-9c5c9712527c
github.com/juju/cmd v0.0.0-20200108104440-8e43f3faa5c9
Expand Down Expand Up @@ -74,7 +74,6 @@ require (
github.com/juju/txn v0.0.0-20210302043154-251cea9e140a
github.com/juju/utils v0.0.0-20200604140309-9d78121a29e0
github.com/juju/utils/v2 v2.0.0-20200923005554-4646bfea2ef1
github.com/juju/version v0.0.0-20191219164919-81c1be00b9a6
github.com/juju/version/v2 v2.0.0-20210319015800-dcfac8f4f057
github.com/juju/webbrowser v1.0.0
github.com/juju/worker/v2 v2.0.0-20200916234526-d6e694f1c54a
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ github.com/juju/charm/v7 v7.0.0-20200625165032-ef717232a815/go.mod h1:gcqIN/pHfz
github.com/juju/charm/v8 v8.0.0-20200925053015-07d39c0154ac/go.mod h1:QZwgFXYuJI/PZPnS5feY4/7Ue2v1zm1YtT8rsXHeWCg=
github.com/juju/charm/v9 v9.0.0-20210125110411-23fabd67cb4c/go.mod h1:ffLfwuA4E426HlTtqgMvKZdBAWXOwbgeeHye/1ITTLc=
github.com/juju/charm/v9 v9.0.0-20210304052111-31c24cedd783/go.mod h1:82L0Bk5mPMnoGOtP9hsxDumxYWKvjsrFjKiYvte6gP8=
github.com/juju/charm/v9 v9.0.0-20210309091641-7e600f16b30f h1:zHUKNECfsOIRmQlAYwxj/Rvealq8Jkypy316V4cTag0=
github.com/juju/charm/v9 v9.0.0-20210309091641-7e600f16b30f/go.mod h1:82L0Bk5mPMnoGOtP9hsxDumxYWKvjsrFjKiYvte6gP8=
github.com/juju/charm/v9 v9.0.0-20210324234318-1204b46e47ee h1:Sa+juB94sYHtCPAaEQRrckf8xZfLzE+Mhn+dSv4wrxs=
github.com/juju/charm/v9 v9.0.0-20210324234318-1204b46e47ee/go.mod h1:iMgXKAsiVw2Qd5LvT7GHzJiPpC7V4PacaD3LdAjTmuE=
github.com/juju/charmrepo/v5 v5.0.0-20200424225329-cddcb4fdcd09/go.mod h1:KJGLR+Nx+PY2hw4EBNAjBWQacWlnxv1oVan1kJ9MlLM=
github.com/juju/charmrepo/v5 v5.0.0-20200626080438-30e3069e6e8e/go.mod h1:cnwzYYTH1gV7V4ywqBix21av9LhFmdwbFEyE9CwpJ0s=
github.com/juju/charmrepo/v7 v7.0.0-20210125112315-0c95be42cafc/go.mod h1:R9PTZ6VsweDsg/J2skiWj5ulVpxYPj7JW5IyQxBA4UU=
Expand Down
3 changes: 1 addition & 2 deletions state/charm.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,7 @@ func (st *State) AddCharm(info CharmInfo) (stch *Charm, err error) {
charms, closer := st.db().GetCollection(charmsC)
defer closer()

minVer := info.Charm.Meta().MinJujuVersion
if err := jujuversion.CheckJujuMinVersion(jujuversion.ToVersion2(minVer), jujuversion.Current); err != nil {
if err := jujuversion.CheckJujuMinVersion(info.Charm.Meta().MinJujuVersion, jujuversion.Current); err != nil {
return nil, errors.Trace(err)
}
model, err := st.Model()
Expand Down
2 changes: 1 addition & 1 deletion state/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/juju/errors"
"github.com/juju/mgo/v2"
"github.com/juju/mgo/v2/bson"
"github.com/juju/version"
"github.com/juju/version/v2"
)

// dashboardSettingsDoc represents the Juju Dashboard settings in MongoDB.
Expand Down
3 changes: 1 addition & 2 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,8 +1038,7 @@ func (st *State) AddApplication(args AddApplicationArgs) (_ *Application, err er
return nil, errors.Errorf("AttachStorage is non-empty but NumUnits is %d, must be 1", args.NumUnits)
}

minver := args.Charm.Meta().MinJujuVersion
if err := jujuversion.CheckJujuMinVersion(jujuversion.ToVersion2(minver), jujuversion.Current); err != nil {
if err := jujuversion.CheckJujuMinVersion(args.Charm.Meta().MinJujuVersion, jujuversion.Current); err != nil {
return nil, errors.Trace(err)
}

Expand Down
31 changes: 1 addition & 30 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"strings"

"github.com/juju/errors"
semversion1 "github.com/juju/version"
semversion "github.com/juju/version/v2"
)

Expand All @@ -31,7 +30,7 @@ const UserAgentVersion = "Juju/" + version
const (
// TreeStateDirty when the build was made with a dirty checkout.
TreeStateDirty = "dirty"
// TreeStateClean when the build was made with a clean checkout.
// TreeStateClean when the build was made with a clean checkout.kubernetes/provider/cloud_test.go
TreeStateClean = "clean"
// TreeStateArchive when the build was made outside of a git checkout.
TreeStateArchive = "archive"
Expand Down Expand Up @@ -133,31 +132,3 @@ func IsMinVersionError(err error) bool {
_, ok := errors.Cause(err).(minJujuVersionErr)
return ok
}

// TODO(juju3) - remove these once juju/charm and juju/description
// have been updated to use juju/version/v2

// The following are for compatibility with upstream repos that have
// not yet been updated to use juju/version/v2.

// ToVersion2 converts version number v1 to v2.
func ToVersion2(v semversion1.Number) semversion.Number {
return semversion.Number{
Major: v.Major,
Minor: v.Minor,
Tag: v.Tag,
Patch: v.Patch,
Build: v.Build,
}
}

// ToVersion1 converts version number v2 to v1.
func ToVersion1(v semversion.Number) semversion1.Number {
return semversion1.Number{
Major: v.Major,
Minor: v.Minor,
Tag: v.Tag,
Patch: v.Patch,
Build: v.Build,
}
}

0 comments on commit b001fb3

Please sign in to comment.