Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions api/v1beta1/clustersummary_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ type FeatureSummary struct {
// +optional
Hash []byte `json:"hash,omitempty"`

// ReferenceHashes records, for each resource the feature configuration depends on (referenced
// ConfigMaps, Secrets and sources, templateResourceRefs), a short hash of its content at the time
// Hash was computed. Comparing it with the current content tells which resource changed when the
// feature has changes not deployed yet (see ClusterSummary Status.PendingFeatures).
// It always describes the configuration Hash was computed from. Not used by the Helm feature:
// HelmReleaseSummaries already records the same information.
// +listType=atomic
// +optional
ReferenceHashes []ReferenceHash `json:"referenceHashes,omitempty"`

// ReferencesRecorded is true when ReferenceHashes was recorded together with Hash. An empty
// ReferenceHashes then means the feature depends on no resource. It is false for a feature last
// deployed by a version that did not record ReferenceHashes.
// +optional
ReferencesRecorded bool `json:"referencesRecorded,omitempty"`

// The number of consecutive deployment failures.
// +optional
ConsecutiveFailures uint `json:"consecutiveFailures,omitempty"`
Expand Down Expand Up @@ -92,6 +108,41 @@ type FeatureSummary struct {
DriftHistory *DriftHistory `json:"driftHistory,omitempty"`
}

// ReferenceSource tells where a resource a feature depends on is referenced from
// +kubebuilder:validation:Enum:=PolicyRef;KustomizationRef;TemplateResourceRef
type ReferenceSource string

const (
// ReferenceSourcePolicyRef is a resource referenced in the PolicyRefs section
ReferenceSourcePolicyRef = ReferenceSource("PolicyRef")

// ReferenceSourceKustomizationRef is a resource referenced in the KustomizationRefs section
ReferenceSourceKustomizationRef = ReferenceSource("KustomizationRef")

// ReferenceSourceTemplateResourceRef is a management cluster resource referenced in the
// TemplateResourceRefs section
ReferenceSourceTemplateResourceRef = ReferenceSource("TemplateResourceRef")
)

// ReferenceHash is a short hash of the content of a resource a feature depends on.
type ReferenceHash struct {
// Source tells where the resource is referenced from
Source ReferenceSource `json:"source"`

// Kind of the resource
Kind string `json:"kind"`

// Namespace of the resource. Empty for cluster scoped resources.
// +optional
Namespace string `json:"namespace,omitempty"`

// Name of the resource
Name string `json:"name"`

// Hash is a short hash of the content of the resource
Hash string `json:"hash"`
}

// DriftHistory describes the configuration drifts detected on the resources deployed by a feature.
type DriftHistory struct {
// LastDetectedTime is when the most recent drift was detected. When the component that
Expand Down Expand Up @@ -306,6 +357,106 @@ type ClusterSummaryStatus struct {
// SuspensionReason provides a brief explanation of why the reconciliation is suspended.
// +optional
SuspensionReason *string `json:"suspensionReason,omitempty"`

// PendingFeatures lists the features whose desired configuration differs from what is currently
// deployed. It is only populated while reconciliation is suspended (for instance because the
// cluster is paused): in that state nothing is deployed, so this tells which features will be
// redeployed once reconciliation resumes. It is evaluated each time the ClusterSummary is
// reconciled while suspended, so it reflects the state at that moment. Cleared when reconciliation
// resumes.
// +listType=map
// +listMapKey=featureID
// +optional
PendingFeatures []PendingFeature `json:"pendingFeatures,omitempty"`
}

// PendingFeatureReason explains why a feature is listed in ClusterSummary Status.PendingFeatures
// +kubebuilder:validation:Enum:=ConfigurationChanged;NotDeployed;PendingRemoval;EvaluationFailed
type PendingFeatureReason string

const (
// PendingReasonConfigurationChanged indicates the feature is deployed but its desired
// configuration is different from the one deployed
PendingReasonConfigurationChanged = PendingFeatureReason("ConfigurationChanged")

// PendingReasonNotDeployed indicates the feature is configured but has not been successfully
// deployed yet
PendingReasonNotDeployed = PendingFeatureReason("NotDeployed")

// PendingReasonPendingRemoval indicates the feature is deployed but it is not configured
// anymore, so it will be removed
PendingReasonPendingRemoval = PendingFeatureReason("PendingRemoval")

// PendingReasonEvaluationFailed indicates it was not possible to establish whether the
// feature has pending changes. Message contains the error.
PendingReasonEvaluationFailed = PendingFeatureReason("EvaluationFailed")
)

// PendingFeature describes a feature with changes that are not deployed yet.
type PendingFeature struct {
// FeatureID is an identifier of the feature with pending changes
FeatureID libsveltosv1beta1.FeatureID `json:"featureID"`

// Reason is why the feature has pending changes
Reason PendingFeatureReason `json:"reason"`

// Message provides more information. Set when Reason is EvaluationFailed, or when Items does not
// tell the whole story (for instance Items is empty because what changed cannot be attributed
// to a referenced resource).
// +optional
Message *string `json:"message,omitempty"`

// Items lists what changed in the feature configuration, when it can be established.
// For raw YAML and Kustomize a referenced resource is reported as a whole: which part of it
// changed is not reported. Changes that cannot be attributed to an item (the profile settings,
// or content fetched from a remote URL) are not listed.
// +listType=atomic
// +optional
Items []PendingItem `json:"items,omitempty"`

// ItemsTruncated is true when more than MaxPendingItems items changed, so Items is not complete.
// +optional
ItemsTruncated bool `json:"itemsTruncated,omitempty"`
}

const (
// MaxPendingItems is the maximum number of items reported for a feature
MaxPendingItems = 50
)

// PendingChange is what happened to an item since the feature was last deployed
// +kubebuilder:validation:Enum:=Added;Removed;Changed
type PendingChange string

const (
// PendingChangeAdded indicates the item is part of the configuration but was not deployed yet
PendingChangeAdded = PendingChange("Added")

// PendingChangeRemoved indicates the item is not part of the configuration anymore but is still deployed
PendingChangeRemoved = PendingChange("Removed")

// PendingChangeChanged indicates the item is deployed but its desired content is different
PendingChangeChanged = PendingChange("Changed")
)

// PendingItem describes one change not deployed yet.
type PendingItem struct {
// Kind of the item: the kind of the referenced resource, or HelmChart
Kind string `json:"kind"`

// Namespace of the item. For a HelmChart it is the release namespace.
// +optional
Namespace string `json:"namespace,omitempty"`

// Name of the item. For a HelmChart it is the release name.
Name string `json:"name"`

// Change is what happened to the item
Change PendingChange `json:"change"`

// Detail provides more information, for instance what changed in a HelmChart
// +optional
Detail string `json:"detail,omitempty"`
}

//nolint: lll // marker
Expand All @@ -314,6 +465,7 @@ type ClusterSummaryStatus struct {
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of ClusterSummary"
// +kubebuilder:printcolumn:name="Pending",type="string",JSONPath=".status.pendingFeatures[*].featureID",description="Features with changes not deployed because reconciliation is suspended"
// +kubebuilder:printcolumn:name="HelmCharts",type="string",JSONPath=".status.featureSummaries[?(@.featureID==\"Helm\")].status",description="Indicates whether HelmCharts are all provisioned",priority=2
// +kubebuilder:printcolumn:name="KustomizeRefs",type="string",JSONPath=".status.featureSummaries[?(@.featureID==\"Kustomize\")].status",description="Indicates whether KustomizeRefs are all provisioned",priority=2
// +kubebuilder:printcolumn:name="PolicyRefs",type="string",JSONPath=".status.featureSummaries[?(@.featureID==\"Resources\")].status",description="Indicates whether PolicyRefs are all provisioned",priority=2
Expand Down
67 changes: 67 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

Loading