<p dir="auto">I would like to set an http request timeout in the kubernetes Go client, however:</p>
<ol dir="auto">
<li>The underlying http client is not exposed.</li>
<li>Even if I access the underlying http client through an (admittedly inelegant) cast and set the timeout, requests fail because the Transport does not support the CancelRequest method.</li>
</ol>
<p dir="auto">The example below fails with <code class="notranslate">cannot make request: net/http: Client Transport of type *unversioned.userAgentRoundTripper doesn't support CancelRequest; Timeout not supported</code></p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="package main

import (
        &quot;fmt&quot;
        k8sClient &quot;k8s.io/kubernetes/pkg/client/unversioned&quot;
        &quot;net/http&quot;
        &quot;time&quot;
)

func main() {
        client, err := k8sClient.NewInCluster()
        if err != nil {
                fmt.Printf(&quot;cannot create client: %s\n&quot;, err)
                return
        }
        httpClient, ok := client.RESTClient.Client.(*http.Client)
        if !ok {
                fmt.Println(&quot;cannot cast k8s client to http client&quot;)
        }
        httpClient.Timeout = time.Millisecond * 500
        if _, err := client.Services(&quot;default&quot;).Get(&quot;foo&quot;); err != nil {
                fmt.Printf(&quot;cannot make request: %s\n&quot;, err)
        }
}"><pre class="notranslate"><span class="pl-k">package</span> main

<span class="pl-k">import</span> (
        <span class="pl-s">"fmt"</span>
        k8sClient <span class="pl-s">"k8s.io/kubernetes/pkg/client/unversioned"</span>
        <span class="pl-s">"net/http"</span>
        <span class="pl-s">"time"</span>
)

<span class="pl-k">func</span> <span class="pl-en">main</span>() {
        <span class="pl-s1">client</span>, <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">k8sClient</span>.<span class="pl-en">NewInCluster</span>()
        <span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
                <span class="pl-s1">fmt</span>.<span class="pl-en">Printf</span>(<span class="pl-s">"cannot create client: %s<span class="pl-cce">\n</span>"</span>, <span class="pl-s1">err</span>)
                <span class="pl-k">return</span>
        }
        <span class="pl-s1">httpClient</span>, <span class="pl-s1">ok</span> <span class="pl-c1">:=</span> <span class="pl-s1">client</span>.<span class="pl-c1">RESTClient</span>.<span class="pl-c1">Client</span>.(<span class="pl-c1">*</span>http.<span class="pl-smi">Client</span>)
        <span class="pl-k">if</span> <span class="pl-c1">!</span><span class="pl-s1">ok</span> {
                <span class="pl-s1">fmt</span>.<span class="pl-en">Println</span>(<span class="pl-s">"cannot cast k8s client to http client"</span>)
        }
        <span class="pl-s1">httpClient</span>.<span class="pl-c1">Timeout</span> <span class="pl-c1">=</span> <span class="pl-s1">time</span>.<span class="pl-c1">Millisecond</span> <span class="pl-c1">*</span> <span class="pl-c1">500</span>
        <span class="pl-k">if</span> <span class="pl-s1">_</span>, <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">client</span>.<span class="pl-en">Services</span>(<span class="pl-s">"default"</span>).<span class="pl-en">Get</span>(<span class="pl-s">"foo"</span>); <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
                <span class="pl-s1">fmt</span>.<span class="pl-en">Printf</span>(<span class="pl-s">"cannot make request: %s<span class="pl-cce">\n</span>"</span>, <span class="pl-s1">err</span>)
        }
}</pre></div>
<p dir="auto"><strong>What keywords did you search in Kubernetes issues before filing this one?</strong> (If you have found any duplicates, you should instead reply there.): "scheduledjob", "scheduledjob replace", "scheduledjob not found", "scheduledjob FailedGet"</p>
<hr>
<p dir="auto"><strong>Is this a BUG REPORT or FEATURE REQUEST?</strong>: BUG REPORT</p>

