Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable drift detection + takeover experience in work applier #950

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions apis/placement/v1beta1/clusterresourceplacement_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,11 @@ const (
// ComparisonOptionTypePartialComparison will compare only fields that are managed by Fleet, i.e.,
// fields that are specified explicitly in the hub cluster manifest. Unmanaged fields
// are ignored.
ComparisonOptionTypePartialComparison ComparisonOptionType = "PartialDiff"
ComparisonOptionTypePartialComparison ComparisonOptionType = "PartialComparison"

// ComparisonOptionTypeFullDiff will compare all fields of the resource, even if the fields
// are absent from the hub cluster manifest.
ComparisonOptionTypeFullComparison ComparisonOptionType = "FullDiff"
ComparisonOptionTypeFullComparison ComparisonOptionType = "FullComparison"
)

// WhenToApplyType describes when Fleet would apply the manifests on the hub cluster to
Expand Down
96 changes: 81 additions & 15 deletions apis/placement/v1beta1/work_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,85 @@ type WorkResourceIdentifier struct {
// Kind is the kind of the resource.
Kind string `json:"kind,omitempty"`

// Resource is the resource type of the resource
// Resource is the resource type of the resource.
Resource string `json:"resource,omitempty"`

// Namespace is the namespace of the resource, the resource is cluster scoped if the value
// is empty
// is empty.
Namespace string `json:"namespace,omitempty"`

// Name is the name of the resource
// Name is the name of the resource.
Name string `json:"name,omitempty"`

// GenerateName is the generate name of the resource.
GenerateName string `json:"generateName,omitempty"`
}

// DriftDetails describes the observed configuration drifts.
type DriftDetails struct {
// ObservationTime is the timestamp when the drift was last detected.
//
// +kubebuilder:validation:Required
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=date-time
ObservationTime metav1.Time `json:"observationTime"`

// ObservedInMemberClusterGeneration is the generation of the applied manifest on the member
// cluster side.
//
// +kubebuilder:validation:Required
ObservedInMemberClusterGeneration int64 `json:"observedInMemberClusterGeneration"`

// FirsftDriftedObservedTime is the timestamp when the drift was first detected.
//
// +kubebuilder:validation:Required
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=date-time
FirstDriftedObservedTime metav1.Time `json:"firstDriftedObservedTime"`

// ObservedDrifts describes each drifted field found from the applied manifest.
// Fleet might truncate the details as appropriate to control object size.
//
// Each entry specifies how the live state (the state on the member cluster side) compares
// against the desired state (the state kept in the hub cluster manifest).
//
// +kubebuilder:validation:Optional
ObservedDrifts []PatchDetail `json:"observedDrifts,omitempty"`
}

// DiffDetails describes the observed configuration differences.
type DiffDetails struct {
// ObservationTime is the timestamp when the configuration difference was last detected.
//
// +kubebuilder:validation:Required
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=date-time
ObservationTime metav1.Time `json:"observationTime"`

// ObservedInMemberClusterGeneration is the generation of the applied manifest on the member
// cluster side.
//
// +kubebuilder:validation:Required
ObservedInMemberClusterGeneration int64 `json:"observedInMemberClusterGeneration"`

// FirsftDiffedObservedTime is the timestamp when the configuration difference
// was first detected.
//
// +kubebuilder:validation:Required
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=date-time
FirstDiffedObservedTime metav1.Time `json:"firstDiffedObservedTime"`

// ObservedDiffs describes each field with configuration difference as found from the
// member cluster side.
//
// Fleet might truncate the details as appropriate to control object size.
//
// Each entry specifies how the live state (the state on the member cluster side) compares
// against the desired state (the state kept in the hub cluster manifest).
//
// +kubebuilder:validation:Optional
ObservedDiffs []PatchDetail `json:"observedDiffs,omitempty"`
}

// ManifestCondition represents the conditions of the resources deployed on
Expand All @@ -124,31 +194,27 @@ type ManifestCondition struct {
// +required
Conditions []metav1.Condition `json:"conditions"`

// ObservedDrifts explains the details about the observed configuration drifts.
// DriftDetails explains about the observed configuration drifts.
// Fleet might truncate the details as appropriate to control object size.
//
// Each detail entry specifies how the live state (the state on the member
// cluster side) compares against the desired state (the state kept in the hub cluster manifest).
//
// Note that configuration drifts can only occur on a resource if it is currently owned by
// Fleet and its corresponding placement is set to use the ClientSideApply or ServerSideApply
// apply strategy. In other words, ObservedDrifts and ObservedDiffs will not be populated
// apply strategy. In other words, DriftDetails and DiffDetails will not be populated
// at the same time.
//
// +kubebuilder:validation:Optional
ObservedDrifts []PatchDetail `json:"observedDrifts,omitempty"`
DriftDetails *DriftDetails `json:"driftDetails,omitempty"`

// ObservedDiffs explains the details about the observed configuration differences.
// DiffDetails explains the details about the observed configuration differences.
// Fleet might truncate the details as appropriate to control object size.
//
// Each detail entry specifies how the live state (the state on the member
// cluster side) compares against the desired state (the state kept in the hub cluster manifest).
//
// Note that configuration differences can only occur on a resource if it is not currently owned
// by Fleet (i.e., it is a pre-existing resource that needs to be taken over), or if its
// corresponding placement is set to use the ReportDiff apply strategy. In other words,
// ObservedDiffs and ObservedDrifts will not be populated at the same time.
// DiffDetails and DriftDetails will not be populated at the same time.
//
// +kubebuilder:validation:Optional
ObservedDiffs []PatchDetail `json:"observedDiffs,omitempty"`
DiffDetails *DiffDetails `json:"diffDetails,omitempty"`
}

// +genclient
Expand Down
60 changes: 52 additions & 8 deletions apis/placement/v1beta1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -182,27 +182,30 @@ spec:
AppliedResourceMeta represents the group, version, resource, name and namespace of a resource.
Since these resources have been created, they must have valid group, version, resource, namespace, and name.
properties:
generateName:
description: GenerateName is the generate name of the resource.
type: string
group:
description: Group is the group of the resource.
type: string
kind:
description: Kind is the kind of the resource.
type: string
name:
description: Name is the name of the resource
description: Name is the name of the resource.
type: string
namespace:
description: |-
Namespace is the namespace of the resource, the resource is cluster scoped if the value
is empty
is empty.
type: string
ordinal:
description: |-
Ordinal represents an index in manifests list, so the condition can still be linked
to a manifest even though manifest cannot be parsed successfully.
type: integer
resource:
description: Resource is the resource type of the resource
description: Resource is the resource type of the resource.
type: string
uid:
description: |-
Expand Down
Loading
Loading