Skip to content

Commit 0eecfe5

Browse files
authored
Merge pull request #179 from phillebaba/fix/default-values
Set default values in api objects
2 parents aa49afb + 0596513 commit 0eecfe5

11 files changed

+20
-40
lines changed

api/v1beta1/bucket_types.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,21 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20-
"time"
21-
2220
"github.com/fluxcd/pkg/apis/meta"
2321
corev1 "k8s.io/api/core/v1"
2422
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2523
)
2624

2725
const (
28-
BucketKind = "Bucket"
29-
BucketTimeout = time.Second * 20
26+
// BucketKind is the string representation of a Bucket.
27+
BucketKind = "Bucket"
3028
)
3129

3230
// BucketSpec defines the desired state of an S3 compatible bucket
3331
type BucketSpec struct {
3432
// The S3 compatible storage provider name, default ('generic').
3533
// +kubebuilder:validation:Enum=generic;aws
34+
// +kubebuilder:default:=generic
3635
// +optional
3736
Provider string `json:"provider,omitempty"`
3837

@@ -62,6 +61,7 @@ type BucketSpec struct {
6261
Interval metav1.Duration `json:"interval"`
6362

6463
// The timeout for download operations, defaults to 20s.
64+
// +kubebuilder:default="20s"
6565
// +optional
6666
Timeout *metav1.Duration `json:"timeout,omitempty"`
6767

@@ -158,14 +158,6 @@ func BucketReadyMessage(bucket Bucket) string {
158158
return ""
159159
}
160160

161-
// GetTimeout returns the configured timeout or the default.
162-
func (in *Bucket) GetTimeout() time.Duration {
163-
if in.Spec.Timeout != nil {
164-
return in.Spec.Timeout.Duration
165-
}
166-
return BucketTimeout
167-
}
168-
169161
// GetArtifact returns the latest artifact from the source if present in the
170162
// status sub-resource.
171163
func (in *Bucket) GetArtifact() *Artifact {

api/v1beta1/gitrepository_types.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20-
"time"
21-
2220
"github.com/fluxcd/pkg/apis/meta"
2321
corev1 "k8s.io/api/core/v1"
2422
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2523
)
2624

2725
const (
28-
GitRepositoryKind = "GitRepository"
29-
GitRepositoryTimeout = time.Second * 20
26+
// GitRepositoryKind is the string representation of a GitRepository.
27+
GitRepositoryKind = "GitRepository"
3028
)
3129

3230
// GitRepositorySpec defines the desired state of a Git repository.
@@ -49,6 +47,7 @@ type GitRepositorySpec struct {
4947
Interval metav1.Duration `json:"interval"`
5048

5149
// The timeout for remote Git operations like cloning, defaults to 20s.
50+
// +kubebuilder:default="20s"
5251
// +optional
5352
Timeout *metav1.Duration `json:"timeout,omitempty"`
5453

@@ -71,6 +70,7 @@ type GitRepositorySpec struct {
7170
// GitRepositoryRef defines the Git ref used for pull and checkout operations.
7271
type GitRepositoryRef struct {
7372
// The Git branch to checkout, defaults to master.
73+
// +kubebuilder:default:=master
7474
// +optional
7575
Branch string `json:"branch,omitempty"`
7676

@@ -181,14 +181,6 @@ func GitRepositoryReadyMessage(repository GitRepository) string {
181181
return ""
182182
}
183183

184-
// GetTimeout returns the configured timeout or the default.
185-
func (in *GitRepository) GetTimeout() time.Duration {
186-
if in.Spec.Timeout != nil {
187-
return in.Spec.Timeout.Duration
188-
}
189-
return GitRepositoryTimeout
190-
}
191-
192184
// GetArtifact returns the latest artifact from the source if present in the
193185
// status sub-resource.
194186
func (in *GitRepository) GetArtifact() *Artifact {

api/v1beta1/helmchart_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323
)
2424

25+
// HelmChartKind is the string representation of a HelmChart.
2526
const HelmChartKind = "HelmChart"
2627

2728
// HelmChartSpec defines the desired state of a Helm chart.
@@ -32,6 +33,7 @@ type HelmChartSpec struct {
3233

3334
// The chart version semver expression, ignored for charts from GitRepository
3435
// and Bucket sources. Defaults to latest when omitted.
36+
// +kubebuilder:default:=*
3537
// +optional
3638
Version string `json:"version,omitempty"`
3739

api/v1beta1/helmrepository_types.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20-
"time"
21-
2220
"github.com/fluxcd/pkg/apis/meta"
2321
corev1 "k8s.io/api/core/v1"
2422
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -27,9 +25,6 @@ import (
2725
const (
2826
// HelmRepositoryKind is the string representation of a HelmRepository.
2927
HelmRepositoryKind = "HelmRepository"
30-
// HelmRepositoryTimeout is the default timeout used for Helm repository
31-
// operations like fetching indexes, or downloading charts from a repository.
32-
HelmRepositoryTimeout = time.Second * 60
3328
// HelmRepositoryURLIndexKey is the key to use for indexing HelmRepository
3429
// resources by their HelmRepositorySpec.URL.
3530
HelmRepositoryURLIndexKey = ".metadata.helmRepositoryURL"
@@ -55,6 +50,7 @@ type HelmRepositorySpec struct {
5550
Interval metav1.Duration `json:"interval"`
5651

5752
// The timeout of index downloading, defaults to 60s.
53+
// +kubebuilder:default:="60s"
5854
// +optional
5955
Timeout *metav1.Duration `json:"timeout,omitempty"`
6056
}
@@ -153,14 +149,6 @@ func (in *HelmRepository) GetInterval() metav1.Duration {
153149
return in.Spec.Interval
154150
}
155151

156-
// GetTimeout returns the configured timeout or the default.
157-
func (in *HelmRepository) GetTimeout() time.Duration {
158-
if in.Spec.Timeout != nil {
159-
return in.Spec.Timeout.Duration
160-
}
161-
return HelmRepositoryTimeout
162-
}
163-
164152
// +genclient
165153
// +genclient:Namespaced
166154
// +kubebuilder:object:root=true

config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ spec:
6969
description: The interval at which to check for bucket updates.
7070
type: string
7171
provider:
72+
default: generic
7273
description: The S3 compatible storage provider name, default ('generic').
7374
enum:
7475
- generic
@@ -87,6 +88,7 @@ spec:
8788
type: string
8889
type: object
8990
timeout:
91+
default: 20s
9092
description: The timeout for download operations, defaults to 20s.
9193
type: string
9294
required:

config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ spec:
6363
defaults to master branch.
6464
properties:
6565
branch:
66+
default: master
6667
description: The Git branch to checkout, defaults to master.
6768
type: string
6869
commit:
@@ -89,6 +90,7 @@ spec:
8990
type: string
9091
type: object
9192
timeout:
93+
default: 20s
9294
description: The timeout for remote Git operations like cloning, defaults
9395
to 20s.
9496
type: string

config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ spec:
9191
expected to be a relative path in the SourceRef. Ignored when omitted.
9292
type: string
9393
version:
94+
default: '*'
9495
description: The chart version semver expression, ignored for charts
9596
from GitRepository and Bucket sources. Defaults to latest when omitted.
9697
type: string

config/crd/bases/source.toolkit.fluxcd.io_helmrepositories.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ spec:
6464
type: string
6565
type: object
6666
timeout:
67+
default: 60s
6768
description: The timeout of index downloading, defaults to 60s.
6869
type: string
6970
url:

controllers/bucket_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func (r *BucketReconciler) reconcile(ctx context.Context, bucket sourcev1.Bucket
173173
}
174174
defer os.RemoveAll(tempDir)
175175

176-
ctxTimeout, cancel := context.WithTimeout(ctx, bucket.GetTimeout())
176+
ctxTimeout, cancel := context.WithTimeout(ctx, bucket.Spec.Timeout.Duration)
177177
defer cancel()
178178

179179
exists, err := s3Client.BucketExists(ctxTimeout, bucket.Spec.BucketName)

controllers/helmchart_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
252252

253253
clientOpts = opts
254254
}
255-
clientOpts = append(clientOpts, getter.WithTimeout(repository.GetTimeout()))
255+
clientOpts = append(clientOpts, getter.WithTimeout(repository.Spec.Timeout.Duration))
256256

257257
// Initialize the chart repository and load the index file
258258
chartRepo, err := helm.NewChartRepository(repository.Spec.URL, r.Getters, clientOpts)

0 commit comments

Comments
 (0)