From 6cbee9e2e9ba6388e4369a13ba6db0d98d77b9b1 Mon Sep 17 00:00:00 2001 From: Igor Vinokur Date: Mon, 21 Oct 2024 22:50:02 +0300 Subject: [PATCH] fix: ensure unique init ssh agent command for all components (#1329) Signed-off-by: ivinokur --- pkg/constants/constants.go | 2 +- pkg/library/ssh/event.go | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index d50079c2c..e5e021200 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -45,7 +45,7 @@ const ( HomeInitEventId = "init-persistent-home" - SshAgentStartEventId = "init-ssh-agent" + SshAgentStartEventId = "init-ssh-agent-command" ServiceAccount = "devworkspace" diff --git a/pkg/library/ssh/event.go b/pkg/library/ssh/event.go index 309506e97..7ebdca1e4 100644 --- a/pkg/library/ssh/event.go +++ b/pkg/library/ssh/event.go @@ -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" @@ -38,12 +40,13 @@ 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, @@ -51,7 +54,7 @@ func AddSshAgentPostStartEvent(spec *v1alpha2.DevWorkspaceTemplateSpec) error { }, }, }) + spec.Events.PostStart = append(spec.Events.PostStart, commandId) } - spec.Events.PostStart = append(spec.Events.PostStart, constants.SshAgentStartEventId) return err }