From b37d915c754b594a663aa2cd33f4102609a6a30f Mon Sep 17 00:00:00 2001 From: Jack Shaw Date: Thu, 9 Nov 2023 13:26:02 +0000 Subject: [PATCH] Remove the places we compare charmurl series to bundle This is legacy code from the charmstore days. Now we no longer use charmstore, it is impossible (and not supported) for charm urls to have "bundle" in the series field In charmhub, we designate entities to be bundles using the charm origin 'type' field. --- .../application/deployer/bundlehandler.go | 4 ++-- cmd/juju/application/store/charmadapter.go | 6 +---- .../application/store/charmadapter_test.go | 23 +++++++++++++++++-- cmd/juju/application/store/resolve.go | 3 --- cmd/juju/resource/charmresources.go | 4 ---- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/cmd/juju/application/deployer/bundlehandler.go b/cmd/juju/application/deployer/bundlehandler.go index 5ff6fa45d97..be4558dceaf 100644 --- a/cmd/juju/application/deployer/bundlehandler.go +++ b/cmd/juju/application/deployer/bundlehandler.go @@ -368,7 +368,7 @@ func (h *bundleHandler) resolveCharmsAndEndpoints() error { } h.ctx.Infof(formatLocatedText(ch, origin)) - if url.Series == "bundle" || origin.Type == "bundle" { + if origin.Type == "bundle" { return errors.Errorf("expected charm, got bundle %q", ch.Name) } @@ -648,7 +648,7 @@ func (h *bundleHandler) addCharm(change *bundlechanges.AddCharmChange) error { if err != nil { return errors.Annotatef(err, "cannot resolve %q", ch.Name) } - if url.Series == "bundle" || resolvedOrigin.Type == "bundle" { + if resolvedOrigin.Type == "bundle" { return errors.Errorf("expected charm, got bundle %q %v", ch.Name, resolvedOrigin) } workloadBases, err := SupportedJujuBases(jujuclock.WallClock.Now(), base, h.modelConfig.ImageStream()) diff --git a/cmd/juju/application/store/charmadapter.go b/cmd/juju/application/store/charmadapter.go index 5216bee3f63..439ee197e7b 100644 --- a/cmd/juju/application/store/charmadapter.go +++ b/cmd/juju/application/store/charmadapter.go @@ -85,14 +85,10 @@ func (c *CharmAdaptor) ResolveBundleURL(maybeBundle *charm.URL, preferredOrigin return nil, commoncharm.Origin{}, errors.Trace(err) } // We're a bundle so return out before handling the invalid flow. - if transport.BundleType.Matches(origin.Type) || storeCharmOrBundleURL.Series == "bundle" { + if transport.BundleType.Matches(origin.Type) { return storeCharmOrBundleURL, origin, nil } - logger.Debugf( - `cannot interpret as charmstore bundle: %v (series) != "bundle"`, - storeCharmOrBundleURL.Series, - ) return nil, commoncharm.Origin{}, errors.NotValidf("charmstore bundle %q", maybeBundle) } diff --git a/cmd/juju/application/store/charmadapter_test.go b/cmd/juju/application/store/charmadapter_test.go index 6e0602aae2f..c91ad5c7412 100644 --- a/cmd/juju/application/store/charmadapter_test.go +++ b/cmd/juju/application/store/charmadapter_test.go @@ -90,12 +90,12 @@ func (s *resolveSuite) TestResolveBundle(c *gc.C) { curl, err := charm.ParseURL("ch:testme") c.Assert(err, jc.ErrorIsNil) - s.expectCharmResolutionCall(curl, "edge", nil) + s.expectBundleResolutionCall(curl, "edge", nil) - curl.Series = "bundle" origin := commoncharm.Origin{ Source: commoncharm.OriginCharmHub, Risk: "edge", + Type: "bundle", } charmAdapter := store.NewCharmAdaptor(s.charmsAPI, func() (store.DownloadBundleClient, error) { return s.downloadClient, nil @@ -154,10 +154,28 @@ func (s *resolveSuite) setupMocks(c *gc.C) *gomock.Controller { return ctrl } +func (s *resolveSuite) expectBundleResolutionCall(curl *charm.URL, out string, err error) { + origin := commoncharm.Origin{ + Source: commoncharm.OriginCharmHub, + Risk: out, + Type: "bundle", + } + retVal := []apicharm.ResolvedCharm{{ + URL: curl, + Origin: origin, + SupportedBases: []base.Base{ + base.MustParseBaseFromString("ubuntu@18.04"), + base.MustParseBaseFromString("ubuntu@20.04"), + }, + }} + s.charmsAPI.EXPECT().ResolveCharms(gomock.Any()).Return(retVal, err) +} + func (s *resolveSuite) expectCharmResolutionCall(curl *charm.URL, out string, err error) { origin := commoncharm.Origin{ Source: commoncharm.OriginCharmHub, Risk: out, + Type: "charm", } retVal := []apicharm.ResolvedCharm{{ URL: curl, @@ -174,6 +192,7 @@ func (s *resolveSuite) expectCharmResolutionCallWithAPIError(curl *charm.URL, ou origin := commoncharm.Origin{ Source: commoncharm.OriginCharmHub, Risk: out, + Type: "charm", } retVal := []apicharm.ResolvedCharm{{ URL: curl, diff --git a/cmd/juju/application/store/resolve.go b/cmd/juju/application/store/resolve.go index 6cff051ac79..1859019f848 100644 --- a/cmd/juju/application/store/resolve.go +++ b/cmd/juju/application/store/resolve.go @@ -6,11 +6,8 @@ package store import ( "github.com/juju/charm/v11" "github.com/juju/errors" - "github.com/juju/loggo" ) -var logger = loggo.GetLogger("juju.cmd.juju.application.store") - // ResolvedBundle decorates a charm.Bundle instance with a type that implements // the charm.BundleDataSource interface. type ResolvedBundle struct { diff --git a/cmd/juju/resource/charmresources.go b/cmd/juju/resource/charmresources.go index 90348fa71f8..ec00eea784f 100644 --- a/cmd/juju/resource/charmresources.go +++ b/cmd/juju/resource/charmresources.go @@ -228,10 +228,6 @@ func resolveCharm(raw string) (*charm.URL, error) { if err != nil { return nil, errors.Trace(err) } - - if charmURL.Series == "bundle" { - return nil, errors.NotSupportedf("charm bundles") - } if !charm.CharmHub.Matches(charmURL.Schema) { return nil, errors.BadRequestf("only supported with charmhub charms") }