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

Add resize volume functionality to Logstash operator #7519

Merged
merged 19 commits into from
Feb 5, 2024

Conversation

robbavey
Copy link
Member

This commit adds support for expanding Logstash volumes by editing the storage requests
in spec.VolumeClaimTemplate, based on the existing implenentation in Elasticsearch
implemented in #3752.

The same constraints hold -

  • Volume size can only be increased, not decreased
  • Storage class must specify allowVolumeExpansion: true
  • Filesystem resize without pod recreation is only possible if the storage driver allows it

This is based on the Elasticsearch implementation

An update of the storage request in the volumeClaimTemplate will

  • Update the storage requests spec of all existing PVCs: they are immediately resized by the storage driver, if inline expansion is supported. Otherwise Pods need to be recreated.
  • Delete the StatefulSet, but not the pod that it owns, storing recreation details in an annotation on the owning Logstash resource
  • Recreate the StatefulSet with the new volumeClaimTemplate spec
  • Remove the recreation annotation from the Logstash resource

Note:

Testing Notes

minikube does not have a storage class that supports volume expansion - functionality has been tested in google cloud

@botelastic botelastic bot added the triage label Jan 30, 2024
@robbavey robbavey changed the title Feature/logstash volumeresize Add resize volume functionality to Logstash operator Jan 30, 2024
@robbavey robbavey force-pushed the feature/logstash_volumeresize branch from 0d6edbd to 346d19b Compare January 30, 2024 03:35
@thbkrkr thbkrkr added >feature Adds or discusses adding a feature to the product :logstash labels Jan 30, 2024
@botelastic botelastic bot removed the triage label Jan 30, 2024
@robbavey robbavey force-pushed the feature/logstash_volumeresize branch 2 times, most recently from 6b23bf1 to c0815cb Compare January 31, 2024 17:34
@robbavey robbavey marked this pull request as ready for review January 31, 2024 18:46
Copy link
Contributor

@kaisecheng kaisecheng left a comment

Choose a reason for hiding this comment

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

The PVC check in validation can add a checking to ensure the request size is increase like here, otherwise, LGTM

@robbavey robbavey force-pushed the feature/logstash_volumeresize branch from aba1347 to 86ca421 Compare February 1, 2024 15:58
@robbavey
Copy link
Member Author

robbavey commented Feb 1, 2024

@kaisecheng I've added the additional check that you suggested, and reworked the webhook validation to check for this too

Copy link
Contributor

@kaisecheng kaisecheng left a comment

Choose a reason for hiding this comment

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

LGTM :)

robbavey and others added 11 commits February 1, 2024 18:11
This commit moves some of the statefulset functonality from an elasticsearch package to a common one to facilitate its use in other resources
This commit adds support for expanding Logstash volumes by editing the storage requests
in spec.VolumeClaimTemplate, based on the existing implenentation in Elasticsearch
implemented in elastic#3752.

The same constraints hold -

* Volume size can only be increased, not decreased
* Storage class must specify allowVolumeExpansion: true
* Filesystem resize without pod recreation is only possible if the storage driver allows it

This is based on the Elasticsearch implementation

An update of the storage request in the volumeClaimTemplate will

* Update the storage requests spec of all existing PVCs: they are immediately resized by the storage driver, if inline expansion is supported. Otherwise Pods need to be recreated.
* Delete the StatefulSet, but not the pod that it owns, storing recreation details in an annotation on the owning Logstash resource
* Recreate the StatefulSet with the new volumeClaimTemplate spec
* Remove the recreation annotation from the Logstash resource
Co-authored-by: Karen Metts <35154725+karenzone@users.noreply.github.com>
This commit reworks the webhook validation to validate that storage updates fulfill
the requirements (only increasing storage, using a valid storage class that allows
storage expansion).

This required moving the webhook validation into the controller package to allow use
of the k8sclient without a dependency cycle, and requires some rework in webhook
registration
@robbavey robbavey force-pushed the feature/logstash_volumeresize branch from 86ca421 to 1fa362a Compare February 1, 2024 23:11
@robbavey
Copy link
Member Author

robbavey commented Feb 1, 2024

@pebrc @thbkrkr @barkbay This is ready for review

@pebrc
Copy link
Collaborator

pebrc commented Feb 2, 2024

buildkite test this -f p=gke,t=TestVolumeExpansion

Copy link
Collaborator

@pebrc pebrc left a comment

Choose a reason for hiding this comment

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

This looks really good. I did a first pass, only a few superficial findings. Wanted to run a few more tests (I did test the basic functionality) but ran out of time today.

pkg/controller/elasticsearch/nodespec/statefulset.go Outdated Show resolved Hide resolved
pkg/controller/common/statefulset/fixtures.go Outdated Show resolved Hide resolved
pkg/controller/common/volume/pvc_expansion.go Outdated Show resolved Hide resolved
pkg/controller/common/volume/pvc_expansion.go Outdated Show resolved Hide resolved
pkg/controller/common/volume/pvc_expansion.go Outdated Show resolved Hide resolved
})
}
}

func Test_recreateStatefulSets(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems to almost duplicate the test with the same name in the common/volumes package which tests the function that this recreateStatefulSets delegates too. The only difference seems the additional kind attribute.

pkg/controller/logstash/labels/labels.go Outdated Show resolved Hide resolved
@@ -113,7 +117,8 @@ type ReconcileLogstash struct {
dynamicWatches watches.DynamicWatches
operator.Parameters
// iteration is the number of times this controller has run its Reconcile method
iteration uint64
iteration uint64
expectations *expectations.ClustersExpectation
Copy link
Collaborator

Choose a reason for hiding this comment

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

ClustersExpectations seems like a name that does not fit well for anything not Elasticsearch.

Copy link
Member Author

Choose a reason for hiding this comment

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

We used the ClustersExpectation, rather than the standard Expectation to allow expectations for multiple sets of Logstashes to be stored safely in the same ECK instance, and my understanding was that this was required

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes my point was more about the naming, because Logstash is not really a clustered application, not about the fact that you are using it which is appropriate.

pkg/controller/logstash/logstash_controller_test.go Outdated Show resolved Hide resolved
pkg/controller/logstash/logstash_controller_test.go Outdated Show resolved Hide resolved
Co-authored-by: Peter Brachwitz <peter.brachwitz@gmail.com>
@robbavey robbavey force-pushed the feature/logstash_volumeresize branch from 2cda740 to fbed4df Compare February 2, 2024 19:27
@robbavey robbavey force-pushed the feature/logstash_volumeresize branch from 8f2b898 to 7822d0c Compare February 2, 2024 21:26
@robbavey robbavey force-pushed the feature/logstash_volumeresize branch from 538238f to 697ac88 Compare February 2, 2024 22:34
@robbavey
Copy link
Member Author

robbavey commented Feb 2, 2024

I think this is ready for another round @pebrc

@thbkrkr thbkrkr added the v2.12.0 label Feb 5, 2024
Copy link
Collaborator

@pebrc pebrc left a comment

Choose a reason for hiding this comment

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

LGTM

@robbavey
Copy link
Member Author

robbavey commented Feb 5, 2024

Thank you @pebrc! I don't have merge access to this repo, so would you mind hitting the merge button?

@pebrc pebrc merged commit 6d681b3 into elastic:main Feb 5, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>feature Adds or discusses adding a feature to the product :logstash v2.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants