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: kb-0.7 support reconfigure operation for multi component (#5906) #5995

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
11 changes: 9 additions & 2 deletions apis/apps/v1alpha1/opsrequest_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func NewReconfigureCondition(ops *OpsRequest) *metav1.Condition {
LastTransitionTime: metav1.Now(),
Message: fmt.Sprintf("Start to reconfigure in Cluster: %s, Component: %s",
ops.Spec.ClusterRef,
ops.Spec.Reconfigure.ComponentName),
getComponentName(ops.Spec)),
}
}

Expand All @@ -300,7 +300,7 @@ func NewReconfigureRunningCondition(ops *OpsRequest, conditionType string, confi
}
message := fmt.Sprintf("Reconfiguring in Cluster: %s, Component: %s, ConfigSpec: %s",
ops.Spec.ClusterRef,
ops.Spec.Reconfigure.ComponentName,
getComponentName(ops.Spec),
configSpecName)
if len(info) > 0 {
message = message + ", info: " + info[0]
Expand All @@ -314,6 +314,13 @@ func NewReconfigureRunningCondition(ops *OpsRequest, conditionType string, confi
}
}

func getComponentName(request OpsRequestSpec) string {
if request.Reconfigure != nil {
return request.Reconfigure.ComponentName
}
return ""
}

// NewReconfigureFailedCondition creates a condition for the failed reconfigure.
func NewReconfigureFailedCondition(ops *OpsRequest, err error) *metav1.Condition {
var msg string
Expand Down
25 changes: 24 additions & 1 deletion apis/apps/v1alpha1/opsrequest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,22 @@ type OpsRequestSpec struct {
// +listMapKey=componentName
VerticalScalingList []VerticalScaling `json:"verticalScaling,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"componentName"`

// Deprecate: replace by reconfigures.

// reconfigure defines the variables that need to input when updating configuration.
// +optional
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update spec.reconfigure"
// +kubebuilder:validation:XValidation:rule="self.configurations.size() > 0", message="Value can not be empty"
Reconfigure *Reconfigure `json:"reconfigure,omitempty"`

// reconfigure defines the variables that need to input when updating configuration.
// +optional
// +patchMergeKey=componentName
// +patchStrategy=merge,retainKeys
// +listType=map
// +listMapKey=componentName
Reconfigures []Reconfigure `json:"reconfigures,omitempty"`

// expose defines services the component needs to expose.
// +optional
// +patchMergeKey=componentName
Expand Down Expand Up @@ -469,10 +479,16 @@ type OpsRequestStatus struct {
// +optional
CancelTimestamp metav1.Time `json:"cancelTimestamp,omitempty"`

// Deprecate: replace by ReconfiguringStatusAsComponent.

// reconfiguringStatus defines the status information of reconfiguring.
// +optional
ReconfiguringStatus *ReconfiguringStatus `json:"reconfiguringStatus,omitempty"`

// reconfiguringStatus defines the status information of reconfiguring.
// +optional
ReconfiguringStatusAsComponent map[string]*ReconfiguringStatus `json:"reconfiguringStatusAsComponent,omitempty"`

// conditions describes opsRequest detail status.
// +optional
// +patchMergeKey=type
Expand Down Expand Up @@ -576,9 +592,16 @@ type OpsRequestComponentStatus struct {
}

type ReconfiguringStatus struct {
// conditions describes reconfiguring detail status.
// +optional
// +patchMergeKey=type
// +patchStrategy=merge
// +listType=map
// +listMapKey=type
Conditions []metav1.Condition `json:"conditions,omitempty"`

// configurationStatus describes the status of the component reconfiguring.
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinItems=1
// +patchMergeKey=name
// +patchStrategy=merge,retainKeys
// +listType=map
Expand Down
14 changes: 13 additions & 1 deletion apis/apps/v1alpha1/opsrequest_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,21 @@ func (r *OpsRequest) validateReconfigure(cluster *Cluster) error {
return nil
}
reconfigure := r.Spec.Reconfigure
if reconfigure == nil {
if reconfigure == nil && len(r.Spec.Reconfigures) == 0 {
return notEmptyError("spec.reconfigure")
}
if reconfigure != nil {
return r.validateReconfigureParams(cluster, reconfigure)
}
for _, reconfigure := range r.Spec.Reconfigures {
if err := r.validateReconfigureParams(cluster, &reconfigure); err != nil {
return err
}
}
return nil
}

func (r *OpsRequest) validateReconfigureParams(cluster *Cluster, reconfigure *Reconfigure) error {
if cluster.Spec.GetComponentByName(reconfigure.ComponentName) == nil {
return fmt.Errorf("component %s not found", reconfigure.ComponentName)
}
Expand Down
29 changes: 29 additions & 0 deletions apis/apps/v1alpha1/zz_generated.deepcopy.go

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

Loading
Loading