Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SALTO-218: apply changes from state to bps post deploy #343

Merged
merged 6 commits into from
Nov 5, 2019

Conversation

hadard
Copy link
Contributor

@hadard hadard commented Nov 4, 2019

No description provided.

@hadard hadard requested a review from a team November 4, 2019 15:36
getConfigFromUser,
shouldDeploy({ stdout: this.stdout, stderr: this.stderr }),
(action: PlanItem) => this.updateCurrentAction(action), this.force)
this.endCurrentAction()
return CliExitCode.Success
if (result.changes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's sync tomorrow about how this works with my changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 👍

return getApprovedChanges(changes, formatFetchChangeForApproval, isConflict)
}

export const getApprovedDetailedChanges = async (
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe getApprovedDeployChanges for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

message: formatFetchChangeForApproval(change, idx, changes.length),
when: answers => isConflict(change) || !shouldDeployAll(answers),
message: message(change, idx, changes.length),
when: answers => (when ? when(change) : false) || !shouldDeployAll(answers),
Copy link
Contributor

Choose a reason for hiding this comment

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

not related to this PR but shouldDeployAll should not be called deploy, should probably be called shouldApproveAll
Also, allowing the function when to come from an external source can cause confusion IMO because its decision is sometimes overridden by logic that is internal to this function.

Generally I think there is no reason to have different behavior for changes originating from apply and changes originating from fetch, IMO they can use the same types and the same flow and I think that would make the code much simpler

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure how we can do it, in fetch flow we have FetchChange and in deploy flow we have diff between state and workspace which is only DetailedChange. Do you suggest to build in deploy flow fake FetchChange?

getConfigFromUser,
shouldDeploy({ stdout: this.stdout, stderr: this.stderr }),
(action: PlanItem) => this.updateCurrentAction(action), this.force)
this.endCurrentAction()
return CliExitCode.Success
if (result.changes) {
const changes = wu(result.changes).toArray()
Copy link
Contributor

Choose a reason for hiding this comment

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

style nit: no need to use wu when just filling an array, can be written as [...result.changes]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

header(Prompts.FETCH_CHANGE_HEADER(idx + 1, totalChanges)),
body(formatDetailedChanges([[change]])),
header(Prompts.FETCH_SHOULD_APPROVE_CHANGE),
].join('\n'))
Copy link
Contributor

Choose a reason for hiding this comment

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

a change with no conflict behaves exactly the same (and we really want to the be exactly the same for UX consistency) so this code duplication is not a good idea IMO

export const importFromCsvFile = async (): Promise<void> => {}
export const deleteFromCsvFile = async (): Promise<void> => {}
export const importFromCsvFile = async (): Promise<void> => { }
export const deleteFromCsvFile = async (): Promise<void> => { }
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: why add the space here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😄 vscode added it

@@ -105,13 +105,12 @@ export const deployCommand = async (
}

try {
deployProcess = deploy(
await deploy(
Copy link
Contributor

Choose a reason for hiding this comment

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

cli and vscode should behave consistently, if the cli command updates the workspace, so should vscode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you right opened: SALTO-296

export const preview = async (
workspace: Workspace,
): Promise<Plan> => {
const state = new State(workspace.config.stateLocation)
return getPlan(await state.get(), workspace.elements)
}

export interface DeployResult {
sucesses: boolean
changes?: Iterable<DetailedChange>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should prefer returning an empty list to having changes optional here. optional fields are annoying to handle in the code and when using lists it means there are actually two different ways for express no changes (undefined and empty list)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the optional is for the case of success=false not sure what's better..

@@ -56,8 +57,12 @@ export const deploy = async (
reportProgress,
(action, element) => deployActionOnState(state, action, element)
)
return {
sucesses: true,
changes: getDetailedChanges(workspace.elements, await state.get()) || undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need || undefined here? doesn't really make sense given that getDetailedChanges should always return an iterable

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 wasn't sure how this is going to behave - you probably right and I will remove it

changes: ReadonlyArray<FetchChange>,
): Promise<ReadonlyArray<FetchChange>> => {
const isConflict = (change: FetchChange): boolean => change.pendingChange !== undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

please revert this one so we can avoid conflict

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

action: 'remove',
data: { before: 'asd' },
},
]
Copy link
Contributor

Choose a reason for hiding this comment

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

if this is already here we can use the detailedChange function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -56,8 +57,15 @@ export const deploy = async (
reportProgress,
(action, element) => deployActionOnState(state, action, element)
)

const changes = wu(getDetailedChanges(workspace.elements, await state.get()))
Copy link
Contributor

Choose a reason for hiding this comment

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

probably better not to state.get() again here, instead I would suggest storing the state elements and leaving a comment saying they are mutated during deploy and we rely on this

@hadard hadard merged commit 5762728 into salto-io:master Nov 5, 2019
orendig added a commit that referenced this pull request Nov 6, 2019
* Added settings filter

* End help message with EOL (#340)

* removed extension readme badges (#345)

* fixes command title (#339)

* added event listener to file changes in extension (#338)

* added error severity in extension (#344)

* added error severity in extension

* changed event filter out non-bp file changes (#341)

* added wrapper to run aggr set function (fixes SALTO-264) (#342)

* try #1 to fix Capriza failure: "TypeError: Cannot read property 'lookupFilter' of undefined" (#346)

* SALTO-218: apply changes from state to bps post deploy (#343)

* Replaced async-file package (#347)

* upgraded inquirer.js to fix hang in Windows 10
* moved accesses to fs module to centralized file module
* using tmp-promise instead of tmp

* change default fetch behavior to auto approve incoming changes (#350)

* Added settings filter

* Hadar CR

* Consistent list order (#348)

List ordering for specific ObjectTypes and records (InstanceElements)

* missing await in apply changes post deploy (#356)

* added missing await in fetch (#353)

* Consistent list order (#348)

List ordering for specific ObjectTypes and records (InstanceElements)

* missing await in apply changes post deploy (#356)

* Added settings filter

* Hadar CR

* add debug logs (#355)

* blacklisted static resources (#352)

* shouldn't add default ObjectType annotations upon adapter.update (#357)

* Hadar comments

* rename elemId fieldType name to field_name since it collides with a Custom object that named Name and it causes undesired merge of the ObjectTypes (#354)

* Fixed e2e

* Fixed e2e

* Added settings filter

* Hadar CR

* Hadar comments

* Fixed e2e

* Fixed e2e
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.

None yet

4 participants