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

fix: unexpected behaviour with sync and multiple ws #576

Merged
merged 2 commits into from
Feb 7, 2022

Conversation

GGabriele
Copy link
Collaborator

When passing to sync multiple files (or a folder) with different
_workspace definition, sync merges the files and applies them
only to a single workspace.

This change makes sync returning an error when attempting
a deployment with multiple workspaces.

When passing to sync multiple files (or a folder) with different
_workspace definition, sync merge the files and applies them
only to a single workspace.

This change makes sync returning an error when attempting
a deployment with multiple workspaces.
@codecov-commenter
Copy link

codecov-commenter commented Feb 1, 2022

Codecov Report

Merging #576 (3bd1818) into main (be847ba) will increase coverage by 0.07%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #576      +/-   ##
==========================================
+ Coverage   51.07%   51.15%   +0.07%     
==========================================
  Files          73       73              
  Lines        7996     8009      +13     
==========================================
+ Hits         4084     4097      +13     
  Misses       3542     3542              
  Partials      370      370              
Impacted Files Coverage Δ
file/readfile.go 84.61% <100.00%> (+0.68%) ⬆️
file/validate.go 90.00% <100.00%> (+3.63%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update be847ba...3bd1818. Read the comment docs.

@hbagdi
Copy link
Member

hbagdi commented Feb 1, 2022

@rainest Do we allow for "workspace" provided via CLI flag and that provided in the state file to differ?
That's one thing we need to take into account otherwise this is good.

@rainest
Copy link
Contributor

rainest commented Feb 3, 2022

Current behavior is to print a warning and then proceed, preferring the

/tmp/adeck sync -s decs --workspace foo
Warning: Workspace 'foo' specified via --workspace flag is different from workspace 'bar' found in state file(s).
...
Error: 1 errors occurred:
	while processing event: {Create} route r2 failed: HTTP status 409 (message: "API route collides with an existing API")

This is after I'd synced to the workspace in the manifest, so it failed to create a new one due to path collision.

With the new patch, it's rejected regardless:

13:13:42-0800 esenin $ /tmp/bdeck sync -s decs                
Error: cannot sync multiple workspaces at the same time: [bar ]
13:15:12-0800 esenin $ /tmp/bdeck sync -s decs --workspace foo
Error: cannot sync multiple workspaces at the same time: [bar ]

I think that's what we want, but that said, it looks like the output of the error is a bit off: I'd expect this to print [bar, baz], but one of the workspaces is being omitted.

@GGabriele
Copy link
Collaborator Author

I think that's what we want, but that said, it looks like the output of the error is a bit off: I'd expect this to print [bar, baz], but one of the workspaces is being omitted.

What's the content of those files? I can't reproduce it:

$ deck sync -s ws1.yaml -s ws2.yaml
Error: cannot sync multiple workspaces at the same time: [ws1 ws2]

@rainest
Copy link
Contributor

rainest commented Feb 3, 2022

Nevermind, weird malformed YAML from botched paste behavior strikes again. One had:

 _format_version: "0.1"
_workspace: baz

It properly detected the duplicate workspaces but then couldn't actually read it due to the leading space on the format. Edge case we don't care about for this, it should be solved with a general failure on any malformed YAML for #578

@GGabriele
Copy link
Collaborator Author

Let me know if any of you have more comments or if this is good to go

Copy link
Member

@hbagdi hbagdi left a comment

Choose a reason for hiding this comment

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

Merge with approval from Travis.

file/validate.go Outdated
func validateWorkspaces(workspaces []string) error {
utils.RemoveDuplicates(&workspaces)
if len(workspaces) > 1 {
return fmt.Errorf("cannot sync multiple workspaces at the same time: %v", workspaces)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("cannot sync multiple workspaces at the same time: %v", workspaces)
return fmt.Errorf("It seems like you are trying to sync multiple workspaces at the same time (%v). decK doesn't support syncing multiple workspaces at the same time, please sync one workspace at a time.", workspaces)

Use appropriate \ns and maybe add an HTTP link to docs if we have one.
cc @lena-larionova

Copy link
Contributor

@lena-larionova lena-larionova Feb 7, 2022

Choose a reason for hiding this comment

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

The doc is light on this and needs some improvement, but we do have something: https://docs.konghq.com/deck/1.10.x/guides/kong-enterprise/#workspaces

@hbagdi
Copy link
Member

hbagdi commented Feb 7, 2022

Current behavior is to print a warning and then proceed, preferring the

Preferring what? Whatever it be, we must ensure that behavior is not broken - a user ignoring the warning shouldn't receive an error after this patch.

@GGabriele
Copy link
Collaborator Author

Current behavior is to print a warning and then proceed, preferring the

Preferring what? Whatever it be, we must ensure that behavior is not broken - a user ignoring the warning shouldn't receive an error after this patch.

Confirming this patch doesn't change that behaviour:

$ deck sync -s kong.yaml --workspace test
Warning: Workspace 'test' specified via --workspace flag is different from workspace 'ws1' found in state file(s).
...
...
Error: 1 errors occurred:
	while processing event: {Create} route r1 failed: HTTP status 409 (message: "API route collides with an existing API")

Copy link
Contributor

@rainest rainest left a comment

Choose a reason for hiding this comment

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

Preferring the workspace in the flag, whoops.

@rainest rainest merged commit 348129e into main Feb 7, 2022
@rainest rainest deleted the error_sync_workspaces branch February 7, 2022 17:35
AntoineJac pushed a commit that referenced this pull request Jan 23, 2024
When passing to sync multiple files (or a folder) with different
_workspace definition, sync merge the files and applies them
only to a single workspace.

This change makes sync returning an error when attempting
a deployment with multiple workspaces.
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.

5 participants