From 559bb397642873d49df973acd2e49234ded1be70 Mon Sep 17 00:00:00 2001 From: Angel Misevski Date: Thu, 29 Jun 2023 10:18:15 -0400 Subject: [PATCH] Fix potential nil pointer dereference in reconcile loop Fix potential for a panic due to nil pointer dereference if the workspace ServiceAccount does not exist. Signed-off-by: Angel Misevski --- controllers/workspace/devworkspace_controller.go | 6 ++++-- pkg/provision/workspace/pull_secret.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/controllers/workspace/devworkspace_controller.go b/controllers/workspace/devworkspace_controller.go index 097614b30..f3b2595c8 100644 --- a/controllers/workspace/devworkspace_controller.go +++ b/controllers/workspace/devworkspace_controller.go @@ -443,8 +443,10 @@ func (r *DevWorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request return reconcileResult, reconcileErr } - allPodAdditions = append(allPodAdditions, *pullSecretPodAdditions) - reconcileStatus.setConditionTrue(conditions.PullSecretsReady, "DevWorkspace secrets ready") + if pullSecretPodAdditions != nil && pullSecretPodAdditions.PullSecrets != nil { + allPodAdditions = append(allPodAdditions, *pullSecretPodAdditions) + reconcileStatus.setConditionTrue(conditions.PullSecretsReady, "DevWorkspace secrets ready") + } if kubesync.HasKubelikeComponent(workspace) { err := kubesync.HandleKubernetesComponents(workspace, clusterAPI) diff --git a/pkg/provision/workspace/pull_secret.go b/pkg/provision/workspace/pull_secret.go index ecf5d2aa8..95b742607 100644 --- a/pkg/provision/workspace/pull_secret.go +++ b/pkg/provision/workspace/pull_secret.go @@ -64,7 +64,7 @@ func PullSecrets(clusterAPI sync.ClusterAPI, serviceAccountName, namespace strin if err != nil { if k8sErrors.IsNotFound(err) { // ServiceAccount does not exist, no pull secrets to extract - return nil, nil + return &v1alpha1.PodAdditions{}, nil } return nil, err }