<p dir="auto"><strong>Kubernetes version</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Client Version: version.Info{Major:&quot;1&quot;, Minor:&quot;4+&quot;, GitVersion:&quot;v1.4.0-alpha.3-dirty&quot;, GitCommit:&quot;b44b716965db2d54c8c7dfcdbcb1d54792ab8559&quot;, GitTreeState:&quot;dirty&quot;, BuildDate:&quot;2016-09-27T14:29:43Z&quot;, GoVersion:&quot;go1.7.1&quot;, Compiler:&quot;gc&quot;, Platform:&quot;darwin/amd64&quot;}
Server Version: version.Info{Major:&quot;1&quot;, Minor:&quot;4+&quot;, GitVersion:&quot;v1.4.0-beta.10&quot;, GitCommit:&quot;3aa6d31d3a213ba04b3252cc123ddef26d44cd0e&quot;, GitTreeState:&quot;dirty&quot;, BuildDate:&quot;1970-01-01T00:00:00Z&quot;, GoVersion:&quot;go1.6.2&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}"><pre class="notranslate"><code class="notranslate">Client Version: version.Info{Major:"1", Minor:"4+", GitVersion:"v1.4.0-alpha.3-dirty", GitCommit:"b44b716965db2d54c8c7dfcdbcb1d54792ab8559", GitTreeState:"dirty", BuildDate:"2016-09-27T14:29:43Z", GoVersion:"go1.7.1", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"4+", GitVersion:"v1.4.0-beta.10", GitCommit:"3aa6d31d3a213ba04b3252cc123ddef26d44cd0e", GitTreeState:"dirty", BuildDate:"1970-01-01T00:00:00Z", GoVersion:"go1.6.2", Compiler:"gc", Platform:"linux/amd64"}
</code></pre></div>
<p dir="auto"><strong>Environment</strong>:</p>
<ul dir="auto">
<li><strong>Cloud provider or hardware configuration</strong>: Run under minikube v0.10.0 w/ VirtualBox</li>
<li><strong>OS</strong> (from /etc/os-release):</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="NAME=Boot2Docker
VERSION=1.11.1
ID=boot2docker
ID_LIKE=tcl
VERSION_ID=1.11.1"><pre class="notranslate"><code class="notranslate">NAME=Boot2Docker
VERSION=1.11.1
ID=boot2docker
ID_LIKE=tcl
VERSION_ID=1.11.1
</code></pre></div>
<ul dir="auto">
<li><strong>Kernel</strong> (<code class="notranslate">uname -a</code>):<br>
<code class="notranslate">Linux minikube 4.4.14-boot2docker #1 SMP Fri Jul 1 21:46:36 UTC 2016 x86_64 GNU/Linux</code></li>
</ul>
<p dir="auto"><strong>What happened</strong>:</p>
<p dir="auto"><em>The period of the scheduled jobs: 1 minute</em></p>
<p dir="auto">If running a scheduled job with the <strong>Replace</strong> concurrencyPolicy option, and if the first job is replaced by a new one that was supposed to start, then no new jobs (after the second one) are created. <strong>The second job finishes successfully</strong>.</p>
<p dir="auto">In addition, the first job and pod disappear and cannot be accessed using <code class="notranslate">kubectl logs</code>, <code class="notranslate">kubectl get job</code> etc. with the following error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ kubectl logs pyserv-1857390410-of6ut
Error from server: pods &quot;pyserv-1857390410-of6ut&quot; not found"><pre class="notranslate"><code class="notranslate">$ kubectl logs pyserv-1857390410-of6ut
Error from server: pods "pyserv-1857390410-of6ut" not found
</code></pre></div>
<p dir="auto">The template used:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="apiVersion: batch/v2alpha1
kind: ScheduledJob
metadata:
  name: pyserv
spec:
  schedule: 0/1 * * * ?
  concurrencyPolicy: Replace
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: pyserv
            image: adrian/ubuntu:v3
            args:
            - python2.7
            - /app/server.py
          restartPolicy: OnFailure"><pre class="notranslate"><code class="notranslate">apiVersion: batch/v2alpha1
kind: ScheduledJob
metadata:
  name: pyserv
spec:
  schedule: 0/1 * * * ?
  concurrencyPolicy: Replace
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: pyserv
            image: adrian/ubuntu:v3
            args:
            - python2.7
            - /app/server.py
          restartPolicy: OnFailure
</code></pre></div>
<p dir="auto">Upon inspection of the scheduled job I get the following warning:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  FirstSeen LastSeen Count From                           SubobjectPath Type     Reason           Message
  --------- -------- ----- ----                           ------------- -------- ------           -------
  3m        3m       1     {scheduled-job-controller }                  Normal   SuccessfulCreate Created job pyserv-1857390410
  2m        2m       1     {scheduled-job-controller }                  Normal   SuccessfulDelete Deleted job pyserv-1857390410
  2m        2m       1     {scheduled-job-controller }                  Normal   SuccessfulCreate Created job pyserv-2009171792
  1m        8s       7     {scheduled-job-controller }                  Warning  FailedGet        Get job: jobs.batch &quot;pyserv-1857390410&quot; not found"><pre class="notranslate"><code class="notranslate">  FirstSeen LastSeen Count From                           SubobjectPath Type     Reason           Message
  --------- -------- ----- ----                           ------------- -------- ------           -------
  3m        3m       1     {scheduled-job-controller }                  Normal   SuccessfulCreate Created job pyserv-1857390410
  2m        2m       1     {scheduled-job-controller }                  Normal   SuccessfulDelete Deleted job pyserv-1857390410
  2m        2m       1     {scheduled-job-controller }                  Normal   SuccessfulCreate Created job pyserv-2009171792
  1m        8s       7     {scheduled-job-controller }                  Warning  FailedGet        Get job: jobs.batch "pyserv-1857390410" not found
</code></pre></div>
<p dir="auto">The count of the failed event keeps increasing and after a while, the jobs disappear and the only thing remaining is this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  FirstSeen LastSeen Count From                           SubobjectPath Type     Reason           Message
  --------- -------- ----- ----                           ------------- -------- ------           -------
  1h        5s       457   {scheduled-job-controller }                  Warning  FailedGet        Get job: jobs.batch &quot;pyserv-1857390410&quot; not found"><pre class="notranslate"><code class="notranslate">  FirstSeen LastSeen Count From                           SubobjectPath Type     Reason           Message
  --------- -------- ----- ----                           ------------- -------- ------           -------
  1h        5s       457   {scheduled-job-controller }                  Warning  FailedGet        Get job: jobs.batch "pyserv-1857390410" not found
</code></pre></div>
<p dir="auto"><strong>What you expected to happen</strong>:</p>
<ol dir="auto">
<li>For the scheduled jobs to still run</li>
<li>For the first job to still exist</li>
</ol>
<p dir="auto"><strong>How to reproduce it</strong> (as minimally and precisely as possible):</p>
<ol dir="auto">
<li>Start minikube <code class="notranslate">minikube start --kubernetes-version="v1.4.0-beta.10" --vm-driver=virtualbox</code></li>
<li>Create a ScheduledJob with the concurrencyPolicy set to Replace that runs a script that lasts more than 1 minute, with the following schedule: <code class="notranslate">schedule: 0/1 * * * ?</code></li>
</ol>