-
Notifications
You must be signed in to change notification settings - Fork 22
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
Resizing PVC #403
Resizing PVC #403
Conversation
4ef2717
to
35ea861
Compare
controllers/resize_pvc.go
Outdated
pvcac := corev1ac.PersistentVolumeClaim(pvc.Name, pvc.Namespace). | ||
WithSpec(corev1ac.PersistentVolumeClaimSpec(). | ||
WithResources(corev1ac.ResourceRequirements(). | ||
WithRequests(corev1.ResourceList{corev1.ResourceStorage: *newSize}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there possibility that the current size is already bigger than the new size?
For example, with the help of pvc-autoresizer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late reply, I have created a design document to discuss the specifications
Please review 🙏
#412
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@d-kuro Thank you for the document. LGTM.
20273d6
to
87b3539
Compare
@d-kuro Could you extend the scope of the original issue to include cases where users might edit metadata of volumeClaimTemplates? |
@ymmt2005 |
Signed-off-by: d-kuro <[email protected]>
Signed-off-by: d-kuro <[email protected]>
Signed-off-by: d-kuro <[email protected]>
Signed-off-by: d-kuro <[email protected]>
Signed-off-by: d-kuro <[email protected]>
Signed-off-by: d-kuro <[email protected]>
Signed-off-by: d-kuro <[email protected]>
Signed-off-by: d-kuro <[email protected]>
Signed-off-by: d-kuro <[email protected]>
opt := metav1.DeletePropagationOrphan | ||
if err := r.Delete(ctx, &orig, &client.DeleteOptions{ | ||
PropagationPolicy: &opt, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
envtest is not able to test using DeletePropagationOrphan
because kube-controller-manager does not exist.
Will verify when adding the E2E test.
} | ||
} | ||
|
||
func setupMockClient(t *testing.T, cluster *mocov1beta2.MySQLCluster, sts *appsv1.StatefulSet) client.Client { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the env test, controller-manager is not running, so testing with child resources is not possible (e.g. StatefulSet's child PVCs).
Therefore, the mock client is used.
I will add the E2E test later.
Signed-off-by: d-kuro <[email protected]>
Signed-off-by: d-kuro <[email protected]>
controllers/pvc.go
Outdated
return true | ||
} | ||
|
||
if sts.Generation > sts.Status.ObservedGeneration && *sts.Spec.Replicas == sts.Status.Replicas { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you tell me the purpose of this condition(*sts.Spec.Replicas == sts.Status.Replicas
)?
I cannot understand this condition just by reading this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the code that kubectl is doing to determine if the StatefulSet is in the process of updating, and it seems that this condition is incorrect.
I will fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed: 8335537
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the update.
Could you write the URL which links to the referenced code as a comment?
In the original code, sts.Status.ObservedGeneration == 0
is determined to be in updating.
The decision seems to be different from MOCO's. Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I had omitted the Object condition for testing purposes, and it was still there.
Fixed: 8bddef7
controllers/pvc.go
Outdated
|
||
for _, pvc := range cluster.Spec.VolumeClaimTemplates { | ||
if _, ok := pvcSet[pvc.Name]; !ok { | ||
delete(pvcSet, pvc.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This delete
is unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I found another problem, so I fixed it and added a test.
eb8ec57
@@ -242,6 +243,24 @@ func (s MySQLClusterSpec) validateUpdate(old MySQLClusterSpec) field.ErrorList { | |||
allErrs = append(allErrs, field.Forbidden(p, "not editable")) | |||
} | |||
|
|||
oldPVCSet := make(map[string]PersistentVolumeClaim) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you confirm the existance of resources
and resources.requests.storage
in the pvcTemplates?
When the resources
is missing:
apiVersion: moco.cybozu.com/v1beta2
kind: MySQLCluster
...
spec:
...
volumeClaimTemplates:
- metadata:
name: mysql-data
spec:
accessModes: [ "ReadWriteOnce" ]
# resources:
# requests:
# storage: 1Gi
logRotationSchedule: "@every 10s"
The controller will be panic.
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x150f2c2]
goroutine 475 [running]:
github.com/cybozu-go/moco/controllers.(*MySQLClusterReconciler).needResizePVC(0x0, 0xc000367900, 0xc0005cef00)
/work/controllers/pvc.go:159 +0x2e2
github.com/cybozu-go/moco/controllers.(*MySQLClusterReconciler).reconcilePVC(0xc0005ca000, {0x1af42d8, 0xc0002bc450}, {{{0xc000a51a67, 0x0}, {0xc000a51aa0, 0xc000a51aa0}}}, 0xc000367900)
/work/controllers/pvc.go:51 +0x2f0
github.com/cybozu-go/moco/controllers.(*MySQLClusterReconciler).reconcileV1(0xc0005ca000, {0x1af42d8, 0xc0002bc450}, {{{0xc000a51a67, 0xc000a51aa0}, {0xc000a51aa0, 0x1b42ab0}}}, 0xc000367900)
/work/controllers/mysqlcluster_controller.go:233 +0x585
github.com/cybozu-go/moco/controllers.(*MySQLClusterReconciler).Reconcile(0xc0005ca000, {0x1af42d8, 0xc0002bc450}, {{{0xc000a51a67, 0x1791b80}, {0xc000a51aa0, 0x30}}})
/work/controllers/mysqlcluster_controller.go:168 +0x1c7
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile(0xc0004c29a0, {0x1af42d8, 0xc0002bc330}, {{{0xc000a51a67, 0x1791b80}, {0xc000a51aa0, 0x413974}}})
/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:114 +0x26f
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler(0xc0004c29a0, {0x1af4230, 0xc0005aa0c0}, {0x16ce7e0, 0xc000acaf40})
/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:311 +0x33e
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem(0xc0004c29a0, {0x1af4230, 0xc0005aa0c0})
/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:266 +0x205
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2()
/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:227 +0x85
created by sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2
/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:223 +0x357
When the resources.requests.storage
is missing:
volumeClaimTemplates:
- metadata:
name: mysql-data
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storoge: 1Gi # typo
The StatefulSet controller cannot create PVC.
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedCreate 29s (x12 over 40s) statefulset-controller create Pod moco-test-0 in StatefulSet moco-test failed error: failed to create PVC mysql-data-moco-test-0: PersistentVolumeClaim "mysql-data-moco-test-0" is invalid: spec.resources[storage]: Required value
Warning FailedCreate 19s (x13 over 40s) statefulset-controller create Claim mysql-data-moco-test-0 for Pod moco-test-0 in StatefulSet moco-test failed error: PersistentVolumeClaim "mysql-data-moco-test-0" is invalid: spec.resources[storage]: Required value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed validation webhook to validate storage size.
a6de68a
Signed-off-by: d-kuro <[email protected]>
Signed-off-by: d-kuro <[email protected]>
Signed-off-by: d-kuro <[email protected]>
4e86677
to
5ee1909
Compare
Signed-off-by: d-kuro <[email protected]>
5ee1909
to
0a1fc69
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late replay. Please respond #403 (comment).
Other than it, it's fine.
Signed-off-by: d-kuro <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
refs: #265
Add enhancement to support applying PVC template changes to StatefulSet.
See #412 for design docs.
This PR implements the core functionality, but the following elements are done in a separate pull request
Manually tested before adding E2E test: