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

Scaling StatefulSet filtered using label selectors #3948

Closed
bhavin192 opened this issue Mar 8, 2022 · 5 comments · Fixed by #4053
Closed

Scaling StatefulSet filtered using label selectors #3948

bhavin192 opened this issue Mar 8, 2022 · 5 comments · Fixed by #4053
Assignees

Comments

@bhavin192
Copy link
Contributor

Is your enhancement related to a problem? Please describe

I'm trying scale a StatefulSet by selecting it using its labels. For example, kubectl allows following:

$ kubectl scale statefulset -l release=yb,app.kubernetes.io/name=yb-tserver --replicas=4
statefulset.apps/yb-yugabyte-yb-tserver scaled

But when we filter StatefulSets with label selectors, the scale() method is not there.

Describe the solution you'd like

I'm thinking of something similar like this:

client
    .apps()
    .statefulSets()
    .withLabel("release", "yb")
    .withLabel(appLabel, "yb-tserver")
    .scale(4);

Describe alternatives you've considered

So far I have tried using list(), and then getting the first StatefulSet out of it. But when I tried to load the StatefulSet into client, the scale() method was not present. So, I had to use the metadata.name.

StatefulSet sts =
    client
	.apps()
	.statefulSets()
	.withLabel("release", "yb")
	.withLabel(appLabel, "yb-tserver")
	.list()
	.getItems()
	.get(0);

// This was not possible (should I create a separate issue for this?)
client.resource(sts).scale(4);

// I had to do this instead
client
    .apps()
    .statefulSets()
    .withName(sts.getMetadata().getName())
    .scale(4);

Additional context

When kubectl finds multiple StatefulSets filtered the label selectors, it just scales all of them.

$ kubectl scale statefulset -l release=yb --replicas=4
statefulset.apps/yb-yugabyte-yb-master scaled
statefulset.apps/yb-yugabyte-yb-tserver scaled
@bhavin192 bhavin192 changed the title Scaling StatefulSet using label selectors Scaling StatefulSet filtered using label selectors Mar 8, 2022
@shawkins
Copy link
Contributor

shawkins commented Mar 8, 2022

// This was not possible (should I create a separate issue for this?)
client.resource(sts).scale(4);

That won't be possible because we don't know the type of Resource to return. At a minimum you'd have to specify
client.resource(sts, RollableScalableResource.class).scale(4); - and then you'd have to cast to RollableScalableResource<StatefulSet>

Alternatively fabric8 6 will support:

client.apps().statefulSets().withItem(sts).scale(4);

@manusa @rohanKanojia is resource a better method name than withItem here?

For now you would do something like:

var statefulSets = client.apps().statefulSets();
statefulSets
  .withLabel("release", "yb")
  .withLabel(appLabel, "yb-tserver")
  .list().getItems()
  .forEach(s -> statefulSets.withName(s.getName()).scale(4));

I think we can easily make that better with an enhancement that would add a resourceList or similar method that would return a List of the Resource subclasses:

var statefulSets = client.apps().statefulSets();
statefulSets
  .withLabel("release", "yb")
  .withLabel(appLabel, "yb-tserver")
  .resourceList().forEach(s -> s.scale(4));

@bhavin192
Copy link
Contributor Author

That won't be possible because we don't know the type of Resource to return. At a minimum you'd have to specify
client.resource(sts, RollableScalableResource.class).scale(4); - and then you'd have to cast to RollableScalableResource

Alternatively fabric8 6 will support:

client.apps().statefulSets().withItem(sts).scale(4);

Right, that makes sense. This new method seems to be useful.

Thank you for the forEach idea, that gives us same behavior as kubectl scale. forEach didn't come to my mind as I'm not much used to writing Java 😄

Does it makes sense to add an example for this in the docs/examples directory (I can add it if we agree to do so).

@shawkins
Copy link
Contributor

shawkins commented Mar 9, 2022

Does it makes sense to add an example for this in the docs/examples directory (I can add it if we agree to do so).

Yes, an example would be good. Then either this issue or a new one could be for adding a resourceList method to clean this up a bit.

@shawkins
Copy link
Contributor

a resources method was added with #3973

client.apps().statefulSets()
  .withLabel("release", "yb")
  .withLabel(appLabel, "yb-tserver")
  .resources()
  .forEach(s -> s.scale(4));

@bhavin192
Copy link
Contributor Author

That's great, thanks! I have been away for a while, I will send PR for docs/example entry next week. With my PR we can close this issue.

bhavin192 added a commit to bhavin192/kubernetes-client that referenced this issue Apr 7, 2022
Fixes fabric8io#3948

Signed-off-by: Bhavin Gandhi <bhavin7392@gmail.com>
bhavin192 added a commit to bhavin192/kubernetes-client that referenced this issue Apr 7, 2022
Fixes fabric8io#3948

Signed-off-by: Bhavin Gandhi <bhavin7392@gmail.com>
bhavin192 added a commit to bhavin192/kubernetes-client that referenced this issue Apr 8, 2022
Fixes fabric8io#3948

Signed-off-by: Bhavin Gandhi <bhavin7392@gmail.com>
bhavin192 added a commit to bhavin192/kubernetes-client that referenced this issue Apr 20, 2022
Fixes fabric8io#3948

Signed-off-by: Bhavin Gandhi <bhavin7392@gmail.com>
manusa pushed a commit that referenced this issue Apr 26, 2022
Fixes #3948

Signed-off-by: Bhavin Gandhi <bhavin7392@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants