Skip to content

Commit

Permalink
Clean up the bootstrap comments regarding series
Browse files Browse the repository at this point in the history
Add better comments around bootstrap.

Driveby: Remove Empty to prevent miss-use.
  • Loading branch information
SimonRichardson committed Jan 9, 2024
1 parent 6fbb8a5 commit 7aebace
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
13 changes: 5 additions & 8 deletions core/base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@ type Base struct {
Channel Channel
}

// Empty is an empty base.
var Empty = Base{}

// ParseBase constructs a Base from the os and channel string.
func ParseBase(os string, channel string) (Base, error) {
if os == "" && channel == "" {
return Empty, nil
return Base{}, nil
}
if os == "" || channel == "" {
return Empty, errors.NotValidf("missing base os or channel")
return Base{}, errors.NotValidf("missing base os or channel")
}
ch, err := ParseChannelNormalize(channel)
if err != nil {
return Empty, errors.Annotatef(err, "parsing base %s@%s", os, channel)
return Base{}, errors.Annotatef(err, "parsing base %s@%s", os, channel)
}
return Base{OS: strings.ToLower(os), Channel: ch}, nil
}
Expand All @@ -44,11 +41,11 @@ func ParseBase(os string, channel string) (Base, error) {
func ParseBaseFromString(b string) (Base, error) {
parts := strings.Split(b, "@")
if len(parts) != 2 {
return Empty, errors.New("expected base string to contain os and channel separated by '@'")
return Base{}, errors.New("expected base string to contain os and channel separated by '@'")
}
channel, err := ParseChannelNormalize(parts[1])
if err != nil {
return Empty, errors.Trace(err)
return Base{}, errors.Trace(err)
}
return Base{OS: parts[0], Channel: channel}, nil
}
Expand Down
7 changes: 7 additions & 0 deletions internal/bootstrap/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ const controllerCharmURL = "juju-controller"

// PopulateControllerCharm is the function that is used to populate the
// controller charm.
// When deploying a local charm, it is expected that the charm is located
// in a certain location. If the charm is not located there, we'll get an
// error indicating that the charm is not found.
// If the errors is not found locally, we'll try to download it from
// charm hub.
// Once the charm is added, set up the controller application.
func PopulateControllerCharm(ctx context.Context, deployer ControllerCharmDeployer) error {
controllerAddress, err := deployer.ControllerAddress(ctx)
if err != nil {
Expand Down Expand Up @@ -47,6 +53,7 @@ func PopulateControllerCharm(ctx context.Context, deployer ControllerCharmDeploy
return errors.Annotatef(err, "adding controller application")
}

// Finally, complete the process.
if err := deployer.CompleteProcess(ctx, controllerUnit); err != nil {
return errors.Annotatef(err, "completing process")
}
Expand Down
10 changes: 5 additions & 5 deletions internal/bootstrap/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ type Model interface {
type Unit interface {
// UpdateOperation returns a model operation that will update a unit.
UpdateOperation(state.UnitUpdateProperties) *state.UpdateUnitOperation
// AssignToMachine assigns this unit to a given machine.
// AssignToMachineRef assigns this unit to a given machine.
AssignToMachineRef(state.MachineRef) error
// UnitTag returns the tag of the unit.
UnitTag() names.UnitTag
Expand Down Expand Up @@ -306,15 +306,15 @@ func (b *baseDeployer) DeployCharmhubCharm(ctx context.Context, arch string, bas
}

// Since we're running on the machine to which the controller charm will be
// deployed, we know the exact platform to ask for, not need to review the
// supported series.
// deployed, we know the exact platform to ask for, no need to review the
// supported base.
//
// We prefer the latest LTS series, if the current series is not one,
// We prefer the latest LTS bases, if the current base is not one,
// charmRepo.ResolveWithPreferredChannel, will return an origin with the
// latest LTS based on data provided by charmhub in the revision-not-found
// error response.
//
// The controller charm doesn't have any series specific code.
// The controller charm doesn't have any base specific code.
curl, origin, _, err = charmRepo.ResolveWithPreferredChannel(ctx, curl.Name, origin)
if err != nil {
return "", nil, errors.Annotatef(err, "resolving %q", controllerCharmURL)
Expand Down
2 changes: 1 addition & 1 deletion internal/bootstrap/deployer_iaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (d *IAASDeployer) ControllerAddress(context.Context) (string, error) {
func (d *IAASDeployer) ControllerCharmBase() (corebase.Base, error) {
m, err := d.machineGetter.Machine(agent.BootstrapControllerId)
if err != nil {
return corebase.Empty, errors.Trace(err)
return corebase.Base{}, errors.Trace(err)
}

machineBase := m.Base()
Expand Down

0 comments on commit 7aebace

Please sign in to comment.