-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Abstract k8s container representation from debug transformers #6335
Conversation
8d3f35f
to
13496b9
Compare
Codecov Report
@@ Coverage Diff @@
## main #6335 +/- ##
==========================================
+ Coverage 70.27% 70.42% +0.15%
==========================================
Files 510 515 +5
Lines 22988 23121 +133
==========================================
+ Hits 16154 16284 +130
- Misses 5776 5779 +3
Partials 1058 1058
Continue to review full report at Codecov.
|
13496b9
to
c821a9e
Compare
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'd recommend a bigger refactor. Basically the containerTransformer
s need to:
- possibly rewrite the command-line
- possibly rewrite (add to) the environment
- allocate and a port with a name (recorded in the ContainerDebugConfiguration)
- return a debug-setup image reference
The Kubernetes manifest transformer turns that into a set of changes against a podspec, altering the container Command and Args, adding a ContainerPort, and adding an initContainer + volume. And it provides a port-allocator that looks through the podspec to ensure it doesn't allocate a clashing port.
So I think you could change the containerTransformer.Apply() method to drop the v1.Container and instead return an updated imageConfiguration
object. You could then get rid of the Adapter, ExecutableContainer, and ContainerPort objects.
Then the Kubernetes code would be the rest of the rewriteContainers().
The Docker code would create a volume and set up a first round of containers to initialize the volume before launching the real containers.
} | ||
|
||
type ContainerEnv struct { | ||
Order []string |
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.
Why does the order matter?
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.
to be honest, it really only matters for testing. marshalling/unmarshalling the env map back and forth made the ordering undeterministic, meaning any tests examining the env would flake.
the alternative would be implementing some custom comparison logic in the test - however, it's relatively cheap to maintain here, so unless you see problems with it i'm inclined to leave it
c821a9e
to
b60d309
Compare
@briandealwis thanks for the review. I'm onboard with taking this further, but I don't think it's as simple as it looks on the surface.
I experimented with this, and I'm not confident that we can use the skaffold/pkg/skaffold/debug/cnb.go Lines 145 to 152 in 41375f3
so I think the way this code is written, there are scenarios where we need the container to be passed in along with the
worth noting that without doing your previously suggested change, this is still the end result right now! so it's quite close to your original suggestion I feel. I'm open to suggestions on how this can be restructured, but I'm inclined to try and get this merged as is and iterate on it later since this PR is already getting quite large. |
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.
There are a few small issues
c2b52ff
to
16f127c
Compare
3bef5d1
to
30b0a4e
Compare
30b0a4e
to
cae1c55
Compare
Related: #6107
Description
This change removes references to
k8sv1.Container
objects in the debug transformer functions. This will allow these to be referenced by other deploy-related packages which don't operate on Kubernetes-specific objects.To accomplish this, a
ContainerAdapter
interface is introduced, which provides an abstraction away from the underlying container representation. TheContainerAdapter
will make use of theExectuableContainer
, which effectively intercepts the transforms being applied by the various transformers, and can then be used later to retroactively apply these transformations to the underlying container representation. This will allow thek8sv1.Container
object to still be used by the Kubernetes debug transforms.Follow-up Work (remove if N/A)
Implement debugging transformations for containers deployed by the
Docker
deployer.