Skip to content

Commit

Permalink
Merge pull request juju#17418 from manadart/3.5-into-3.6
Browse files Browse the repository at this point in the history
juju#17418

Zero-conflict merge from 3.5 to bring forward:
- juju#17416 from hpidcock/merge-3.4-to-3.5-20240524
- juju#17415 from hpidcock/fix-non-rootless
  • Loading branch information
jujubot authored May 24, 2024
2 parents 5be5c43 + d6bf993 commit 70fa29d
Show file tree
Hide file tree
Showing 33 changed files with 650 additions and 350 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/microk8s-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
microk8s: [1.28/stable]
microk8s: [1.30/stable]

steps:
- name: Checking out repo
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
if: matrix.cloud == 'microk8s'
uses: balchua/microk8s-actions@e99a1ffcd3bb2682d941104cf6c1a215c657903f
with:
channel: "1.28-strict/stable"
channel: "1.30-strict/stable"
addons: '["dns", "hostpath-storage", "rbac"]'
launch-configuration: "$GITHUB_WORKSPACE/.github/microk8s-launch-config-aws.yaml"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jobs:
if: matrix.cloud == 'microk8s'
uses: balchua/microk8s-actions@e99a1ffcd3bb2682d941104cf6c1a215c657903f
with:
channel: "1.28-strict/stable"
channel: "1.30-strict/stable"
addons: '["dns", "hostpath-storage"]'
launch-configuration: "$GITHUB_WORKSPACE/.github/microk8s-launch-config-aws.yaml"

Expand Down
3 changes: 2 additions & 1 deletion allowed_signers
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ [email protected] namespaces="git" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5A
[email protected] namespaces="git" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPKjQDDaO24INaGFnUdVebD1wYcDXmm/cLKH+27S2SnC wallyworld-git-signing-key
[email protected] namespaces="git" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINP0LQkkiiHuMdVz4aF7ypsxNLQscgGd1UrmHrjyEd9F jack-w-shaw-git-signing-key
[email protected] namespaces="git" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKdk2GDbpmHUP/FQVunGu6Bl9TD1Hh5Z8oYAD17CzPP6 joe-signing-key
[email protected] namespaces="git" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFk9Tf6k0uZaUEYpeY49rJQvwxCTf05EyCuaf63pTGfB joe-signing-key-notebook
[email protected] namespaces="git" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFk9Tf6k0uZaUEYpeY49rJQvwxCTf05EyCuaf63pTGfB joe-signing-key-t440p
[email protected] namespaces="git" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIICzxkC8I7x1mNrTuuuMlezc8a+xTi84ScECdqAhisvp joe-signing-key-s76
[email protected] namespaces="git" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHu5ROyG1P7OQnNE5uNw0JVjKzZdbqGg3cHqywTt/Ynb jameinel-git-signing-key
[email protected] namespaces="git" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHu5ROyG1P7OQnNE5uNw0JVjKzZdbqGg3cHqywTt/Ynb jameinel-git-signing-key
[email protected] namespaces="git" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPqO5HpXaSh6MJ9FVt8nyoxhWN+AqlFxIXE68JGrRysb [email protected]
Expand Down
12 changes: 8 additions & 4 deletions api/common/charms/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func (s *suite) TestCharmInfo(c *gc.C) {
Location: "/cockroach/cockroach-data",
},
},
Uid: 5000,
Gid: 5001,
Uid: intPtr(5000),
Gid: intPtr(5001),
},
},
Storage: map[string]params.CharmStorage{
Expand Down Expand Up @@ -136,8 +136,8 @@ func (s *suite) TestCharmInfo(c *gc.C) {
Location: "/cockroach/cockroach-data",
},
},
Uid: 5000,
Gid: 5001,
Uid: intPtr(5000),
Gid: intPtr(5001),
},
},
Storage: map[string]charm.Storage{
Expand Down Expand Up @@ -198,3 +198,7 @@ func (s *suite) TestApplicationCharmInfo(c *gc.C) {
}
c.Assert(got, gc.DeepEquals, want)
}

