Skip to content

Commit

Permalink
Remove the centos7 hack and model app base not series in state
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyworld committed Oct 10, 2022
1 parent 0fd66e4 commit 2c66bb9
Show file tree
Hide file tree
Showing 154 changed files with 1,255 additions and 5,155 deletions.
2 changes: 1 addition & 1 deletion api/client/resources/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func newAddPendingResourcesArgsV2(tag names.ApplicationTag, chID CharmID, csMac
Revision: chID.Origin.Revision,
Track: chID.Origin.Track,
Architecture: chID.Origin.Architecture,
Base: params.Base{Name: chID.Origin.Base.Name, Channel: chID.Origin.Base.Channel.String()},
Base: params.Base{Name: chID.Origin.Base.OS, Channel: chID.Origin.Base.Channel.String()},
}
args.CharmStoreMacaroon = csMac
return args, nil
Expand Down
4 changes: 2 additions & 2 deletions api/common/charm/charmorigin.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (o Origin) ParamsCharmOrigin() params.CharmOrigin {
Track: o.Track,
Branch: o.Branch,
Architecture: o.Architecture,
Base: params.Base{Name: o.Base.Name, Channel: o.Base.Channel.String()},
Base: params.Base{Name: o.Base.OS, Channel: o.Base.Channel.String()},
InstanceKey: o.InstanceKey,
}
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func (o Origin) CoreCharmOrigin() corecharm.Origin {
Channel: channel,
Platform: corecharm.Platform{
Architecture: o.Architecture,
OS: o.Base.Name,
OS: o.Base.OS,
Channel: o.Base.Channel.Track,
},
InstanceKey: o.InstanceKey,
Expand Down
3 changes: 2 additions & 1 deletion apiserver/common/imagecommon/imagemetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func Save(st ImageMetadataInterface, metadata params.MetadataSaveParams) ([]para
func ParseMetadataListFromParams(p params.CloudImageMetadataList, cfg *config.Config) []cloudimagemetadata.Metadata {
results := make([]cloudimagemetadata.Metadata, len(p.Metadata))
for i, metadata := range p.Metadata {
mSeries, _ := series.VersionSeries(metadata.Version)
// We only cache ubuntu image metdata in state.
mSeries, _ := series.GetSeriesFromChannel("ubuntu", metadata.Version)
results[i] = cloudimagemetadata.Metadata{
MetadataAttributes: cloudimagemetadata.MetadataAttributes{
Stream: metadata.Stream,
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/agent/provisioner/imagemetadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (s *ImageMetadataSuite) getTestMachinesTags(c *gc.C) params.Entities {
func (s *ImageMetadataSuite) convertCloudImageMetadata(c *gc.C, all []params.CloudImageMetadata) []cloudimagemetadata.Metadata {
expected := make([]cloudimagemetadata.Metadata, len(all))
for i, one := range all {
mSeries, err := series.VersionSeries(one.Version)
mSeries, err := series.GetSeriesFromChannel("ubuntu", one.Version)
c.Assert(err, jc.ErrorIsNil)
expected[i] = cloudimagemetadata.Metadata{
cloudimagemetadata.MetadataAttributes{
Expand Down
5 changes: 3 additions & 2 deletions apiserver/facades/agent/provisioner/provisioninginfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (api *ProvisionerAPI) getProvisioningInfoBase(m *state.Machine,
return params.ProvisioningInfo{}, errors.Trace(err) // Should never happen.
}
result := params.ProvisioningInfo{
Base: params.Base{Name: base.Name, Channel: base.Channel.String()},
Base: params.Base{Name: base.OS, Channel: base.Channel.String()},
Placement: m.Placement(),
CloudInitUserData: env.Config().CloudInitUserData(),

Expand Down Expand Up @@ -732,7 +732,8 @@ func (api *ProvisionerAPI) imageMetadataFromDataSources(env environs.Environ, co
continue
}
for _, m := range found {
mSeries, err := series.VersionSeries(m.Version)
// We only use cached image metadata for ubuntu images.
mSeries, err := series.GetSeriesFromChannel("ubuntu", m.Version)
if err != nil {
logger.Warningf("could not determine series for image id %s: %v", m.Id, err)
continue
Expand Down
5 changes: 3 additions & 2 deletions apiserver/facades/agent/uniter/uniter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3879,8 +3879,9 @@ func (s *uniterNetworkInfoSuite) SetUpTest(c *gc.C) {
})
var err error
s.wordpress, err = s.State.AddApplication(state.AddApplicationArgs{
Name: "wordpress",
Charm: s.wpCharm,
Name: "wordpress",
Charm: s.wpCharm,
CharmOrigin: &state.CharmOrigin{Platform: &state.Platform{OS: "ubuntu", Channel: "12.10/stable"}},
EndpointBindings: map[string]string{
"db": "internal", // relation name
"admin-api": "public", // extra-binding name
Expand Down
2 changes: 1 addition & 1 deletion apiserver/facades/agent/upgradeseries/upgradeseries.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (a *API) FinishUpgradeSeries(args params.UpdateChannelArgs) (params.ErrorRe
result.Results[i].Error = apiservererrors.ServerError(err)
continue
}
argSeries, err = series.GetSeriesFromChannel(base.Name, arg.Channel)
argSeries, err = series.GetSeriesFromChannel(base.OS, arg.Channel)
if err != nil {
result.Results[i].Error = apiservererrors.ServerError(err)
continue
Expand Down
10 changes: 8 additions & 2 deletions apiserver/facades/client/action/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ func (s *runSuite) TestRunMachineAndApplication(c *gc.C) {
s.addMachine(c)

charm := s.AddTestingCharm(c, "dummy")
magic, err := s.State.AddApplication(state.AddApplicationArgs{Name: "magic", Charm: charm})
magic, err := s.State.AddApplication(state.AddApplicationArgs{
Name: "magic", Charm: charm,
CharmOrigin: &state.CharmOrigin{Platform: &state.Platform{OS: "ubuntu", Channel: "20.04/stable"}},
})
c.Assert(err, jc.ErrorIsNil)
s.addUnit(c, magic)
s.addUnit(c, magic)
Expand Down Expand Up @@ -155,7 +158,10 @@ func (s *runSuite) TestRunApplicationWorkload(c *gc.C) {
s.addMachine(c)

charm := s.AddTestingCharm(c, "dummy")
magic, err := s.State.AddApplication(state.AddApplicationArgs{Name: "magic", Charm: charm})
magic, err := s.State.AddApplication(state.AddApplicationArgs{
Name: "magic", Charm: charm,
CharmOrigin: &state.CharmOrigin{Platform: &state.Platform{OS: "ubuntu", Channel: "20.04/stable"}},
})
c.Assert(err, jc.ErrorIsNil)
s.addUnit(c, magic)
s.addUnit(c, magic)
Expand Down
96 changes: 3 additions & 93 deletions apiserver/facades/client/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net"
"reflect"
"strings"
"time"

"github.com/juju/charm/v9"
csparams "github.com/juju/charmrepo/v7/csclient/params"
Expand Down Expand Up @@ -577,7 +576,7 @@ func convertCharmOrigin(origin *params.CharmOrigin, curl *charm.URL, charmStoreC
}
platform = corecharm.Platform{
Architecture: origin.Architecture,
OS: base.Name,
OS: base.OS,
Channel: base.Channel.Track,
}
}
Expand Down Expand Up @@ -901,19 +900,8 @@ func (api *APIBase) updateOneApplicationSeries(arg params.UpdateChannelArg) erro
if err != nil {
return errors.Trace(err)
}
var baseName string
origin := app.CharmOrigin()
if origin.Platform != nil {
baseName = origin.Platform.OS
} else {
appSeries := app.Series()
base, err := series.GetBaseFromSeries(appSeries)
if err != nil {
return errors.Trace(err)
}
baseName = base.Name
}
argSeries, err = series.GetSeriesFromChannel(baseName, arg.Channel)
argSeries, err = series.GetSeriesFromChannel(origin.Platform.OS, arg.Channel)
if err != nil {
return errors.Trace(err)
}
Expand Down Expand Up @@ -1125,82 +1113,9 @@ func (api *APIBase) applicationSetCharm(
return errors.New("cannot downgrade from v2 charm format to v1")
}

// If upgrading from a pod-spec (v1) charm to sidecar (v2), override the
// application's series to what it would be for a fresh sidecar deploy.
oldSeries := params.Application.Series()
if oldSeries == series.Kubernetes.String() && charm.MetaFormat(newCharm) >= charm.FormatV2 && corecharm.IsKubernetes(newCharm) {
// Disallow upgrading from a v1 DaemonSet or Deployment type charm
// (only StatefulSet is supported in v2 right now).
deployment := oldCharm.Meta().Deployment
if deployment != nil && deployment.DeploymentType != charm.DeploymentStateful {
return errors.Errorf("cannot upgrade from v1 %s deployment to v2", deployment.DeploymentType)
}

modelConfig, err := api.model.ModelConfig()
if err != nil {
return errors.Trace(err)
}

var supported []string
for _, base := range newCharm.Manifest().Bases {
series, err := series.VersionSeries(base.Channel.Track)
if err != nil {
continue
}
supported = append(supported, series)
}

newSeries, err := sidecarUpgradeSeries(modelConfig, supported)
if err != nil {
return errors.Trace(err)
}
logger.Debugf("upgrading pod-spec to sidecar charm, setting series to %q", newSeries)
cfg.Series = newSeries
}

return params.Application.SetCharm(cfg)
}

// sidecarUpgradeSeries is a cut-down version of seriesSelector.charmSeries
// for a refresh from a pod-spec to a sidecar charm. It looks at the model's
// default and falls back to the charm's series (no support for "--series",
// series in charm URL, or default LTS).
func sidecarUpgradeSeries(modelConfig *environsconfig.Config, supported []string) (string, error) {
supportedJuju, err := series.WorkloadSeries(time.Now(), "", modelConfig.ImageStream())
if err != nil {
return "", errors.Trace(err)
}

// Use model default series, if explicitly set and supported by the charm.
if selected, explicit := modelConfig.DefaultSeries(); explicit {
if _, err := corecharm.SeriesForCharm(selected, supported); err == nil {
// validate the series we get from the charm
if !supportedJuju.Contains(selected) {
return "", errors.NotSupportedf("series: %q", selected)
}
return selected, nil
}
}

// Fall back to the charm's list of series, filtered to what's supported
// by Juju. Preserve the order of the supported series from the charm
// metadata, as the order could be out of order compared to Ubuntu series
// order (precise, xenial, bionic, trusty, etc).
var filtered []string
for _, charmSeries := range supported {
if supportedJuju.Contains(charmSeries) {
filtered = append(filtered, charmSeries)
}
}
selected, err := corecharm.SeriesForCharm("", filtered)
if err == nil {
return selected, nil
}

// Otherwise it's an error
return "", err
}

// charmConfigFromYamlConfigValues will parse a yaml produced by juju get and
// generate charm.Settings from it that can then be sent to the application.
func charmConfigFromYamlConfigValues(yamlContents string) (charm.Settings, error) {
Expand Down Expand Up @@ -1284,12 +1199,7 @@ func makeParamsCharmOrigin(origin *state.CharmOrigin) (params.CharmOrigin, error
}
if origin.Platform != nil {
retOrigin.Architecture = origin.Platform.Architecture
// TODO(juju3) - use channel not series in state
base, err := series.GetBaseFromSeries(origin.Platform.Series)
if err != nil {
return params.CharmOrigin{}, errors.Trace(err)
}
retOrigin.Base = params.Base{Name: base.Name, Channel: base.Channel.String()}
retOrigin.Base = params.Base{Name: origin.Platform.OS, Channel: origin.Platform.Channel}
}
return retOrigin, nil
}
Expand Down
Loading

0 comments on commit 2c66bb9

Please sign in to comment.