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

juju info: get "supports" list from Charmhub instead of metadata.yaml #14554

Merged
merged 3 commits into from
Sep 5, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 16 additions & 26 deletions cmd/juju/charmhub/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,25 @@ func convertCharmInfoResult(info transport.InfoResponse, arch, series string) (I
Tags: categories(info.Entity.Categories),
StoreURL: info.Entity.StoreURL,
}
var isKubernetes bool
switch transport.Type(ir.Type) {
case transport.BundleType:
ir.Bundle = convertBundle(info.Entity.Charms)
// TODO (stickupkid): Get the Bundle.Release and set it to the
// InfoResponse at a high level.
case transport.CharmType:
var err error
ir.Charm, ir.Series, err = convertCharm(info)
if err != nil {
return InfoResponse{}, errors.Trace(err)
ir.Charm, isKubernetes = convertCharm(info)
}

for _, base := range info.DefaultRelease.Revision.Bases {
s, _ := coreseries.VersionSeries(base.Channel)
if s != "" {
ir.Series = append(ir.Series, s)
}
}

var err error
ir.Tracks, ir.Channels, err = filterChannels(info.ChannelMap, isKubernetes(ir.Series), arch, series)
ir.Tracks, ir.Channels, err = filterChannels(info.ChannelMap, isKubernetes, arch, series)
if err != nil {
return ir, errors.Trace(err)
}
Expand Down Expand Up @@ -85,36 +89,22 @@ func convertBundle(charms []transport.Charm) *Bundle {
return bundle
}

func convertCharm(info transport.InfoResponse) (*Charm, []string, error) {
charmHubCharm := Charm{
func convertCharm(info transport.InfoResponse) (ch *Charm, isKubernetes bool) {
ch = &Charm{
UsedBy: info.Entity.UsedBy,
}
var series []string
var err error
if meta := unmarshalCharmMetadata(info.DefaultRelease.Revision.MetadataYAML); meta != nil {
charmHubCharm.Subordinate = meta.Subordinate
charmHubCharm.Relations = transformRelations(meta.Requires, meta.Provides)

// TODO: hml 2021-04-15
// Implementation of Manifest in charmhub InfoResponse is
// required. In the default-release channel map.
ch.Subordinate = meta.Subordinate
ch.Relations = transformRelations(meta.Requires, meta.Provides)
cm := charmMeta{meta: meta}
series, err = corecharm.ComputedSeries(cm)
if err != nil {
return nil, nil, errors.Trace(err)
}
isKubernetes = corecharm.IsKubernetes(cm)
}
if cfg := unmarshalCharmConfig(info.DefaultRelease.Revision.ConfigYAML); cfg != nil {
charmHubCharm.Config = &charm.Config{
ch.Config = &charm.Config{
Options: toCharmOptionMap(cfg),
}
}
return &charmHubCharm, series, nil
}

func isKubernetes(series []string) bool {
seriesSet := set.NewStrings(series...)
return seriesSet.Contains("kubernetes")
return ch, isKubernetes
}

func includeChannel(p []corecharm.Platform, architecture, series string) bool {
Expand Down
7 changes: 5 additions & 2 deletions cmd/juju/charmhub/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,12 @@ func (s *infoSuite) expectInfo() {
},
DefaultRelease: transport.InfoChannelMap{
Revision: transport.InfoRevision{
MetadataYAML: entityMeta,
ConfigYAML: entityConfig,
MetadataYAML: entityMeta,
Bases: []transport.Base{
{Name: "ubuntu", Channel: "18.04"},
{Name: "ubuntu", Channel: "16.04"},
},
},
},
ChannelMap: []transport.InfoChannelMap{{
Expand Down Expand Up @@ -299,7 +303,6 @@ description: |
This will install and setup services optimized to run in the cloud.
By default it will place Ngnix configured to scale horizontally
with Nginx's reverse proxy.
series: [bionic, xenial]
provides:
source:
interface: dummy-token
Expand Down
1 change: 0 additions & 1 deletion cmd/juju/charmhub/infowriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ type bundleInfoOutput struct {
Description string `yaml:"description,omitempty"`
StoreURL string `yaml:"store-url,omitempty"`
ID string `yaml:"bundle-id,omitempty"`
Supports string `yaml:"supports,omitempty"`
Tags string `yaml:"tags,omitempty"`
Charms string `yaml:"charms,omitempty"`
Channels string `yaml:"channels,omitempty"`
Expand Down