Skip to content

Add forwarding deployer muxer to enable multiple deployers#3391

Merged
dgageot merged 3 commits intoGoogleContainerTools:masterfrom
corneliusweig:w/deployer-mux/muxer
Jan 15, 2020
Merged

Add forwarding deployer muxer to enable multiple deployers#3391
dgageot merged 3 commits intoGoogleContainerTools:masterfrom
corneliusweig:w/deployer-mux/muxer

Conversation

@corneliusweig
Copy link
Copy Markdown
Contributor

@corneliusweig corneliusweig commented Dec 16, 2019

Relates to #2875, #3292

Should merge before : #3392

Description

Add a deployer implementation (DeployerMux) that multiplexes the deployer actions with multiple deployer instances. This new deployer is simply a []deploy.Deployer which forwards the commands of the Deployer interface to the instances in the list. When encountering an error, DeployerMux aborts and returns this error. Otherwise it collects the outputs and returns all results in bulk.

This is a pre-requisite for enabling multiple deployers in skaffold.yaml.

User facing changes

n/a

This PR only adds the functionality but does not enable anything.

Next PRs.

  • adapt skaffold.yaml to accept multiple deployer configurations in the deploy field.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes unit tests
  • Mentions any output changes.
  • Adds documentation as needed: user docs, YAML reference, CLI reference.
  • Adds integration tests if needed.

Reviewer Notes

  • The code flow looks good.
  • Unit test added.
  • User facing changes look good.

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 16, 2019

Codecov Report

Merging #3391 into master will increase coverage by 0.12%.
The diff coverage is 87.71%.

Impacted Files Coverage Δ
pkg/skaffold/deploy/kubectl.go 65.87% <100%> (+2.16%) ⬆️
pkg/skaffold/deploy/util.go 79.16% <80%> (+0.21%) ⬆️
pkg/skaffold/deploy/deploy_mux.go 89.13% <89.13%> (ø)
...affold/kubernetes/portforward/kubectl_forwarder.go 65.85% <0%> (-2.44%) ⬇️
pkg/skaffold/deploy/labels.go 13.41% <0%> (+3.65%) ⬆️

@balopat balopat added the kokoro:run runs the kokoro jobs on a PR label Dec 18, 2019
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Dec 18, 2019
// it collects the results and returns it in bulk.
type DeployerMux []Deployer

var _ Deployer = DeployerMux{}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What does this line do?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

gotcha, it is just a compile time check to make sure that DeployerMux implements the Deployer interface.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

a comment would be nice?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Exactly, this was my local compile check that I have implemented the interface. As this pattern seems to be unused in Skaffold, I opted to remove the line instead.

Copy link
Copy Markdown
Contributor

@balopat balopat left a comment

Choose a reason for hiding this comment

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

This looks good, but I have some small comments on set usage and the labelling strategy.

func (m DeployerMux) Labels() map[string]string {
labels := make(map[string]string)
for _, deployer := range m {
copyMap(labels, deployer.Labels())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this is what we want, if I understand this correctly this will result in a single label with skaffold.dev/deployer: <last deployer>.

The best would be to label resources with their own deployers. However that seems hard with this current architecture.

So I'd rather have something like:

skaffold.dev/deployer0: helm 
skaffold.dev/deployer1: kubectl 
skaffold.dev/deployer2: kustomize

WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. This was already addressed with #3390, where the deployer labels are removed from the global list of labellers and are applied just in the specific deployer instead.
So I think the semantics of this line is correct.

}

func (m DeployerMux) Deploy(ctx context.Context, w io.Writer, as []build.Artifact, ls []Labeller) *Result {
seenNamespaces := sets.String{}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is cool, but kinda scares me that it's in kubernetes. Haven't made up my mind yet about it.
The risk of it disappearing / changing is minimal as skaffold is for kubernetes. But in general we tend to avoid depending on utilities from dependencies - unless the dependency is specifically for that utility. E.g. docker has some great stuff in their ioutils package but we decided not to use them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah that totally makes sense. The de-duplication is easily implemented so there's no need to add a dependency here.
I think there are a few places where Skaffold code could benefit from a StringSet util, but this is not the right PR to make that change :). So I've inlined a small helper in this file.

This allows re-use by other deployer renderers.

Signed-off-by: Cornelius Weig <22861411+corneliusweig@users.noreply.github.com>
This Deployer implemenation forwards commands to all of the deployers in
his list. It will be useful to allow multiple deployers in skaffold.yaml.

Signed-off-by: Cornelius Weig <22861411+corneliusweig@users.noreply.github.com>
Signed-off-by: Cornelius Weig <22861411+corneliusweig@users.noreply.github.com>
@corneliusweig
Copy link
Copy Markdown
Contributor Author

Sorry for my confusion. I accidentally committed the review comments to the wrong branch 2 weeks ago 🤦‍♂️
Please have another look :)

@dgageot dgageot self-assigned this Jan 15, 2020
Copy link
Copy Markdown
Contributor

@dgageot dgageot left a comment

Choose a reason for hiding this comment

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

LGTM with a nit

@dgageot dgageot added the kokoro:run runs the kokoro jobs on a PR label Jan 15, 2020
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Jan 15, 2020
@dgageot dgageot dismissed balopat’s stale review January 15, 2020 17:52

Changes were made. Looks good

@dgageot dgageot merged commit f2aeb3a into GoogleContainerTools:master Jan 15, 2020
@corneliusweig corneliusweig deleted the w/deployer-mux/muxer branch January 15, 2020 20:39
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.

5 participants