Skip to content

Commit 0d9ecaf

Browse files
authored
Merge pull request #4332 from jnummelin/fix/helm-timeout
Fix the typing of Helm chart timeout duration
2 parents 6592e62 + 7a7255e commit 0d9ecaf

File tree

5 files changed

+47
-15
lines changed

5 files changed

+47
-15
lines changed

pkg/apis/k0s/v1beta1/extensions.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ package v1beta1
1919
import (
2020
"errors"
2121
"fmt"
22-
"time"
2322

2423
"helm.sh/helm/v3/pkg/chartutil"
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
)
2626

2727
var _ Validateable = (*ClusterExtensions)(nil)
@@ -91,13 +91,15 @@ func (he HelmExtensions) Validate() []error {
9191

9292
// Chart single helm addon
9393
type Chart struct {
94-
Name string `json:"name"`
95-
ChartName string `json:"chartname"`
96-
Version string `json:"version"`
97-
Values string `json:"values"`
98-
TargetNS string `json:"namespace"`
99-
Timeout time.Duration `json:"timeout"`
100-
Order int `json:"order"`
94+
Name string `json:"name"`
95+
ChartName string `json:"chartname"`
96+
Version string `json:"version"`
97+
Values string `json:"values"`
98+
TargetNS string `json:"namespace"`
99+
// Timeout specifies the timeout for how long to wait for the chart installation to finish.
100+
// A duration string is a sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
101+
Timeout metav1.Duration `json:"timeout"`
102+
Order int `json:"order"`
101103
}
102104

103105
// ManifestFileName returns filename to use for the crd manifest

pkg/apis/k0s/v1beta1/extenstions_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ package v1beta1
1818

1919
import (
2020
"testing"
21+
"time"
2122

2223
"github.com/stretchr/testify/assert"
24+
"github.com/stretchr/testify/require"
25+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2326
)
2427

2528
func TestValidation(t *testing.T) {
@@ -106,5 +109,32 @@ func TestValidation(t *testing.T) {
106109
assert.Equal(t, chart1.ManifestFileName(), "1_helm_extension_release.yaml")
107110
assert.Equal(t, chart2.ManifestFileName(), "2_helm_extension_release.yaml")
108111
})
112+
}
113+
114+
func TestDurationParsing(t *testing.T) {
115+
yaml := `
116+
apiVersion: k0s.k0sproject.io/v1beta1
117+
kind: ClusterConfig
118+
metadata:
119+
name: foobar
120+
spec:
121+
extensions:
122+
helm:
123+
charts:
124+
- name: prometheus-stack
125+
chartname: prometheus-community/prometheus
126+
version: "14.6.1"
127+
timeout: 20m
128+
`
129+
130+
c, err := ConfigFromString(yaml)
131+
require := require.New(t)
132+
133+
require.NoError(err)
109134

135+
chart := c.Spec.Extensions.Helm.Charts[0]
136+
expectedDuration := metav1.Duration{
137+
Duration: 20 * time.Minute,
138+
}
139+
require.Equal(expectedDuration, chart.Timeout)
110140
}

pkg/apis/k0s/v1beta1/zz_generated.deepcopy.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/component/controller/extensions_controller.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
"helm.sh/helm/v3/pkg/release"
4242
"helm.sh/helm/v3/pkg/storage/driver"
4343
apierrors "k8s.io/apimachinery/pkg/api/errors"
44+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4445
"k8s.io/apimachinery/pkg/runtime/schema"
4546
"k8s.io/apimachinery/pkg/types"
4647
"k8s.io/client-go/tools/clientcmd"
@@ -147,7 +148,7 @@ func addOpenEBSHelmExtension(helmSpec *k0sAPI.HelmExtensions, storageExtension *
147148
TargetNS: "openebs",
148149
Version: constant.OpenEBSVersion,
149150
Values: values,
150-
Timeout: time.Duration(time.Minute * 30), // it takes a while to install openebs
151+
Timeout: metav1.Duration{Duration: time.Duration(time.Minute * 30)}, // it takes a while to install openebs
151152
})
152153
return helmSpec, nil
153154
}
@@ -391,7 +392,7 @@ metadata:
391392
spec:
392393
chartName: {{ .ChartName }}
393394
releaseName: {{ .Name }}
394-
timeout: {{ .Timeout }}
395+
timeout: {{ .Timeout.Duration }}
395396
values: |
396397
{{ .Values | nindent 4 }}
397398
version: {{ .Version }}

static/manifests/v1beta1/CustomResourceDefinition/k0s.k0sproject.io_clusterconfigs.yaml

+3-5
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,9 @@ spec:
102102
type: integer
103103
timeout:
104104
description: |-
105-
A Duration represents the elapsed time between two instants
106-
as an int64 nanosecond count. The representation limits the
107-
largest representable duration to approximately 290 years.
108-
format: int64
109-
type: integer
105+
Timeout specifies the timeout for how long to wait for the chart installation to finish.
106+
A duration string is a sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
107+
type: string
110108
values:
111109
type: string
112110
version:

0 commit comments

Comments
 (0)