From a3b3716483fc737685d541158ee3270ee114e34e Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Fri, 8 Nov 2024 11:02:15 -0700 Subject: [PATCH] Handle nil pointer potential: As the Hardware spec.metadata and spec.metadata.instance are not required in the hardware object they could be nil. Handle checking this so we don't nil pointer panic. Signed-off-by: Jacob Weinstock --- internal/backend/kubernetes/backend.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/backend/kubernetes/backend.go b/internal/backend/kubernetes/backend.go index 6d6e5654..3abd513a 100644 --- a/internal/backend/kubernetes/backend.go +++ b/internal/backend/kubernetes/backend.go @@ -162,7 +162,7 @@ type listerClient interface { func toEC2Instance(hw tinkv1.Hardware) ec2.Instance { var i ec2.Instance - if hw.Spec.Metadata.Instance != nil { + if hw.Spec.Metadata != nil && hw.Spec.Metadata.Instance != nil { i.Metadata.InstanceID = hw.Spec.Metadata.Instance.ID i.Metadata.Hostname = hw.Spec.Metadata.Instance.Hostname i.Metadata.LocalHostname = hw.Spec.Metadata.Instance.Hostname @@ -195,7 +195,7 @@ func toEC2Instance(hw tinkv1.Hardware) ec2.Instance { } } - if hw.Spec.Metadata.Facility != nil { + if hw.Spec.Metadata != nil && hw.Spec.Metadata.Facility != nil { i.Metadata.Plan = hw.Spec.Metadata.Facility.PlanSlug i.Metadata.Facility = hw.Spec.Metadata.Facility.FacilityCode }