Skip to content

feat: wire river into JIMM's upgrade to handler#1845

Merged
kian99 merged 4 commits intocanonical:v3from
kian99:upgrade-to-handler
Feb 3, 2026
Merged

feat: wire river into JIMM's upgrade to handler#1845
kian99 merged 4 commits intocanonical:v3from
kian99:upgrade-to-handler

Conversation

@kian99
Copy link
Contributor

@kian99 kian99 commented Feb 2, 2026

Description

This PR wires up the River client into the JIMM domain layer, allowing us to insert river jobs as necessary.

The main challenge I faced with this was the potential for circular dependencies. To resolve this I've made a package called rivertypes, thanks @luci1900 for the discussion on this. This package holds the job arguments that are used when inserting a job using the river client. The package go doc explains this nicely,

// River job args are analogous to a schema for traditional queue systems, defining what
// we will insert into the DB for processing later by workers. By defining them
// in a 3rd package we avoid circular dependencies between the domain layer and the

There was one more issue with the tests, to try and summarise

  • internal/river depends on types from internal/jimm/upgrade for its UpgradeTo interface definition (though technically the current methods only use base types, but I've added a blank import to simulate the future problem).
  • That revealed an import cycle in tests. The river tests create a DB using internal/jimmtest/ helpers. The import cycle came from the fact that internal/jimmtest/ imports internal/jimm/ and internal/jimm/ imports the thing river wrapper we have to make it easier to mock in tests.
  • The solution was simply to move the DB related helpers into internal/jimmtest/dbtest/

I recommend reviewing the commits separately.

Fixes JUJU-9057

Engineering checklist

  • Documentation updated
  • Covered by unit tests
  • Covered by integration tests

@kian99 kian99 requested a review from a team as a code owner February 2, 2026 13:55
@kian99 kian99 force-pushed the upgrade-to-handler branch from 9582749 to f451c0f Compare February 2, 2026 14:25
In internal/river tests we imported `"github.com/canonical/jimm/v3/internal/testutils/jimmtest"` for creation of test DBs. That package imports internal/jimm.
Internal/jimm will (optionally) import internal/river if we have a wrapper around River's client. This change ensures DB creation is not wrapped up in this dependency tree.
var newControllerName = fmt.Sprintf("controller-%d", time.Now().Unix())

if targetVersion == version.Zero {
return 0, errors.E(errors.CodeBadRequest, "target version cannot be zero")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the added value of wrapping the error with errors.E in this case (and below)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None (besides adding codes in this scenario), I think everyone just sticks errors.E everywhere since that's our standard approach. Which we'll hopefully get rid of soon.

}

// UpgradeEnqueuer defines the method to enqueue an upgrade job.
type UpgradeEnqueuer interface {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpgradeJobManager?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't call it a manager since that term has some usage already in JIMM associated with the business logic domains.

Copy link
Contributor

@SimoneDutto SimoneDutto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! it's very similar to what I set up originally! Plus the rivertypes.

@kian99 kian99 force-pushed the upgrade-to-handler branch from f451c0f to d1de503 Compare February 3, 2026 09:00
@kian99 kian99 merged commit 1faa771 into canonical:v3 Feb 3, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants