Skip to content

Commit

Permalink
Remove the places we compare charmurl series to bundle
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jack-w-shaw committed Nov 15, 2023
1 parent ea265d9 commit b37d915
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
4 changes: 2 additions & 2 deletions cmd/juju/application/deployer/bundlehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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())
Expand Down
6 changes: 1 addition & 5 deletions cmd/juju/application/store/charmadapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
23 changes: 21 additions & 2 deletions cmd/juju/application/store/charmadapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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("[email protected]"),
base.MustParseBaseFromString("[email protected]"),
},
}}
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,
Expand All @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions cmd/juju/application/store/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions cmd/juju/resource/charmresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit b37d915

Please sign in to comment.