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

CNF-15742: Add Reinstall spec and status fields to ClusterInstance #134

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
23 changes: 23 additions & 0 deletions api/v1alpha1/clusterinstance_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright 2024.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

// ClusterInstance preservation label constants
const (
PreservationLabelKey = Group + "/preserve"
ClusterIdentityLabelValue = "cluster-identity"
)
80 changes: 80 additions & 0 deletions api/v1alpha1/clusterinstance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,43 @@ const (
ClusterTypeHighlyAvailable ClusterType = "HighlyAvailable"
)

// PreservationMode represents the modes of data preservation for a ClusterInstance during reinstallation.
type PreservationMode string

// Supported modes of data preservation for reinstallation.
const (
// PreservationModeNone indicates that no data preservation will be performed.
PreservationModeNone PreservationMode = "None"

// PreservationModeAll indicates that all resources labeled with PreservationLabelKey will be preserved.
PreservationModeAll PreservationMode = "All"

// PreservationModeClusterIdentity indicates that only cluster identity resources labeled with
// PreservationLabelKey and ClusterIdentityLabelValue will be preserved.
PreservationModeClusterIdentity PreservationMode = "ClusterIdentity"
)

// ReinstallSpec defines the configuration for reinstallation of a ClusterInstance.
type ReinstallSpec struct {
// Generation specifies the desired generation for the reinstallation operation.
// Updating this field triggers a new reinstall request.
// +required
Generation string `json:"generation"`

// PreservationMode defines the strategy for data preservation during reinstallation.
// Supported values:
// - None: No data will be preserved.
// - All: All Secrets and ConfigMaps in the ClusterInstance namespace labeled with the PreservationLabelKey will be
// preserved.
// - ClusterIdentity: Only Secrets and ConfigMaps in the ClusterInstance namespace labeled with both the
// PreservationLabelKey and the ClusterIdentityLabelValue will be preserved.
// This field ensures critical cluster identity data is preserved when required.
// +kubebuilder:validation:Enum=None;All;ClusterIdentity
// +kubebuilder:default=None
// +required
PreservationMode PreservationMode `json:"preservationMode"`
}

// ClusterInstanceSpec defines the desired state of ClusterInstance
type ClusterInstanceSpec struct {
// Desired state of cluster
Expand Down Expand Up @@ -355,8 +392,13 @@ type ClusterInstanceSpec struct {
// +optional
CaBundleRef *corev1.LocalObjectReference `json:"caBundleRef,omitempty"`

// List of node objects
// +required
Nodes []NodeSpec `json:"nodes"`

// Reinstall specifications
// +optional
Reinstall *ReinstallSpec `json:"reinstall,omitempty"`
}

const (
Expand Down Expand Up @@ -406,6 +448,40 @@ type ManifestReference struct {
Message string `json:"message,omitempty"`
}

// ReinstallHistory represents a record of a reinstallation event for a ClusterInstance.
type ReinstallHistory struct {
// Generation specifies the generation of the ClusterInstance at the time of the reinstallation.
// This value corresponds to the ReinstallSpec.Generation field associated with the reinstallation request.
// +required
Generation string `json:"generation"`

// Timestamp indicates the date and time when the reinstallation occurred.
// +required
Timestamp metav1.Time `json:"timestamp"`

// ClusterInstanceSpecDiff provides a JSON representation of the differences between the
// ClusterInstance spec at the time of reinstallation and the previous spec.
// This field helps in tracking changes that triggered the reinstallation.
// +required
ClusterInstanceSpecDiff string `json:"clusterInstanceSpecDiff"`
}

// ReinstallStatus represents the current state and historical details of reinstall operations for a ClusterInstance.
type ReinstallStatus struct {
// ObservedGeneration is the generation of the ClusterInstance that has been processed for reinstallation.
// It corresponds to the Generation field in ReinstallSpec and indicates the latest reinstall request that
// the controller has acted upon.
// +required
ObservedGeneration string `json:"observedGeneration"`

// History maintains a record of all previous reinstallation attempts.
// Each entry captures details such as the generation, timestamp, and the differences in the ClusterInstance
// specification that triggered the reinstall.
// This field is useful for debugging, auditing, and tracking reinstallation events over time.
// +optional
History []ReinstallHistory `json:"history,omitempty"`
}

// ClusterInstanceStatus defines the observed state of ClusterInstance
type ClusterInstanceStatus struct {
// Important: Run "make" to regenerate code after modifying this file
Expand All @@ -428,6 +504,10 @@ type ClusterInstanceStatus struct {

// Track the observed generation to avoid unnecessary reconciles
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// Reinstall status information.
// +optional
Reinstall *ReinstallStatus `json:"reinstall,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
63 changes: 63 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

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

Loading
Loading