devfile / devworkspace-operator

Apache License 2.0
67 stars 55 forks source link

Fix Start ssh-agent post start event #1329

Closed vinokurig closed 1 month ago

vinokurig commented 1 month ago

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 https://github.com/devfile/devworkspace-operator/issues/1330

Is it tested? How?

  1. Start a workspace with more than one component e.g:
    schemaVersion: 2.3.0
    metadata:
    name: test local
    components:
    - name: component-1
    container:
      image: quay.io/devfile/universal-developer-image:ubi8-latest
    - name: component-2
    container:
      image: quay.io/devfile/universal-developer-image:ubi8-latest
  2. See: the ssh agent post start event command is present in both components of the workspace pod yaml:
    spec:
    containers:
    - lifecycle:
        postStart:
          exec:
            command:
              - /bin/sh
              - '-c'
              - |
                {
                nohup /checode/entrypoint-volume.sh > /checode/entrypoint-logs.txt 2>&1 &
                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: component-1

    PR Checklist

openshift-ci[bot] commented 1 month ago

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
dkwon17 commented 1 month ago

Thank you @vinokurig I'm able to clone, commit, and push: image

AObuchow commented 1 month ago

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:

  1. id must be unique

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
openshift-ci[bot] commented 1 month ago

[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: - ~~[OWNERS](https://github.com/devfile/devworkspace-operator/blob/main/OWNERS)~~ [AObuchow,dkwon17] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment