Skip to content

Conversation

amisevsk
Copy link
Contributor

@amisevsk amisevsk commented Feb 9, 2021

Description

When /exec/init is called (e.g. in the web terminal operator), it resolves the first container that supports a shell, but does not use this container for injecting kubeconfig. When no container name is provided, the kubeconfig is injected into the first container, which causes kubeconfig injection to fail when the first container in the pod does not support a shell.

Issue

Fixes devfile/devworkspace-operator#258

@@ -52,7 +52,7 @@ func HandleInit(c *gin.Context) {
return
}

err := HandleKubeConfigCreation(c, &initConfigParams, token)
err := HandleKubeConfigCreation(&initConfigParams.KubeConfigParams, token, execRequest.ContainerName)
Copy link
Member

Choose a reason for hiding this comment

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

I believe it could work in more optimal way.
execRequest already has pod name, while HandleKubeConfigCreation resolves it again in https://github.com/eclipse/che-machine-exec/blob/35dff49aa0ac5db3d847569a24e9f97ff7b7bf66/filter/kubernetes_filter.go#L104

So, the whole ContainerInfo could be propagated instead of just container name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue is that the other flow (execKubeConfig) currently doesn't do the resolve step and uses containerName from initConfigParams, so we would have to change that process as well.

Copy link
Member

@sleshchenko sleshchenko left a comment

Choose a reason for hiding this comment

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

@sleshchenko
Copy link
Member

On more thing that we would need to do for WebTerminal and DevWorkspace on Che - make che-machine-exec independent from CHE_MACHINE_NAME env var. But it's for sure deserves a dedicated issue

Copy link
Member

@sleshchenko sleshchenko left a comment

Choose a reason for hiding this comment

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

The changes solve the faced issue. So, I'm approving it and I'm OK with leaving as is currently, non-optimal way.
Though optimization is welcome if it's going to be a quick fix.

Copy link
Contributor

@JPinkney JPinkney left a comment

Choose a reason for hiding this comment

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

I'm OK with leaving it as is as well

@amisevsk
Copy link
Contributor Author

Consider updating
che-machine-exec/api/model/model_types.go
to say something like // first suitable (with shell available)

Technically neither doc is accurate -- InitConfigParams is used for exec/config as well where container name is not optional :P

@amisevsk
Copy link
Contributor Author

amisevsk commented Feb 10, 2021

@sleshchenko I tried to rework the flow slightly to avoid having to filter twice, but I'm not sure it's clearer. I think long-term a large refactor pass is necessary as there's some confusing constructs.

Please re-review

@amisevsk amisevsk requested a review from sleshchenko February 10, 2021 19:31
execRequest := handleContainerResolve(c, token, initConfigParams.ContainerName)
if execRequest == nil {
rest.WriteResponse(c, http.StatusInternalServerError, "Could not retrieve exec request")
return
}

err := HandleKubeConfigCreation(&initConfigParams.KubeConfigParams, token, execRequest.ContainerName)
err := HandleKubeConfigCreation(&kubeConfigParams, execRequest)
Copy link
Member

Choose a reason for hiding this comment

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

Does that func really needs execRequest? I think it's better to convert it to containerInfo as soon as possible. Or even avoid converting like in the following sleshchenko@5de74ca

Copy link
Member

Choose a reason for hiding this comment

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

^ that's not tested, maybe I missed some point and it's better to avoid extending. If you have any concern about it, feel free to just ignore the proposal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly just me avoiding making too many changes for a simple fix :)

I did find it strange we had two almost identical structs.

return
}

err := HandleKubeConfigCreation(&kubeConfigParams, execRequest)
Copy link
Member

Choose a reason for hiding this comment

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

As far as I understand you dropped token argument to make args list shorter, but now you kind of re-purposing kubeConfigParams.BearerToken, because in addition to propagate into kubeconfig, you also use it to create K8s API and make API call.
Ideally, I think K8sAPI should be created per request(on demand since there is requests in exec manager which does not need it) and reused in places where it's needed, without need to propagate the token.

If I made this PR I would introduce one more argument without dropping token, but I'm not against the made change here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps I misunderstood the existing code -- my understanding is that token is derived from the same value, i.e.

  • if initConfigParams.KubeConfigParams.BearerToken is set, it is used
  • if it's unset, we log in via username/password and get the token

Both current flows explictly set initConfigParams.BearerToken = token in HandleKubeConfigCreation, so I thought I woudl move this step earlier in the call stack and avoid having to pass initConfigParams and the token only to apply the token to initConfigParams.

@amisevsk
Copy link
Contributor Author

I can't tell if this s390x issue is my fault or not.

@sleshchenko
Copy link
Member

sleshchenko commented Feb 24, 2021

I can't tell if this s390x issue is my fault or not.

I can tell for sure, it's not your fault. It's the same instability as Dashboard used to have
Here is a PR that fixes PR check #133

When /exec/init is called (e.g. in the web terminal operator), it
resolves the first container that supports a shell, but does not use
this container for injecting kubeconfig. When no container name is
provided, the kubeconfig is injected into the first container, which
causes kubeconfig injection to fail when the first container in the pod
does not support a shell.

Signed-off-by: Angel Misevski <[email protected]>
@amisevsk amisevsk merged commit a143084 into eclipse-che:master Feb 26, 2021
@amisevsk amisevsk deleted the fix-exec-init branch February 26, 2021 04:43
@che-bot che-bot added this to the 7.27 milestone Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Web Terminal Tooling depends on injecting kubeconfig into the first available container
5 participants