Skip to content

Commit

Permalink
Expect either PV or it's pointer type as arg to PVStore 'Add()' method
Browse files Browse the repository at this point in the history
We were getting following error message while adding a PV to PVStore
as we were expecting only pointer to PV as arg to PVStore Add() method.

err: unexpected object of type v1.PersistentVolume

Signed-off-by: Arun Kumar Mohan <[email protected]>
  • Loading branch information
aruniiird committed Dec 18, 2023
1 parent 10f1b17 commit a63c97a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions metrics/internal/cache/pv.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,14 @@ func appendIfNotExists(slice []string, value string) []string {

// Add inserts to the PersistentVolumeStore.
func (p *PersistentVolumeStore) Add(obj interface{}) error {
pv, ok := obj.(*corev1.PersistentVolume)
if !ok {
var pv *corev1.PersistentVolume
// obj can be of PV type or a pointer to it
switch pvFromObj := obj.(type) {
case *corev1.PersistentVolume:
pv = pvFromObj
case corev1.PersistentVolume:
pv = &pvFromObj
default:
return fmt.Errorf("unexpected object of type %T", obj)
}

Expand Down

0 comments on commit a63c97a

Please sign in to comment.