Skip to content

Commit

Permalink
move to autoscaling/v2 (#658)
Browse files Browse the repository at this point in the history
* Update hpa.go

* replace v2beta2 with v2

* Update CHANGELOG.md

Revert change to documenation

* updated kind version to 1.26.6

* bump k8s dependecies

* fix ci

* fix integration

* fix ci

---------

Co-authored-by: Markus Falkner <[email protected]>
Co-authored-by: Rui Fu <[email protected]>
Co-authored-by: Rui Fu <[email protected]>
  • Loading branch information
4 people authored Jul 25, 2023
1 parent e1b7128 commit 2b4cde0
Show file tree
Hide file tree
Showing 27 changed files with 246 additions and 389 deletions.
16 changes: 8 additions & 8 deletions .ci/helm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,17 @@ function ci::verify_hpa() {
FUNCTION_NAME=$1
kubectl get function
kubectl get function ${FUNCTION_NAME} -o yaml
kubectl get hpa.v2beta2.autoscaling
kubectl get hpa.v2beta2.autoscaling ${FUNCTION_NAME}-function -o yaml
kubectl describe hpa.v2beta2.autoscaling ${FUNCTION_NAME}-function
WC=$(kubectl get hpa.v2beta2.autoscaling ${FUNCTION_NAME}-function -o jsonpath='{.status.conditions[?(@.type=="AbleToScale")].status}' | grep False | wc -l)
kubectl get hpa.v2.autoscaling
kubectl get hpa.v2.autoscaling ${FUNCTION_NAME}-function -o yaml
kubectl describe hpa.v2.autoscaling ${FUNCTION_NAME}-function
WC=$(kubectl get hpa.v2.autoscaling ${FUNCTION_NAME}-function -o jsonpath='{.status.conditions[?(@.type=="AbleToScale")].status}' | grep False | wc -l)
while [[ ${WC} -lt 0 ]]; do
echo ${WC};
sleep 20
kubectl get hpa.v2beta2.autoscaling ${FUNCTION_NAME}-function -o yaml
kubectl describe hpa.v2beta2.autoscaling ${FUNCTION_NAME}-function
kubectl get hpa.v2beta2.autoscaling ${FUNCTION_NAME}-function -o jsonpath='{.status.conditions[?(@.type=="AbleToScale")].status}'
WC=$(kubectl get hpa.v2beta2.autoscaling ${FUNCTION_NAME}-function -o jsonpath='{.status.conditions[?(@.type=="AbleToScale")].status}' | grep False | wc -l)
kubectl get hpa.v2.autoscaling ${FUNCTION_NAME}-function -o yaml
kubectl describe hpa.v2.autoscaling ${FUNCTION_NAME}-function
kubectl get hpa.v2.autoscaling ${FUNCTION_NAME}-function -o jsonpath='{.status.conditions[?(@.type=="AbleToScale")].status}'
WC=$(kubectl get hpa.v2.autoscaling ${FUNCTION_NAME}-function -o jsonpath='{.status.conditions[?(@.type=="AbleToScale")].status}' | grep False | wc -l)
done
}

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ index_build_*/

*.bak
.DS_Store
config/crd/bases/vpa-v1-crd.yaml
Listeners
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ VERSION ?= 0.14.0
DOCKER_REPO := $(if $(DOCKER_REPO),$(DOCKER_REPO),streamnative)
OPERATOR_IMG ?= ${DOCKER_REPO}/function-mesh:v$(VERSION)
OPERATOR_IMG_LATEST ?= ${DOCKER_REPO}/function-mesh:latest
ENVTEST_K8S_VERSION = 1.22.1
ENVTEST_K8S_VERSION = 1.24.2

# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
# This variable is used to construct full image tags for bundle and catalog images.
Expand Down
8 changes: 4 additions & 4 deletions api/compute/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

vpav1 "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"

autov2beta2 "k8s.io/api/autoscaling/v2beta2"
autov2 "k8s.io/api/autoscaling/v2"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -214,15 +214,15 @@ type PodPolicy struct {
// AutoScalingMetrics contains the specifications for which to use to calculate the
// desired replica count (the maximum replica count across all metrics will
// be used).
// More info: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#metricspec-v2beta2-autoscaling
// More info: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#metricspec-v2-autoscaling
// +optional
AutoScalingMetrics []autov2beta2.MetricSpec `json:"autoScalingMetrics,omitempty"`
AutoScalingMetrics []autov2.MetricSpec `json:"autoScalingMetrics,omitempty"`

// AutoScalingBehavior configures the scaling behavior of the target
// in both Up and Down directions (scaleUp and scaleDown fields respectively).
// If not set, the default HPAScalingRules for scale up and scale down are used.
// +optional
AutoScalingBehavior *autov2beta2.HorizontalPodAutoscalerBehavior `json:"autoScalingBehavior,omitempty"`
AutoScalingBehavior *autov2.HorizontalPodAutoscalerBehavior `json:"autoScalingBehavior,omitempty"`

// VPA indicates whether to enable the VerticalPodAutoscaler, it should not be used with HPA
VPA *VPASpec `json:"vpa,omitempty"`
Expand Down
6 changes: 3 additions & 3 deletions api/compute/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions config/crd/bases/compute.functionmesh.io_functionmeshes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ spec:
- value
type: object
type: array
x-kubernetes-list-type: atomic
selectPolicy:
type: string
stabilizationWindowSeconds:
Expand All @@ -754,6 +755,7 @@ spec:
- value
type: object
type: array
x-kubernetes-list-type: atomic
selectPolicy:
type: string
stabilizationWindowSeconds:
Expand Down Expand Up @@ -4214,6 +4216,7 @@ spec:
- value
type: object
type: array
x-kubernetes-list-type: atomic
selectPolicy:
type: string
stabilizationWindowSeconds:
Expand All @@ -4239,6 +4242,7 @@ spec:
- value
type: object
type: array
x-kubernetes-list-type: atomic
selectPolicy:
type: string
stabilizationWindowSeconds:
Expand Down Expand Up @@ -7509,6 +7513,7 @@ spec:
- value
type: object
type: array
x-kubernetes-list-type: atomic
selectPolicy:
type: string
stabilizationWindowSeconds:
Expand All @@ -7534,6 +7539,7 @@ spec:
- value
type: object
type: array
x-kubernetes-list-type: atomic
selectPolicy:
type: string
stabilizationWindowSeconds:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/compute.functionmesh.io_functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ spec:
- value
type: object
type: array
x-kubernetes-list-type: atomic
selectPolicy:
type: string
stabilizationWindowSeconds:
Expand All @@ -751,6 +752,7 @@ spec:
- value
type: object
type: array
x-kubernetes-list-type: atomic
selectPolicy:
type: string
stabilizationWindowSeconds:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/compute.functionmesh.io_sinks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ spec:
- value
type: object
type: array
x-kubernetes-list-type: atomic
selectPolicy:
type: string
stabilizationWindowSeconds:
Expand All @@ -670,6 +671,7 @@ spec:
- value
type: object
type: array
x-kubernetes-list-type: atomic
selectPolicy:
type: string
stabilizationWindowSeconds:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/compute.functionmesh.io_sources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ spec:
- value
type: object
type: array
x-kubernetes-list-type: atomic
selectPolicy:
type: string
stabilizationWindowSeconds:
Expand All @@ -665,6 +666,7 @@ spec:
- value
type: object
type: array
x-kubernetes-list-type: atomic
selectPolicy:
type: string
stabilizationWindowSeconds:
Expand Down
4 changes: 2 additions & 2 deletions controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/streamnative/function-mesh/api/compute/v1alpha1"
"github.com/streamnative/function-mesh/controllers/spec"
appsv1 "k8s.io/api/apps/v1"
autoscaling "k8s.io/api/autoscaling/v1"
autov2 "k8s.io/api/autoscaling/v2"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -92,7 +92,7 @@ func observeVPA(ctx context.Context, r client.Reader, name types.NamespacedName,
}

func applyVPA(ctx context.Context, r client.Client, logger logr.Logger, condition v1alpha1.ResourceCondition, meta *metav1.ObjectMeta,
targetRef *autoscaling.CrossVersionObjectReference, vpaSpec *v1alpha1.VPASpec, component string, namespace string, name string) error {
targetRef *autov2.CrossVersionObjectReference, vpaSpec *v1alpha1.VPASpec, component string, namespace string, name string) error {
switch condition.Action {
case v1alpha1.Create:
vpa := spec.MakeVPA(meta, targetRef, vpaSpec)
Expand Down
9 changes: 4 additions & 5 deletions controllers/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import (
"github.com/streamnative/function-mesh/api/compute/v1alpha1"
"github.com/streamnative/function-mesh/controllers/spec"
appsv1 "k8s.io/api/apps/v1"
autoscaling "k8s.io/api/autoscaling/v1"
autov2beta2 "k8s.io/api/autoscaling/v2beta2"
autov2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -177,7 +176,7 @@ func (r *FunctionReconciler) ObserveFunctionHPA(ctx context.Context, function *v
return nil
}

hpa := &autov2beta2.HorizontalPodAutoscaler{}
hpa := &autov2.HorizontalPodAutoscaler{}
err := r.Get(ctx, types.NamespacedName{Namespace: function.Namespace,
Name: spec.MakeFunctionObjectMeta(function).Name}, hpa)
if err != nil {
Expand Down Expand Up @@ -244,7 +243,7 @@ func (r *FunctionReconciler) ApplyFunctionVPA(ctx context.Context, function *v1a
}

objectMeta := spec.MakeFunctionObjectMeta(function)
targetRef := &autoscaling.CrossVersionObjectReference{
targetRef := &autov2.CrossVersionObjectReference{
Kind: function.Kind,
Name: function.Name,
APIVersion: function.APIVersion,
Expand Down Expand Up @@ -333,6 +332,6 @@ func (r *FunctionReconciler) checkIfStatefulSetNeedUpdate(statefulSet *appsv1.St
return !spec.CheckIfStatefulSetSpecIsEqual(&statefulSet.Spec, &spec.MakeFunctionStatefulSet(function).Spec)
}

func (r *FunctionReconciler) checkIfHPANeedUpdate(hpa *autov2beta2.HorizontalPodAutoscaler, function *v1alpha1.Function) bool {
func (r *FunctionReconciler) checkIfHPANeedUpdate(hpa *autov2.HorizontalPodAutoscaler, function *v1alpha1.Function) bool {
return !spec.CheckIfHPASpecIsEqual(&hpa.Spec, &spec.MakeFunctionHPA(function).Spec)
}
4 changes: 2 additions & 2 deletions controllers/function_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/streamnative/function-mesh/controllers/spec"
"github.com/streamnative/function-mesh/utils"
appsv1 "k8s.io/api/apps/v1"
autov2beta2 "k8s.io/api/autoscaling/v2beta2"
autov2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -154,7 +154,7 @@ func (r *FunctionReconciler) SetupWithManager(mgr ctrl.Manager) error {
For(&v1alpha1.Function{}).
Owns(&appsv1.StatefulSet{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Owns(&corev1.Service{}).
Owns(&autov2beta2.HorizontalPodAutoscaler{}).
Owns(&autov2.HorizontalPodAutoscaler{}).
Owns(&corev1.Secret{}).
Owns(&v1.Job{})

Expand Down
24 changes: 12 additions & 12 deletions controllers/function_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"

autov2beta2 "k8s.io/api/autoscaling/v2beta2"
autov2 "k8s.io/api/autoscaling/v2"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -130,23 +130,23 @@ var _ = Describe("Function Controller (HPA)", func() {
Context("Simple Function Item with HPA", func() {
function := makeFunctionSample(TestFunctionHPAName)
cpuPercentage := int32(20)
function.Spec.Pod.AutoScalingMetrics = []autov2beta2.MetricSpec{
function.Spec.Pod.AutoScalingMetrics = []autov2.MetricSpec{
{
Type: autov2beta2.ResourceMetricSourceType,
Resource: &autov2beta2.ResourceMetricSource{
Type: autov2.ResourceMetricSourceType,
Resource: &autov2.ResourceMetricSource{
Name: v1.ResourceCPU,
Target: autov2beta2.MetricTarget{
Type: autov2beta2.UtilizationMetricType,
Target: autov2.MetricTarget{
Type: autov2.UtilizationMetricType,
AverageUtilization: &cpuPercentage,
},
},
},
{
Type: autov2beta2.ResourceMetricSourceType,
Resource: &autov2beta2.ResourceMetricSource{
Type: autov2.ResourceMetricSourceType,
Resource: &autov2.ResourceMetricSource{
Name: v1.ResourceMemory,
Target: autov2beta2.MetricTarget{
Type: autov2beta2.UtilizationMetricType,
Target: autov2.MetricTarget{
Type: autov2.UtilizationMetricType,
AverageUtilization: &cpuPercentage,
},
},
Expand Down Expand Up @@ -267,7 +267,7 @@ func createFunction(function *v1alpha1.Function) {

It("HPA should be created", func() {
if function.Spec.MaxReplicas != nil {
hpa := &autov2beta2.HorizontalPodAutoscaler{}
hpa := &autov2.HorizontalPodAutoscaler{}
Eventually(func() bool {
err := k8sClient.Get(context.Background(), types.NamespacedName{Namespace: function.Namespace,
Name: spec.MakeFunctionObjectMeta(function).Name}, hpa)
Expand Down Expand Up @@ -341,7 +341,7 @@ func createFunction(function *v1alpha1.Function) {
log.Info("StatefulSet resource deleted", "namespace", key.Namespace, "name", key.Name, "test",
CurrentGinkgoTestDescription().FullTestText)

hpa := new(autov2beta2.HorizontalPodAutoscaler)
hpa := new(autov2.HorizontalPodAutoscaler)
hpaKey := key
hpaKey.Name = spec.MakeFunctionObjectMeta(function).Name
err = k8sClient.Get(context.Background(), hpaKey, hpa)
Expand Down
9 changes: 4 additions & 5 deletions controllers/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import (
"github.com/streamnative/function-mesh/api/compute/v1alpha1"
"github.com/streamnative/function-mesh/controllers/spec"
appsv1 "k8s.io/api/apps/v1"
autoscaling "k8s.io/api/autoscaling/v1"
autov2beta2 "k8s.io/api/autoscaling/v2beta2"
autov2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -177,7 +176,7 @@ func (r *SinkReconciler) ObserveSinkHPA(ctx context.Context, sink *v1alpha1.Sink
return nil
}

hpa := &autov2beta2.HorizontalPodAutoscaler{}
hpa := &autov2.HorizontalPodAutoscaler{}
err := r.Get(ctx, types.NamespacedName{Namespace: sink.Namespace,
Name: spec.MakeSinkObjectMeta(sink).Name}, hpa)
if err != nil {
Expand Down Expand Up @@ -244,7 +243,7 @@ func (r *SinkReconciler) ApplySinkVPA(ctx context.Context, sink *v1alpha1.Sink)
}

objectMeta := spec.MakeSinkObjectMeta(sink)
targetRef := &autoscaling.CrossVersionObjectReference{
targetRef := &autov2.CrossVersionObjectReference{
Kind: sink.Kind,
Name: sink.Name,
APIVersion: sink.APIVersion,
Expand Down Expand Up @@ -333,6 +332,6 @@ func (r *SinkReconciler) checkIfStatefulSetNeedUpdate(statefulSet *appsv1.Statef
return !spec.CheckIfStatefulSetSpecIsEqual(&statefulSet.Spec, &spec.MakeSinkStatefulSet(sink).Spec)
}

func (r *SinkReconciler) checkIfHPANeedUpdate(hpa *autov2beta2.HorizontalPodAutoscaler, sink *v1alpha1.Sink) bool {
func (r *SinkReconciler) checkIfHPANeedUpdate(hpa *autov2.HorizontalPodAutoscaler, sink *v1alpha1.Sink) bool {
return !spec.CheckIfHPASpecIsEqual(&hpa.Spec, &spec.MakeSinkHPA(sink).Spec)
}
4 changes: 2 additions & 2 deletions controllers/sink_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/streamnative/function-mesh/controllers/spec"
"github.com/streamnative/function-mesh/utils"
appsv1 "k8s.io/api/apps/v1"
autov2beta2 "k8s.io/api/autoscaling/v2beta2"
autov2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -152,7 +152,7 @@ func (r *SinkReconciler) SetupWithManager(mgr ctrl.Manager) error {
For(&v1alpha1.Sink{}).
Owns(&appsv1.StatefulSet{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Owns(&corev1.Service{}).
Owns(&autov2beta2.HorizontalPodAutoscaler{}).
Owns(&autov2.HorizontalPodAutoscaler{}).
Owns(&v1.Job{})
if r.WatchFlags != nil && r.WatchFlags.WatchVPACRDs {
manager.Owns(&vpav1.VerticalPodAutoscaler{})
Expand Down
Loading

0 comments on commit 2b4cde0

Please sign in to comment.