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

check to see if the volumeName is empty before the sync pv labels #177

Merged
merged 1 commit into from
Nov 13, 2018
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
3 changes: 3 additions & 0 deletions pkg/manager/meta/meta_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ func (pmm *metaManager) Sync(tc *v1alpha1.TidbCluster) error {
if err != nil {
return err
}
if pvc.Spec.VolumeName == "" {
continue
}
// update meta info for pv
pv, err := pmm.pvLister.Get(pvc.Spec.VolumeName)
if err != nil {
Expand Down
316 changes: 173 additions & 143 deletions pkg/manager/meta/meta_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,20 @@ import (
func TestMetaManagerSync(t *testing.T) {
g := NewGomegaWithT(t)
type testcase struct {
name string
podHasLabels bool
pvcHasLabels bool
podRefPvc bool
podUpdateErr bool
getClusterErr bool
getMemberErr bool
getStoreErr bool
pvcUpdateErr bool
pvUpdateErr bool
podChanged bool
pvcChanged bool
pvChanged bool
name string
podHasLabels bool
pvcHasLabels bool
pvcHasVolumeName bool
podRefPvc bool
podUpdateErr bool
getClusterErr bool
getMemberErr bool
getStoreErr bool
pvcUpdateErr bool
pvUpdateErr bool
podChanged bool
pvcChanged bool
pvChanged bool
}

testFn := func(test *testcase, t *testing.T) {
Expand All @@ -63,6 +64,9 @@ func TestMetaManagerSync(t *testing.T) {
if !test.pvcHasLabels {
pvc1.Labels = nil
}
if !test.pvcHasVolumeName {
pvc1.Spec.VolumeName = ""
}

if !test.podRefPvc {
pod1.Spec = newPodSpec(v1alpha1.TiDBMemberType.String(), pvc1.GetName())
Expand Down Expand Up @@ -166,154 +170,180 @@ func TestMetaManagerSync(t *testing.T) {

tests := []testcase{
{
name: "normal",
podHasLabels: true,
pvcHasLabels: true,
podRefPvc: true,
podUpdateErr: false,
getClusterErr: false,
getMemberErr: false,
getStoreErr: false,
pvcUpdateErr: false,
pvUpdateErr: false,
podChanged: true,
pvcChanged: true,
pvChanged: true,
name: "normal",
podHasLabels: true,
pvcHasLabels: true,
pvcHasVolumeName: true,
podRefPvc: true,
podUpdateErr: false,
getClusterErr: false,
getMemberErr: false,
getStoreErr: false,
pvcUpdateErr: false,
pvUpdateErr: false,
podChanged: true,
pvcChanged: true,
pvChanged: true,
},
{
name: "pod don't have labels",
podHasLabels: false,
pvcHasLabels: true,
pvcHasVolumeName: true,
podRefPvc: true,
podUpdateErr: false,
getClusterErr: false,
getMemberErr: false,
getStoreErr: false,
pvcUpdateErr: false,
pvUpdateErr: false,
podChanged: false,
pvcChanged: false,
pvChanged: false,
},
{
name: "pod don't have labels",
podHasLabels: false,
pvcHasLabels: true,
podRefPvc: true,
podUpdateErr: false,
getClusterErr: false,
getMemberErr: false,
getStoreErr: false,
pvcUpdateErr: false,
pvUpdateErr: false,
podChanged: false,
pvcChanged: false,
pvChanged: false,
name: "pvc don't have labels",
podHasLabels: true,
pvcHasLabels: false,
pvcHasVolumeName: true,
podRefPvc: true,
podUpdateErr: false,
getClusterErr: false,
getMemberErr: false,
getStoreErr: false,
pvcUpdateErr: false,
pvUpdateErr: false,
podChanged: true,
pvcChanged: true,
pvChanged: true,
},
{
name: "pvc don't have labels",
podHasLabels: true,
pvcHasLabels: false,
podRefPvc: true,
podUpdateErr: false,
getClusterErr: false,
getMemberErr: false,
getStoreErr: false,
pvcUpdateErr: false,
pvUpdateErr: false,
podChanged: true,
pvcChanged: true,
pvChanged: true,
name: "pvc don't have volumeName",
podHasLabels: true,
pvcHasLabels: false,
pvcHasVolumeName: false,
podRefPvc: true,
podUpdateErr: false,
getClusterErr: false,
getMemberErr: false,
getStoreErr: false,
pvcUpdateErr: false,
pvUpdateErr: false,
podChanged: true,
pvcChanged: true,
pvChanged: false,
},
{
name: "the volume name of the pod is not tikv and pd",
podHasLabels: true,
pvcHasLabels: true,
podRefPvc: false,
podUpdateErr: false,
getClusterErr: false,
getMemberErr: false,
getStoreErr: false,
pvcUpdateErr: false,
pvUpdateErr: false,
podChanged: true,
pvcChanged: false,
pvChanged: false,
name: "the volume name of the pod is not tikv and pd",
podHasLabels: true,
pvcHasLabels: true,
pvcHasVolumeName: true,
podRefPvc: false,
podUpdateErr: false,
getClusterErr: false,
getMemberErr: false,
getStoreErr: false,
pvcUpdateErr: false,
pvUpdateErr: false,
podChanged: true,
pvcChanged: false,
pvChanged: false,
},
{
name: "pod update failed",
podHasLabels: true,
pvcHasLabels: true,
podRefPvc: true,
podUpdateErr: true,
getClusterErr: false,
getMemberErr: false,
getStoreErr: false,
pvcUpdateErr: false,
pvUpdateErr: false,
podChanged: false,
pvcChanged: false,
pvChanged: false,
name: "pod update failed",
podHasLabels: true,
pvcHasLabels: true,
pvcHasVolumeName: true,
podRefPvc: true,
podUpdateErr: true,
getClusterErr: false,
getMemberErr: false,
getStoreErr: false,
pvcUpdateErr: false,
pvUpdateErr: false,
podChanged: false,
pvcChanged: false,
pvChanged: false,
},
{
name: "get cluster ID from PD failed",
podHasLabels: true,
pvcHasLabels: true,
podRefPvc: true,
podUpdateErr: false,
getClusterErr: true,
getMemberErr: false,
getStoreErr: false,
pvcUpdateErr: false,
pvUpdateErr: false,
podChanged: false,
pvcChanged: false,
pvChanged: false,
name: "get cluster ID from PD failed",
podHasLabels: true,
pvcHasLabels: true,
pvcHasVolumeName: true,
podRefPvc: true,
podUpdateErr: false,
getClusterErr: true,
getMemberErr: false,
getStoreErr: false,
pvcUpdateErr: false,
pvUpdateErr: false,
podChanged: false,
pvcChanged: false,
pvChanged: false,
},
{
name: "get member ID from PD failed",
podHasLabels: true,
pvcHasLabels: true,
podRefPvc: true,
podUpdateErr: false,
getClusterErr: false,
getMemberErr: true,
getStoreErr: false,
pvcUpdateErr: false,
pvUpdateErr: false,
podChanged: false,
pvcChanged: false,
pvChanged: false,
name: "get member ID from PD failed",
podHasLabels: true,
pvcHasLabels: true,
pvcHasVolumeName: true,
podRefPvc: true,
podUpdateErr: false,
getClusterErr: false,
getMemberErr: true,
getStoreErr: false,
pvcUpdateErr: false,
pvUpdateErr: false,
podChanged: false,
pvcChanged: false,
pvChanged: false,
},
{
name: "get store ID from PD failed",
podHasLabels: true,
pvcHasLabels: true,
podRefPvc: true,
podUpdateErr: false,
getClusterErr: false,
getMemberErr: false,
getStoreErr: true,
pvcUpdateErr: false,
pvUpdateErr: false,
podChanged: false,
pvcChanged: false,
pvChanged: false,
name: "get store ID from PD failed",
podHasLabels: true,
pvcHasLabels: true,
pvcHasVolumeName: true,
podRefPvc: true,
podUpdateErr: false,
getClusterErr: false,
getMemberErr: false,
getStoreErr: true,
pvcUpdateErr: false,
pvUpdateErr: false,
podChanged: false,
pvcChanged: false,
pvChanged: false,
},
{
name: "pvc update failed",
podHasLabels: true,
pvcHasLabels: true,
podRefPvc: true,
podUpdateErr: false,
getClusterErr: false,
getMemberErr: false,
getStoreErr: false,
pvcUpdateErr: true,
pvUpdateErr: false,
podChanged: true,
pvcChanged: false,
pvChanged: false,
name: "pvc update failed",
podHasLabels: true,
pvcHasLabels: true,
pvcHasVolumeName: true,
podRefPvc: true,
podUpdateErr: false,
getClusterErr: false,
getMemberErr: false,
getStoreErr: false,
pvcUpdateErr: true,
pvUpdateErr: false,
podChanged: true,
pvcChanged: false,
pvChanged: false,
},
{
name: "pv update failed",
podHasLabels: true,
pvcHasLabels: true,
podRefPvc: true,
podUpdateErr: false,
getClusterErr: false,
getMemberErr: false,
getStoreErr: false,
pvcUpdateErr: false,
pvUpdateErr: true,
podChanged: true,
pvcChanged: true,
pvChanged: false,
name: "pv update failed",
podHasLabels: true,
pvcHasLabels: true,
pvcHasVolumeName: true,
podRefPvc: true,
podUpdateErr: false,
getClusterErr: false,
getMemberErr: false,
getStoreErr: false,
pvcUpdateErr: false,
pvUpdateErr: true,
podChanged: true,
pvcChanged: true,
pvChanged: false,
},
}

Expand Down