Skip to content

Commit

Permalink
Handle nil pointer potential:
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jacobweinstock committed Nov 8, 2024
1 parent 4600371 commit 2288856
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/backend/kubernetes/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 2288856

Please sign in to comment.