Skip to content

Commit b6d9340

Browse files
committed
Remove debugging left behind, tidy up k8s base handling
1 parent 9f81904 commit b6d9340

File tree

11 files changed

+80
-77
lines changed

11 files changed

+80
-77
lines changed

api/common/charm/charmorigin.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,17 @@ type Origin struct {
5858
InstanceKey string
5959
}
6060

61-
// WithSeries allows to update the series of an origin.
62-
// TODO(juju3) - remove, replace with os/channel
63-
func (o Origin) WithSeries(aseries string) Origin {
61+
// WithBase allows to update the base of an origin.
62+
func (o Origin) WithBase(b *series.Base) Origin {
6463
other := o
65-
if aseries != "" {
66-
// Legacy k8s charms - assume ubuntu focal.
67-
if aseries == "kubernetes" {
68-
aseries = "focal"
69-
}
70-
other.Base, _ = series.GetBaseFromSeries(aseries)
64+
other.Base = series.Base{}
65+
if b != nil {
66+
other.Base = *b
7167
}
7268
return other
7369
}
7470

75-
// CharmChannel returns the the channel indicated by this origin.
71+
// CharmChannel returns the channel indicated by this origin.
7672
func (o Origin) CharmChannel() charm.Channel {
7773
var track string
7874
if o.Track != nil {

cmd/juju/application/deployer/bundlehandler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ func (h *bundleHandler) resolveCharmsAndEndpoints() error {
414414
Name: url.Name,
415415
Revision: -1,
416416
}
417-
origin = origin.WithSeries("")
417+
origin = origin.WithBase(nil)
418418
}
419419

420420
h.ctx.Infof(formatLocatedText(ch, origin))
@@ -939,7 +939,7 @@ func (h *bundleHandler) addApplication(change *bundlechanges.AddApplicationChang
939939
// Only Kubernetes bundles send the unit count and placement with the deploy API call.
940940
numUnits := 0
941941
var placement []*instance.Placement
942-
if h.data.Type == "kubernetes" {
942+
if h.data.Type == series.Kubernetes.String() {
943943
numUnits = p.NumUnits
944944
}
945945

cmd/juju/application/deployer/charm.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,16 @@ func (c *repositoryCharm) PrepareAndDeploy(ctx *cmd.Context, deployAPI DeployerA
482482
}
483483

484484
// Ensure we save the origin.
485-
origin = origin.WithSeries(series)
485+
var base coreseries.Base
486+
if series == coreseries.Kubernetes.String() {
487+
base = coreseries.LegacyKubernetesBase()
488+
} else {
489+
base, err = coreseries.GetBaseFromSeries(series)
490+
if err != nil {
491+
return errors.Trace(err)
492+
}
493+
}
494+
origin = origin.WithBase(&base)
486495

487496
// In-order for the url to represent the following updates to the origin
488497
// and machine, we need to ensure that the series is actually correct as

cmd/juju/application/refresher/refresher.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/juju/charmrepo/v7"
1313
jujuclock "github.com/juju/clock"
1414
"github.com/juju/errors"
15-
"github.com/juju/loggo"
1615

1716
commoncharm "github.com/juju/juju/api/common/charm"
1817
"github.com/juju/juju/cmd/juju/application/store"
@@ -73,8 +72,6 @@ func NewRefresherFactory(deps RefresherDependencies) RefresherFactory {
7372
return d
7473
}
7574

76-
var logger = loggo.GetLogger("xxxxx")
77-
7875
// Run executes over a series of refreshers using a given config. It will
7976
// execute each refresher if it's allowed, otherwise it will move on to the
8077
// next one.
@@ -83,7 +80,7 @@ var logger = loggo.GetLogger("xxxxx")
8380
// If no refresher matches the config or if each one is exhausted then it will
8481
// state that it was unable to refresh.
8582
func (d *factory) Run(cfg RefresherConfig) (*CharmID, error) {
86-
for i, fn := range d.refreshers {
83+
for _, fn := range d.refreshers {
8784
// Failure to correctly setup a refresher will call all of the
8885
// refreshers to fail.
8986
refresh, err := fn(cfg)
@@ -99,7 +96,6 @@ func (d *factory) Run(cfg RefresherConfig) (*CharmID, error) {
9996
}
10097

10198
charmID, err := refresh.Refresh()
102-
logger.Criticalf("REFRESH %d: %+v", i, charmID)
10399
// We've exhausted this refresh task, attempt another one.
104100
if errors.Cause(err) == ErrExhausted {
105101
continue
@@ -381,7 +377,6 @@ func (r *charmStoreRefresher) Allowed(cfg RefresherConfig) (bool, error) {
381377
// Bundles are not supported as there is no physical representation in Juju.
382378
func (r *charmStoreRefresher) Refresh() (*CharmID, error) {
383379
newURL, origin, err := r.ResolveCharm()
384-
logger.Criticalf("RES NEW %s: %+v", newURL, origin)
385380
if errors.Is(err, ErrAlreadyUpToDate) {
386381
// The charm itself is uptodate but we may need the
387382
// URL, origin and macaroon (if there is one)
@@ -402,13 +397,11 @@ func (r *charmStoreRefresher) Refresh() (*CharmID, error) {
402397
if !r.deployedBase.Channel.Empty() {
403398
origin.Base = r.deployedBase
404399
}
405-
curl, csMac, res, err := store.AddCharmWithAuthorizationFromURL(r.charmAdder, r.authorizer, newURL, origin, r.force)
400+
curl, csMac, _, err := store.AddCharmWithAuthorizationFromURL(r.charmAdder, r.authorizer, newURL, origin, r.force)
406401
if err != nil {
407402
return nil, errors.Trace(err)
408403
}
409404

410-
logger.Criticalf("RES RES %s: %+v", newURL, res)
411-
412405
return &CharmID{
413406
URL: curl,
414407
Origin: origin.CoreCharmOrigin(),

cmd/juju/application/utils/origin.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ func DeduceOrigin(url *charm.URL, channel charm.Channel, platform corecharm.Plat
3535

3636
var origin commoncharm.Origin
3737
// Legacy k8s charms - assume ubuntu focal.
38-
if platform.OS == "kubernetes" || platform.Channel == "kubernetes" {
39-
platform.OS = "ubuntu"
40-
platform.Channel = "20.04"
38+
if platform.OS == coreseries.Kubernetes.String() || platform.Channel == coreseries.Kubernetes.String() {
39+
b := coreseries.LegacyKubernetesBase()
40+
platform.OS = b.OS
41+
platform.Channel = b.Channel.Track
4142
}
4243
switch url.Schema {
4344
case "cs":

core/bundle/changes/handlers.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/juju/naturalsort"
1515

1616
corecharm "github.com/juju/juju/core/charm"
17+
"github.com/juju/juju/core/series"
1718
)
1819

1920
type resolver struct {
@@ -49,7 +50,7 @@ func (r *resolver) handleApplications() (map[string]string, error) {
4950
application := applications[name]
5051
// Legacy k8s charms - assume ubuntu focal.
5152
if application.Series == kubernetes {
52-
application.Series = "focal"
53+
application.Series = series.LegacyKubernetesSeries()
5354
}
5455
existingApp := existing.GetApplication(name)
5556
series, err := getSeries(application, defaultSeries)
@@ -1265,13 +1266,12 @@ func getSeries(application *charm.ApplicationSpec, defaultSeries string) (string
12651266
if err != nil {
12661267
return "", errors.Trace(err)
12671268
}
1268-
series := charmURL.Series
1269-
if series != "" {
1269+
if charmURL.Series != "" {
12701270
// Legacy k8s charms - assume ubuntu focal.
1271-
if series == kubernetes {
1272-
return "focal", nil
1271+
if charmURL.Series == kubernetes {
1272+
return series.LegacyKubernetesSeries(), nil
12731273
}
1274-
return series, nil
1274+
return charmURL.Series, nil
12751275
}
12761276
return defaultSeries, nil
12771277
}

core/series/base.go

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package series
55

66
import (
77
"fmt"
8-
"runtime/debug"
98
"strings"
109

1110
"github.com/juju/errors"
@@ -22,10 +21,6 @@ type Base struct {
2221

2322
// ParseBase constructs a Base from the os and channel string.
2423
func ParseBase(os string, channel string) (Base, error) {
25-
if channel == "kubernetes" {
26-
logger.Criticalf("%s", debug.Stack())
27-
}
28-
2924
if os == "" && channel == "" {
3025
return Base{}, nil
3126
}
@@ -41,42 +36,35 @@ func ParseBase(os string, channel string) (Base, error) {
4136

4237
// MakeDefaultBase creates a base from an os and simple version string, eg "22.04".
4338
func MakeDefaultBase(os string, channel string) Base {
44-
if channel == "kubernetes" {
45-
logger.Criticalf("%s", debug.Stack())
46-
}
47-
4839
return Base{OS: os, Channel: MakeDefaultChannel(channel)}
4940
}
5041

5142
func (b Base) String() string {
5243
if b.OS == "" {
5344
return ""
5445
}
55-
//if b.OS == "kubernetes" {
56-
// return b.OS
57-
//}
5846
return fmt.Sprintf("%s:%s", b.OS, b.Channel)
5947
}
6048

49+
// IsCompatible returns true if base other is the same underlying
50+
// OS version, ignoring risk.
6151
func (b Base) IsCompatible(other Base) bool {
6252
return b.OS == other.OS && b.Channel.Track == other.Channel.Track
6353
}
6454

65-
func (b *Base) DisplayString() string {
66-
if b == nil || b.OS == "" {
55+
// DisplayString returns the base string ignoring risk.
56+
func (b Base) DisplayString() string {
57+
if b.Channel.Track == "" || b.OS == "" {
6758
return ""
6859
}
69-
if b.OS == "kubernetes" {
60+
if b.OS == Kubernetes.String() {
7061
return b.OS
7162
}
7263
return b.OS + ":" + b.Channel.DisplayString()
7364
}
7465

7566
// GetBaseFromSeries returns the Base infor for a series.
7667
func GetBaseFromSeries(series string) (Base, error) {
77-
if series == "kubernetes" {
78-
logger.Criticalf("%s", debug.Stack())
79-
}
8068
var result Base
8169
osName, err := GetOSFromSeries(series)
8270
if err != nil {
@@ -117,3 +105,13 @@ func GetSeriesFromBase(v Base) (string, error) {
117105
}
118106
return "", errors.NotFoundf("os %q version %q", v.OS, v.Channel.Track)
119107
}
108+
109+
// LegacyKubernetesBase is the ubuntu base image for legacy k8s charms.
110+
func LegacyKubernetesBase() Base {
111+
return MakeDefaultBase("ubuntu", "20.04")
112+
}
113+
114+
// LegacyKubernetesSeries is the ubuntu series for legacy k8s charms.
115+
func LegacyKubernetesSeries() string {
116+
return "focal"
117+
}

juju/testing/conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ func (s *JujuConnSuite) AddTestingCharmForSeries(c *gc.C, name, series string) *
842842
func (s *JujuConnSuite) AddTestingApplication(c *gc.C, name string, ch *state.Charm) *state.Application {
843843
appSeries := ch.URL().Series
844844
if appSeries == "kubernetes" {
845-
appSeries = "focal"
845+
appSeries = series.LegacyKubernetesSeries()
846846
}
847847
base, err := series.GetBaseFromSeries(appSeries)
848848
c.Assert(err, jc.ErrorIsNil)

state/application.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/juju/juju/core/model"
3434
"github.com/juju/juju/core/network"
3535
"github.com/juju/juju/core/network/firewall"
36+
"github.com/juju/juju/core/os"
3637
"github.com/juju/juju/core/series"
3738
"github.com/juju/juju/core/status"
3839
mgoutils "github.com/juju/juju/mongo/utils"
@@ -1851,19 +1852,22 @@ func checkSeriesForSetCharm(currentPlatform *Platform, charm *Charm, ForceBase b
18511852
if err != nil {
18521853
return errors.Trace(err)
18531854
}
1855+
charmSeries, err := corecharm.ComputedSeries(charm)
1856+
if err != nil {
1857+
return errors.Trace(err)
1858+
}
18541859
if charm.URL().Series != "" {
18551860
// Allow series change when switching to charmhub charms.
18561861
// Account for legacy charms with "kubernetes" series in the URL.
1857-
if charm.URL().Schema != "ch" && charm.URL().Series != "kubernetes" && charm.URL().Series != curSeries {
1862+
if charm.URL().Schema != "ch" && charm.URL().Series != series.Kubernetes.String() && charm.URL().Series != curSeries {
18581863
return errors.Errorf("cannot change an application's series")
18591864
}
18601865
} else if !ForceBase {
18611866
supported := false
1862-
charmSeries, err := corecharm.ComputedSeries(charm)
1863-
if err != nil {
1864-
return errors.Trace(err)
1865-
}
18661867
for _, oneSeries := range charmSeries {
1868+
if oneSeries == series.Kubernetes.String() {
1869+
oneSeries = series.LegacyKubernetesSeries()
1870+
}
18671871
if oneSeries == curSeries {
18681872
supported = true
18691873
break
@@ -1880,19 +1884,14 @@ func checkSeriesForSetCharm(currentPlatform *Platform, charm *Charm, ForceBase b
18801884
// Even with forceBase=true, we do not allow a charm to be used which is for
18811885
// a different OS. This assumes the charm declares it has supported series which
18821886
// we can check for OS compatibility. Otherwise, we just accept the series supplied.
1883-
currentOS, err := series.GetOSFromSeries(curSeries)
1884-
if err != nil {
1885-
// We don't expect an error here but there's not much we can
1886-
// do to recover.
1887-
return err
1888-
}
1887+
currentOS := os.OSTypeForName(currentPlatform.OS)
18891888
supportedOS := false
1890-
supportedSeries, err := corecharm.ComputedSeries(charm)
1891-
if err != nil {
1892-
return errors.Trace(err)
1893-
}
1894-
for _, chSeries := range supportedSeries {
1895-
charmSeriesOS, err := series.GetOSFromSeries(chSeries)
1889+
for _, oneSeries := range charmSeries {
1890+
if oneSeries == series.Kubernetes.String() {
1891+
supportedOS = true
1892+
break
1893+
}
1894+
charmSeriesOS, err := series.GetOSFromSeries(oneSeries)
18961895
if err != nil {
18971896
return nil
18981897
}
@@ -1901,7 +1900,7 @@ func checkSeriesForSetCharm(currentPlatform *Platform, charm *Charm, ForceBase b
19011900
break
19021901
}
19031902
}
1904-
if !supportedOS && len(supportedSeries) > 0 {
1903+
if !supportedOS && len(charmSeries) > 0 {
19051904
return errors.Errorf("OS %q not supported by charm", currentOS)
19061905
}
19071906
}

state/state.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,16 +1434,19 @@ func (st *State) processCommonModelApplicationArgs(args *AddApplicationArgs) (Ba
14341434
}
14351435
if len(supportedSeries) > 0 {
14361436
supportedOperatingSystems := make(map[string]bool)
1437-
for _, supportedSeries := range supportedSeries {
1438-
os, err := series.GetOSFromSeries(supportedSeries)
1437+
for _, chSeries := range supportedSeries {
1438+
if chSeries == series.Kubernetes.String() {
1439+
chSeries = series.LegacyKubernetesSeries()
1440+
}
1441+
os, err := series.GetOSFromSeries(chSeries)
14391442
if err != nil {
14401443
// If we can't figure out a series written in the charm
14411444
// just skip it.
14421445
continue
14431446
}
14441447
supportedOperatingSystems[strings.ToLower(os.String())] = true
14451448
}
1446-
if !supportedOperatingSystems[appBase.OS] && !supportedOperatingSystems["kubernetes"] {
1449+
if !supportedOperatingSystems[appBase.OS] {
14471450
series, _ := series.GetSeriesFromBase(appBase)
14481451
return Base{}, errors.NewNotSupported(errors.Errorf(
14491452
"series %q not supported by charm, supported series are %q",
@@ -2185,22 +2188,26 @@ func (st *State) AddRelation(eps ...Endpoint) (r *Relation, err error) {
21852188
if err != nil {
21862189
return nil, errors.Trace(err)
21872190
}
2188-
var charmBasees []string
2191+
var charmBases []string
21892192
for _, s := range charmSeries {
2193+
if s == series.Kubernetes.String() {
2194+
charmBases = append(charmBases, series.LegacyKubernetesBase().DisplayString())
2195+
continue
2196+
}
21902197
b, err := series.GetBaseFromSeries(s)
21912198
if err != nil {
21922199
return nil, errors.Trace(err)
21932200
}
2194-
charmBasees = append(charmBasees, b.DisplayString())
2201+
charmBases = append(charmBases, b.DisplayString())
21952202
}
2196-
if len(charmBasees) == 0 {
2203+
if len(charmBases) == 0 {
21972204
localBase, err := series.ParseBase(localApp.Base().OS, localApp.Base().Channel)
21982205
if err != nil {
21992206
return nil, errors.Trace(err)
22002207
}
2201-
charmBasees = []string{localBase.DisplayString()}
2208+
charmBases = []string{localBase.DisplayString()}
22022209
}
2203-
appBases[localApp.doc.Name] = charmBasees
2210+
appBases[localApp.doc.Name] = charmBases
22042211
ops = append(ops, txn.Op{
22052212
C: applicationsC,
22062213
Id: st.docID(ep.ApplicationName),

testing/factory/factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ func (factory *Factory) MakeApplicationReturningPassword(c *gc.C, params *Applic
497497
chSeries := params.Charm.URL().Series
498498
// Legacy k8s charms - assume ubuntu focal.
499499
if chSeries == "kubernetes" {
500-
chSeries = "focal"
500+
chSeries = coreseries.LegacyKubernetesSeries()
501501
}
502502
base, err := coreseries.GetBaseFromSeries(chSeries)
503503
c.Assert(err, jc.ErrorIsNil)

0 commit comments

Comments
 (0)