Add staticcheck fixes (#3221)

* Add staticcheck fixes

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

* update golangci-lint version

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

---------

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
Sanket Sudake
2025-05-18 22:27:45 +05:30
committed by GitHub
parent 6cc6498844
commit 2b13af0a5e
58 changed files with 228 additions and 226 deletions
+1 -1
View File
@@ -72,7 +72,7 @@ func refreshPods(ctx context.Context, logger *zap.Logger, funcs []fv1.Function,
if exists {
err = et.RefreshFuncPods(ctx, logger, f)
} else {
err = fmt.Errorf("Unknown executor type '%s'", f.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType)
err = fmt.Errorf("unknown executor type '%s'", f.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType)
}
if err != nil {
+3 -3
View File
@@ -232,7 +232,7 @@ func (executor *Executor) createServiceForFunction(ctx context.Context, fn *fv1.
t := fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType
e, ok := executor.executorTypes[t]
if !ok {
return nil, fmt.Errorf("Unknown executor type '%s'", t)
return nil, fmt.Errorf("unknown executor type '%s'", t)
}
fsvc, fsvcErr := e.GetFuncSvc(ctx, fn)
@@ -253,7 +253,7 @@ func (executor *Executor) getFunctionServiceFromCache(ctx context.Context, fn *f
t := fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType
e, ok := executor.executorTypes[t]
if !ok {
return nil, fmt.Errorf("Unknown executor type '%s'", t)
return nil, fmt.Errorf("unknown executor type '%s'", t)
}
return e.GetFuncSvcFromCache(ctx, fn)
}
@@ -282,7 +282,7 @@ func StartExecutor(ctx context.Context, clientGen crd.ClientGeneratorInterface,
fetcherConfig, err := fetcherConfig.MakeFetcherConfig("/userfunc")
if err != nil {
return fmt.Errorf("Error making fetcher config: %w", err)
return fmt.Errorf("error making fetcher config: %w", err)
}
executorInstanceID := strings.ToLower(uniuri.NewLen(8))
@@ -436,27 +436,27 @@ func (caaf *Container) fnCreate(ctx context.Context, fn *fv1.Function) (*fscache
{
// obj.TypeMeta.Kind does not work hence this, needs investigation and a fix
Kind: "deployment",
Name: depl.ObjectMeta.Name,
APIVersion: depl.TypeMeta.APIVersion,
Namespace: depl.ObjectMeta.Namespace,
ResourceVersion: depl.ObjectMeta.ResourceVersion,
UID: depl.ObjectMeta.UID,
Name: depl.Name,
APIVersion: depl.APIVersion,
Namespace: depl.Namespace,
ResourceVersion: depl.ResourceVersion,
UID: depl.UID,
},
{
Kind: "service",
Name: svc.ObjectMeta.Name,
APIVersion: svc.TypeMeta.APIVersion,
Namespace: svc.ObjectMeta.Namespace,
ResourceVersion: svc.ObjectMeta.ResourceVersion,
UID: svc.ObjectMeta.UID,
Name: svc.Name,
APIVersion: svc.APIVersion,
Namespace: svc.Namespace,
ResourceVersion: svc.ResourceVersion,
UID: svc.UID,
},
{
Kind: "horizontalpodautoscaler",
Name: hpa.ObjectMeta.Name,
APIVersion: hpa.TypeMeta.APIVersion,
Namespace: hpa.ObjectMeta.Namespace,
ResourceVersion: hpa.ObjectMeta.ResourceVersion,
UID: hpa.ObjectMeta.UID,
Name: hpa.Name,
APIVersion: hpa.APIVersion,
Namespace: hpa.Namespace,
ResourceVersion: hpa.ResourceVersion,
UID: hpa.UID,
},
}
@@ -471,18 +471,18 @@ func (caaf *Container) fnCreate(ctx context.Context, fn *fv1.Function) (*fscache
_, err = caaf.fsCache.Add(*fsvc)
if err != nil {
caaf.logger.Error("error adding function to cache", zap.Error(err), zap.Any("function", fsvc.Function))
metrics.ColdStartsError.WithLabelValues(fn.ObjectMeta.Name, fn.ObjectMeta.Namespace).Inc()
metrics.ColdStartsError.WithLabelValues(fn.Name, fn.Namespace).Inc()
return fsvc, err
}
metrics.ColdStarts.WithLabelValues(fn.ObjectMeta.Name, fn.ObjectMeta.Namespace).Inc()
metrics.ColdStarts.WithLabelValues(fn.Name, fn.Namespace).Inc()
return fsvc, nil
}
func (caaf *Container) updateFunction(ctx context.Context, oldFn *fv1.Function, newFn *fv1.Function) error {
if oldFn.ObjectMeta.ResourceVersion == newFn.ObjectMeta.ResourceVersion {
if oldFn.ResourceVersion == newFn.ResourceVersion {
return nil
}
@@ -482,7 +482,7 @@ func (deploy *NewDeploy) fnCreate(ctx context.Context, fn *fv1.Function) (*fscac
// obj.TypeMeta.Kind does not work hence this, needs investigation and a fix
Kind: "deployment",
Name: depl.ObjectMeta.Name,
APIVersion: depl.TypeMeta.APIVersion,
APIVersion: depl.APIVersion,
Namespace: depl.ObjectMeta.Namespace,
ResourceVersion: depl.ObjectMeta.ResourceVersion,
UID: depl.ObjectMeta.UID,
@@ -490,7 +490,7 @@ func (deploy *NewDeploy) fnCreate(ctx context.Context, fn *fv1.Function) (*fscac
{
Kind: "service",
Name: svc.ObjectMeta.Name,
APIVersion: svc.TypeMeta.APIVersion,
APIVersion: svc.APIVersion,
Namespace: svc.ObjectMeta.Namespace,
ResourceVersion: svc.ObjectMeta.ResourceVersion,
UID: svc.ObjectMeta.UID,
@@ -498,7 +498,7 @@ func (deploy *NewDeploy) fnCreate(ctx context.Context, fn *fv1.Function) (*fscac
{
Kind: "horizontalpodautoscaler",
Name: hpa.ObjectMeta.Name,
APIVersion: hpa.TypeMeta.APIVersion,
APIVersion: hpa.APIVersion,
Namespace: hpa.ObjectMeta.Namespace,
ResourceVersion: hpa.ObjectMeta.ResourceVersion,
UID: hpa.ObjectMeta.UID,
+2 -2
View File
@@ -415,7 +415,7 @@ func (gp *GenericPool) specializePod(ctx context.Context, pod *apiv1.Pod, fn *fv
// for fetcher we don't need to create a service, just talk to the pod directly
podIP := pod.Status.PodIP
if len(podIP) == 0 {
return fmt.Errorf("Pod %s in namespace %s has no IP", pod.ObjectMeta.Name, pod.ObjectMeta.Namespace)
return fmt.Errorf("pod %s in namespace %s has no IP", pod.ObjectMeta.Name, pod.ObjectMeta.Namespace)
}
for _, cm := range fn.Spec.ConfigMaps {
_, err := gp.kubernetesClient.CoreV1().ConfigMaps(gp.fnNamespace).Get(ctx, cm.Name, metav1.GetOptions{})
@@ -601,7 +601,7 @@ func (gp *GenericPool) getFuncSvc(ctx context.Context, fn *fv1.Function) (*fscac
{
Kind: "pod",
Name: pod.ObjectMeta.Name,
APIVersion: pod.TypeMeta.APIVersion,
APIVersion: pod.APIVersion,
Namespace: pod.ObjectMeta.Namespace,
ResourceVersion: pod.ObjectMeta.ResourceVersion,
UID: pod.ObjectMeta.UID,
+1 -1
View File
@@ -458,7 +458,7 @@ func (gpm *GenericPoolManager) AdoptExistingResources(ctx context.Context) {
{
Kind: "pod",
Name: pod.Name,
APIVersion: pod.TypeMeta.APIVersion,
APIVersion: pod.APIVersion,
Namespace: pod.ObjectMeta.Namespace,
ResourceVersion: pod.ObjectMeta.ResourceVersion,
UID: pod.ObjectMeta.UID,
+3 -3
View File
@@ -306,7 +306,7 @@ func (c *PoolCache) service() {
datawriter := bufio.NewWriter(req.dumpWriter)
writefnSvcGrp := func(svcGrp *funcSvcGroup) error {
_, err := datawriter.WriteString(fmt.Sprintf("svc_waiting:%d\tqueue_len:%d", svcGrp.svcWaiting, svcGrp.queue.Len()))
_, err := fmt.Fprintf(datawriter, "svc_waiting:%d\tqueue_len:%d", svcGrp.svcWaiting, svcGrp.queue.Len())
if err != nil {
return err
}
@@ -319,8 +319,8 @@ func (c *PoolCache) service() {
}
for addr, fnSvc := range svcGrp.svcs {
_, err := datawriter.WriteString(fmt.Sprintf("\tfunction_name:%s\tfn_svc_address:%s\tactive_req:%d\tcurrent_cpu_usage:%v\tcpu_limit:%v\n",
fnSvc.val.Function.Name, addr, fnSvc.activeRequests, fnSvc.currentCPUUsage, fnSvc.cpuLimit))
_, err := fmt.Fprintf(datawriter, "\tfunction_name:%s\tfn_svc_address:%s\tactive_req:%d\tcurrent_cpu_usage:%v\tcpu_limit:%v\n",
fnSvc.val.Function.Name, addr, fnSvc.activeRequests, fnSvc.currentCPUUsage, fnSvc.cpuLimit)
if err != nil {
return err
}
+1 -1
View File
@@ -55,7 +55,7 @@ securityContext:
}
var permissionNum int64 = 10001
var runAsNonRoot bool = true
var runAsNonRoot = true
testSpecPatch := apiv1.PodSpec{
SecurityContext: &apiv1.PodSecurityContext{