Implement HelmRepository timeout

This commit is contained in:
stefanprodan 2020-08-12 11:30:45 +03:00
parent 8970f3f84d
commit 4486ab7a5e
8 changed files with 70 additions and 8 deletions

View File

@ -23,7 +23,10 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const GitRepositoryKind = "GitRepository"
const (
GitRepositoryKind = "GitRepository"
GitRepositoryTimeout = time.Second * 20
)
// GitRepositorySpec defines the desired state of a Git repository.
type GitRepositorySpec struct {
@ -194,7 +197,7 @@ func (in *GitRepository) GetTimeout() time.Duration {
if in.Spec.Timeout != nil {
return in.Spec.Timeout.Duration
}
return time.Second * 20
return GitRepositoryTimeout
}
// GetArtifact returns the latest artifact from the source

View File

@ -17,11 +17,16 @@ limitations under the License.
package v1alpha1
import (
"time"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const HelmRepositoryKind = "HelmRepository"
const (
HelmRepositoryKind = "HelmRepository"
HelmRepositoryTimeout = time.Second * 60
)
// HelmRepositorySpec defines the reference to a Helm repository.
type HelmRepositorySpec struct {
@ -41,6 +46,10 @@ type HelmRepositorySpec struct {
// The interval at which to check the upstream for updates.
// +required
Interval metav1.Duration `json:"interval"`
// The timeout of index downloading, defaults to 60s.
// +optional
Timeout *metav1.Duration `json:"timeout,omitempty"`
}
// HelmRepositoryStatus defines the observed state of the HelmRepository.
@ -148,6 +157,14 @@ func (in *HelmRepository) GetInterval() metav1.Duration {
return in.Spec.Interval
}
// GetTimeout returns the configured timeout or the default.
func (in *HelmRepository) GetTimeout() time.Duration {
if in.Spec.Timeout != nil {
return in.Spec.Timeout.Duration
}
return HelmRepositoryTimeout
}
// +genclient
// +genclient:Namespaced
// +kubebuilder:object:root=true

View File

@ -371,6 +371,11 @@ func (in *HelmRepositorySpec) DeepCopyInto(out *HelmRepositorySpec) {
**out = **in
}
out.Interval = in.Interval
if in.Timeout != nil {
in, out := &in.Timeout, &out.Timeout
*out = new(metav1.Duration)
**out = **in
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HelmRepositorySpec.

View File

@ -63,6 +63,9 @@ spec:
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
type: object
timeout:
description: The timeout of index downloading, defaults to 60s.
type: string
url:
description: The Helm repository URL, a valid URL contains at least
a protocol and host.

View File

@ -204,8 +204,8 @@ func (r *HelmRepositoryReconciler) reconcile(ctx context.Context, repository sou
clientOpts = opts
}
// TODO(hidde): implement timeout from the HelmRepository
// https://github.com/helm/helm/pull/7950
clientOpts = append(clientOpts, getter.WithTimeout(repository.GetTimeout()))
res, err := c.Get(u.String(), clientOpts...)
if err != nil {
return sourcev1.HelmRepositoryNotReady(repository, sourcev1.IndexationFailedReason, err.Error()), err

View File

@ -37,9 +37,10 @@ import (
var _ = Describe("HelmRepositoryReconciler", func() {
const (
timeout = time.Second * 30
interval = time.Second * 1
indexInterval = time.Second * 2
timeout = time.Second * 30
interval = time.Second * 1
indexInterval = time.Second * 2
repositoryTimeout = time.Second * 5
)
Context("HelmRepository", func() {
@ -87,6 +88,7 @@ var _ = Describe("HelmRepositoryReconciler", func() {
Spec: sourcev1.HelmRepositorySpec{
URL: helmServer.URL(),
Interval: metav1.Duration{Duration: indexInterval},
Timeout: &metav1.Duration{Duration: repositoryTimeout},
},
}
Expect(k8sClient.Create(context.Background(), created)).Should(Succeed())

View File

@ -418,6 +418,20 @@ Kubernetes meta/v1.Duration
<p>The interval at which to check the upstream for updates.</p>
</td>
</tr>
<tr>
<td>
<code>timeout</code><br>
<em>
<a href="https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#Duration">
Kubernetes meta/v1.Duration
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>The timeout of index downloading, defaults to 60s.</p>
</td>
</tr>
</table>
</td>
</tr>
@ -998,6 +1012,20 @@ Kubernetes meta/v1.Duration
<p>The interval at which to check the upstream for updates.</p>
</td>
</tr>
<tr>
<td>
<code>timeout</code><br>
<em>
<a href="https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#Duration">
Kubernetes meta/v1.Duration
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>The timeout of index downloading, defaults to 60s.</p>
</td>
</tr>
</tbody>
</table>
</div>

View File

@ -27,6 +27,10 @@ type HelmRepositorySpec struct {
// The interval at which to check the upstream for updates.
// +required
Interval metav1.Duration `json:"interval"`
// The timeout of index downloading, defaults to 60s.
// +optional
Timeout *metav1.Duration `json:"timeout,omitempty"`
}
```