Skip to content

Commit

Permalink
chore: remove the deprecated apis from the opsRequest (#8191)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyelei authored Sep 25, 2024
1 parent 2c4c9df commit e0bd32a
Show file tree
Hide file tree
Showing 18 changed files with 180 additions and 1,415 deletions.
24 changes: 0 additions & 24 deletions apis/operations/v1alpha1/opsdefinition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,6 @@ type OpsDefinitionSpec struct {
type PreCondition struct {
// Specifies the conditions that must be met for the operation to execute.
Rule *Rule `json:"rule,omitempty"`

// Represents a job that will be run to execute the PreCondition.
// The operation will only be executed if the job is successful.
// +optional
// Exec *PreConditionExec `json:"exec,omitempty"`
}

// PreConditionExec is deprecated.
type PreConditionExec struct {
// Specifies the name of the image used for execution.
// +kubebuilder:validation:Required
Image string `json:"image"`

// Specifies a list of environment variables to be set in the container.
// +optional
Env []corev1.EnvVar `json:"env,omitempty"`

// Specifies the command to be executed in the container.
// +optional
Command []string `json:"command,omitempty"`

// Specifies the arguments to be passed to the command in the container.
// +optional
Args []string `json:"args,omitempty"`
}

type Rule struct {
Expand Down
8 changes: 5 additions & 3 deletions apis/operations/v1alpha1/opsrequest_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
"fmt"
"strings"

"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -319,10 +320,11 @@ func NewReconfigureRunningCondition(ops *OpsRequest, conditionType string, confi
}

func getComponentName(request OpsRequestSpec) string {
if request.Reconfigure != nil {
return request.Reconfigure.ComponentName
var compNames []string
for _, v := range request.Reconfigures {
compNames = append(compNames, v.ComponentName)
}
return ""
return strings.Join(compNames, ",")
}

// NewReconfigureFailedCondition creates a condition for the failed reconfigure.
Expand Down
9 changes: 6 additions & 3 deletions apis/operations/v1alpha1/opsrequest_conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ func TestNewAllCondition(t *testing.T) {
NewReconfigureFailedCondition(opsRequest, errors.New("reconfigure opsRequest failed"))
NewBackupCondition(opsRequest)

opsRequest.Spec.Reconfigure = &Reconfigure{
ComponentOps: ComponentOps{
ComponentName: "testReconfiguring",
opsRequest.Spec.Reconfigures = []Reconfigure{
{

ComponentOps: ComponentOps{
ComponentName: "testReconfiguring",
},
},
}
NewReconfigureCondition(opsRequest)
Expand Down
75 changes: 5 additions & 70 deletions apis/operations/v1alpha1/opsrequest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ type OpsRequestSpec struct {
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update spec.clusterName"
ClusterName string `json:"clusterName,omitempty"`

// Deprecated: since v0.9, use clusterName instead.
// Specifies the name of the Cluster resource that this operation is targeting.
// +kubebuilder:deprecatedversion:warning="This field has been deprecated since 0.9.0"
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update spec.clusterRef"
ClusterRef string `json:"clusterRef,omitempty"`

// Indicates whether the current operation should be canceled and terminated gracefully if it's in the
// "Pending", "Creating", or "Running" state.
//
Expand Down Expand Up @@ -173,13 +167,6 @@ type SpecificOpsRequest struct {
// +listMapKey=componentName
VerticalScalingList []VerticalScaling `json:"verticalScaling,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"componentName"`

// Specifies a component and its configuration updates.
//
// This field is deprecated and replaced by `reconfigures`.
//
// +optional
Reconfigure *Reconfigure `json:"reconfigure,omitempty"`

// Lists Reconfigure objects, each specifying a Component and its configuration updates.
//
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update spec.reconfigure"
Expand All @@ -195,33 +182,20 @@ type SpecificOpsRequest struct {
// +optional
ExposeList []Expose `json:"expose,omitempty"`

// Specifies the parameters to backup a Cluster.
// Specifies the parameters to back up a Cluster.
// +optional
Backup *Backup `json:"backup,omitempty"`

// Deprecated: since v0.9, use backup instead.
// Specifies the parameters to backup a Cluster.
// +optional
// +kubebuilder:deprecatedversion:warning="This field has been deprecated since 0.9.0"
BackupSpec *Backup `json:"backupSpec,omitempty"`

// Specifies the parameters to restore a Cluster.
// Note that this restore operation will roll back cluster services.
//
// +optional
Restore *Restore `json:"restore,omitempty"`

// Deprecated: since v0.9, use restore instead.
// Specifies the parameters to restore a Cluster.
// Note that this restore operation will roll back cluster services.
// +kubebuilder:deprecatedversion:warning="This field has been deprecated since 0.9.0"
// +optional
RestoreSpec *Restore `json:"restoreSpec,omitempty"`

// Specifies the parameters to rebuild some instances.
// Rebuilding an instance involves restoring its data from a backup or another database replica.
// The instances being rebuilt usually serve as standby in the cluster.
// Hence rebuilding instances is often also referred to as "standby reconstruction".
// Hence, rebuilding instances is often also referred to as "standby reconstruction".
//
// +optional
// +patchMergeKey=componentName
Expand Down Expand Up @@ -323,12 +297,6 @@ type Switchover struct {

// Upgrade defines the parameters for an upgrade operation.
type Upgrade struct {
// Deprecated: since v0.9 because ClusterVersion is deprecated.
// Specifies the name of the target ClusterVersion for the upgrade.
//
// +kubebuilder:deprecatedversion:warning="This field has been deprecated since 0.9.0"
ClusterVersionRef *string `json:"clusterVersionRef,omitempty"`

// Lists components to be upgrade based on desired ComponentDefinition and ServiceVersion.
// From the perspective of cluster API, the reasonable combinations should be:
// 1. (comp-def, service-ver) - upgrade to the specified service version and component definition, the user takes the responsibility to ensure that they are compatible.
Expand Down Expand Up @@ -451,13 +419,6 @@ type HorizontalScaling struct {
// Specifies the name of the Component.
ComponentOps `json:",inline"`

// Deprecated: since v0.9, use scaleOut and scaleIn instead.
// Specifies the number of replicas for the component. Cannot be used with "scaleIn" and "scaleOut".
// +kubebuilder:deprecatedversion:warning="This field has been deprecated since 0.9.0"
// +kubebuilder:validation:Minimum=0
// +optional
Replicas *int32 `json:"replicas,omitempty"`

// Specifies the replica changes for scaling out components and instance templates,
// and brings offline instances back online. Can be used in conjunction with the "scaleIn" operation.
// Note: Any configuration that deletes instances is considered invalid.
Expand Down Expand Up @@ -995,11 +956,6 @@ type OpsRequestStatus struct {
// +optional
CancelTimestamp metav1.Time `json:"cancelTimestamp,omitempty"`

// Deprecated: Replaced by ReconfiguringStatusAsComponent.
// Defines the status information of reconfiguring.
// +optional
ReconfiguringStatus *ReconfiguringStatus `json:"reconfiguringStatus,omitempty"`

// Records the status of a reconfiguring operation if `opsRequest.spec.type` equals to "Reconfiguring".
// +optional
ReconfiguringStatusAsComponent map[string]*ReconfiguringStatus `json:"reconfiguringStatusAsComponent,omitempty"`
Expand Down Expand Up @@ -1113,10 +1069,6 @@ type LastComponentConfiguration struct {
}

type LastConfiguration struct {
// Specifies the name of the ClusterVersion.
// Deprecated and should be removed in the future version.
// +optional
ClusterVersionRef string `json:"clusterVersionRef,omitempty"`

// Records the configuration of each Component prior to any changes.
// +optional
Expand Down Expand Up @@ -1152,14 +1104,6 @@ type OpsRequestComponentStatus struct {
Message string `json:"message,omitempty" protobuf:"bytes,6,opt,name=message"`
}

type OverrideBy struct {
// Indicates the name of the OpsRequest.
// +optional
OpsName string `json:"opsName"`

LastComponentConfiguration `json:",inline"`
}

type PreCheckResult struct {
// Indicates whether the preCheck operation passed or failed.
// +kubebuilder:validation:Required
Expand Down Expand Up @@ -1312,24 +1256,15 @@ func (r OpsRequestSpec) ToExposeListToMap() map[string]Expose {
}

func (r OpsRequestSpec) GetClusterName() string {
if r.ClusterName != "" {
return r.ClusterName
}
return r.ClusterRef
return r.ClusterName
}

func (r OpsRequestSpec) GetBackup() *Backup {
if r.Backup != nil {
return r.Backup
}
return r.BackupSpec
return r.Backup
}

func (r OpsRequestSpec) GetRestore() *Restore {
if r.Restore != nil {
return r.Restore
}
return r.RestoreSpec
return r.Restore
}

func (p *ProgressStatusDetail) SetStatusAndMessage(status ProgressStatus, message string) {
Expand Down
17 changes: 2 additions & 15 deletions apis/operations/v1alpha1/opsrequest_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ func (r *OpsRequest) validateUpgrade(ctx context.Context, k8sClient client.Clien
if upgrade == nil {
return notEmptyError("spec.upgrade")
}
if upgrade.ClusterVersionRef != nil && *upgrade.ClusterVersionRef != "" {
return fmt.Errorf("not supported")
}
if len(r.Spec.Upgrade.Components) == 0 {
return notEmptyError("spec.upgrade.components")
}
Expand Down Expand Up @@ -245,12 +242,8 @@ func (r *OpsRequest) validateVerticalScaling(cluster *appsv1.Cluster) error {
func (r *OpsRequest) validateReconfigure(ctx context.Context,
k8sClient client.Client,
cluster *appsv1.Cluster) error {
reconfigure := r.Spec.Reconfigure
if reconfigure == nil && len(r.Spec.Reconfigures) == 0 {
return notEmptyError("spec.reconfigure")
}
if reconfigure != nil {
return r.validateReconfigureParams(ctx, k8sClient, cluster, reconfigure)
if len(r.Spec.Reconfigures) == 0 {
return notEmptyError("spec.reconfigures")
}
for _, reconfigure := range r.Spec.Reconfigures {
if err := r.validateReconfigureParams(ctx, k8sClient, cluster, &reconfigure); err != nil {
Expand Down Expand Up @@ -367,12 +360,6 @@ func (r *OpsRequest) CountOfflineOrOnlineInstances(clusterName, componentName st
func (r *OpsRequest) validateHorizontalScalingSpec(hScale HorizontalScaling, compSpec appsv1.ClusterComponentSpec, clusterName string, isSharding bool) error {
scaleIn := hScale.ScaleIn
scaleOut := hScale.ScaleOut
if hScale.Replicas != nil && (scaleIn != nil || scaleOut != nil) {
return fmt.Errorf(`"replicas" has been deprecated and cannot be used with "scaleOut" and "scaleIn"`)
}
if hScale.Replicas != nil {
return nil
}
if lastCompConfiguration, ok := r.Status.LastConfiguration.Components[hScale.ComponentName]; ok {
// use last component configuration snapshot
compSpec.Instances = lastCompConfiguration.Instances
Expand Down
78 changes: 0 additions & 78 deletions apis/operations/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit e0bd32a

Please sign in to comment.