Skip to content

Commit

Permalink
Feat: support modifying volume's attributes (pingcap#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
fgksgf authored Oct 23, 2024
1 parent fe0c7c2 commit e337f1e
Show file tree
Hide file tree
Showing 29 changed files with 1,730 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
pull_request:
branches:
- main
types: [review_requested, ready_for_review, synchronize]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
branches:
- main
types: [review_requested, ready_for_review, synchronize]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand Down
3 changes: 3 additions & 0 deletions apis/core/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ type Volume struct {
Storage resource.Quantity `json:"storage"`

// StorageClassName means the storage class the volume used.
// You can modify volumes' attributes by changing the StorageClass
// when VolumeAttributesClass is not available.
// Note that only newly created PV will use the new StorageClass.
StorageClassName *string `json:"storageClassName,omitempty"`
}

Expand Down
3 changes: 3 additions & 0 deletions apis/core/v1alpha1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
// +kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=core,resources=persistentvolumeclaims,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=core,resources=persistentvolumes,verbs=get;list;watch
// +kubebuilder:rbac:groups=core,resources=services,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=core,resources=events,verbs=get;list;watch;create;update;patch;delete
Expand All @@ -14,6 +15,8 @@
//
// +kubebuilder:rbac:groups=apps,resources=controllerrevisions,verbs=get;list;watch;create;update;patch;delete
//
// +kubebuilder:rbac:groups=storage.k8s.io,resources=storageclasses,verbs=get;list;watch
//
// +kubebuilder:rbac:groups=core.pingcap.com,resources=clusters,verbs=get;list;watch;update
// +kubebuilder:rbac:groups=core.pingcap.com,resources=clusters/status,verbs=get;update;patch
//
Expand Down
7 changes: 7 additions & 0 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"go.uber.org/zap/zapcore"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/labels"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
_ "k8s.io/client-go/plugin/pkg/client/auth"
Expand Down Expand Up @@ -129,6 +130,12 @@ func main() {
Label: labels.Everything(),
},
&appsv1.ControllerRevision{}: {},
&corev1.PersistentVolume{}: {
Label: labels.Everything(),
},
&storagev1.StorageClass{}: {
Label: labels.Everything(),
},
},
DefaultLabelSelector: labels.SelectorFromSet(labels.Set{
v1alpha1.LabelKeyManagedBy: v1alpha1.LabelValManagedByOperator,
Expand Down
16 changes: 15 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ toolchain go1.22.3

require (
github.com/Masterminds/semver/v3 v3.3.0
github.com/aws/aws-sdk-go-v2 v1.30.5
github.com/aws/aws-sdk-go-v2/config v1.27.35
github.com/aws/aws-sdk-go-v2/service/ec2 v1.177.3
github.com/aws/smithy-go v1.20.4
github.com/docker/go-units v0.5.0
github.com/evanphx/json-patch v4.12.0+incompatible
github.com/go-logr/logr v1.4.2
Expand All @@ -28,6 +32,7 @@ require (
k8s.io/cli-runtime v0.31.0
k8s.io/client-go v0.31.0
k8s.io/code-generator v0.31.0
k8s.io/klog/v2 v2.130.1
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340
k8s.io/kubectl v0.31.0
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
Expand All @@ -43,6 +48,16 @@ require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.33 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.13 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.19 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.22.8 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.8 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.30.8 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
Expand Down Expand Up @@ -125,7 +140,6 @@ require (
k8s.io/apiextensions-apiserver v0.31.0 // indirect
k8s.io/component-base v0.31.0 // indirect
k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.17.2 // indirect
sigs.k8s.io/kustomize/kyaml v0.17.1 // indirect
Expand Down
28 changes: 28 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,34 @@ github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/aws/aws-sdk-go-v2 v1.30.5 h1:mWSRTwQAb0aLE17dSzztCVJWI9+cRMgqebndjwDyK0g=
github.com/aws/aws-sdk-go-v2 v1.30.5/go.mod h1:CT+ZPWXbYrci8chcARI3OmI/qgd+f6WtuLOoaIA8PR0=
github.com/aws/aws-sdk-go-v2/config v1.27.35 h1:jeFgiWYNV0vrgdZqB4kZBjYNdy0IKkwrAjr2fwpHIig=
github.com/aws/aws-sdk-go-v2/config v1.27.35/go.mod h1:qnpEvTq8ZfjrCqmJGRfWZuF+lGZ/vG8LK2K0L/TY1gQ=
github.com/aws/aws-sdk-go-v2/credentials v1.17.33 h1:lBHAQQznENv0gLHAZ73ONiTSkCtr8q3pSqWrpbBBZz0=
github.com/aws/aws-sdk-go-v2/credentials v1.17.33/go.mod h1:MBuqCUOT3ChfLuxNDGyra67eskx7ge9e3YKYBce7wpI=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.13 h1:pfQ2sqNpMVK6xz2RbqLEL0GH87JOwSxPV2rzm8Zsb74=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.13/go.mod h1:NG7RXPUlqfsCLLFfi0+IpKN4sCB9D9fw/qTaSB+xRoU=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17 h1:pI7Bzt0BJtYA0N/JEC6B8fJ4RBrEMi1LBrkMdFYNSnQ=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17/go.mod h1:Dh5zzJYMtxfIjYW+/evjQ8uj2OyR/ve2KROHGHlSFqE=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17 h1:Mqr/V5gvrhA2gvgnF42Zh5iMiQNcOYthFYwCyrnuWlc=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17/go.mod h1:aLJpZlCmjE+V+KtN1q1uyZkfnUWpQGpbsn89XPKyzfU=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvKgqdiXoTxAF4HQcQ=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.177.3 h1:dqdCh1M8h+j8OGNUpxTs7eBPFr6lOdLpdlE6IPLLSq4=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.177.3/go.mod h1:TFSALWR7Xs7+KyMM87ZAYxncKFBvzEt2rpK/BJCH2ps=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.4 h1:KypMCbLPPHEmf9DgMGw51jMj77VfGPAN2Kv4cfhlfgI=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.4/go.mod h1:Vz1JQXliGcQktFTN/LN6uGppAIRoLBR2bMvIMP0gOjc=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.19 h1:rfprUlsdzgl7ZL2KlXiUAoJnI/VxfHCvDFr2QDFj6u4=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.19/go.mod h1:SCWkEdRq8/7EK60NcvvQ6NXKuTcchAD4ROAsC37VEZE=
github.com/aws/aws-sdk-go-v2/service/sso v1.22.8 h1:JRwuL+S1Qe1owZQoxblV7ORgRf2o0SrtzDVIbaVCdQ0=
github.com/aws/aws-sdk-go-v2/service/sso v1.22.8/go.mod h1:eEygMHnTKH/3kNp9Jr1n3PdejuSNcgwLe1dWgQtO0VQ=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.8 h1:+HpGETD9463PFSj7lX5+eq7aLDs85QUIA+NBkeAsscA=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.8/go.mod h1:bCbAxKDqNvkHxRaIMnyVPXPo+OaPRwvmgzMxbz1VKSA=
github.com/aws/aws-sdk-go-v2/service/sts v1.30.8 h1:bAi+4p5EKnni+jrfcAhb7iHFQ24bthOAV9t0taf3DCE=
github.com/aws/aws-sdk-go-v2/service/sts v1.30.8/go.mod h1:NXi1dIAGteSaRLqYgarlhP/Ij0cFT+qmCwiJqWh/U5o=
github.com/aws/smithy-go v1.20.4 h1:2HK1zBdPgRbjFOHlfeQZfpC4r72MOb9bZkiFwggKO+4=
github.com/aws/smithy-go v1.20.4/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
Expand Down
7 changes: 5 additions & 2 deletions manifests/crd/core.pingcap.com_pdgroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8654,8 +8654,11 @@ spec:
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
storageClassName:
description: StorageClassName means the storage class
the volume used.
description: |-
StorageClassName means the storage class the volume used.
You can modify volumes' attributes by changing the StorageClass
when VolumeAttributesClass is not available.
Note that only newly created PV will use the new StorageClass.
type: string
required:
- for
Expand Down
7 changes: 5 additions & 2 deletions manifests/crd/core.pingcap.com_pds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8435,8 +8435,11 @@ spec:
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
storageClassName:
description: StorageClassName means the storage class the volume
used.
description: |-
StorageClassName means the storage class the volume used.
You can modify volumes' attributes by changing the StorageClass
when VolumeAttributesClass is not available.
Note that only newly created PV will use the new StorageClass.
type: string
required:
- for
Expand Down
7 changes: 5 additions & 2 deletions manifests/crd/core.pingcap.com_tidbgroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8670,8 +8670,11 @@ spec:
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
storageClassName:
description: StorageClassName means the storage class
the volume used.
description: |-
StorageClassName means the storage class the volume used.
You can modify volumes' attributes by changing the StorageClass
when VolumeAttributesClass is not available.
Note that only newly created PV will use the new StorageClass.
type: string
required:
- for
Expand Down
7 changes: 5 additions & 2 deletions manifests/crd/core.pingcap.com_tidbs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8423,8 +8423,11 @@ spec:
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
storageClassName:
description: StorageClassName means the storage class the volume
used.
description: |-
StorageClassName means the storage class the volume used.
You can modify volumes' attributes by changing the StorageClass
when VolumeAttributesClass is not available.
Note that only newly created PV will use the new StorageClass.
type: string
required:
- for
Expand Down
7 changes: 5 additions & 2 deletions manifests/crd/core.pingcap.com_tiflashes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8451,8 +8451,11 @@ spec:
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
storageClassName:
description: StorageClassName means the storage class the volume
used.
description: |-
StorageClassName means the storage class the volume used.
You can modify volumes' attributes by changing the StorageClass
when VolumeAttributesClass is not available.
Note that only newly created PV will use the new StorageClass.
type: string
required:
- for
Expand Down
7 changes: 5 additions & 2 deletions manifests/crd/core.pingcap.com_tiflashgroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8658,8 +8658,11 @@ spec:
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
storageClassName:
description: StorageClassName means the storage class
the volume used.
description: |-
StorageClassName means the storage class the volume used.
You can modify volumes' attributes by changing the StorageClass
when VolumeAttributesClass is not available.
Note that only newly created PV will use the new StorageClass.
type: string
required:
- for
Expand Down
7 changes: 5 additions & 2 deletions manifests/crd/core.pingcap.com_tikvgroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8643,8 +8643,11 @@ spec:
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
storageClassName:
description: StorageClassName means the storage class
the volume used.
description: |-
StorageClassName means the storage class the volume used.
You can modify volumes' attributes by changing the StorageClass
when VolumeAttributesClass is not available.
Note that only newly created PV will use the new StorageClass.
type: string
required:
- for
Expand Down
7 changes: 5 additions & 2 deletions manifests/crd/core.pingcap.com_tikvs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8430,8 +8430,11 @@ spec:
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
storageClassName:
description: StorageClassName means the storage class the volume
used.
description: |-
StorageClassName means the storage class the volume used.
You can modify volumes' attributes by changing the StorageClass
when VolumeAttributesClass is not available.
Note that only newly created PV will use the new StorageClass.
type: string
required:
- for
Expand Down
9 changes: 9 additions & 0 deletions manifests/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ rules:
- ""
resources:
- nodes
- persistentvolumes
- secrets
verbs:
- get
Expand Down Expand Up @@ -115,3 +116,11 @@ rules:
- patch
- update
- watch
- apiGroups:
- storage.k8s.io
resources:
- storageclasses
verbs:
- get
- list
- watch
2 changes: 1 addition & 1 deletion pkg/client/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func (c *fakeUnderlayClient) Get(ctx context.Context, key client.ObjectKey, obj
if namespaced {
action = testing.NewGetAction(mapping.Resource, key.Namespace, key.Name)
} else {
action = testing.NewRootGetAction(mapping.Resource, key.Namespace)
action = testing.NewRootGetAction(mapping.Resource, key.Name)
}

newObj, err := c.Invokes(action, nil)
Expand Down
12 changes: 12 additions & 0 deletions pkg/controllers/tikv/tasks/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"strconv"

"github.com/aws/aws-sdk-go-v2/config"
"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -15,6 +16,8 @@ import (
pdv1 "github.com/pingcap/tidb-operator/pkg/timanager/apis/pd/v1"
pdm "github.com/pingcap/tidb-operator/pkg/timanager/pd"
"github.com/pingcap/tidb-operator/pkg/utils/task"
"github.com/pingcap/tidb-operator/pkg/volumes"
"github.com/pingcap/tidb-operator/pkg/volumes/cloud/aws"
)

type ReconcileContext struct {
Expand Down Expand Up @@ -44,6 +47,8 @@ type ReconcileContext struct {
// Since the config map's name is the same as the tidb's name,
// we use this variable to decide whether to recreate pods.
ConfigChanged bool

VolumeModifier volumes.Modifier
}

func (ctx *ReconcileContext) Self() *ReconcileContext {
Expand Down Expand Up @@ -123,6 +128,13 @@ func (t *TaskContext) Sync(ctx task.Context[ReconcileContext]) task.Result {
return task.Complete().With("tikv is suspended")
}

cfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
t.Logger.Error(err, "failed to load aws config")
} else {
rtx.VolumeModifier = volumes.NewRawModifier(aws.NewEBSModifier(cfg, t.Logger), t.Client, t.Logger)
}

c, ok := t.PDClientManager.Get(pdm.PrimaryKey(cluster.Namespace, cluster.Name))
if !ok {
return task.Fail().With("pd client is not registered")
Expand Down
48 changes: 41 additions & 7 deletions pkg/controllers/tikv/tasks/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,57 @@ func (t *TaskPVC) Sync(ctx task.Context[ReconcileContext]) task.Result {
rtx := ctx.Self()

if rtx.Cluster.ShouldSuspendCompute() {
return task.Complete().With("skip pvc for suspension")
return task.Complete().With("skip expectPVC for suspension")
}

pvcs := newPVCs(rtx.TiKV)
for _, pvc := range pvcs {
if err := t.Client.Apply(rtx, pvc); err != nil {
return task.Fail().With("can't apply pvc %s of pd: %v", pvc.Name, err)
for _, expectPVC := range pvcs {
var actualPVC corev1.PersistentVolumeClaim
if err := t.Client.Get(rtx, client.ObjectKey{
Namespace: expectPVC.Namespace,
Name: expectPVC.Name,
}, &actualPVC); err != nil {
if client.IgnoreNotFound(err) != nil {
return task.Fail().With("can't get expectPVC %s/%s of tikv: %v", expectPVC.Namespace, expectPVC.Name, err)
}

// Create PVC
if e := t.Client.Apply(rtx, expectPVC); e != nil {
return task.Fail().With("can't create expectPVC %s/%s of tikv: %v", expectPVC.Namespace, expectPVC.Name, e)
}
continue
}
}

// TODO: check config updation
// Set default storage class name if it's not specified and the claim is bound.
if expectPVC.Spec.StorageClassName == nil && actualPVC.Status.Phase == corev1.ClaimBound {
expectPVC.Spec.StorageClassName = actualPVC.Spec.StorageClassName
}
vol, err := rtx.VolumeModifier.GetActualVolume(ctx, expectPVC, &actualPVC)
if err != nil {
return task.Fail().Continue().With("failed to get actual volume %s/%s: %v", expectPVC.Namespace, expectPVC.Name, err)
}
if rtx.VolumeModifier.ShouldModify(ctx, vol) {
t.Logger.Info("modifying volume's attributes", "expectPVC", expectPVC.Name)
if e := rtx.VolumeModifier.Modify(ctx, vol); e != nil {
return task.Fail().Continue().With("failed to modify volume's attributes %s/%s: %v", expectPVC.Namespace, expectPVC.Name, e)
}
} else {
if expectPVC.Spec.StorageClassName != nil && actualPVC.Spec.StorageClassName != nil && *expectPVC.Spec.StorageClassName != *actualPVC.Spec.StorageClassName {
// Avoid updating the storage class name as it's immutable.
expectPVC.Spec.StorageClassName = actualPVC.Spec.StorageClassName
}

if err := t.Client.Apply(rtx, expectPVC); err != nil {
return task.Fail().With("can't update expectPVC %s/%s of tikv: %v", expectPVC.Namespace, expectPVC.Name, err)
}
}
}

return task.Complete().With("pvcs are synced")
}

func newPVCs(tikv *v1alpha1.TiKV) []*corev1.PersistentVolumeClaim {
pvcs := []*corev1.PersistentVolumeClaim{}
var pvcs []*corev1.PersistentVolumeClaim
for _, vol := range tikv.Spec.Volumes {
pvcs = append(pvcs, &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Expand Down
Loading

0 comments on commit e337f1e

Please sign in to comment.