Merge pull request #179 from phillebaba/fix/default-values
Set default values in api objects
This commit is contained in:
commit
0eecfe57cc
|
@ -17,22 +17,21 @@ limitations under the License.
|
|||
package v1beta1
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/fluxcd/pkg/apis/meta"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
const (
|
||||
BucketKind = "Bucket"
|
||||
BucketTimeout = time.Second * 20
|
||||
// BucketKind is the string representation of a Bucket.
|
||||
BucketKind = "Bucket"
|
||||
)
|
||||
|
||||
// BucketSpec defines the desired state of an S3 compatible bucket
|
||||
type BucketSpec struct {
|
||||
// The S3 compatible storage provider name, default ('generic').
|
||||
// +kubebuilder:validation:Enum=generic;aws
|
||||
// +kubebuilder:default:=generic
|
||||
// +optional
|
||||
Provider string `json:"provider,omitempty"`
|
||||
|
||||
|
@ -62,6 +61,7 @@ type BucketSpec struct {
|
|||
Interval metav1.Duration `json:"interval"`
|
||||
|
||||
// The timeout for download operations, defaults to 20s.
|
||||
// +kubebuilder:default="20s"
|
||||
// +optional
|
||||
Timeout *metav1.Duration `json:"timeout,omitempty"`
|
||||
|
||||
|
@ -158,14 +158,6 @@ func BucketReadyMessage(bucket Bucket) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
// GetTimeout returns the configured timeout or the default.
|
||||
func (in *Bucket) GetTimeout() time.Duration {
|
||||
if in.Spec.Timeout != nil {
|
||||
return in.Spec.Timeout.Duration
|
||||
}
|
||||
return BucketTimeout
|
||||
}
|
||||
|
||||
// GetArtifact returns the latest artifact from the source if present in the
|
||||
// status sub-resource.
|
||||
func (in *Bucket) GetArtifact() *Artifact {
|
||||
|
|
|
@ -17,16 +17,14 @@ limitations under the License.
|
|||
package v1beta1
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/fluxcd/pkg/apis/meta"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
const (
|
||||
GitRepositoryKind = "GitRepository"
|
||||
GitRepositoryTimeout = time.Second * 20
|
||||
// GitRepositoryKind is the string representation of a GitRepository.
|
||||
GitRepositoryKind = "GitRepository"
|
||||
)
|
||||
|
||||
// GitRepositorySpec defines the desired state of a Git repository.
|
||||
|
@ -49,6 +47,7 @@ type GitRepositorySpec struct {
|
|||
Interval metav1.Duration `json:"interval"`
|
||||
|
||||
// The timeout for remote Git operations like cloning, defaults to 20s.
|
||||
// +kubebuilder:default="20s"
|
||||
// +optional
|
||||
Timeout *metav1.Duration `json:"timeout,omitempty"`
|
||||
|
||||
|
@ -71,6 +70,7 @@ type GitRepositorySpec struct {
|
|||
// GitRepositoryRef defines the Git ref used for pull and checkout operations.
|
||||
type GitRepositoryRef struct {
|
||||
// The Git branch to checkout, defaults to master.
|
||||
// +kubebuilder:default:=master
|
||||
// +optional
|
||||
Branch string `json:"branch,omitempty"`
|
||||
|
||||
|
@ -181,14 +181,6 @@ func GitRepositoryReadyMessage(repository GitRepository) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
// GetTimeout returns the configured timeout or the default.
|
||||
func (in *GitRepository) GetTimeout() time.Duration {
|
||||
if in.Spec.Timeout != nil {
|
||||
return in.Spec.Timeout.Duration
|
||||
}
|
||||
return GitRepositoryTimeout
|
||||
}
|
||||
|
||||
// GetArtifact returns the latest artifact from the source if present in the
|
||||
// status sub-resource.
|
||||
func (in *GitRepository) GetArtifact() *Artifact {
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
// HelmChartKind is the string representation of a HelmChart.
|
||||
const HelmChartKind = "HelmChart"
|
||||
|
||||
// HelmChartSpec defines the desired state of a Helm chart.
|
||||
|
@ -32,6 +33,7 @@ type HelmChartSpec struct {
|
|||
|
||||
// The chart version semver expression, ignored for charts from GitRepository
|
||||
// and Bucket sources. Defaults to latest when omitted.
|
||||
// +kubebuilder:default:=*
|
||||
// +optional
|
||||
Version string `json:"version,omitempty"`
|
||||
|
||||
|
|
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||
package v1beta1
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/fluxcd/pkg/apis/meta"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
@ -27,9 +25,6 @@ import (
|
|||
const (
|
||||
// HelmRepositoryKind is the string representation of a HelmRepository.
|
||||
HelmRepositoryKind = "HelmRepository"
|
||||
// HelmRepositoryTimeout is the default timeout used for Helm repository
|
||||
// operations like fetching indexes, or downloading charts from a repository.
|
||||
HelmRepositoryTimeout = time.Second * 60
|
||||
// HelmRepositoryURLIndexKey is the key to use for indexing HelmRepository
|
||||
// resources by their HelmRepositorySpec.URL.
|
||||
HelmRepositoryURLIndexKey = ".metadata.helmRepositoryURL"
|
||||
|
@ -55,6 +50,7 @@ type HelmRepositorySpec struct {
|
|||
Interval metav1.Duration `json:"interval"`
|
||||
|
||||
// The timeout of index downloading, defaults to 60s.
|
||||
// +kubebuilder:default:="60s"
|
||||
// +optional
|
||||
Timeout *metav1.Duration `json:"timeout,omitempty"`
|
||||
}
|
||||
|
@ -153,14 +149,6 @@ 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
|
||||
|
|
|
@ -69,6 +69,7 @@ spec:
|
|||
description: The interval at which to check for bucket updates.
|
||||
type: string
|
||||
provider:
|
||||
default: generic
|
||||
description: The S3 compatible storage provider name, default ('generic').
|
||||
enum:
|
||||
- generic
|
||||
|
@ -87,6 +88,7 @@ spec:
|
|||
type: string
|
||||
type: object
|
||||
timeout:
|
||||
default: 20s
|
||||
description: The timeout for download operations, defaults to 20s.
|
||||
type: string
|
||||
required:
|
||||
|
|
|
@ -63,6 +63,7 @@ spec:
|
|||
defaults to master branch.
|
||||
properties:
|
||||
branch:
|
||||
default: master
|
||||
description: The Git branch to checkout, defaults to master.
|
||||
type: string
|
||||
commit:
|
||||
|
@ -89,6 +90,7 @@ spec:
|
|||
type: string
|
||||
type: object
|
||||
timeout:
|
||||
default: 20s
|
||||
description: The timeout for remote Git operations like cloning, defaults
|
||||
to 20s.
|
||||
type: string
|
||||
|
|
|
@ -91,6 +91,7 @@ spec:
|
|||
expected to be a relative path in the SourceRef. Ignored when omitted.
|
||||
type: string
|
||||
version:
|
||||
default: '*'
|
||||
description: The chart version semver expression, ignored for charts
|
||||
from GitRepository and Bucket sources. Defaults to latest when omitted.
|
||||
type: string
|
||||
|
|
|
@ -64,6 +64,7 @@ spec:
|
|||
type: string
|
||||
type: object
|
||||
timeout:
|
||||
default: 60s
|
||||
description: The timeout of index downloading, defaults to 60s.
|
||||
type: string
|
||||
url:
|
||||
|
|
|
@ -173,7 +173,7 @@ func (r *BucketReconciler) reconcile(ctx context.Context, bucket sourcev1.Bucket
|
|||
}
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
ctxTimeout, cancel := context.WithTimeout(ctx, bucket.GetTimeout())
|
||||
ctxTimeout, cancel := context.WithTimeout(ctx, bucket.Spec.Timeout.Duration)
|
||||
defer cancel()
|
||||
|
||||
exists, err := s3Client.BucketExists(ctxTimeout, bucket.Spec.BucketName)
|
||||
|
|
|
@ -252,7 +252,7 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
|
|||
|
||||
clientOpts = opts
|
||||
}
|
||||
clientOpts = append(clientOpts, getter.WithTimeout(repository.GetTimeout()))
|
||||
clientOpts = append(clientOpts, getter.WithTimeout(repository.Spec.Timeout.Duration))
|
||||
|
||||
// Initialize the chart repository and load the index file
|
||||
chartRepo, err := helm.NewChartRepository(repository.Spec.URL, r.Getters, clientOpts)
|
||||
|
|
|
@ -181,7 +181,7 @@ func (r *HelmRepositoryReconciler) reconcile(ctx context.Context, repository sou
|
|||
defer cleanup()
|
||||
clientOpts = opts
|
||||
}
|
||||
clientOpts = append(clientOpts, getter.WithTimeout(repository.GetTimeout()))
|
||||
clientOpts = append(clientOpts, getter.WithTimeout(repository.Spec.Timeout.Duration))
|
||||
|
||||
chartRepo, err := helm.NewChartRepository(repository.Spec.URL, r.Getters, clientOpts)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue