-
Notifications
You must be signed in to change notification settings - Fork 261
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
Add support for multi-containers #1382
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dsimansk: 1 warning.
In response to this:
Description
This PR adds support for multiple containers through file or piped cmds.
The
container create
is not truly create cmd, rather it's printingPodSpec.Containers
tostdout
in yaml for now. Afterwards it can be combined through unix pipe or stored in file and used as e.g.--containers containers.yaml
.UX exampleds
kn container create --image foo.bar | \ kn container create --image bar.foo | \ kn service create --image yet.another --containers -
kn service create --image yet.another --containers containers.yaml
Changes
- Add
container create
command- Add
--containers
flag toservice create/update
- TBD tests tests tests
Reference
Fixes #997
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
Codecov Report
@@ Coverage Diff @@
## main #1382 +/- ##
==========================================
+ Coverage 78.33% 78.68% +0.35%
==========================================
Files 160 162 +2
Lines 8270 8361 +91
==========================================
+ Hits 6478 6579 +101
+ Misses 1103 1098 -5
+ Partials 689 684 -5
Continue to review full report at Codecov.
|
dadaf22
to
c210272
Compare
9d7c9cd
to
9a99645
Compare
9a99645
to
dd0840b
Compare
pkg/kn/flags/podspec_helper.go
Outdated
// UpdateContainers updates the containers array with additional ones provided from file or os.Stdin | ||
func UpdateContainers(spec *corev1.PodSpec, containers []corev1.Container) { | ||
spec.Containers = append(spec.Containers, containers...) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rhuss the current mode is append additional containers. However, that might not work very well for update operation. I wonder if replacing whatever spec.Containers[1:]
is a good solution.
Additionally we could require container's name
parameter and match those if Containers array is already populated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question. Updating a list is always tricky, but I like the idea with correlating via name. "update" is always an incremental operation, you don't have to specify the full state (that is different to "apply"). But if we would like to update based on position in the list, you would need to be able either to specify the index of the container within this list or provide always all containers to update. I think it is fair to require the container name (and I would even enforce this on creation). If we update a list with containers where not all containers have a name (e.g. on existing services that thas not been created with kn), then we would just ignore those containers on an update.
wdyt ? is this a fair solution ? @dprotaso as kind of stakeholder for this feature ;-) would it be ok to require a name for a container that is managed by kn in a multi-container setup ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Various questions and feedback. Happy to take a second look when you are ready to remove the WIP tag.
And of course, many thanks for the contribution. Cheers 🍻
/ok-to-test |
cd15149
to
092e617
Compare
Unrelated sink test failed. |
@maximilien @itsmurugappan @rhuss I'd like to kindly ask for another review cycle so we could aim this release for release tomorrow. 🤞 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finished a first round of reviews. The only thing that I think is critical is that the update should really correlate via the name over existing containers, so that e.g. kn service apply
stays idempotent when the same command is issued twice.
Maybe also add test with updating containers with the same name ?
docs/cmd/kn_container_add.md
Outdated
|
||
The 'container add' represents utility command that prints YAML container spec to standard output. It's useful for | ||
multi-container use cases to create definition with help of standard 'kn' option flags. The command can be chained through | ||
Unix pipes to create multiple containers at once. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe mention here that this command supports all container relevant options like kn service create
?
### Options inherited from parent commands | ||
|
||
``` | ||
--cluster string name of the kubeconfig cluster to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably out of scope for this PR, but cluster/config configuration doesn't make any sense for this offline-online command (and might even confuse users)
pkg/kn/flags/podspec_helper.go
Outdated
c := containerOfPodSpec(spec) | ||
spec.Containers = []corev1.Container{} | ||
spec.Containers = append(spec.Containers, *c) | ||
spec.Containers = append(spec.Containers, containers...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't dived deep enough into the code, but shouldn't you correlated via the container name instead of just appending ? I.e. lookup whether the extra containers' name are already present in the existing containers and replace those in case instead of just appending ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently we're in drop&replace
as I was aiming to have a solution to replace all sidecars at once. E.g. when Ksvc
is created from file without named containers etc.
Is it better now? I can confirm that kn apply
works with the change. I'll add more tests if it's accepted.
21567d3
/retest |
2 similar comments
/retest |
/retest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks !
/approve
/lgtm
Looks good, but I think some test needs to be updated, that still uses |
Yep, sorry I should have checked it better first time. Updated. |
Co-authored-by: Roland Huß <[email protected]>
The following is the coverage report on the affected files.
|
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dsimansk, rhuss The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
sorry @dsimansk I could not get to this as there was a power outage in my area for most of the day and just got it back. |
Description
This PR adds support for multiple containers through file or piped cmds.
The
container create
is not truly create cmd, rather it's printingPodSpec.Containers
tostdout
in yaml for now. Afterwards it can be combined through unix pipe or stored in file and used as e.g.--containers containers.yaml
.UX examples:
/cc @rhuss @dprotaso
Changes
container create
command--containers
flag toservice create/update
Reference
Fixes #997