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

feat(sync/diff) Create workspace if needed #187

Merged
merged 4 commits into from
Jul 30, 2020
Merged

Conversation

cwurm
Copy link
Contributor

@cwurm cwurm commented Jul 12, 2020

Adds the workspace as another entity to decK.

Some notes on the implementation:

  1. A workspace is only ever created, not updated or deleted. Updating is not really necessary since the deck syntax at the moment only supports the workspace name in the _workspace property. Deleting a workspace is quite tricky esp. when the Dev Portal is enabled.
  2. Supports both sync and diff - other workspace-related behavior e.g. in reset and dump remains unchanged (though some code has changed).
  3. Updates to the current master of go-kong for workspace support.
  4. Since go-kong does not offer complete support for workspaces a separate rootClient is needed to create a workspace. Fortunately, the code changes for that were not too bad.
  5. The changes in file/schema.go are not from this PR - somewhere something changed and it wasn't updated.

Example output:

$ deck sync -s workspace-demo.yaml -s openid-connect-okta.yaml
creating workspace Demo
creating service mockbin-okta
creating route okta
creating plugin openid-connect for route 8a7f17df-2998-4c71-9da8-0b75ff72373b
Summary:
  Created: 4
  Updated: 0
  Deleted: 0

Resolves #158.

@hbagdi hbagdi changed the base branch from master to main July 14, 2020 21:09
cmd/common.go Outdated
// Using ListAll() to get all workspaces instead of Get() to get just
// the one to make sure there is no underlying error - Get() does not
// expose the response.
workspaces, err := rootClient.Workspaces.ListAll(nil)
Copy link
Member

Choose a reason for hiding this comment

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

the one to make sure there is no underlying error

Yes, this is a limitation and go-kong needs to improve to fix this problem but I still think we should use Get() instead. You can use IsNotFoundErr() to check if it was a 404 or not.

If there is an underlying error, return it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, and done.

@hbagdi
Copy link
Member

hbagdi commented Jul 14, 2020

This is great work and provides a very good end-user experience but I feel this is more complicated than it should be.

  • We can get away with simulating a workspace sync rather than add it to solver, diff and setup the whole machinery around it. This is possible because we are only ever going to create a workspace and never going to update or delete it.
  • Another reason to avoid adding this in is because we are not at a point where we would like to manage workspaces using decK. If this PR is merged as is, it will open gates for adding declarative configuration of workspaces entity in Kong itself, which is plagued with problems and I think it will be best for decK to not get anywhere near that dragon.
  • We could do the following, which will result in a smaller and more maintainable patch:
    • Diff
      • check if workspace exists, if not then run a diff against an empty state (the current patch in the PR already does this)
      • if workspace exists, then dump and then do the diff
    • Sync
      • if workspace doesn't exist, create it and then start the dump and diff logic
      • if does exist, then nothing needs to be done

Also, please also take a look at #186 which will need to work with this.

@cwurm
Copy link
Contributor Author

cwurm commented Jul 15, 2020

  • We can get away with simulating a workspace sync rather than add it to solver, diff and setup the whole machinery around it. This is possible because we are only ever going to create a workspace and never going to update or delete it.

Sure, so that we be something close to the first commit (which already worked for sync just needs to be extended to diff): ebad319 (#187)

The reason I expanded to the full solver/syncer is that without it the workspace doesn't appear in the entity counter at the end. But if that's not a concern I agree there is a much simpler way to do this and I'll just go back to the first commit and expand it. Let me know.

  • Another reason to avoid adding this in is because we are not at a point where we would like to manage workspaces using decK. If this PR is merged as is, it will open gates for adding declarative configuration of workspaces entity in Kong itself, which is plagued with problems and I think it will be best for decK to not get anywhere near that dragon.

I agree workspace management is too far out for decK at this point. But - this PR alone does not commit us in any way to go in this direction - there never has to be a further change to this code.

Also, please also take a look at #186 which will need to work with this.

Good shout, I'll test that scenario. What's probably required is to be able to disable workspace checking and creating completely with that flag - but need to take a closer look.

@hbagdi
Copy link
Member

hbagdi commented Jul 22, 2020

Sure, so that we be something close to the first commit (which already worked for sync just needs to be extended to diff): ebad319 (#187)

Pretty much. The only thing to note is that deck diff should not create a workspace in kong.

The reason I expanded to the full solver/syncer is that without it the workspace doesn't appear in the entity counter at the end. But if that's not a concern I agree there is a much simpler way to do this and I'll just go back to the first commit and expand it. Let me know.

That's could be considered a little odd but if we are taking the stance that workspace management is not something deck is responsible for, that's okay in my opinion.

But - this PR alone does not commit us in any way to go in this direction - there never has to be a further change to this code.

This PR doesn't intend to do that but in the current for, it has the potential to give new contributors ideas around what could be done with workspaces and decK. OSS users can and do sometimes get very creative, which is not always good from a Software Engineering standpoint.

Ping me once you have reworked this one. Thanks!

@cwurm
Copy link
Contributor Author

cwurm commented Jul 25, 2020

@hbagdi Alright, I've simplified the logic.

The output is now:

$ deck sync -s workspace-demo.yaml -s openid-connect-okta.yaml
creating workspace Demo
creating service mockbin-okta
creating route okta
creating plugin openid-connect for route ff9dcb66-0aae-45ef-abad-c627ebd2201c
Summary:
  Created: 3
  Updated: 0
  Deleted: 0

The created workspace no longer appears as a created entity in the summary - but the code is a lot simpler.

@cwurm cwurm requested a review from hbagdi July 25, 2020 15:19
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.

cmd/common.go can be a more readable but I'll take care of that after merge freeze for 1.2.
Thanks for contributing this long-asked feature!

@hbagdi hbagdi merged commit bdc3113 into Kong:main Jul 30, 2020
@cwurm cwurm deleted the create_workspace branch August 13, 2020 18:03
rainest pushed a commit that referenced this pull request Apr 21, 2021
With this patch, decK creates a workspace in Kong Enterprise
during if one doesn't exist.

The follow behavior is intentional:
- `deck diff` doesn't create a workspace; this is to
preserve read only nature of the diff command
- `deck sync` creates a workspace if one is not present;
it should be noted that the behavior of creating a workspace
via API vs via UI (Kong Manager) is different. Kong Manager
creates default RBAC roles for the workspace.
- Workspace meta data cannot be adjusted using decK.
- `deck reset` doesn't delete a workspace. Deleting a workspace
is, unfortunately, a pretty complicated operation in Kong Enterprise
requiring emptying a workspace, an operation decK is not capable
of doing at this point of time.


In summary, decK only creates a workspace and doesn't
treat workspace as a regular Kong entity.

From #187
AntoineJac pushed a commit that referenced this pull request Jan 23, 2024
With this patch, decK creates a workspace in Kong Enterprise
during if one doesn't exist.

The follow behavior is intentional:
- `deck diff` doesn't create a workspace; this is to
preserve read only nature of the diff command
- `deck sync` creates a workspace if one is not present;
it should be noted that the behavior of creating a workspace
via API vs via UI (Kong Manager) is different. Kong Manager
creates default RBAC roles for the workspace.
- Workspace meta data cannot be adjusted using decK.
- `deck reset` doesn't delete a workspace. Deleting a workspace
is, unfortunately, a pretty complicated operation in Kong Enterprise
requiring emptying a workspace, an operation decK is not capable
of doing at this point of time.


In summary, decK only creates a workspace and doesn't
treat workspace as a regular Kong entity.

From #187
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create workspace automatically if it doesn't exist on sync
2 participants