Skip to content

Commit

Permalink
PersistentVolume.Obtain(): Fix `invalid memory address or nil point…
Browse files Browse the repository at this point in the history
…er dereference`
  • Loading branch information
lippserd committed Apr 15, 2024
1 parent 8e17208 commit 230491b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pkg/schema/v1/persistent_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type PersistentVolume struct {
Phase string
Reason string
Message string
Claim PersistentVolumeClaimRef `db:"-"`
Claim *PersistentVolumeClaimRef `db:"-"`
}

type PersistentVolumeClaimRef struct {
Expand Down Expand Up @@ -62,15 +62,21 @@ func (p *PersistentVolume) Obtain(k8s kmetav1.Object) {
panic(err)
}

p.Claim = PersistentVolumeClaimRef{
PersistentVolumeId: p.Id,
Kind: persistentVolume.Spec.ClaimRef.Kind,
Name: persistentVolume.Spec.ClaimRef.Name,
Uid: persistentVolume.Spec.ClaimRef.UID,
if persistentVolume.Spec.ClaimRef != nil {
p.Claim = &PersistentVolumeClaimRef{
PersistentVolumeId: p.Id,
Kind: persistentVolume.Spec.ClaimRef.Kind,
Name: persistentVolume.Spec.ClaimRef.Name,
Uid: persistentVolume.Spec.ClaimRef.UID,
}
}
}

func (p *PersistentVolume) Relations() []database.Relation {
if p.Claim == nil {
return []database.Relation{}
}

fk := database.WithForeignKey("persistent_volume_id")

return []database.Relation{
Expand Down

0 comments on commit 230491b

Please sign in to comment.