Skip to content

Commit

Permalink
fix: ensure unique init ssh agent command for all components (#1329)
Browse files Browse the repository at this point in the history
Signed-off-by: ivinokur <[email protected]>
  • Loading branch information
vinokurig authored and AObuchow committed Oct 21, 2024
1 parent 0dc3621 commit 6cbee9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const (

HomeInitEventId = "init-persistent-home"

SshAgentStartEventId = "init-ssh-agent"
SshAgentStartEventId = "init-ssh-agent-command"

ServiceAccount = "devworkspace"

Expand Down
9 changes: 6 additions & 3 deletions pkg/library/ssh/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package ssh

import (
"fmt"

"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/devworkspace-operator/pkg/constants"
"github.com/devfile/devworkspace-operator/pkg/library/lifecycle"
Expand All @@ -38,20 +40,21 @@ func AddSshAgentPostStartEvent(spec *v1alpha2.DevWorkspaceTemplateSpec) error {
}

_, mainComponents, err := lifecycle.GetInitContainers(spec.DevWorkspaceTemplateSpecContent)
for _, component := range mainComponents {
for id, component := range mainComponents {
if component.Container == nil {
continue
}
commandId := fmt.Sprintf("%s-%d", constants.SshAgentStartEventId, id)
spec.Commands = append(spec.Commands, v1alpha2.Command{
Id: constants.SshAgentStartEventId,
Id: commandId,
CommandUnion: v1alpha2.CommandUnion{
Exec: &v1alpha2.ExecCommand{
CommandLine: commandLine,
Component: component.Name,
},
},
})
spec.Events.PostStart = append(spec.Events.PostStart, commandId)
}
spec.Events.PostStart = append(spec.Events.PostStart, constants.SshAgentStartEventId)
return err
}

0 comments on commit 6cbee9e

Please sign in to comment.