-
Notifications
You must be signed in to change notification settings - Fork 55
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
Fix Start ssh-agent post start event #1329
Conversation
Hi @vinokurig. Thanks for your PR. I'm waiting for a devfile member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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-sigs/prow repository. |
Signed-off-by: ivinokur <[email protected]>
Thank you @vinokurig I'm able to clone, commit, and push: |
This PR & the bug it addresses made me realize we aren't calling the devfile validation library to validate commands. The devfile API does not allow for commands with duplicate ids:
Prior to this PR, we had commands with the same id, but targeting different components: commands:
(...)
- exec:
commandLine: |-
SSH_ENV_PATH=$HOME/ssh-environment \
&& if [ -f /etc/ssh/passphrase ] && command -v ssh-add >/dev/null; \
then ssh-agent | sed 's/^echo/#echo/' > $SSH_ENV_PATH \
&& chmod 600 $SSH_ENV_PATH && source $SSH_ENV_PATH \
&& ssh-add /etc/ssh/dwo_ssh_key < /etc/ssh/passphrase \
&& if [ -f $HOME/.bashrc ] && [ -w $HOME/.bashrc ]; then echo "source ${SSH_ENV_PATH}" >> $HOME/.bashrc; fi; fi
component: tools
id: init-ssh-agent
- exec:
commandLine: |-
SSH_ENV_PATH=$HOME/ssh-environment \
&& if [ -f /etc/ssh/passphrase ] && command -v ssh-add >/dev/null; \
then ssh-agent | sed 's/^echo/#echo/' > $SSH_ENV_PATH \
&& chmod 600 $SSH_ENV_PATH && source $SSH_ENV_PATH \
&& ssh-add /etc/ssh/dwo_ssh_key < /etc/ssh/passphrase \
&& if [ -f $HOME/.bashrc ] && [ -w $HOME/.bashrc ]; then echo "source ${SSH_ENV_PATH}" >> $HOME/.bashrc; fi; fi
component: second-component
id: init-ssh-agent
- apply:
component: init-persistent-home
id: init-persistent-home |
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.
LGTM, great work @vinokurig :)
If we get a chance before merging this, could be maybe change the commit description to something like fix: ensure unique init ssh agent command for all components
? Though since we're pressed for time with the DWO 0.31.1 bug fix release (to include this PR in the upcoming DevSpaces release), this is not critical.
I'll also create a DWO issue for this PR so that we can (retrospectively) add it to the DWO 0.31.x milestones.
In my flattened devworkspace, I saw the unique commands & events:
commands:
- exec:
commandLine: |-
SSH_ENV_PATH=$HOME/ssh-environment \
&& if [ -f /etc/ssh/passphrase ] && command -v ssh-add >/dev/null; \
then ssh-agent | sed 's/^echo/#echo/' > $SSH_ENV_PATH \
&& chmod 600 $SSH_ENV_PATH && source $SSH_ENV_PATH \
&& ssh-add /etc/ssh/dwo_ssh_key < /etc/ssh/passphrase \
&& if [ -f $HOME/.bashrc ] && [ -w $HOME/.bashrc ]; then echo "source ${SSH_ENV_PATH}" >> $HOME/.bashrc; fi; fi
component: web-terminal
id: init-ssh-agent-command-0
- exec:
commandLine: |-
SSH_ENV_PATH=$HOME/ssh-environment \
&& if [ -f /etc/ssh/passphrase ] && command -v ssh-add >/dev/null; \
then ssh-agent | sed 's/^echo/#echo/' > $SSH_ENV_PATH \
&& chmod 600 $SSH_ENV_PATH && source $SSH_ENV_PATH \
&& ssh-add /etc/ssh/dwo_ssh_key < /etc/ssh/passphrase \
&& if [ -f $HOME/.bashrc ] && [ -w $HOME/.bashrc ]; then echo "source ${SSH_ENV_PATH}" >> $HOME/.bashrc; fi; fi
component: second-component
id: init-ssh-agent-command-1
components:
- container:
command:
- tail
- -f
- /dev/null
image: quay.io/wto/web-terminal-tooling:next
memoryLimit: 512Mi
memoryRequest: 256Mi
mountSources: true
sourceMapping: /projects
name: web-terminal
- container:
command:
- tail
- -f
- /dev/null
image: quay.io/wto/web-terminal-tooling:next
memoryLimit: 512Mi
memoryRequest: 256Mi
mountSources: true
sourceMapping: /projects
name: second-component
events:
postStart:
- init-ssh-agent-command-0
- init-ssh-agent-command-1
And saw the postStart hooks in the pod spec:
lifecycle:
postStart:
exec:
command:
- /bin/sh
- -c
- |
{
SSH_ENV_PATH=$HOME/ssh-environment \
&& if [ -f /etc/ssh/passphrase ] && command -v ssh-add >/dev/null; \
then ssh-agent | sed 's/^echo/#echo/' > $SSH_ENV_PATH \
&& chmod 600 $SSH_ENV_PATH && source $SSH_ENV_PATH \
&& ssh-add /etc/ssh/dwo_ssh_key < /etc/ssh/passphrase \
&& if [ -f $HOME/.bashrc ] && [ -w $HOME/.bashrc ]; then echo "source ${SSH_ENV_PATH}" >> $HOME/.bashrc; fi; fi
} 1>/tmp/poststart-stdout.txt 2>/tmp/poststart-stderr.txt
name: web-terminal
(...)
lifecycle:
postStart:
exec:
command:
- /bin/sh
- -c
- |
{
SSH_ENV_PATH=$HOME/ssh-environment \
&& if [ -f /etc/ssh/passphrase ] && command -v ssh-add >/dev/null; \
then ssh-agent | sed 's/^echo/#echo/' > $SSH_ENV_PATH \
&& chmod 600 $SSH_ENV_PATH && source $SSH_ENV_PATH \
&& ssh-add /etc/ssh/dwo_ssh_key < /etc/ssh/passphrase \
&& if [ -f $HOME/.bashrc ] && [ -w $HOME/.bashrc ]; then echo "source ${SSH_ENV_PATH}" >> $HOME/.bashrc; fi; fi
} 1>/tmp/poststart-stdout.txt 2>/tmp/poststart-stderr.txt
name: second-component
if component.Container == nil { | ||
continue | ||
} | ||
commandId := fmt.Sprintf("%s-%d", constants.SshAgentStartEventId, id) |
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.
Since the command names are now unique, this unfortunately makes resolving eclipse-che/che#23144 a little bit harder (since we cannot use a hard-coded command id to be filtered out by CheCode) , but it's the only way to proceed here as the command ids must be unique.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: AObuchow, dkwon17, vinokurig 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 |
Signed-off-by: ivinokur <[email protected]>
What does this PR do?
Fix a bug when the ssh agent post start event command is present only in the first component of the workspace pod yaml.
What issues does this PR fix or reference?
https://issues.redhat.com/browse/CRW-6614
Fix #1330
Is it tested? How?
PR Checklist
/test v8-devworkspace-operator-e2e, v8-che-happy-path
to trigger)v8-devworkspace-operator-e2e
: DevWorkspace e2e testv8-che-happy-path
: Happy path for verification integration with Che