Skip to content

Commit

Permalink
update to autoscaling/v2beta2 (#66)
Browse files Browse the repository at this point in the history
- not updating to autoscaling/v2 to avoid breaking client manifests
  • Loading branch information
akodali18 committed Mar 20, 2024
1 parent af1121b commit 90e61f3
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion deploy/hpa-examples/hpa-cpu-usage.yaml
@@ -1,4 +1,4 @@
apiVersion: autoscaling/v2beta1
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: example-hpa-custom-metrics
Expand Down
2 changes: 1 addition & 1 deletion deploy/hpa-examples/hpa-external-selector.yaml
@@ -1,4 +1,4 @@
apiVersion: autoscaling/v2beta1
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: example-hpa-custom-metrics
Expand Down
2 changes: 1 addition & 1 deletion deploy/hpa-examples/hpa-external.yaml
@@ -1,4 +1,4 @@
apiVersion: autoscaling/v2beta1
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: example-hpa-custom-metrics
Expand Down
2 changes: 1 addition & 1 deletion deploy/hpa-examples/hpa-node.yaml
@@ -1,4 +1,4 @@
apiVersion: autoscaling/v2beta1
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: example-hpa-custom-metrics
Expand Down
2 changes: 1 addition & 1 deletion deploy/hpa-examples/hpa-pods.yaml
@@ -1,4 +1,4 @@
apiVersion: autoscaling/v2beta1
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: example-hpa-custom-metrics
Expand Down
4 changes: 2 additions & 2 deletions docs/introduction.md
Expand Up @@ -22,7 +22,7 @@ Metrics can be specified via annotations on HPAs or via a static configuration f
The adapter can dynamically discover HPAs and source external metrics via annotations. The annotations should be of the form `wavefront.com.external.metric/<metric_name>: '<ts query>'`. For example:

```yaml
apiVersion: autoscaling/v2beta1
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: example-app
Expand Down Expand Up @@ -51,4 +51,4 @@ To specify external metrics via a configuration file:
3. Deploy an [HPA](/deploy/hpa-examples/hpa-external.yaml) based on an external metric.

## Kubernetes HPA Spec
Refer to the [autoscaling spec](https://pkg.go.dev/k8s.io/api/autoscaling/v2beta1#MetricSpec) for more details on configuring HPAs based on the custom or external metrics APIs.
Refer to the [autoscaling spec](https://pkg.go.dev/k8s.io/api/autoscaling/v2beta2#MetricSpec) for more details on configuring HPAs based on the custom or external metrics APIs.
12 changes: 6 additions & 6 deletions pkg/provider/hpa.go
Expand Up @@ -4,14 +4,14 @@
package provider

import (
"k8s.io/api/autoscaling/v2beta2"
"reflect"
"strings"

log "github.com/sirupsen/logrus"

"github.com/wavefronthq/wavefront-kubernetes-adapter/pkg/config"

"k8s.io/api/autoscaling/v2beta1"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -43,19 +43,19 @@ func (l *hpaListener) listen() {

rc := l.kubeClient.AutoscalingV2beta1().RESTClient()
lw := cache.NewListWatchFromClient(rc, "horizontalpodautoscalers", v1.NamespaceAll, fields.Everything())
inf := cache.NewSharedInformer(lw, &v2beta1.HorizontalPodAutoscaler{}, 0)
inf := cache.NewSharedInformer(lw, &v2beta2.HorizontalPodAutoscaler{}, 0)

inf.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
hpa := obj.(*v2beta1.HorizontalPodAutoscaler)
hpa := obj.(*v2beta2.HorizontalPodAutoscaler)
rules := rulesFromAnnotations(hpa.Annotations)
if len(rules) > 0 {
l.addFunc(rules)
}
},
UpdateFunc: func(oldObj, newObj interface{}) {
oldHPA := oldObj.(*v2beta1.HorizontalPodAutoscaler)
newHPA := newObj.(*v2beta1.HorizontalPodAutoscaler)
oldHPA := oldObj.(*v2beta2.HorizontalPodAutoscaler)
newHPA := newObj.(*v2beta2.HorizontalPodAutoscaler)

// HPA objects are updated frequently when status changes
// validate if annotations have changed
Expand All @@ -74,7 +74,7 @@ func (l *hpaListener) listen() {
}
},
DeleteFunc: func(obj interface{}) {
hpa := obj.(*v2beta1.HorizontalPodAutoscaler)
hpa := obj.(*v2beta2.HorizontalPodAutoscaler)
rules := rulesFromAnnotations(hpa.Annotations)
if len(rules) > 0 {
l.deleteFunc(rules)
Expand Down

0 comments on commit 90e61f3

Please sign in to comment.