Skip to content

Commit 5a77852

Browse files
nvinuesajack-w-shaw
authored andcommitted
chore: add Version() to charm interfaces
The version retrieval method `.Version()` was part of the state Charm struct but wasn't implemented on the apiserver nor domain structs. This commit brings it in and fixes the missing version on the status facade.
1 parent 276cd3e commit 5a77852

File tree

28 files changed

+480
-352
lines changed

28 files changed

+480
-352
lines changed

api/common/charms/common.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type CharmInfo struct {
6767
Actions *charm.Actions
6868
Manifest *charm.Manifest
6969
LXDProfile *charm.LXDProfile
70+
Version string
7071
}
7172

7273
func (info *CharmInfo) Charm() charm.Charm {
@@ -90,6 +91,7 @@ func convertCharm(info *params.Charm) (*CharmInfo, error) {
9091
Actions: convertCharmActions(info.Actions),
9192
Manifest: manifest,
9293
LXDProfile: convertCharmLXDProfile(info.LXDProfile),
94+
Version: info.Version,
9395
}
9496
return result, nil
9597
}
@@ -338,6 +340,10 @@ func (c *charmImpl) Revision() int {
338340
return c.info.Revision
339341
}
340342

343+
func (c *charmImpl) Version() string {
344+
return c.info.Version
345+
}
346+
341347
func convertCharmManifest(input *params.CharmManifest) (*charm.Manifest, error) {
342348
if input == nil {
343349
return nil, nil

apiserver/common/charms/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ func convertCharm(name string, ch charm.Charm, locator applicationcharm.CharmLoc
210210
Meta: convertCharmMeta(ch.Meta()),
211211
Actions: convertCharmActions(ch.Actions()),
212212
Manifest: convertCharmManifest(ch.Manifest()),
213+
Version: ch.Version(),
213214
}
214215

215216
profiler, ok := ch.(charm.LXDProfiler)

apiserver/facades/client/application/application_get.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ func (c *domainCharm) URL() string {
367367
return curl.String()
368368
}
369369

370+
func (c *domainCharm) Version() string {
371+
return c.charm.Version()
372+
}
373+
370374
func ptr[T any](v T) *T {
371375
return &v
372376
}

apiserver/facades/client/application/backend.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,8 @@ type Charm interface {
101101
Config() *charm.Config
102102
Actions() *charm.Actions
103103
Revision() int
104-
// TODO(nvinuesa): IsUploaded is not implemented yet.
105-
// See https://warthogs.atlassian.net/browse/JUJU-6845
106-
// IsUploaded() bool
107104
URL() string
105+
Version() string
108106
}
109107

110108
// CharmMeta describes methods that inform charm operation.

apiserver/facades/client/application/charm_mock_test.go

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apiserver/facades/client/client/status.go

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -883,19 +883,6 @@ func fetchAllApplicationsAndUnits(st Backend, model *state.Model, spaceInfos net
883883
// Don't look up revision for local charms
884884
}
885885
}
886-
887-
// ch, _, err := app.Charm()
888-
// if err != nil {
889-
// continue
890-
// }
891-
// chName := lxdprofile.Name(model.Name(), app.Name(), ch.Revision())
892-
// if profile := ch.LXDProfile(); profile != nil {
893-
// lxdProfiles[chName] = &charm.LXDProfile{
894-
// Description: profile.Description,
895-
// Config: profile.Config,
896-
// Devices: profile.Devices,
897-
// }
898-
// }
899886
}
900887

901888
for baseURL := range latestCharms {
@@ -1289,13 +1276,6 @@ func (context *statusContext) processApplication(ctx context.Context, applicatio
12891276
return params.ApplicationStatus{Err: apiservererrors.ServerError(err)}
12901277
}
12911278

1292-
// var charmProfileName string
1293-
// if lxdprofile.NotEmpty(lxdStateCharmProfiler{
1294-
// Charm: applicationCharm,
1295-
// }) {
1296-
// charmProfileName = lxdprofile.Name(context.model.Name(), application.Name(), applicationCharm.Revision())
1297-
// }
1298-
12991279
mappedExposedEndpoints, err := context.mapExposedEndpointsFromState(application.ExposedEndpoints())
13001280
if err != nil {
13011281
return params.ApplicationStatus{Err: apiservererrors.ServerError(err)}
@@ -1317,9 +1297,8 @@ func (context *statusContext) processApplication(ctx context.Context, applicatio
13171297
return params.ApplicationStatus{Err: apiservererrors.ServerError(err)}
13181298
}
13191299
var processedStatus = params.ApplicationStatus{
1320-
Charm: applicationCharm.URL(),
1321-
// CharmVersion: applicationCharm.Version(),
1322-
// CharmProfile: charmProfileName,
1300+
Charm: applicationCharm.URL(),
1301+
CharmVersion: applicationCharm.Version(),
13231302
CharmRev: applicationCharm.Revision(),
13241303
CharmChannel: channel,
13251304
Base: params.Base{

apiserver/facades/schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4678,6 +4678,9 @@
46784678
},
46794679
"url": {
46804680
"type": "string"
4681+
},
4682+
"version": {
4683+
"type": "string"
46814684
}
46824685
},
46834686
"additionalProperties": false,

cmd/juju/application/deployer/mocks/charm_mock.go

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/juju/application/refresher/charm_mock_test.go

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/charm/adaptor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ func (adaptor charmInfoAdaptor) Actions() *charm.Actions {
3838
func (adaptor charmInfoAdaptor) Revision() int {
3939
return 0 // not part of the essential metadata
4040
}
41+
42+
func (adaptor charmInfoAdaptor) Version() string {
43+
return "" // not part of the essential metadata
44+
}

domain/application/service/charm.go

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,16 @@ func (s *Service) GetCharm(ctx context.Context, id corecharm.ID) (internalcharm.
303303
Architecture: ch.Architecture,
304304
}
305305

306-
return internalcharm.NewCharmBase(
306+
charmBase := internalcharm.NewCharmBase(
307307
&metadata,
308308
&manifest,
309309
&config,
310310
&actions,
311311
&lxdProfile,
312-
), locator, nil
312+
)
313+
charmBase.SetVersion(ch.Version)
314+
315+
return charmBase, locator, nil
313316
}
314317

315318
// GetCharmMetadata returns the metadata for the charm using the charm ID.
@@ -551,24 +554,6 @@ func (s *Service) GetCharmArchiveBySHA256Prefix(ctx context.Context, sha256Prefi
551554
return reader, nil
552555
}
553556

554-
// GetCharmHash returns the hash of the charm archive identified by its charm
555-
// ID.
556-
//
557-
// If the charm does not exist, a [applicationerrors.CharmNotFound] error is
558-
// returned.
559-
func (s *Service) GetCharmHash(ctx context.Context, id corecharm.ID) (string, error) {
560-
if err := id.Validate(); err != nil {
561-
return "", internalerrors.Errorf("charm id: %w", err)
562-
}
563-
564-
_, hash, err := s.st.GetCharmArchiveMetadata(ctx, id)
565-
if err != nil {
566-
return "", internalerrors.Errorf("getting charm hash: %w", err)
567-
}
568-
569-
return hash, nil
570-
}
571-
572557
// IsCharmAvailable returns whether the charm is available for use. This
573558
// indicates if the charm has been uploaded to the controller.
574559
// This will return true if the charm is available, and false otherwise.

domain/application/service/charm_mock_test.go

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

domain/application/service/charm_test.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -521,29 +521,6 @@ func (s *charmServiceSuite) TestGetCharmArchiveCharmNotFound(c *gc.C) {
521521
c.Assert(err, jc.ErrorIs, applicationerrors.CharmNotFound)
522522
}
523523

524-
func (s *charmServiceSuite) TestGetCharmHash(c *gc.C) {
525-
defer s.setupMocks(c).Finish()
526-
527-
id := charmtesting.GenCharmID(c)
528-
529-
s.state.EXPECT().GetCharmArchiveMetadata(gomock.Any(), id).Return("archive-path", "hash", nil)
530-
531-
hash, err := s.service.GetCharmHash(context.Background(), id)
532-
c.Assert(err, jc.ErrorIsNil)
533-
c.Check(hash, gc.Equals, "hash")
534-
}
535-
536-
func (s *charmServiceSuite) TestGetCharmHashCharmNotFound(c *gc.C) {
537-
defer s.setupMocks(c).Finish()
538-
539-
id := charmtesting.GenCharmID(c)
540-
541-
s.state.EXPECT().GetCharmArchiveMetadata(gomock.Any(), id).Return("", "", applicationerrors.CharmNotFound)
542-
543-
_, err := s.service.GetCharmHash(context.Background(), id)
544-
c.Assert(err, jc.ErrorIs, applicationerrors.CharmNotFound)
545-
}
546-
547524
func (s *charmServiceSuite) TestSetCharmAvailable(c *gc.C) {
548525
defer s.setupMocks(c).Finish()
549526

domain/application/watcher_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,3 +599,7 @@ func (s *stubCharm) Actions() *internalcharm.Actions {
599599
func (s *stubCharm) Revision() int {
600600
return 0
601601
}
602+
603+
func (s *stubCharm) Version() string {
604+
return ""
605+
}

domain/secret/watcher_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,3 +971,7 @@ func (m *stubCharm) Actions() *charm.Actions {
971971
func (m *stubCharm) Revision() int {
972972
return 1
973973
}
974+
975+
func (m *stubCharm) Version() string {
976+
return ""
977+
}

0 commit comments

Comments
 (0)