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

Fix labelselector error in reclaimPolicyManager #2707

Merged
merged 3 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 10 additions & 2 deletions pkg/controller/pv_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,17 @@ func (rpc *realPVControl) PatchPVReclaimPolicy(obj runtime.Object, pv *corev1.Pe

name := metaObj.GetName()
pvName := pv.GetName()
patchBytes := []byte(fmt.Sprintf(`{"spec":{"persistentVolumeReclaimPolicy":"%s"}}`, reclaimPolicy))

err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
latestPV, err := rpc.kubeCli.CoreV1().PersistentVolumes().Get(pvName, metav1.GetOptions{})
if err != nil {
return err
}
if string(latestPV.Spec.PersistentVolumeReclaimPolicy) == string(reclaimPolicy) {
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't check here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

patchBytes := []byte(fmt.Sprintf(`{"spec":{"persistentVolumeReclaimPolicy":"%s"}}`, reclaimPolicy))

err = retry.RetryOnConflict(retry.DefaultBackoff, func() error {
_, err := rpc.kubeCli.CoreV1().PersistentVolumes().Patch(pvName, types.StrategicMergePatchType, patchBytes)
return err
})
Expand Down
28 changes: 22 additions & 6 deletions pkg/manager/meta/reclaim_policy_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
package meta

import (
"fmt"

"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
"github.com/pingcap/tidb-operator/pkg/controller"
"github.com/pingcap/tidb-operator/pkg/label"
"github.com/pingcap/tidb-operator/pkg/manager"
"github.com/pingcap/tidb-operator/pkg/monitor"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
corelisters "k8s.io/client-go/listers/core/v1"
)
Expand Down Expand Up @@ -53,18 +56,31 @@ func NewReclaimPolicyMonitorManager(pvcLister corelisters.PersistentVolumeClaimL
}

func (rpm *reclaimPolicyManager) Sync(tc *v1alpha1.TidbCluster) error {
return rpm.sync(tc.GetNamespace(), tc.GetInstanceName(), tc.IsPVReclaimEnabled(), tc.Spec.PVReclaimPolicy, tc)
return rpm.sync(v1alpha1.TiDBClusterKind, tc.GetNamespace(), tc.GetInstanceName(), tc.IsPVReclaimEnabled(), tc.Spec.PVReclaimPolicy, tc)
}

func (rpm *reclaimPolicyManager) SyncMonitor(tm *v1alpha1.TidbMonitor) error {
return rpm.sync(tm.GetNamespace(), tm.GetName(), false, tm.Spec.PVReclaimPolicy, tm)
return rpm.sync(v1alpha1.TiDBMonitorKind, tm.GetNamespace(), tm.GetName(), false, tm.Spec.PVReclaimPolicy, tm)
}

func (rpm *reclaimPolicyManager) sync(ns, instanceName string, isPVReclaimEnabled bool, policy corev1.PersistentVolumeReclaimPolicy, obj runtime.Object) error {
l, err := label.New().Instance(instanceName).Selector()
if err != nil {
return err
func (rpm *reclaimPolicyManager) sync(kind, ns, instanceName string, isPVReclaimEnabled bool, policy corev1.PersistentVolumeReclaimPolicy, obj runtime.Object) error {
var l labels.Selector
var err error
switch kind {
case v1alpha1.TiDBMonitorKind:
l, err = label.NewMonitor().Instance(instanceName).Monitor().Selector()
if err != nil {
return err
}
case v1alpha1.TiDBClusterKind:
l, err = label.New().Instance(instanceName).Selector()
if err != nil {
return err
}
default:
return fmt.Errorf("unknown kind = %s", kind)
}

pvcs, err := rpm.pvcLister.PersistentVolumeClaims(ns).List(l)
if err != nil {
return err
Expand Down