Skip to content

Commit

Permalink
feat: change scope of feat VolumeModifying
Browse files Browse the repository at this point in the history
Signed-off-by: liubo02 <[email protected]>
  • Loading branch information
liubog2008 authored and ti-chi-bot committed Jul 14, 2023
1 parent 641159c commit 4267553
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
9 changes: 3 additions & 6 deletions pkg/controller/tidbcluster/tidb_cluster_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1/defaulting"
v1alpha1validation "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1/validation"
"github.com/pingcap/tidb-operator/pkg/controller"
"github.com/pingcap/tidb-operator/pkg/features"
"github.com/pingcap/tidb-operator/pkg/manager"
"github.com/pingcap/tidb-operator/pkg/manager/member"
"github.com/pingcap/tidb-operator/pkg/manager/volumes"
Expand Down Expand Up @@ -283,11 +282,9 @@ func (c *defaultTidbClusterControl) updateTidbCluster(tc *v1alpha1.TidbCluster)
}

// modify volumes if necessary
if features.DefaultFeatureGate.Enabled(features.VolumeModifying) {
if err := c.pvcModifier.Sync(tc); err != nil {
metrics.ClusterUpdateErrors.WithLabelValues(ns, tcName, "pvc_modifier").Inc()
return err
}
if err := c.pvcModifier.Sync(tc); err != nil {
metrics.ClusterUpdateErrors.WithLabelValues(ns, tcName, "pvc_modifier").Inc()
return err
}

// syncing the some tidbcluster status attributes
Expand Down
1 change: 1 addition & 0 deletions pkg/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const (
AutoScaling string = "AutoScaling"

// VolumeModifying controls whether allow to modify volumes
// NOTE: volume resize is always allowed even if this feature is disabled
VolumeModifying string = "VolumeModifying"
)

Expand Down
15 changes: 6 additions & 9 deletions pkg/manager/member/tikv_upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
"github.com/pingcap/tidb-operator/pkg/controller"
"github.com/pingcap/tidb-operator/pkg/features"
mngerutils "github.com/pingcap/tidb-operator/pkg/manager/utils"
"github.com/pingcap/tidb-operator/pkg/manager/volumes"
"github.com/pingcap/tidb-operator/pkg/pdapi"
Expand Down Expand Up @@ -211,14 +210,12 @@ func (u *tikvUpgrader) upgradeTiKVPod(tc *v1alpha1.TidbCluster, ordinal int32, n
return controller.RequeueErrorf("upgradeTiKVPod: evicting leader of pod %s for tc %s/%s", upgradePodName, ns, tcName)
}

if features.DefaultFeatureGate.Enabled(features.VolumeModifying) {
done, err = u.modifyVolumesBeforeUpgrade(tc, upgradePod)
if err != nil {
return fmt.Errorf("upgradeTiKVPod: failed to modify volumes of pod %s for tc %s/%s, error: %s", upgradePodName, ns, tcName, err)
}
if !done {
return controller.RequeueErrorf("upgradeTiKVPod: modifying volumes of pod %s for tc %s/%s", upgradePodName, ns, tcName)
}
done, err = u.modifyVolumesBeforeUpgrade(tc, upgradePod)
if err != nil {
return fmt.Errorf("upgradeTiKVPod: failed to modify volumes of pod %s for tc %s/%s, error: %s", upgradePodName, ns, tcName, err)
}
if !done {
return controller.RequeueErrorf("upgradeTiKVPod: modifying volumes of pod %s for tc %s/%s", upgradePodName, ns, tcName)
}

mngerutils.SetUpgradePartition(newSet, ordinal)
Expand Down
14 changes: 9 additions & 5 deletions pkg/manager/volumes/pod_vol_modifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
"github.com/pingcap/tidb-operator/pkg/controller"
"github.com/pingcap/tidb-operator/pkg/features"
"github.com/pingcap/tidb-operator/pkg/manager/volumes/delegation"
"github.com/pingcap/tidb-operator/pkg/manager/volumes/delegation/aws"
)
Expand Down Expand Up @@ -90,12 +91,15 @@ type podVolModifier struct {
}

func NewPodVolumeModifier(deps *controller.Dependencies) PodVolumeModifier {
return &podVolModifier{
deps: deps,
modifiers: map[string]delegation.VolumeModifier{
"ebs.csi.aws.com": aws.NewEBSModifier(deps.AWSConfig),
},
m := &podVolModifier{
deps: deps,
modifiers: map[string]delegation.VolumeModifier{},
}
if features.DefaultFeatureGate.Enabled(features.VolumeModifying) {
m.modifiers["ebs.csi.aws.com"] = aws.NewEBSModifier(deps.AWSConfig)
}

return m
}

func (p *podVolModifier) ShouldModify(actual []ActualVolume) bool {
Expand Down

0 comments on commit 4267553

Please sign in to comment.