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

Change horizontal pod autoscaler to use otelcol scale subresource #941

Closed
wants to merge 30 commits into from
Closed

Change horizontal pod autoscaler to use otelcol scale subresource #941

wants to merge 30 commits into from

Conversation

kevinearls
Copy link
Member

@kevinearls kevinearls commented Jun 23, 2022

Signed-off-by: Kevin Earls kearls@redhat.com

This fixes #801 so that the HPA is created on an OpenTelemetryCollector rather than a Deployment.

I believe it also fixes #922
I believe it also fixes #906 but will confirm

Signed-off-by: Kevin Earls <kearls@redhat.com>
@kevinearls kevinearls requested a review from a team June 23, 2022 13:11
Signed-off-by: Kevin Earls <kearls@redhat.com>
@@ -37,6 +37,10 @@ type OpenTelemetryCollectorSpec struct {
// +optional
Replicas *int32 `json:"replicas,omitempty"`

// MinReplicas sets a lower bound to the autoscaling feature
// +optional
MinReplicas int32 `json:"minReplicas,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

What is the relationship between MinReplicas and Replicas? Which one should be used when? This is something that should be documented.

Copy link
Member

Choose a reason for hiding this comment

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

With that we probably need to add some checks to the webhook

if r.Spec.Replicas != nil && *r.Spec.Replicas > *r.Spec.MaxReplicas {
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, replicas must not be greater than maxReplicas")
}

to test the minreplicas or any relationship between replicas, minreplias and maxreplicas.

@@ -35,18 +35,18 @@ func HorizontalPodAutoscaler(cfg config.Config, logger logr.Logger, otelcol v1al

return autoscalingv1.HorizontalPodAutoscaler{
ObjectMeta: metav1.ObjectMeta{
Name: naming.Collector(otelcol),
Name: otelcol.Name,
Copy link
Member

Choose a reason for hiding this comment

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

What is the rationale for the name change? Could this produce an invalid name?

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 are now scaling on the OpenTelemetryCollector rather than the deployment. If the otelcol.Name is "simple" we append "-collector" to the deployment name.

If you think it's a good idea I could add a function to naming which just does

	return DNSName(Truncate("%s", 63, otelcol.Name))

@pavolloffay
Copy link
Member

I would like to see e2e test for this functionality. It can be actually two tests - scaling up and down with the HPA.

Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
Copy link
Contributor

@yuriolisa yuriolisa left a comment

Choose a reason for hiding this comment

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

Please fix the lint.

…ntelemetry-operator into hpa-use-scale-subresource
Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
@kevinearls
Copy link
Member Author

@pavolloffay Please review. I think I've covered all of the things we discussed.

@yuriolisa lint now passes

// +optional
MaxReplicas *int32 `json:"maxReplicas,omitempty"`
Copy link
Member

@pavolloffay pavolloffay Jul 4, 2022

Choose a reason for hiding this comment

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

I am not sure if we can change the CRD. In this case, a field is removed.

controllers/opentelemetrycollector_controller.go Outdated Show resolved Hide resolved
Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
@kevinearls
Copy link
Member Author

@pavolloffay Can you please review this, re-running the checks first if needed? (The 1.24 e2e tests are failing in a place I didn't touch.)

I have reverted to using autoscaling v1 and removed the AutoScaleSpec changes (I can do both later) so I think that covers everything we've discussed.

@@ -0,0 +1,6 @@
#!/bin/bash

# Install metrics-server for autoscale tests
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed for mimikube as well or only for kind? It should be documented.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, with minikube you can just add --addons "metrics-server" to the start command.

Where should I document this? In this script? In the Makefile?

Copy link
Member

Choose a reason for hiding this comment

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

Probably closer to the source - script

Signed-off-by: Kevin Earls <kearls@redhat.com>
Copy link
Member

@pavolloffay pavolloffay left a comment

Choose a reason for hiding this comment

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

@kevinearls could you please confirm that the change of HPA implementation will not disrupt existing instances provisioned by the previous version of the operator?

Signed-off-by: Kevin Earls <kearls@redhat.com>
Copy link
Contributor

@yuriolisa yuriolisa left a comment

Choose a reason for hiding this comment

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

@kevinearls, please ensure that change will not disrupt the existing instances like @pavolloffay mentioned above. LGTM.

Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
@kevinearls
Copy link
Member Author

@yuriolisa @pavolloffay I have added code that takes care of the upgrade. Please review and merge if it looks ok.

@@ -52,6 +52,7 @@ func TestExpectedHPA(t *testing.T) {
maxReplicas := int32(3)
updateParms := paramsWithHPA()
updateParms.Instance.Spec.Replicas = &minReplicas
updateParms.Instance.Spec.Replicas = &minReplicas
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix this duplicated code.

}

if r.Spec.MinReplicas != nil && *r.Spec.MinReplicas < int32(1) {
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, minReplicas should be more than one")
Copy link
Contributor

Choose a reason for hiding this comment

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

I consider MinReplicas should be at least one, correct?

@@ -223,6 +223,10 @@ spec:
If MaxReplicas is set autoscaling is enabled.
format: int32
type: integer
minReplicas:
description: MinReplicas sets a lower bound to the autoscaling feature.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add here the lowest value?

@@ -221,6 +221,10 @@ spec:
If MaxReplicas is set autoscaling is enabled.
format: int32
type: integer
minReplicas:
description: MinReplicas sets a lower bound to the autoscaling feature.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add here the lowest value?

docs/api.md Outdated
<td><b>minReplicas</b></td>
<td>integer</td>
<td>
MinReplicas sets a lower bound to the autoscaling feature.<br/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Also here.

metadata:
name: simplest
spec:
replicas: 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this field be automatically filled, once the minReplicas is the default lower bound of that instance?

Signed-off-by: Kevin Earls <kearls@redhat.com>
Signed-off-by: Kevin Earls <kearls@redhat.com>
Copy link
Contributor

@yuriolisa yuriolisa left a comment

Choose a reason for hiding this comment

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

LGTM.

@kevinearls
Copy link
Member Author

kevinearls commented Jul 15, 2022

Closing this in favor of #984 as I managed to get myself into rebase hell.

@kevinearls kevinearls closed this Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants