Skip to content

Commit

Permalink
fix: only raise nil responses for k8s list calls as errors
Browse files Browse the repository at this point in the history
Empty items should just be treated as such.
  • Loading branch information
josegonzalez committed Dec 12, 2024
1 parent 3f25b7e commit 233e588
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions plugins/scheduler-k3s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ func (e *NotFoundError) Error() string {
return e.Message
}

type EmptyResultsError struct {
type NilResponseError struct {
Message string
}

func (e *EmptyResultsError) Error() string {
func (e *NilResponseError) Error() string {
return e.Message
}

Expand Down Expand Up @@ -541,8 +541,8 @@ func (k KubernetesClient) ListClusterTriggerAuthentications(ctx context.Context,
return []kedav1alpha1.ClusterTriggerAuthentication{}, err
}

if response == nil || len(response.Items) == 0 {
return []kedav1alpha1.ClusterTriggerAuthentication{}, &EmptyResultsError{"cluster trigger authentications is nil"}
if response == nil {
return []kedav1alpha1.ClusterTriggerAuthentication{}, &NilResponseError{"cluster trigger authentications is nil"}
}

triggerAuthentications := []kedav1alpha1.ClusterTriggerAuthentication{}
Expand Down Expand Up @@ -580,8 +580,8 @@ func (k KubernetesClient) ListCronJobs(ctx context.Context, input ListCronJobsIn
return []batchv1.CronJob{}, err
}

if cronJobs == nil || len(cronJobs.Items) == 0 {
return []batchv1.CronJob{}, &EmptyResultsError{"cron jobs is nil"}
if cronJobs == nil {
return []batchv1.CronJob{}, &NilResponseError{"cron jobs is nil"}
}

return cronJobs.Items, err
Expand All @@ -604,8 +604,8 @@ func (k KubernetesClient) ListDeployments(ctx context.Context, input ListDeploym
return []appsv1.Deployment{}, err
}

if deployments == nil || len(deployments.Items) == 0 {
return []appsv1.Deployment{}, &EmptyResultsError{"deployments list is nil"}
if deployments == nil {
return []appsv1.Deployment{}, &NilResponseError{"deployments list is nil"}
}

return deployments.Items, nil
Expand All @@ -628,8 +628,8 @@ func (k KubernetesClient) ListIngresses(ctx context.Context, input ListIngresses
return []networkingv1.Ingress{}, err
}

if ingresses == nil || len(ingresses.Items) == 0 {
return []networkingv1.Ingress{}, &EmptyResultsError{"ingresses is nil"}
if ingresses == nil {
return []networkingv1.Ingress{}, &NilResponseError{"ingresses is nil"}
}

return ingresses.Items, nil
Expand All @@ -641,8 +641,8 @@ func (k KubernetesClient) ListNamespaces(ctx context.Context) ([]corev1.Namespac
if err != nil {
return []corev1.Namespace{}, err
}
if namespaces == nil || len(namespaces.Items) == 0 {
return []corev1.Namespace{}, &EmptyResultsError{"namespaces list is nil"}
if namespaces == nil {
return []corev1.Namespace{}, &NilResponseError{"namespaces list is nil"}
}

return namespaces.Items, nil
Expand All @@ -666,8 +666,8 @@ func (k KubernetesClient) ListNodes(ctx context.Context, input ListNodesInput) (
return []corev1.Node{}, err
}

if nodeList == nil || len(nodeList.Items) == 0 {
return []corev1.Node{}, &EmptyResultsError{"pod list is nil"}
if nodeList == nil {
return []corev1.Node{}, &NilResponseError{"pod list is nil"}
}

return nodeList.Items, err
Expand All @@ -690,8 +690,8 @@ func (k KubernetesClient) ListPods(ctx context.Context, input ListPodsInput) ([]
return []corev1.Pod{}, err
}

if podList == nil || len(podList.Items) == 0 {
return []corev1.Pod{}, &EmptyResultsError{"pod list is nil"}
if podList == nil {
return []corev1.Pod{}, &NilResponseError{"pod list is nil"}
}

return podList.Items, err
Expand Down Expand Up @@ -721,8 +721,8 @@ func (k KubernetesClient) ListTriggerAuthentications(ctx context.Context, input
return []kedav1alpha1.TriggerAuthentication{}, err
}

if response == nil || len(response.Items) == 0 {
return []kedav1alpha1.TriggerAuthentication{}, &EmptyResultsError{"trigger authentications is nil"}
if response == nil {
return []kedav1alpha1.TriggerAuthentication{}, &NilResponseError{"trigger authentications is nil"}
}

triggerAuthentications := []kedav1alpha1.TriggerAuthentication{}
Expand Down

0 comments on commit 233e588

Please sign in to comment.