func intPtr(i int) *int {
return &i
}
12 changes: 8 additions & 4 deletions apiserver/common/charms/appcharminfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ func (s *appCharmInfoSuite) TestSidecarCharm(c *gc.C) {
Storage: "my-storage",
Location: "/my/storage/location",
}},
Uid: 5000,
Gid: 5001,
Uid: intPtr(5000),
Gid: intPtr(5001),
},
},
Storage: map[string]charm.Storage{
Expand Down Expand Up @@ -163,8 +163,8 @@ func (s *appCharmInfoSuite) TestSidecarCharm(c *gc.C) {
Storage: "my-storage",
Location: "/my/storage/location",
}},
Uid: 5000,
Gid: 5001,
Uid: intPtr(5000),
Gid: intPtr(5001),
},
},
Resources: map[string]params.CharmResourceMeta{
Expand All @@ -183,3 +183,7 @@ func (s *appCharmInfoSuite) TestSidecarCharm(c *gc.C) {
Manifest: &params.CharmManifest{},
})
}

func intPtr(i int) *int {
return &i
}
1 change: 1 addition & 0 deletions apiserver/facades/client/application/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ type CharmMeta interface {
type Machine interface {
Base() state.Base
HardwareCharacteristics() (*instance.HardwareCharacteristics, error)
Id() string
PublicAddress() (network.SpaceAddress, error)
IsLockedForSeriesUpgrade() (bool, error)
IsParentLockedForSeriesUpgrade() (bool, error)
Expand Down
134 changes: 89 additions & 45 deletions apiserver/facades/client/application/deployrepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,19 +581,21 @@ func (v *deployFromRepositoryValidator) createOrigin(arg params.DeployFromReposi

// deducePlatform returns a platform for initial resolveCharm call.
// At minimum, it must contain an architecture.
// Platform is determined by the args: architecture constraint and
// provided base.
// - Check placement to determine known machine platform. If diffs from
// other provided data return error.
// Platform is determined by the args: architecture constraint and provided
// base. Or from the model default architecture and base.
// - If no base provided, use model default base.
// - If no model default base, will be determined later.
// - If no architecture provided, use model default. Fallback
// to DefaultArchitecture.
//
// Then check for the platform of any machine scoped placement directives.
// Use that for the platform if no base provided by the user.
// Return an error if the placement platform and user provided base do not
// match.
func (v *deployFromRepositoryValidator) deducePlatform(arg params.DeployFromRepositoryArg) (corecharm.Platform, bool, error) {
argArch := arg.Cons.Arch
argBase := arg.Base
var usedModelDefaultBase bool
var usedModelDefaultArch bool

// Try argBase with provided argArch and argBase first.
platform := corecharm.Platform{}
Expand All @@ -610,7 +612,6 @@ func (v *deployFromRepositoryValidator) deducePlatform(arg params.DeployFromRepo
platform.Architecture = *mConst.Arch
} else {
platform.Architecture = arch.DefaultArchitecture
usedModelDefaultArch = true
}
}
if argBase != nil {
Expand All @@ -619,9 +620,7 @@ func (v *deployFromRepositoryValidator) deducePlatform(arg params.DeployFromRepo
return corecharm.Platform{}, usedModelDefaultBase, err
}
platform.OS = base.OS
// platform channels don't model the concept of a risk
// so ensure that only the track is included
platform.Channel = base.Channel.Track
platform.Channel = base.Channel.String()
}

// Initial validation of platform from known data.
Expand All @@ -630,78 +629,123 @@ func (v *deployFromRepositoryValidator) deducePlatform(arg params.DeployFromRepo
return corecharm.Platform{}, usedModelDefaultBase, err
}

// Match against platforms from placement
placementPlatform, placementsMatch, err := v.platformFromPlacement(arg.Placement)
if err != nil && !errors.Is(err, errors.NotFound) {
if err != nil {
return corecharm.Platform{}, usedModelDefaultBase, err
}
if err == nil && !placementsMatch {
return corecharm.Platform{}, usedModelDefaultBase, errors.BadRequestf("bases of existing placement machines do not match")
// No machine scoped placement to match, return after checking
// if using default model base.
if placementPlatform == nil {
return v.modelDefaultBase(platform)
}
// There can be only 1 platform.
if !placementsMatch {
return corecharm.Platform{}, usedModelDefaultBase, errors.BadRequestf("bases of existing placement machines do not match each other")
}

// No platform args, and one platform from placement, use that.
if placementsMatch && usedModelDefaultArch && argBase == nil {
return placementPlatform, usedModelDefaultBase, nil
// No base args provided. Use the placement platform to deploy.
if argBase == nil {
deployRepoLogger.Tracef("using placement platform %q to deploy", placementPlatform.String())
return *placementPlatform, usedModelDefaultBase, nil
}
if platform.Channel == "" {
mCfg, err := v.model.Config()
if err != nil {
return corecharm.Platform{}, usedModelDefaultBase, err
}
if db, ok := mCfg.DefaultBase(); ok {
defaultBase, err := corebase.ParseBaseFromString(db)
if err != nil {
return corecharm.Platform{}, usedModelDefaultBase, err
}
platform.OS = defaultBase.OS
// platform channels don't model the concept of a risk
// so ensure that only the track is included
platform.Channel = defaultBase.Channel.Track
usedModelDefaultBase = true
}

// Check that the placement platform and the derived platform match
// when a base is supplied. There is no guarantee that all placement
// directives are machine scoped.
if placementPlatform.String() == platform.String() {
return *placementPlatform, usedModelDefaultBase, nil
}
var msg string
if usedModelDefaultBase {
msg = fmt.Sprintf("base from placements, %q, does not match model default base %q", placementPlatform.String(), platform.String())
} else {
msg = fmt.Sprintf("base from placements, %q, does not match requested base %q", placementPlatform.String(), platform.String())
}
return corecharm.Platform{}, usedModelDefaultBase, fmt.Errorf(msg)

}

func (v *deployFromRepositoryValidator) modelDefaultBase(p corecharm.Platform) (corecharm.Platform, bool, error) {
// No provided platform channel, check model defaults.
if p.Channel != "" {
return p, false, nil
}
mCfg, err := v.model.Config()
if err != nil {
return p, false, nil
}
db, ok := mCfg.DefaultBase()
if !ok {
return p, false, nil
}
defaultBase, err := corebase.ParseBaseFromString(db)
if err != nil {
return corecharm.Platform{}, false, err
}
return platform, usedModelDefaultBase, nil
p.OS = defaultBase.OS
p.Channel = defaultBase.Channel.String()
return p, true, nil
}

func (v *deployFromRepositoryValidator) platformFromPlacement(placements []*instance.Placement) (corecharm.Platform, bool, error) {
// platformFromPlacement attempts to choose a platform to deploy with based on the
// machine scoped placement values provided by the user. The platform for all provided
// machines much match.
func (v *deployFromRepositoryValidator) platformFromPlacement(placements []*instance.Placement) (*corecharm.Platform, bool, error) {
if len(placements) == 0 {
return corecharm.Platform{}, false, errors.NotFoundf("placements")
return nil, false, nil
}

machines := make([]Machine, 0)
var machineScopeCnt int
// Find which machines in placement actually exist.
for _, placement := range placements {
m, err := v.state.Machine(placement.Directive)
if errors.Is(err, errors.NotFound) {
if placement.Scope != instance.MachineScope {
continue
}
machineScopeCnt += 1
m, err := v.state.Machine(placement.Directive)
if err != nil {
return corecharm.Platform{}, false, err
return nil, false, errors.Annotate(err, "verifying machine for placement")
}
machines = append(machines, m)
}
if len(machines) == 0 {
return corecharm.Platform{}, false, errors.NotFoundf("machines in placements")

if machineScopeCnt == 0 {
// Not all placements refer to actual machines, no need to continue.
deployRepoLogger.Tracef("no machine scoped directives found in placements")
return nil, false, nil
}

// Gather platforms for existing machines
var platform corecharm.Platform
// Use a set to determine if all the machines have the same platform.
platStrings := set.NewStrings()
for _, machine := range machines {
b := machine.Base()
a, err := machine.HardwareCharacteristics()
hc, err := machine.HardwareCharacteristics()
if err != nil {
return corecharm.Platform{}, false, err
if errors.Is(err, errors.NotFound) {
return nil, false, fmt.Errorf("machine %q not started, please retry when started", machine.Id())
}
return nil, false, err
}
mArch := hc.Arch
if mArch == nil {
return nil, false, fmt.Errorf("machine %q has no saved architecture", machine.Id())
}
platString := fmt.Sprintf("%s/%s/%s", *a.Arch, b.OS, b.Channel)
platString := fmt.Sprintf("%s/%s/%s", *mArch, b.OS, b.Channel)
p, err := corecharm.ParsePlatformNormalize(platString)
if err != nil {
return corecharm.Platform{}, false, err
return nil, false, err
}
platform = p
platStrings.Add(p.String())
}
if platStrings.Size() != 1 {
deployRepoLogger.Errorf("Mismatched platforms for machine scoped placements %s", platStrings.SortedValues())
}

return platform, platStrings.Size() == 1, nil
return &platform, platStrings.Size() == 1, nil
}

func (v *deployFromRepositoryValidator) resolveCharm(curl *charm.URL, requestedOrigin corecharm.Origin, force, usedModelDefaultBase bool, cons constraints.Value) (corecharm.ResolvedDataForDeploy, error) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 70fa29d

Please sign in to comment.