Skip to content

Commit

Permalink
fix(executor): PNS support artifacts for short-running containers (#5427
Browse files Browse the repository at this point in the history
)
  • Loading branch information
alexec authored Mar 18, 2021
1 parent 07ef0e6 commit 2371a6d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 0 additions & 4 deletions test/e2e/artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func (s *ArtifactsSuite) TestOutputOnInput() {

func (s *ArtifactsSuite) TestArtifactPassing() {
s.Need(fixtures.BaseLayerArtifacts)
s.Need(fixtures.None(fixtures.PNS))
s.Given().
Workflow("@smoke/artifact-passing.yaml").
When().
Expand All @@ -55,7 +54,6 @@ func (s *ArtifactsSuite) TestArtifactPassing() {

func (s *ArtifactsSuite) TestDefaultParameterOutputs() {
s.Need(fixtures.BaseLayerArtifacts)
s.Need(fixtures.None(fixtures.PNS))
s.Given().
Workflow(`
apiVersion: argoproj.io/v1alpha1
Expand Down Expand Up @@ -109,7 +107,6 @@ spec:

func (s *ArtifactsSuite) TestSameInputOutputPathOptionalArtifact() {
s.Need(fixtures.BaseLayerArtifacts)
s.Need(fixtures.None(fixtures.PNS))
s.Given().
Workflow("@testdata/same-input-output-path-optional.yaml").
When().
Expand All @@ -119,7 +116,6 @@ func (s *ArtifactsSuite) TestSameInputOutputPathOptionalArtifact() {

func (s *ArtifactsSuite) TestOutputArtifactS3BucketCreationEnabled() {
s.Need(fixtures.BaseLayerArtifacts)
s.Need(fixtures.None(fixtures.PNS))
s.Given().
Workflow("@testdata/output-artifact-with-s3-bucket-creation-enabled.yaml").
When().
Expand Down
16 changes: 14 additions & 2 deletions workflow/executor/pns/pns.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
osspecific "github.com/argoproj/argo-workflows/v3/workflow/executor/os-specific"
)

const anonymousPIDPrefix = "pid/"

type PNSExecutor struct {
*k8sapi.K8sAPIExecutor
podName string
Expand Down Expand Up @@ -284,7 +286,17 @@ func (p *PNSExecutor) killContainer(containerName string, terminationGracePeriod
func (p *PNSExecutor) getContainerPID(containerName string) int {
p.mu.RLock()
defer p.mu.RUnlock()
return p.containerNameToPID[containerName]
if pid, ok := p.containerNameToPID[containerName]; ok {
return pid
}
for n, pid := range p.containerNameToPID {
// the container can't be me, and it must be anonymous, otherwise we would have determined it
if pid != os.Getpid() && strings.HasPrefix(n, anonymousPIDPrefix) {
log.Infof("guessing container %q PID is %d", containerName, pid)
return pid
}
}
return 0
}

func containerNameForPID(pid int) (string, error) {
Expand All @@ -298,7 +310,7 @@ func containerNameForPID(pid int) (string, error) {
return strings.TrimPrefix(l, prefix), nil
}
}
return fmt.Sprintf("pid/%d", pid), nil // we give all a "container name", including a fake name for injected sidecars
return fmt.Sprintf("%s%d", anonymousPIDPrefix, pid), nil // we give all a "container name", including a fake name for injected sidecars
}

func (p *PNSExecutor) secureRootFiles() error {
Expand Down

0 comments on commit 2371a6d

Please sign in to comment.