Repository navigation
Support channels in v2 sync - #1566
Conversation
josephjclark
left a comment
There was a problem hiding this comment.
Just left some musings Frank - it may not all be valid
| logger?.warn('WARNING! No content for file', f); | ||
| } | ||
| } | ||
| // Remove any channels.yaml left over from the previous project, so its |
There was a problem hiding this comment.
Joe to check: this is a little awkward isn't it. Not sure I see a way around it though...
There was a problem hiding this comment.
Agreed. It's needed because checkout rewrites openfn.yaml but doesn't touch other files, so a channels.yaml from the previous project would be left behind and its channels deployed to the new one
|
|
||
| // Channels dropped from the merged project (ie, removed from | ||
| // channels.yaml) need an explicit delete entry in the deploy payload | ||
| export const deletedChannels = (merged: Project, remote: Project) => { |
There was a problem hiding this comment.
I think this should be happening in the Project code - the same way as we track deleted steps and workflows.
CLI should have as little logic as possible
There was a problem hiding this comment.
Done. Merge now flags removed channels with Project.removeChannel(), and to-app-state sends them as delete: true. fyi, I borrowed this logic from Collections, there is a deletedCollections function in deploy.ts
| @@ -0,0 +1,42 @@ | |||
| import type l from '@openfn/lexicon'; | |||
There was a problem hiding this comment.
Are we sure this warrants its own file?
There was a problem hiding this comment.
I'm open to folding this to another file, just not sure where
| import type l from '@openfn/lexicon'; | ||
| import getCredentialName from './get-credential-name'; | ||
|
|
||
| export const CHANNELS_FILE = 'channels.yaml'; |
There was a problem hiding this comment.
I am tempted to suggest that we convert this to resources.yaml and use it to track extra server-side resources. Collections, in particular. But maybe later environments, global functions, all sorts
There was a problem hiding this comment.
Aaah, good idea. Can I proceed with it on this branch?
| } | ||
|
|
||
| // Source channels win, but keep the target's id on a name match. | ||
| // If the source has no channels at all (no channels.yaml), keep the target's |
There was a problem hiding this comment.
Why this rule? Maybe the user just deleted channels.yaml to remove all those pesk channels?
is this tracking a specific use case?
There was a problem hiding this comment.
It protects existing workspaces. Anything pulled before this change has no channels.yaml, so if a missing file meant "no channels", the next deploy would delete every channel on the project
| })); | ||
| } | ||
|
|
||
| // Source channels win, but keep the target's id on a name match. |
There was a problem hiding this comment.
Possibly this should recognise deletes too?
The way we do it in merge-workflow is:
- identifiy removed stuff druing the merge
- call
Workflow.remove(id) - This tells the workflow class that something was removed
- That step is generally ignored from
workflow.steps - But during state serialization we get the list of removed items and set
delete: true
This makes me want to add Project.removeCollection() and have it work in just the same way. Then all the delete logic is only handled by the provosioner serialisation - no-one else needs to worry or care about it.
We'd have to do the same for collections too, but happy to spin out an issue for that.
There was a problem hiding this comment.
Good point. I've done this for channels. If we're to do resources.yaml then maybe we should do it for Collections too
| }; | ||
|
|
||
| // channels.yaml is optional: if it's missing, channels stay undefined and | ||
| // are left untouched on merge/deploy |
There was a problem hiding this comment.
Also slightly questioning this...
Move channel delete detection out of the CLI deploy handler and into the project's merge step, so any caller of toAppState sends removed channels to Lightning as deletes.
b2fc66c to
9c88fa8
Compare
josephjclark
left a comment
There was a problem hiding this comment.
This is great Frank, thank you
I'm just going to look at adding slightly better output in the CLI. I'll either add it and merge it, or spin out an issue if it takes too long. But Ithink it's small...
* restructure project-diff * diff channels in project * log resource diff in CLI * changeset * one more changeset for the road * format * simplify
* Remove trigger.enabled (#1564) * lexicon: remove trigger.enabled from spec * update handling of trigger.enabled * update version hash * changeset * remove log * update version util and fix tests * add notes to docs * remove .only * fix test * update test * fix integration test * Support channels in v2 sync (#1566) * project: read and write channels via channels.yaml * project: fix sandbox merge dropping channels and keep remote channel ids on merge * cli: deploy channel changes and deletions, and clear stale channels.yaml on checkout * project: track removed channels on merge and send them as deletes Move channel delete detection out of the CLI deploy handler and into the project's merge step, so any caller of toAppState sends removed channels to Lightning as deletes. * project: store channels under a channels key in resources.yaml instead of channels.yaml * project: key resources.yaml channels by id with a required name * project: match channels by their resources.yaml id so renames keep the channel * Resource Diffs (#1572) * restructure project-diff * diff channels in project * log resource diff in CLI * changeset * one more changeset for the road * format * simplify --------- Co-authored-by: Joe Clark <joe@openfn.org> * No checkout after deploy (#1573) * don't checkout after deploy * test * changeset * fix test * version --------- Co-authored-by: Midigo Frank <39288959+midigofrank@users.noreply.github.com>
Short Description
Adds v2 sync support for project channels. Channels are managed locally in a new
resources.yamlfile at the workspace root, and pulled, merged and deployed along with the rest of the project.resources.yamlis meant to hold other server-side resources too; collections will move there later.Fixes OFN-4553
Implementation Details
resources.yamlformat. Channels live under achannelskey. Each channel is keyed by an id (slugified from its name on pull) and has a requiredname. There are no uuids, and credentials are referenced by name (owner|name), the same way steps reference them:If
resources.yamlis missing, or has nochannelskey, channels aren't managed locally, and merge and deploy leave remote channels alone. This protects projects synced beforeresources.yamlexisted.channels: {}means "no channels", so any remote channels get deleted.@openfn/project
from-fsreads channels fromresources.yamlif they're there.to-fswrites them only if the project has channels.util/resources.tsconverts between the file format andChannelState.to-app-stateresolves credential names to uuids, mints an id for any channel created locally, and never sends the local key.resources.yamlid, so a rename keeps the remote channel. Remote channels are matched by their slugified name. Sandbox merges used to drop channels completely. That's fixed.resources.yamlonproject.removedChannels, andto-app-statesends them asdelete: true, the same way removed steps and workflows are handled.@openfn/cli
deploytreats channel changes as deployable. Previously a channels-only change reported "Nothing to deploy".checkoutremoves a leftoverresources.yamlwhen the target project has no channels, so one project's channels don't get deployed to another.@openfn/lexicon
ChannelState: aChannelwith an optionalid, a localkey, and adestination_credential_idthat can hold a credential name.Known limitation: Lightning currently rejects channel deletes through the provisioning API (422). That's being fixed on the Lightning side; until then, a deploy that removes a channel fails.
QA Notes
resources.yamlis written with names and credential names, not uuids.resources.yaml, then deploy. Check that each change shows up in Lightning.name, keep its key) and deploy. Check that the channel is updated in place, not recreated.resources.yamland check that the remote channels are unchanged.resources.yamlis removed.AI Usage
You can read more details in our
Responsible AI Policy