Repository: fission/fission (language: go)

Issue:
 New-Deployment executor function is unable to initialize properly


hi, I'm currently trying to learn the fission New-Deployment executor, and I've been following the instructions at 
 **https://fission.io/docs/usage/function/executor/**  However, I've encountered an unexpected issue: After creating a function, the corresponding HPA, Service, and Deployment are not being initialized. When I use 'test,' it gives me the following error message: 'error':'Post "[http://127.0.0.1:8888/specialize\](http://127.0.0.1:8888/specialize%5C)": dial tcp 127.0.0.1:8888: connect: connection refused.' This has left me quite puzzled. **It's worth mentioning that when I use Poolmgr, everything works as expected**.

I'm trying to learn fission's New-Deployment executor, but I've encountered an unexpected issue: After creating a function, the corresponding HPA, Service, and Deployment are not being initialized."

**Expected result**
I hope that Dome can run smoothly with the New-Deployment executor and auto-scale as needed.

**Actual result**
After creating a function, the corresponding HPA, Service, and Deployment are not being initialized."

**To Reproduce**

I've used the following installation command:

```
helm install --version v1.19.0 --namespace fission fission fission-charts/fission-all --set serviceType=NodePort --set routerServiceType=NodePort --set additionalFissionNamespaces[0]=default --set additionalFissionNamespaces[1]=pro  --set additionalFissionNamespaces[2]=pre  --set additionalFissionNamespaces[3]=test --set additionalFissionNamespaces[4]=dev 

todo I'm not sure if the following errors will have an impact
Error: INSTALLATION FAILED: 40 errors occurred:
	* roles.rbac.authorization.k8s.io "fission-buildermgr-fission-cr" already exists
	* roles.rbac.authorization.k8s.io "fission-fluentbit" already exists
	* roles.rbac.authorization.k8s.io "fission-executor-fission-cr" already exists
	...
```


```
$ fission version

client:
  fission/core:
    BuildDate: "2023-05-18T12:33:09Z"
    GitCommit: f955d118
    Version: v1.19.0
server:
  fission/core:
    BuildDate: "2023-05-18T12:33:09Z"
    GitCommit: f955d118
    Version: v1.19.0
```

I'm using K3S because I believe it should be relatively simpler than K8S

```
$ k3s -v

k3s version v1.26.8+k3s1 (631bb3f0)
go version go1.20.7
```

```
$ kubectl version

Client Version: version.Info{Major:"1", Minor:"26", GitVersion:"v1.26.8+k3s1", GitCommit:"631bb3f0feb6049ca4b2e71a3b55bcc45d0eed10", GitTreeState:"clean", BuildDate:"2023-09-05T19:59:36Z", GoVersion:"go1.20.7", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v4.5.7

Server Version: version.Info{Major:"1", Minor:"26", GitVersion:"v1.26.8+k3s1", GitCommit:"631bb3f0feb6049ca4b2e71a3b55bcc45d0eed10", GitTreeState:"clean", BuildDate:"2023-09-05T19:59:36Z", GoVersion:"go1.20.7", Compiler:"gc", Platform:"linux/amd64"}
```


```
$ fission env create --name nodejs --image fission/node-env  -n dev --mincpu 100 --maxcpu 200 --minmemory 128 --maxmemory 256

poolsize setting default to 3
environment 'nodejs' created
```

```
$ fission fn create --name hello --env nodejs --code hello.js --executortype newdeploy      --minmemory 64 --maxmemory 128 --minscale 1 --maxscale 6  --targetcpu 50 -n dev

Package 'hello-582d6c5f-7631-441f-836a-7c95aaa6843f' created
function 'hello' created
```


```
$ fission fn test --name hello  -n dev

Error: Error calling function hello: 500; Please try again or fix the error: error sending request to function

===================================
Function: hello
Environment: nodejs
Namespace: dev
Pod: newdeploy-hello-dev-a370-f517a0d376df-6ffcdc98c6-l6q5w
Container: nodejs
Node: slave2
===================================

> fission-nodejs-runtime@0.1.0 start /usr/src/app
> node server.js

user code loaded in 0sec 0.265448ms
::ffff:127.0.0.1 - - [26/Sep/2023:08:02:31 +0000] "POST /specialize HTTP/1.1" 202 - "-" "Go-http-client/1.1"

===================================
Function: hello
Environment: nodejs
Namespace: dev
Pod: newdeploy-hello-dev-a370-f517a0d376df-6ffcdc98c6-l6q5w
Container: fetcher
Node: slave2
===================================
{"level":"info","ts":"2023-09-26T08:02:25.229Z","caller":"otel/provider.go:50","msg":"OTEL_EXPORTER_OTLP_ENDPOINT not set, skipping Opentelemtry tracing"}
{"level":"info","ts":"2023-09-26T08:02:25.229Z","caller":"app/server.go:119","msg":"fetcher ready to receive requests"}
{"level":"info","ts":"2023-09-26T08:02:25.229Z","caller":"httpserver/server.go:21","msg":"starting server","service":"fetcher","addr":":8000"}
{"level":"info","ts":"2023-09-26T08:02:25.237Z","logger":"fetcher","caller":"fetcher/fetcher.go:388","msg":"successfully placed","trace_id":"c5cb3fdc7aa80ca8a7bb7f6b8be96cdd","location":"/userfunc/user"}
{"level":"info","ts":"2023-09-26T08:02:25.237Z","logger":"fetcher","caller":"fetcher/fetcher.go:722","msg":"calling environment v1 specialization endpoint","trace_id":"c5cb3fdc7aa80ca8a7bb7f6b8be96cdd"}
{"level":"error","ts":"2023-09-26T08:02:25.237Z","logger":"fetcher","caller":"fetcher/fetcher.go:741","msg":"error connecting to function environment pod for specialization request, retrying","trace_id":"c5cb3fdc7aa80ca8a7bb7f6b8be96cdd","error":"Post \"http://127.0.0.1:8888/specialize\": dial tcp 127.0.0.1:8888: connect: connection refused","stacktrace":"github.com/fission/fission/pkg/fetcher.(*Fetcher).SpecializePod\n\tpkg/fetcher/fetcher.go:741\ngithub.com/fission/fission/cmd/fetcher/app.Run.func1\n\tcmd/fetcher/app/server.go:90"}
{"level":"error","ts":"2023-09-26T08:02:26.238Z","logger":"fetcher","caller":"fetcher/fetcher.go:741","msg":"error connecting to function environment pod for specialization request, retrying","trace_id":"c5cb3fdc7aa80ca8a7bb7f6b8be96cdd","error":"Post \"http://127.0.0.1:8888/specialize\": dial tcp 127.0.0.1:8888: connect: connection refused","stacktrace":"github.com/fission/fission/pkg/fetcher.(*Fetcher).SpecializePod\n\tpkg/fetcher/fetcher.go:741\ngithub.com/fission/fission/cmd/fetcher/app.Run.func1\n\tcmd/fetcher/app/server.go:90"}
{"level":"error","ts":"2023-09-26T08:02:28.238Z","logger":"fetcher","caller":"fetcher/fetcher.go:741","msg":"error connecting to function environment pod for specialization request, retrying","trace_id":"c5cb3fdc7aa80ca8a7bb7f6b8be96cdd","error":"Post \"http://127.0.0.1:8888/specialize\": dial tcp 127.0.0.1:8888: connect: connection refused","stacktrace":"github.com/fission/fission/pkg/fetcher.(*Fetcher).SpecializePod\n\tpkg/fetcher/fetcher.go:741\ngithub.com/fission/fission/cmd/fetcher/app.Run.func1\n\tcmd/fetcher/app/server.go:90"}
{"level":"error","ts":"2023-09-26T08:02:31.239Z","logger":"fetcher","caller":"fetcher/fetcher.go:741","msg":"error connecting to function environment pod for specialization request, retrying","trace_id":"c5cb3fdc7aa80ca8a7bb7f6b8be96cdd","error":"Post \"http://127.0.0.1:8888/specialize\": dial tcp 127.0.0.1:8888: connect: connection refused","stacktrace":"github.com/fission/fission/pkg/fetcher.(*Fetcher).SpecializePod\n\tpkg/fetcher/fetcher.go:741\ngithub.com/fission/fission/cmd/fetcher/app.Run.func1\n\tcmd/fetcher/app/server.go:90"}
{"level":"info","ts":"2023-09-26T08:02:31.259Z","logger":"fetcher","caller":"fetcher/fetcher.go:680","msg":"specialize request done","trace_id":"c5cb3fdc7aa80ca8a7bb7f6b8be96cdd","elapsed_time":6.029411151}

Options:
  --name=''               Function name
  --method=[GET]          HTTP Methods: GET,POST,PUT,DELETE,HEAD. To mention single method: --method GET
                          and for multiple methods --method GET --method POST. [DEPRECATED for 'fn create',
                          use 'route create' instead]
  --header=[] (-H)        Request headers
  --body='' (-b)          Request body
  --query=[] (-q)         Request query parameters: -q key1=value1 -q key2=value2
  --timeout=1m0s (-t)     Length of time to wait for the response. If set to zero or negative number, no
                          timeout is set
  --dbtype='kubernetes'   Log database type, e.g. influxdb (currently influxdb and kubernetes logs are
                          supported)
  --subpath=''            Sub Path to check if function internally supports routing

Global Options:
  --server=''          Server URL
  --verbosity=1 (-v)   CLI verbosity (0 is quiet, 1 is the default, 2 is verbose)
  --kube-context=''    Kubernetes context to be used for the execution of Fission commands
  --namespace='' (-n)  If present, the namespace scope for this CLI request

Usage:
  fission function test [options]

Error: error getting function response

```


I tried manually creating an HPA, and I found that it's effective.
```

$ kubectl get hpa notejs-test-dome -n pre


NAME               REFERENCE                     TARGETS   MINPODS   MAXPODS   REPLICAS   AGE
notejs-test-dome   Deployment/notejs-test-dome   0%/50%    1         10        1          36s

```

I'd like to test a function of type Poolmgr in the 'test' namespace.

``` 
fission fn test --name hello  -n test
hello, world!
```

```
$ kubectl get pod -A -o wide

NAMESPACE                   NAME                                         READY   STATUS      RESTARTS      AGE   IP           NODE     NOMINATED NODE   READINESS GATES
kube-system                 helm-install-traefik-crd-rcfjz               0/1     Completed   0             13d   10.42.0.4    master   <none>           <none>
kube-system                 helm-install-traefik-wbxzn                   0/1     Completed   1             13d   10.42.0.3    master   <none>           <none>
kube-system                 svclb-traefik-7f3ed441-tpmzq                 2/2     Running     4 (95m ago)   13d   10.42.0.21   master   <none>           <none>
kube-system                 traefik-57c84cf78d-5p4c7                     1/1     Running     2 (95m ago)   13d   10.42.0.16   master   <none>           <none>
kube-system                 svclb-traefik-7f3ed441-2knml                 2/2     Running     4 (95m ago)   13d   10.42.2.15   slave2   <none>           <none>
cattle-fleet-system         gitjob-85b85d5df8-566fx                      1/1     Running     2 (95m ago)   13d   10.42.2.17   slave2   <none>           <none>
kube-system                 svclb-traefik-7f3ed441-sgs9t                 2/2     Running     2 (13d ago)   13d   10.42.1.13   slave1   <none>           <none>
cattle-fleet-system         fleet-controller-79bdbcd9b4-9bp7v            1/1     Running     2 (95m ago)   13d   10.42.2.18   slave2   <none>           <none>
cattle-fleet-local-system   fleet-agent-7687d78788-nvbfl                 1/1     Running     1 (13d ago)   13d   10.42.1.14   slave1   <none>           <none>
cattle-system               rancher-webhook-788c48b988-4hpqt             1/1     Running     2 (95m ago)   13d   10.42.2.19   slave2   <none>           <none>
kube-system                 coredns-59b4f5bbd5-fcjrx                     1/1     Running     2 (95m ago)   13d   10.42.0.18   master   <none>           <none>
kube-system                 local-path-provisioner-76d776f6f9-rl2nw      1/1     Running     4 (70m ago)   13d   10.42.0.19   master   <none>           <none>
cattle-system               rancher-5d7cd9bbd8-nt4vs                     1/1     Running     2 (95m ago)   13d   10.42.0.20   master   <none>           <none>
kube-system                 metrics-server-68cf49699b-kfqlq              1/1     Running     4 (70m ago)   13d   10.42.0.17   master   <none>           <none>
cattle-system               rancher-5d7cd9bbd8-nw2ch                     1/1     Running     2 (95m ago)   13d   10.42.2.16   slave2   <none>           <none>
cattle-system               rancher-5d7cd9bbd8-vsnh9                     1/1     Running     1 (13d ago)   13d   10.42.1.15   slave1   <none>           <none>
cattle-system               helm-operation-x2m7m                         0/2     Completed   0             59m   10.42.1.21   slave1   <none>           <none>
cattle-system               helm-operation-n2xqt                         0/2     Completed   0             50m   10.42.2.25   slave2   <none>           <none>
cattle-system               helm-operation-9svlc                         0/2     Completed   0             46m   10.42.1.35   slave1   <none>           <none>
cattle-system               helm-operation-495hw                         0/2     Completed   0             19m   10.42.2.48   slave2   <none>           <none>
fission                     webhook-5db9d6dfbd-6bmrp                     1/1     Running     0             18m   10.42.1.58   slave1   <none>           <none>
fission                     router-667fd9f9bf-kq4zk                      1/1     Running     0             18m   10.42.2.50   slave2   <none>           <none>
fission                     kubewatcher-6cd59cc64d-vp58v                 1/1     Running     0             18m   10.42.1.61   slave1   <none>           <none>
fission                     timer-c877f9c66-chg2w                        1/1     Running     0             18m   10.42.1.59   slave1   <none>           <none>
fission                     buildermgr-7866657dc7-ztbs2                  1/1     Running     0             18m   10.42.1.62   slave1   <none>           <none>
fission                     mqtrigger-keda-6d7d877fbc-5rfsk              1/1     Running     0             18m   10.42.1.60   slave1   <none>           <none>
fission                     executor-7b57867bf7-jkrhq                    1/1     Running     0             18m   10.42.0.34   master   <none>           <none>
fission                     storagesvc-b4cc86bcd-krnk8                   1/1     Running     0             18m   10.42.2.51   slave2   <none>           <none>
dev                         poolmgr-nodejs-dev-26164-666f6f8bd-cpjzc     2/2     Running     0             15m   10.42.0.35   master   <none>           <none>
dev                         poolmgr-nodejs-dev-26164-666f6f8bd-pj76m     2/2     Running     0             15m   10.42.1.63   slave1   <none>           <none>
dev                         poolmgr-nodejs-dev-26164-666f6f8bd-4vbl4     2/2     Running     0             15m   10.42.2.52   slave2   <none>           <none>
test                        poolmgr-nodejs-test-26720-5767bc599b-bkctc   2/2     Running     0             13m   10.42.0.41   master   <none>           <none>
test                        poolmgr-nodejs-test-26720-5767bc599b-flgz6   2/2     Running     0             13m   10.42.1.64   slave1   <none>           <none>
test                        poolmgr-nodejs-test-26720-5767bc599b-68mr2   2/2     Running     0             12m   10.42.2.55   slave2   <none>           <none>
pre                         notejs-test-dome-5b94b7fbd5-5vfv7            1/1     Running     0             84s   10.42.0.43   master   <none>           <none>

```





Discussion / hints:
I followed ingyamilmolinar's suggestion from https://github.com/fission/fission/issues/2722 to downgrade the K3S version in order to use the 'New-Deployment' type function.

Fix patch:
diff --git a/crds/v1/fission.io_functions.yaml b/crds/v1/fission.io_functions.yaml
index 1d6c43a55d..d743b34aa2 100644
--- a/crds/v1/fission.io_functions.yaml
+++ b/crds/v1/fission.io_functions.yaml
@@ -112,10 +112,11 @@ spec:
                                   - value
                                   type: object
                                 type: array
+                                x-kubernetes-list-type: atomic
                               selectPolicy:
                                 description: selectPolicy is used to specify which
                                   policy should be used. If not set, the default value
-                                  MaxPolicySelect is used.
+                                  Max is used.
                                 type: string
                               stabilizationWindowSeconds:
                                 description: 'stabilizationWindowSeconds is the number
@@ -168,10 +169,11 @@ spec:
                                   - value
                                   type: object
                                 type: array
+                                x-kubernetes-list-type: atomic
                               selectPolicy:
                                 description: selectPolicy is used to specify which
                                   policy should be used. If not set, the default value
-                                  MaxPolicySelect is used.
+                                  Max is used.
                                 type: string
                               stabilizationWindowSeconds:
                                 description: 'stabilizationWindowSeconds is the number
@@ -198,7 +200,7 @@ spec:
                             should be set at once).
                           properties:
                             containerResource:
-                              description: container resource refers to a resource
+                              description: containerResource refers to a resource
                                 metric (such as those specified in requests and limits)
                                 known to Kubernetes describing a single container
                                 in each pod of the current scale target (e.g. CPU
@@ -381,9 +383,8 @@ spec:
                                 on an Ingress object).
                               properties:
                                 describedObject:
-                                  description: CrossVersionObjectReference contains
-                                    enough information to let you identify the referred
-                                    resource.
+                                  description: describedObject specifies the descriptions
+                                    of a object,such as kind,name apiVersion
                                   properties:
                                     apiVersion:
                                       description: apiVersion is the API version of
diff --git a/pkg/apis/core/v1/types.go b/pkg/apis/core/v1/types.go
index b94614b581..046a9397e7 100644
--- a/pkg/apis/core/v1/types.go
+++ b/pkg/apis/core/v1/types.go
@@ -17,7 +17,7 @@ limitations under the License.
 package v1
 
 import (
-	asv2beta2 "k8s.io/api/autoscaling/v2beta2"
+	asv2 "k8s.io/api/autoscaling/v2"
 	apiv1 "k8s.io/api/core/v1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 )
@@ -475,12 +475,12 @@ type (
 		// created for the function.
 		// Applicable for executor type newdeploy and container.
 		// +optional
-		Metrics []asv2beta2.MetricSpec `json:"hpaMetrics,omitempty"`
+		Metrics []asv2.MetricSpec `json:"hpaMetrics,omitempty"`
 
 		// hpaBehavior is the behavior of HPA when scaling in up/down direction.
 		// Applicable for executor type newdeploy and container.
 		// +optional
-		Behavior *asv2beta2.HorizontalPodAutoscalerBehavior `json:"hpaBehavior,omitempty"`
+		Behavior *asv2.HorizontalPodAutoscalerBehavior `json:"hpaBehavior,omitempty"`
 	}
 
 	// FunctionReferenceType refers to type of Function
diff --git a/pkg/apis/core/v1/zz_generated.deepcopy.go b/pkg/apis/core/v1/zz_generated.deepcopy.go
index 93de8387b9..c78b39e20e 100644
--- a/pkg/apis/core/v1/zz_generated.deepcopy.go
+++ b/pkg/apis/core/v1/zz_generated.deepcopy.go
@@ -21,7 +21,7 @@ limitations under the License.
 package v1
 
 import (
-	"k8s.io/api/autoscaling/v2beta2"
+	"k8s.io/api/autoscaling/v2"
 	corev1 "k8s.io/api/core/v1"
 	"k8s.io/apimachinery/pkg/runtime"
 )
@@ -302,14 +302,14 @@ func (in *ExecutionStrategy) DeepCopyInto(out *ExecutionStrategy) {
 	*out = *in
 	if in.Metrics != nil {
 		in, out := &in.Metrics, &out.Metrics
-		*out = make([]v2beta2.MetricSpec, len(*in))
+		*out = make([]v2.MetricSpec, len(*in))
 		for i := range *in {
 			(*in)[i].DeepCopyInto(&(*out)[i])
 		}
 	}
 	if in.Behavior != nil {
 		in, out := &in.Behavior, &out.Behavior
-		*out = new(v2beta2.HorizontalPodAutoscalerBehavior)
+		*out = new(v2.HorizontalPodAutoscalerBehavior)
 		(*in).DeepCopyInto(*out)
 	}
 }
diff --git a/pkg/executor/reaper/reaper.go b/pkg/executor/reaper/reaper.go
index 8c0f1c4bd8..3d97caceaa 100644
--- a/pkg/executor/reaper/reaper.go
+++ b/pkg/executor/reaper/reaper.go
@@ -56,7 +56,7 @@ func CleanupKubeObject(ctx context.Context, logger *zap.Logger, kubeClient kuber
 		}
 
 	case "horizontalpodautoscaler":
-		err := kubeClient.AutoscalingV2beta2().HorizontalPodAutoscalers(kubeobj.Namespace).Delete(ctx, kubeobj.Name, metav1.DeleteOptions{})
+		err := kubeClient.AutoscalingV2().HorizontalPodAutoscalers(kubeobj.Namespace).Delete(ctx, kubeobj.Name, metav1.DeleteOptions{})
 		if err != nil {
 			logger.Error("error cleaning up horizontalpodautoscaler", zap.Error(err), zap.String("horizontalpodautoscaler", kubeobj.Name))
 		}
@@ -180,7 +180,7 @@ func CleanupServices(ctx context.Context, logger *zap.Logger, client kubernetes.
 // CleanupHpa deletes horizontal pod autoscaler(s) for a given instanceID
 func CleanupHpa(ctx context.Context, logger *zap.Logger, client kubernetes.Interface, instanceID string, listOps metav1.ListOptions) error {
 	cleanupHpa := func(namespace string) error {
-		hpaList, err := client.AutoscalingV2beta2().HorizontalPodAutoscalers(namespace).List(ctx, listOps)
+		hpaList, err := client.AutoscalingV2().HorizontalPodAutoscalers(namespace).List(ctx, listOps)
 		if err != nil {
 			return err
 		}
@@ -193,7 +193,7 @@ func CleanupHpa(ctx context.Context, logger *zap.Logger, client kubernetes.Inter
 			}
 			if ok && id != instanceID {
 				logger.Info("cleaning up HPA", zap.String("hpa", hpa.ObjectMeta.Name))
-				err := client.AutoscalingV2beta2().HorizontalPodAutoscalers(hpa.ObjectMeta.Namespace).Delete(ctx, hpa.ObjectMeta.Name, metav1.DeleteOptions{})
+				err := client.AutoscalingV2().HorizontalPodAutoscalers(hpa.ObjectMeta.Namespace).Delete(ctx, hpa.ObjectMeta.Name, metav1.DeleteOptions{})
 				if err != nil {
 					logger.Error("error cleaning up HPA",
 						zap.Error(err),
diff --git a/pkg/executor/util/hpa/hpa.go b/pkg/executor/util/hpa/hpa.go
index f9fe9f4014..aa770a4f57 100644
--- a/pkg/executor/util/hpa/hpa.go
+++ b/pkg/executor/util/hpa/hpa.go
@@ -21,7 +21,7 @@ import (
 
 	"go.uber.org/zap"
 	appsv1 "k8s.io/api/apps/v1"
-	asv2beta2 "k8s.io/api/autoscaling/v2beta2"
+	asv2 "k8s.io/api/autoscaling/v2"
 	corev1 "k8s.io/api/core/v1"
 	k8s_err "k8s.io/apimachinery/pkg/api/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -51,21 +51,21 @@ func NewHpaOperations(logger *zap.Logger, kubernetesClient kubernetes.Interface,
 	}
 }
 
-func ConvertTargetCPUToCustomMetric(targetCPUVal int32) asv2beta2.MetricSpec {
-	return asv2beta2.MetricSpec{
-		Type: asv2beta2.ResourceMetricSourceType,
-		Resource: &asv2beta2.ResourceMetricSource{
+func ConvertTargetCPUToCustomMetric(targetCPUVal int32) asv2.MetricSpec {
+	return asv2.MetricSpec{
+		Type: asv2.ResourceMetricSourceType,
+		Resource: &asv2.ResourceMetricSource{
 			Name: corev1.ResourceCPU,
-			Target: asv2beta2.MetricTarget{
-				Type:               asv2beta2.UtilizationMetricType,
+			Target: asv2.MetricTarget{
+				Type:               asv2.UtilizationMetricType,
 				AverageUtilization: &targetCPUVal,
 			},
 		},
 	}
 }
 
-func getScaleTargetRef(deployment *appsv1.Deployment) asv2beta2.CrossVersionObjectReference {
-	return asv2beta2.CrossVersionObjectReference{
+func getScaleTargetRef(deployment *appsv1.Deployment) asv2.CrossVersionObjectReference {
+	return asv2.CrossVersionObjectReference{
 		APIVersion: DeploymentVersion,
 		Kind:       DeploymentKind,
 		Name:       deployment.ObjectMeta.Name,
@@ -73,7 +73,7 @@ func getScaleTargetRef(deployment *appsv1.Deployment) asv2beta2.CrossVersionObje
 }
 
 func (hpaops *HpaOperations) CreateOrGetHpa(ctx context.Context, hpaName string, execStrategy *fv1.ExecutionStrategy,
-	depl *appsv1.Deployment, deployLabels map[string]string, deployAnnotations map[string]string) (*asv2beta2.HorizontalPodAutoscaler, error) {
+	depl *appsv1.Deployment, deployLabels map[string]string, deployAnnotations map[string]string) (*asv2.HorizontalPodAutoscaler, error) {
 
 	if depl == nil {
 		return nil, errors.New("failed to create HPA, found empty deployment")
@@ -89,7 +89,7 @@ func (hpaops *HpaOperations) CreateOrGetHpa(ctx context.Context, hpaName string,
 		maxRepl = minRepl
 	}
 	targetCPU := int32(execStrategy.TargetCPUPercent) // nolint: staticcheck
-	var hpaMetrics []asv2beta2.MetricSpec
+	var hpaMetrics []asv2.MetricSpec
 	if targetCPU > 0 && targetCPU < 100 {
 		hpaMetrics = append(hpaMetrics, ConvertTargetCPUToCustomMetric(targetCPU))
 	}
@@ -98,13 +98,13 @@ func (hpaops *HpaOperations) CreateOrGetHpa(ctx context.Context, hpaName string,
 		hpaMetrics = append(hpaMetrics, execStrategy.Metrics...)
 	}
 
-	hpa := &asv2beta2.HorizontalPodAutoscaler{
+	hpa := &asv2.HorizontalPodAutoscaler{
 		ObjectMeta: metav1.ObjectMeta{
 			Name:        hpaName,
 			Labels:      deployLabels,
 			Annotations: deployAnnotations,
 		},
-		Spec: asv2beta2.HorizontalPodAutoscalerSpec{
+		Spec: asv2.HorizontalPodAutoscalerSpec{
 			ScaleTargetRef: getScaleTargetRef(depl),
 			MinReplicas:    &minRepl,
 			MaxReplicas:    maxRepl,
@@ -120,7 +120,7 @@ func (hpaops *HpaOperations) CreateOrGetHpa(ctx context.Context, hpaName string,
 			existingHpa.Annotations = hpa.Annotations
 			existingHpa.Labels = hpa.Labels
 			existingHpa.Spec = hpa.Spec
-			existingHpa, err = hpaops.kubernetesClient.AutoscalingV2beta2().HorizontalPodAutoscalers(depl.ObjectMeta.Namespace).Update(ctx, existingHpa, metav1.UpdateOptions{})
+			existingHpa, err = hpaops.kubernetesClient.AutoscalingV2().HorizontalPodAutoscalers(depl.ObjectMeta.Namespace).Update(ctx, existingHpa, metav1.UpdateOptions{})
 			if err != nil {
 				logger.Warn("error adopting HPA", zap.Error(err),
 					zap.String("HPA", hpaName), zap.String("ns", depl.ObjectMeta.Namespace))
@@ -129,10 +129,10 @@ func (hpaops *HpaOperations) CreateOrGetHpa(ctx context.Context, hpaName string,
 		}
 		return existingHpa, err
 	} else if k8s_err.IsNotFound(err) {
-		cHpa, err := hpaops.kubernetesClient.AutoscalingV2beta2().HorizontalPodAutoscalers(depl.ObjectMeta.Namespace).Create(ctx, hpa, metav1.CreateOptions{})
+		cHpa, err := hpaops.kubernetesClient.AutoscalingV2().HorizontalPodAutoscalers(depl.ObjectMeta.Namespace).Create(ctx, hpa, metav1.CreateOptions{})
 		if err != nil {
 			if k8s_err.IsAlreadyExists(err) {
-				cHpa, err = hpaops.kubernetesClient.AutoscalingV2beta2().HorizontalPodAutoscalers(depl.ObjectMeta.Namespace).Get(ctx, hpaName, metav1.GetOptions{})
+				cHpa, err = hpaops.kubernetesClient.AutoscalingV2().HorizontalPodAutoscalers(depl.ObjectMeta.Namespace).Get(ctx, hpaName, metav1.GetOptions{})
 			}
 			if err != nil {
 				return nil, err
@@ -144,15 +144,15 @@ func (hpaops *HpaOperations) CreateOrGetHpa(ctx context.Context, hpaName string,
 	return nil, err
 }
 
-func (hpaops *HpaOperations) GetHpa(ctx context.Context, ns, name string) (*asv2beta2.HorizontalPodAutoscaler, error) {
-	return hpaops.kubernetesClient.AutoscalingV2beta2().HorizontalPodAutoscalers(ns).Get(ctx, name, metav1.GetOptions{})
+func (hpaops *HpaOperations) GetHpa(ctx context.Context, ns, name string) (*asv2.HorizontalPodAutoscaler, error) {
+	return hpaops.kubernetesClient.AutoscalingV2().HorizontalPodAutoscalers(ns).Get(ctx, name, metav1.GetOptions{})
 }
 
-func (hpaops *HpaOperations) UpdateHpa(ctx context.Context, hpa *asv2beta2.HorizontalPodAutoscaler) error {
-	_, err := hpaops.kubernetesClient.AutoscalingV2beta2().HorizontalPodAutoscalers(hpa.ObjectMeta.Namespace).Update(ctx, hpa, metav1.UpdateOptions{})
+func (hpaops *HpaOperations) UpdateHpa(ctx context.Context, hpa *asv2.HorizontalPodAutoscaler) error {
+	_, err := hpaops.kubernetesClient.AutoscalingV2().HorizontalPodAutoscalers(hpa.ObjectMeta.Namespace).Update(ctx, hpa, metav1.UpdateOptions{})
 	return err
 }
 
 func (hpaops *HpaOperations) DeleteHpa(ctx context.Context, ns string, name string) error {
-	return hpaops.kubernetesClient.AutoscalingV2beta2().HorizontalPodAutoscalers(ns).Delete(ctx, name, metav1.DeleteOptions{})
+	return hpaops.kubernetesClient.AutoscalingV2().HorizontalPodAutoscalers(ns).Delete(ctx, name, metav1.DeleteOptions{})
 }
diff --git a/pkg/fission-cli/cmd/function/create.go b/pkg/fission-cli/cmd/function/create.go
index 3d9e1f91f3..a9efd3fde7 100644
--- a/pkg/fission-cli/cmd/function/create.go
+++ b/pkg/fission-cli/cmd/function/create.go
@@ -21,7 +21,7 @@ import (
 
 	"github.com/pkg/errors"
 	uuid "github.com/satori/go.uuid"
-	asv2beta2 "k8s.io/api/autoscaling/v2beta2"
+	asv2 "k8s.io/api/autoscaling/v2"
 	apiv1 "k8s.io/api/core/v1"
 	k8serrors "k8s.io/apimachinery/pkg/api/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -527,7 +527,7 @@ func getExecutionStrategy(fnExecutor fv1.ExecutorType, input cli.Input) (strateg
 			if err != nil {
 				return nil, err
 			}
-			strategy.Metrics = []asv2beta2.MetricSpec{hpa.ConvertTargetCPUToCustomMetric(int32(targetCPU))}
+			strategy.Metrics = []asv2.MetricSpec{hpa.ConvertTargetCPUToCustomMetric(int32(targetCPU))}
 		}
 	}
 
@@ -620,7 +620,7 @@ func updateExecutionStrategy(input cli.Input, existingExecutionStrategy *fv1.Exe
 			if err != nil {
 				return nil, err
 			}
-			strategy.Metrics = []asv2beta2.MetricSpec{hpa.ConvertTargetCPUToCustomMetric(int32(targetCPU))}
+			strategy.Metrics = []asv2.MetricSpec{hpa.ConvertTargetCPUToCustomMetric(int32(targetCPU))}
 		}
 
 	}
diff --git a/pkg/fission-cli/cmd/support/resources/kubernetes.go b/pkg/fission-cli/cmd/support/resources/kubernetes.go
index eb3924497c..c6cc174a5f 100644
--- a/pkg/fission-cli/cmd/support/resources/kubernetes.go
+++ b/pkg/fission-cli/cmd/support/resources/kubernetes.go
@@ -116,7 +116,7 @@ func (res KubernetesObjectDumper) Dump(ctx context.Context, dumpDir string) {
 		}
 
 	case KubernetesHPA:
-		objs, err := res.client.AutoscalingV2beta2().HorizontalPodAutoscalers(metav1.NamespaceAll).List(ctx, metav1.ListOptions{LabelSelector: res.selector})
+		objs, err := res.client.AutoscalingV2().HorizontalPodAutoscalers(metav1.NamespaceAll).List(ctx, metav1.ListOptions{LabelSelector: res.selector})
 		if err != nil {
 			console.Error(fmt.Sprintf("Error getting %v list with selector %v: %v", res.objType, res.selector, err))
 			return
diff --git a/pkg/utils/otel/attributes.go b/pkg/utils/otel/attributes.go
index b8e30b987d..a393e1f865 100644
--- a/pkg/utils/otel/attributes.go
+++ b/pkg/utils/otel/attributes.go
@@ -6,7 +6,7 @@ import (
 	"go.opentelemetry.io/otel/attribute"
 	"go.opentelemetry.io/otel/trace"
 	appsv1 "k8s.io/api/apps/v1"
-	asv2beta2 "k8s.io/api/autoscaling/v2beta2"
+	asv2 "k8s.io/api/autoscaling/v2"
 
 	apiv1 "k8s.io/api/core/v1"
 
@@ -77,7 +77,7 @@ func GetAttributesForDeployment(deployment *appsv1.Deployment) []attribute.KeyVa
 	}
 }
 
-func GetAttributesForHPA(hpa *asv2beta2.HorizontalPodAutoscaler) []attribute.KeyValue {
+func GetAttributesForHPA(hpa *asv2.HorizontalPodAutoscaler) []attribute.KeyValue {
 	if hpa == nil {
 		return []attribute.KeyValue{}
 	}


Test patch:
diff --git a/pkg/executor/util/hpa/hpa_test.go b/pkg/executor/util/hpa/hpa_test.go
index 3431ead3f5..3010605604 100644
--- a/pkg/executor/util/hpa/hpa_test.go
+++ b/pkg/executor/util/hpa/hpa_test.go
@@ -22,7 +22,7 @@ import (
 
 	"github.com/dchest/uniuri"
 	appsv1 "k8s.io/api/apps/v1"
-	asv2beta2 "k8s.io/api/autoscaling/v2beta2"
+	asv2 "k8s.io/api/autoscaling/v2"
 	corev1 "k8s.io/api/core/v1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/client-go/kubernetes/fake"
@@ -33,13 +33,13 @@ import (
 
 func TestConvertTargetCPUToCustomMetric(t *testing.T) {
 	metricSpec := ConvertTargetCPUToCustomMetric(50)
-	if metricSpec.Type != asv2beta2.ResourceMetricSourceType {
+	if metricSpec.Type != asv2.ResourceMetricSourceType {
 		t.Errorf("Expected metric type to be Resource, got %v", metricSpec.Type)
 	}
 	if metricSpec.Resource.Name != corev1.ResourceCPU {
 		t.Errorf("Expected metric name to be cpu, got %v", metricSpec.Resource.Name)
 	}
-	if metricSpec.Resource.Target.Type != asv2beta2.UtilizationMetricType {
+	if metricSpec.Resource.Target.Type != asv2.UtilizationMetricType {
 		t.Errorf("Expected metric target type to be Utilization, got %v", metricSpec.Resource.Target.Type)
 	}
 	if metricSpec.Resource.Target.AverageUtilization == nil {
@@ -92,13 +92,13 @@ func TestHpaOps(t *testing.T) {
 	if hpa.Spec.MaxReplicas != 5 {
 		t.Errorf("Expected max replicas to be 5, got %v", hpa.Spec.MaxReplicas)
 	}
-	if hpa.Spec.Metrics[0].Type != asv2beta2.ResourceMetricSourceType {
+	if hpa.Spec.Metrics[0].Type != asv2.ResourceMetricSourceType {
 		t.Errorf("Expected metric type to be Resource, got %v", hpa.Spec.Metrics[0].Type)
 	}
 	if hpa.Spec.Metrics[0].Resource.Name != corev1.ResourceCPU {
 		t.Errorf("Expected metric name to be cpu, got %v", hpa.Spec.Metrics[0].Resource.Name)
 	}
-	if hpa.Spec.Metrics[0].Resource.Target.Type != asv2beta2.UtilizationMetricType {
+	if hpa.Spec.Metrics[0].Resource.Target.Type != asv2.UtilizationMetricType {
 		t.Errorf("Expected metric target type to be Utilization, got %v", hpa.Spec.Metrics[0].Resource.Target.Type)
 	}
 	if hpa.Spec.Metrics[0].Resource.Target.AverageUtilization == nil {
diff --git a/pkg/fission-cli/cmd/function/function_test.go b/pkg/fission-cli/cmd/function/function_test.go
index ee2cb2ebdb..40807f87f0 100644
--- a/pkg/fission-cli/cmd/function/function_test.go
+++ b/pkg/fission-cli/cmd/function/function_test.go
@@ -21,7 +21,7 @@ import (
 	"testing"
 
 	"github.com/stretchr/testify/assert"
-	asv2beta2 "k8s.io/api/autoscaling/v2beta2"
+	asv2 "k8s.io/api/autoscaling/v2"
 
 	fv1 "github.com/fission/fission/pkg/apis/core/v1"
 	"github.com/fission/fission/pkg/executor/util/hpa"
@@ -277,7 +277,7 @@ func TestGetInvokeStrategy(t *testing.T) {
 					ExecutorType:          fv1.ExecutorTypeNewdeploy,
 					MinScale:              DEFAULT_MIN_SCALE,
 					MaxScale:              DEFAULT_MIN_SCALE,
-					Metrics:               []asv2beta2.MetricSpec{hpa.ConvertTargetCPUToCustomMetric(50)},
+					Metrics:               []asv2.MetricSpec{hpa.ConvertTargetCPUToCustomMetric(50)},
 					SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
 				},
 			},
@@ -295,7 +295,7 @@ func TestGetInvokeStrategy(t *testing.T) {
 					ExecutorType:          fv1.ExecutorTypeNewdeploy,
 					MinScale:              2,
 					MaxScale:              5,
-					Metrics:               []asv2beta2.MetricSpec{hpa.ConvertTargetCPUToCustomMetric(88)},
+					Metrics:               []asv2.MetricSpec{hpa.ConvertTargetCPUToCustomMetric(88)},
 					SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
 				},
 			},
@@ -305,7 +305,7 @@ func TestGetInvokeStrategy(t *testing.T) {
 					ExecutorType:          fv1.ExecutorTypeNewdeploy,
 					MinScale:              2,
 					MaxScale:              5,
-					Metrics:               []asv2beta2.MetricSpec{hpa.ConvertTargetCPUToCustomMetric(20)},
+					Metrics:               []asv2.MetricSpec{hpa.ConvertTargetCPUToCustomMetric(20)},
 					SpecializationTimeout: fv1.DefaultSpecializationTimeOut,
 				},
 			},