Skip to content

Commit

Permalink
Deploy Item Timeout Detection (#174)
Browse files Browse the repository at this point in the history
* extend api and configuration for progressing timeout detection

* detect progressing and abort timeouts

* extend mock deployer

A new field in the mock configuration was added: initialPhase
It sets the phase of the deploy item status, but only if the phase is either 'Init' or empty.
Furthermore, it suppresses the deploy item being set to 'Succeeded' after a successful reconcile.

The reasoning behind this is that for testing the deploy item timeout, the deploy item needs to be in a non-final phase,
e.g. 'Progressing' for some time. However, if the mock deploy item's 'phase' field is used, the mock deployer will
immediately overwrite any 'Failed' state set by the landscaper again, which makes it hard to observe the timeout behaviour.

* add integration tests for deploy item progressing and aborting timeout detection

* rename webhook test

* refactor timeout configuration

* update documentation

* use wrapper for time.Duration instead of parsing from string for timeout durations

* remove HasTimestampAnnotation and SetTimestampAnnotation methods

* minor refactoring (review feedback)

* fix bug in duration marshal

* add unit tests for deploy item controller

* refactor timeout integration test

* implement review feedback

* rename 'LastChangeReconcileTime' to 'LastReconcileTime'
  • Loading branch information
Diaphteiros authored Apr 22, 2021
1 parent 0ea9489 commit dbdea10
Show file tree
Hide file tree
Showing 65 changed files with 1,818 additions and 287 deletions.
28 changes: 25 additions & 3 deletions apis/.schemes/config-v1alpha1-LandscaperConfiguration.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@
}
}
},
"config-v1alpha1-DeployItemTimeouts": {
"description": "DeployItemTimeouts contains multiple timeout configurations for deploy items",
"type": "object",
"properties": {
"abort": {
"description": "Abort specifies how long the deployer may take to abort handling a deploy item after getting the abort annotation. Allowed values are 'none' (to disable abort timeout detection) and anything that is understood by golang's time.ParseDuration method. Defaults to five minutes if not specified.",
"$ref": "#/definitions/core-v1alpha1-Duration"
},
"pickup": {
"description": "PickupTimeout defines how long a deployer can take to react on changes to a deploy item before the landscaper will mark it as failed. Allowed values are 'none' (to disable pickup timeout detection) and anything that is understood by golang's time.ParseDuration method. Defaults to five minutes if not specified.",
"$ref": "#/definitions/core-v1alpha1-Duration"
},
"progressingDefault": {
"description": "ProgressingDefault specifies how long the deployer may take to apply a deploy item by default. The value can be overwritten per deploy item in 'spec.timeout'. Allowed values are 'none' (to disable abort timeout detection) and anything that is understood by golang's time.ParseDuration method. Defaults to ten minutes if not specified.",
"$ref": "#/definitions/core-v1alpha1-Duration"
}
}
},
"config-v1alpha1-LocalRegistryConfiguration": {
"description": "LocalRegistryConfiguration contains the configuration for a local registry",
"type": "object",
Expand Down Expand Up @@ -128,6 +146,10 @@
"$ref": "#/definitions/config-v1alpha1-OCIConfiguration"
}
}
},
"core-v1alpha1-Duration": {
"description": "Duration is a wrapper for time.Duration that implements JSON marshalling and openapi scheme.",
"type": "string"
}
},
"description": "LandscaperConfiguration contains all configuration for the landscaper controllers",
Expand All @@ -140,9 +162,9 @@
"$ref": "#/definitions/config-v1alpha1-CrdManagementConfiguration",
"description": "CrdManagement configures whether the landscaper controller should deploy the CRDs it needs into the cluster"
},
"deployItemPickupTimeout": {
"description": "DeployItemPickupTimeout defines how long a deployer can take to react on changes to a deploy item before the landscaper will mark it as failed. Allowed values are 'none' (to disable pickup timeout detection) and anything that is understood by golang's time.ParseDuration method. Defaults to five minutes if not specified.",
"type": "string"
"deployItemTimeouts": {
"$ref": "#/definitions/config-v1alpha1-DeployItemTimeouts",
"description": "DeployItemTimeouts contains configuration for multiple deploy item timeouts"
},
"kind": {
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
Expand Down
4 changes: 4 additions & 0 deletions apis/.schemes/mock-v1alpha1-ProviderConfiguration.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"format": "byte",
"type": "string"
},
"initialPhase": {
"description": "InitialPhase sets the phase of the DeployItem, but only if it is empty or \"Init\" Additionally, setting it will suppress the DeployItem phase being set to \"Succeeded\" after successful reconciliation",
"type": "string"
},
"kind": {
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
"type": "string"
Expand Down
23 changes: 21 additions & 2 deletions apis/config/types_landscaper_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package config
import (
cdv2 "github.com/gardener/component-spec/bindings-go/apis/v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

lscore "github.com/gardener/landscaper/apis/core"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand All @@ -25,11 +27,28 @@ type LandscaperConfiguration struct {
// CrdManagement configures whether the landscaper controller should deploy the CRDs it needs into the cluster
// +optional
CrdManagement *CrdManagementConfiguration `json:"crdManagement,omitempty"`
// DeployItemPickupTimeout defines how long a deployer can take to react on changes to a deploy item before the landscaper will mark it as failed.
// DeployItemTimeouts contains configuration for multiple deploy item timeouts
// +optional
DeployItemTimeouts *DeployItemTimeouts `json:"deployItemTimeouts,omitempty"`
}

// DeployItemTimeouts contains multiple timeout configurations for deploy items
type DeployItemTimeouts struct {
// PickupTimeout defines how long a deployer can take to react on changes to a deploy item before the landscaper will mark it as failed.
// Allowed values are 'none' (to disable pickup timeout detection) and anything that is understood by golang's time.ParseDuration method.
// Defaults to five minutes if not specified.
// +optional
DeployItemPickupTimeout string `json:"deployItemPickupTimeout,omitempty"`
Pickup *lscore.Duration `json:"pickup,omitempty"`
// Abort specifies how long the deployer may take to abort handling a deploy item after getting the abort annotation.
// Allowed values are 'none' (to disable abort timeout detection) and anything that is understood by golang's time.ParseDuration method.
// Defaults to five minutes if not specified.
// +optional
Abort *lscore.Duration `json:"abort,omitempty"`
// ProgressingDefault specifies how long the deployer may take to apply a deploy item by default. The value can be overwritten per deploy item in 'spec.timeout'.
// Allowed values are 'none' (to disable abort timeout detection) and anything that is understood by golang's time.ParseDuration method.
// Defaults to ten minutes if not specified.
// +optional
ProgressingDefault *lscore.Duration `json:"progressingDefault,omitempty"`
}

// RegistryConfiguration contains the configuration for the used definition registry
Expand Down
17 changes: 15 additions & 2 deletions apis/config/v1alpha1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
package v1alpha1

import (
"time"

"k8s.io/apimachinery/pkg/runtime"

"github.com/gardener/landscaper/apis/core/v1alpha1"
)

func addDefaultingFuncs(scheme *runtime.Scheme) error {
Expand All @@ -22,8 +26,17 @@ func SetDefaults_LandscaperConfiguration(obj *LandscaperConfiguration) {
UseInMemoryOverlay: false,
}
}
if len(obj.DeployItemPickupTimeout) == 0 {
obj.DeployItemPickupTimeout = "5m"
if obj.DeployItemTimeouts == nil {
obj.DeployItemTimeouts = &DeployItemTimeouts{}
}
if obj.DeployItemTimeouts.Pickup == nil {
obj.DeployItemTimeouts.Pickup = &v1alpha1.Duration{Duration: 5 * time.Minute}
}
if obj.DeployItemTimeouts.Abort == nil {
obj.DeployItemTimeouts.Abort = &v1alpha1.Duration{Duration: 5 * time.Minute}
}
if obj.DeployItemTimeouts.ProgressingDefault == nil {
obj.DeployItemTimeouts.ProgressingDefault = &v1alpha1.Duration{Duration: 10 * time.Minute}
}

}
23 changes: 21 additions & 2 deletions apis/config/v1alpha1/types_landscaper_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package v1alpha1
import (
cdv2 "github.com/gardener/component-spec/bindings-go/apis/v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

lsv1alpha1 "github.com/gardener/landscaper/apis/core/v1alpha1"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand All @@ -25,11 +27,28 @@ type LandscaperConfiguration struct {
// CrdManagement configures whether the landscaper controller should deploy the CRDs it needs into the cluster
// +optional
CrdManagement *CrdManagementConfiguration `json:"crdManagement,omitempty"`
// DeployItemPickupTimeout defines how long a deployer can take to react on changes to a deploy item before the landscaper will mark it as failed.
// DeployItemTimeouts contains configuration for multiple deploy item timeouts
// +optional
DeployItemTimeouts *DeployItemTimeouts `json:"deployItemTimeouts,omitempty"`
}

// DeployItemTimeouts contains multiple timeout configurations for deploy items
type DeployItemTimeouts struct {
// PickupTimeout defines how long a deployer can take to react on changes to a deploy item before the landscaper will mark it as failed.
// Allowed values are 'none' (to disable pickup timeout detection) and anything that is understood by golang's time.ParseDuration method.
// Defaults to five minutes if not specified.
// +optional
DeployItemPickupTimeout string `json:"deployItemPickupTimeout,omitempty"`
Pickup *lsv1alpha1.Duration `json:"pickup,omitempty"`
// Abort specifies how long the deployer may take to abort handling a deploy item after getting the abort annotation.
// Allowed values are 'none' (to disable abort timeout detection) and anything that is understood by golang's time.ParseDuration method.
// Defaults to five minutes if not specified.
// +optional
Abort *lsv1alpha1.Duration `json:"abort,omitempty"`
// ProgressingDefault specifies how long the deployer may take to apply a deploy item by default. The value can be overwritten per deploy item in 'spec.timeout'.
// Allowed values are 'none' (to disable abort timeout detection) and anything that is understood by golang's time.ParseDuration method.
// Defaults to ten minutes if not specified.
// +optional
ProgressingDefault *lsv1alpha1.Duration `json:"progressingDefault,omitempty"`
}

// RegistryConfiguration contains the configuration for the used definition registry
Expand Down
40 changes: 38 additions & 2 deletions apis/config/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions apis/config/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions apis/config/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions apis/core/types_deployitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ type DeployItemSpec struct {
// Note that the type information is used to determine the secret key and the type of the secret.
// +optional
RegistryPullSecrets []ObjectReference `json:"registryPullSecrets,omitempty"`
// Timeout specifies how long the deployer may take to apply the deploy item.
// When the time is exceeded, the landscaper will add the abort annotation to the deploy item
// and later put it in 'Failed' if the deployer doesn't handle the abort properly.
// Value has to be parsable by time.ParseDuration (or 'none' to deactivate the timeout).
// Defaults to ten minutes if not specified.
// +optional
Timeout *Duration `json:"timeout,omitempty"`
}

// DeployItemStatus contains the status of a deploy item
Expand All @@ -72,6 +79,10 @@ type DeployItemStatus struct {
// LastError describes the last error that occurred.
LastError *Error `json:"lastError,omitempty"`

// LastReconcileTime indicates when the reconciliation of the last change to the deploy item has started
// +optional
LastReconcileTime *metav1.Time `json:"lastReconcileTime,omitempty"`

// ProviderStatus contains the provider specific status
// +optional
ProviderStatus *runtime.RawExtension `json:"providerStatus,omitempty"`
Expand Down
Loading

0 comments on commit dbdea10

Please sign in to comment.