Skip to content

Commit

Permalink
patch review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Haleygo committed Sep 22, 2023
1 parent 55fb719 commit 2ba0d8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
23 changes: 10 additions & 13 deletions controllers/factory/k8stools/expansion.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"
"time"

"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
victoriametricsv1beta1 "github.com/VictoriaMetrics/operator/api/v1beta1"
"github.com/VictoriaMetrics/operator/internal/config"
"github.com/go-test/deep"
Expand Down Expand Up @@ -152,26 +151,24 @@ func growSTSPVC(ctx context.Context, rclient client.Client, sts *appsv1.Stateful
return err
}
if len(pvcs.Items) == 0 {
log.Info("PVCs select call returned 0 pvcs, it could be a bug, want match %v in namespace %s", sts.Spec.Selector.MatchLabels, sts.Namespace)
return nil
return fmt.Errorf("got 0 pvcs under %s for selector %v, statefulset could not be working", sts.Namespace, sts.Spec.Selector.MatchLabels)
}
for _, pvc := range pvcs.Items {
var isExist bool
// check if storage class is expandable
isExpandable, err := isStorageClassExpandable(ctx, rclient, &pvc)
if err != nil {
return fmt.Errorf("failed to check storageClass expandability for pvc %s: %v", pvc.Name, err)
}
if !isExpandable {
return fmt.Errorf("want to expand pvc %s but storageClass doesn't support it, need to handle this case manually", pvc.Name)
}
for _, tpvc := range targetPVCs {
if strings.HasPrefix(pvc.Name, fmt.Sprintf("%s-%s", tpvc.Name, sts.Name)) {
isExist = true
// check if storage class is expandable
isExpandable, err := isStorageClassExpandable(ctx, rclient, &pvc)
if err != nil {
logger.Errorf("failed to check storageClass expandability for pvc %s: %v", pvc.Name, err)
break
}
if !isExpandable {
log.Info("want to expand pvc %s but storageClass doesn't support it, need to handle this case manually", pvc.Name)
}
err = growPVCs(ctx, rclient, tpvc.Spec.Resources.Requests.Storage(), &pvc)
if err != nil {
logger.Errorf("failed to expand size for pvc %s: %v", pvc.Name, err)
return fmt.Errorf("failed to expand size for pvc %s: %v", pvc.Name, err)
}
break
}
Expand Down
3 changes: 2 additions & 1 deletion controllers/factory/k8stools/expansion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func Test_growSTSPVC(t *testing.T) {
},
},
{
name: "expand failed",
name: "failed with non-expandable sc",
args: args{
ctx: context.TODO(),
sts: &appsv1.StatefulSet{
Expand Down Expand Up @@ -404,6 +404,7 @@ func Test_growSTSPVC(t *testing.T) {
},
},
},
wantErr: true,
},
{
name: "expand with named class",
Expand Down

0 comments on commit 2ba0d8f

Please sign in to comment.