Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

plugin/k8s: support sidecar containers #2428

Merged
merged 13 commits into from
Oct 12, 2021
Merged

plugin/k8s: support sidecar containers #2428

merged 13 commits into from
Oct 12, 2021

Conversation

xiaolin-ninja
Copy link
Contributor

@xiaolin-ninja xiaolin-ninja commented Oct 5, 2021

Issue
RFC

cc: @izaaklauer

This PR introduces a new feature, allowing advanced Kubernetes users to add sidecar containers to their apps by adding a new “sidecar” stanza to the k8s plugin config.

This PR introduces several new structs, and breaks backwards compatibility by refactoring the "Ports" config.

See usage examples in RFC.

@briancain briancain requested a review from a team October 5, 2021 21:53
@briancain briancain added this to the 0.6.0 milestone Oct 5, 2021
Copy link
Member

@briancain briancain left a comment

Choose a reason for hiding this comment

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

Yo! This looks like a good start 🎉 🚗 I haven't given this a shot yet, so giving some early code review feedback right now. Let me know if you have any questions.

Some high level things, it looks like maybe the PR for enabling dynamic configs got mixed into this and the commits got duplicated in the history? Rebasing to fix that up would be good to do before merge. Then I think some of Evans demo fixups and UI improvements got deleted which should go back as well

.changelog/2416.txt Outdated Show resolved Hide resolved
builtin/k8s/platform.go Outdated Show resolved Hide resolved
builtin/k8s/platform.go Outdated Show resolved Hide resolved
builtin/k8s/platform.go Outdated Show resolved Hide resolved
builtin/k8s/platform.go Outdated Show resolved Hide resolved
builtin/k8s/platform.go Show resolved Hide resolved
builtin/k8s/platform.go Outdated Show resolved Hide resolved
builtin/k8s/platform.go Outdated Show resolved Hide resolved
builtin/k8s/platform.go Outdated Show resolved Hide resolved
builtin/k8s/platform.go Show resolved Hide resolved
builtin/k8s/platform.go Outdated Show resolved Hide resolved
builtin/k8s/platform.go Show resolved Hide resolved
builtin/k8s/platform.go Outdated Show resolved Hide resolved
}

// SidecarContainer describes the configuration for the sidecar container
type SidecarContainer struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Doing that would let people double-specify a bunch of fields: for example, they could give ProbePath in the top-level config, and then again under the Pod.Container struct.

I really don't love how much duplication there is here between fields in SidecarContainer and other fields elsewhere in the config. We explored a bunch of ideas to make this cleaner, but couldn't find anything that wouldn't introduce user confusion or destroy backwards compat. Open to other ideas though!

builtin/k8s/platform.go Show resolved Hide resolved
builtin/k8s/platform.go Outdated Show resolved Hide resolved
builtin/k8s/platform.go Outdated Show resolved Hide resolved
@xiaolin-ninja
Copy link
Contributor Author

Ok I'm going to try to fix this weird merge history. I rebased before making the PR, but I think now that Izaak's PR is merged the rebase should be cleaner.

xiaolin-ninja and others added 10 commits October 11, 2021 21:41
Which I feel like was harder to discover how to use than it needs to be
That is reused between the app container and sidecars
- Adding validators
- Adding field docs
- Hard deprecating top level Ports, and adding a helpful error
@izaaklauer
Copy link
Contributor

Examples here: hashicorp/waypoint-examples#83

Copy link
Contributor

@mitchellh mitchellh 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 great.

@@ -0,0 +1,8 @@
```release-note:feature
plugin/k8s: Allows advanced users to add sidecar containers to apps using the k8s plugin config.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick but I don't think we need to say "advanced users" here, just "Allows users to".

Copy link
Member

@briancain briancain left a comment

Choose a reason for hiding this comment

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

Just a minor comment from me, but these updates look great! 🎉

),
))
if err != nil {
return status.Errorf(codes.InvalidArgument, fmt.Sprintf("Invalid kubernetes platform plugin config: %s", err.Error()))
Copy link
Member

Choose a reason for hiding this comment

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

Small nit: since it's already Errorf you can just do this, I think 🤔

Suggested change
return status.Errorf(codes.InvalidArgument, fmt.Sprintf("Invalid kubernetes platform plugin config: %s", err.Error()))
return status.Errorf(codes.InvalidArgument, "Invalid kubernetes platform plugin config: %s", err.Error())

Containers: []corev1.Container{container},
// App container must have some kind of port
if len(appContainerSpec.Ports) == 0 {
ui.Output(fmt.Sprintf("No ports defined - defaulting to http on port %d", DefaultServicePort), terminal.WithWarningStyle())
Copy link
Member

Choose a reason for hiding this comment

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

I think ui.Output should also let you format without fmt.Sprintf if I remember right

Suggested change
ui.Output(fmt.Sprintf("No ports defined - defaulting to http on port %d", DefaultServicePort), terminal.WithWarningStyle())
ui.Output("No ports defined - defaulting to http on port %d", DefaultServicePort, terminal.WithWarningStyle())

@xiaolin-ninja xiaolin-ninja merged commit 5b46764 into main Oct 12, 2021
@xiaolin-ninja xiaolin-ninja deleted the plugin/k8-sidecar branch October 12, 2021 20:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

plugin/k8s: Support sidecar containers
4 participants