-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(executor): Wait for termination using pod watch for PNS and K8SA…
…PI executors. (#4253)
- Loading branch information
Showing
13 changed files
with
150 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: runasnonroot- | ||
labels: | ||
argo-e2e: true | ||
spec: | ||
entrypoint: main | ||
securityContext: | ||
runAsNonRoot: true | ||
runAsUser: 8737 | ||
templates: | ||
- name: main | ||
container: | ||
image: argoproj/argosay:v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package wait | ||
|
||
import ( | ||
"fmt" | ||
|
||
log "github.com/sirupsen/logrus" | ||
corev1 "k8s.io/api/core/v1" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
v1 "k8s.io/client-go/kubernetes/typed/core/v1" | ||
|
||
"github.com/argoproj/argo/workflow/executor/common" | ||
) | ||
|
||
func UntilTerminated(kubernetesInterface kubernetes.Interface, namespace, podName, containerID string) error { | ||
log.Infof("Waiting for container %s to be terminated", containerID) | ||
podInterface := kubernetesInterface.CoreV1().Pods(namespace) | ||
listOptions := metav1.ListOptions{FieldSelector: "metadata.name=" + podName} | ||
for { | ||
done, err := untilTerminatedAux(podInterface, containerID, listOptions) | ||
if done { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
func untilTerminatedAux(podInterface v1.PodInterface, containerID string, listOptions metav1.ListOptions) (bool, error) { | ||
w, err := podInterface.Watch(listOptions) | ||
if err != nil { | ||
return true, fmt.Errorf("could not watch pod: %w", err) | ||
} | ||
defer w.Stop() | ||
for event := range w.ResultChan() { | ||
pod, ok := event.Object.(*corev1.Pod) | ||
if !ok { | ||
return false, apierrors.FromObject(event.Object) | ||
} | ||
for _, s := range pod.Status.ContainerStatuses { | ||
if common.GetContainerID(&s) == containerID && s.State.Terminated != nil { | ||
return true, nil | ||
} | ||
} | ||
listOptions.ResourceVersion = pod.ResourceVersion | ||
} | ||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters