<p>The main question is if there is a way to finish a pod from the <strong>client-go sdk</strong>, I'm not trying to delete a pod, I just want to finish it with a Phase-Status: <strong>Completed</strong>.</p>
<p>In the code, I'm trying to update the pod phase but It doesn't work, It does not return an error or panic but The pod does not finish.
My code:</p>
<pre><code>func main() {

    // creates the in-cluster config
    config, err := rest.InClusterConfig()
    if err != nil {
        panic(err.Error())
    }
    // creates the clientset
    clientset, err := kubernetes.NewForConfig(config)
    if err != nil {
        panic(err.Error())
    }
    for {

        pods, err := clientset.CoreV1().Pods(&quot;ns&quot;).List(context.TODO(), metav1.ListOptions{})
        if err != nil {
            panic(err.Error())
        }
        for _, pod := range pods.Items {

            podName:= pod.Name
            if strings.Contains(strings.ToLower(podName), &quot;single-condition&quot;) {
            
                fmt.Println(&quot;get pods metadatada&quot;)
                fmt.Println(pod.Name)
                fmt.Printf(&quot;pod.Name %s \n&quot;, pod.Name)
                fmt.Printf(&quot;Status.Phase %s \n&quot;, pod.Status.Phase)
                fmt.Printf(&quot;PodIP %s \n&quot;, pod.Status.PodIP)

                containers := pod.Status.ContainerStatuses
                if len(containers) &gt; 0 {
                    for _ ,c := range containers {
                        fmt.Printf(&quot;c.Name %s \n&quot;, c.Name)
                        fmt.Printf(&quot;c.State %s \n&quot;, c.State)
                        fmt.Printf(&quot;c.State.Terminated %s \n&quot;, c.State.Terminated)

                        stateTerminated := c.State.Terminated
                        stateRunning := c.State.Running
                        if stateTerminated == nil &amp;&amp; stateRunning != nil {
                            fmt.Printf(&quot;c.State.Terminated %s \n&quot;, c.State.Terminated)
                            fmt.Printf(&quot;stateRunning Reason: %s\n&quot;, reflect.TypeOf(c.State.Running))

                            getPod, getErr := clientset.CoreV1().Pods(&quot;ns&quot;).Get(context.TODO(), &quot;single-condition-pipeline-9rqrs-1224102659&quot; , metav1.GetOptions{})
                            if getErr != nil {
                                fmt.Println(&quot;error1&quot;)
                                panic(fmt.Errorf(&quot;Failed to get: %v&quot;, getErr))
                            }
                            fmt.Println(&quot;update values&quot;)
                            fmt.Printf(&quot; getPodName %d \n&quot;, getPod.Name)
                            getPod.Status.Phase = &quot;Succeeded&quot;
                            fmt.Println(&quot;updated status phase&quot;)
                            getContainers := getPod.Status.ContainerStatuses
                            fmt.Printf(&quot;len get container %d \n&quot;, len(getContainers))
                            _, updateErr := clientset.CoreV1().Pods(&quot;argo-workflows&quot;).Update(context.TODO(), getPod, metav1.UpdateOptions{})
                            fmt.Println(&quot;commit update&quot;)
                            if updateErr != nil {
                                fmt.Println(&quot;error updated&quot;)
                                panic(fmt.Errorf(&quot;Failed to update: %v&quot;, updateErr))
                            }

                        } else {
                            fmt.Printf(&quot;c.State.Terminated %s \n&quot;, c.State.Terminated.Reason)
                            //fmt.Println(&quot;Not finished ready!!!&quot;)
                            //fmt.Printf(&quot;c.State.Running %s \n&quot;, c.State.Running)
                            //fmt.Printf(&quot;c.State.Waiting %s \n&quot;, c.State.Waiting)
                        }
                    }
                }
            }
        }
        time.Sleep(10 * time.Second)

    }
}
</code></pre>
<p>and some logs:</p>
<pre><code>single-condition-pipeline-9rqrs-1224102659
pod.Name single-condition-pipeline-9rqrs-1224102659 
Status.Phase Running 
PodIP XXXXXXXXXXXX
c.Name main 
---------------------------------------------------------------------------------------------
c.State {nil &amp;ContainerStateRunning{StartedAt:2021-10-29 04:41:51 +0000 UTC,} nil} 
c.State.Terminated nil 
c.State.Terminated nil 
stateRunning Reason: *v1.ContainerStateRunning
update values
 getPodName %!d(string=single-condition-pipeline-9rqrs-1224102659) 
updated status phase
len get container 2 
commit update
c.Name wait 
c.State {nil &amp;ContainerStateRunning{StartedAt:2021-10-29 04:41:51 +0000 UTC,} nil} 
c.State.Terminated nil 
c.State.Terminated nil 
stateRunning Reason: *v1.ContainerStateRunning
update values
 getPodName %!d(string=single-condition-pipeline-9rqrs-1224102659) 
updated status phase
len get container 2 
---------------------------------------------------------------------------------------------
commit update
---------------------------------------------------------------------------------------------
get pods metadatada
single-condition-pipeline-9rqrs-1224102659
pod.Name single-condition-pipeline-9rqrs-1224102659 
Status.Phase Running 
PodIP XXXXXXXXXX 
c.Name main 
c.State {nil &amp;ContainerStateRunning{StartedAt:2021-10-29 04:41:51 +0000 UTC,} nil} 
c.State.Terminated nil 
c.State.Terminated nil 
stateRunning Reason: *v1.ContainerStateRunning
update values
 getPodName %!d(string=single-condition-pipeline-9rqrs-1224102659) 
updated status phase
len get container 2 
commit update
c.Name wait 
c.State {nil &amp;ContainerStateRunning{StartedAt:2021-10-29 04:41:51 +0000 UTC,} nil} 
c.State.Terminated nil 
c.State.Terminated nil 
stateRunning Reason: *v1.ContainerStateRunning
update values
 getPodName %!d(string=single-condition-pipeline-9rqrs-1224102659) 
updated status phase
len get container 2 
commit update
</code></pre>
<p>so here: <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-readiness-status" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-readiness-status</a>, It mentions a Patch but I don't know how to use it, so if somebody could help me or if there is another way to finish it.</p>

javier_orta
<p>You cannot set the <code>phase</code> or anything else in the Pod <code>status</code> field, it is <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#pod-v1-core" rel="nofollow noreferrer">read only</a>. According to the <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/" rel="nofollow noreferrer">Pod Lifecycle</a> documentation your pod will have a phase of <code>Succeeded</code> after <em>&quot;All containers in the Pod have terminated in success, and will not be restarted.&quot;</em> So this will only happen if you can cause all of your pod's containers to exit with status code <code>0</code> and if the pod <code>restartPolicy</code> is set to <code>onFailure</code> or <code>Never</code>, if it is set to <code>Always</code> (the default) then the containers will eventually restart and your pod will eventually return to the <code>Running</code> phase.</p>
<p>In summary, you cannot do what you are attempting to do via the Kube API directly. You must:</p>
<ol>
<li>Ensure your pod has a <code>restartPolicy</code> that can support the <code>Succeeded</code> phase.</li>
<li>Cause your application to terminate, possibly by sending it <code>SIGINT</code> or <code>SIGTERM</code>, or possibly by commanding it via its own API.</li>
</ol>
