Skip to content

Commit 68502dd

Browse files
Merge pull request #56 from appscode-cloud/sel
Handle both variations of the OffshootSelctors func to fix client-bil…
1 parent 866d13a commit 68502dd

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/billing_event.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ func (p *BillingEventCreator) CreateEvent(obj client.Object) (*api.Event, error)
8585
}
8686

8787
if p.ClientBilling {
88-
if r, ok := obj.(Resource); ok {
88+
if sel, ok := getOffshootSelectorsIfAny(obj); ok {
8989
var podList core.PodList
90-
err = p.PodLister.List(context.TODO(), &podList, client.InNamespace(obj.GetNamespace()), client.MatchingLabels(r.OffshootSelectors()))
90+
err = p.PodLister.List(context.TODO(), &podList, client.InNamespace(obj.GetNamespace()), client.MatchingLabels(sel))
9191
if err != nil {
9292
return nil, err
9393
}
@@ -119,7 +119,7 @@ func (p *BillingEventCreator) CreateEvent(obj client.Object) (*api.Event, error)
119119
res.Spec.Pods = podresources
120120

121121
var pvcList core.PersistentVolumeClaimList
122-
err = p.PVCLister.List(context.TODO(), &pvcList, client.InNamespace(obj.GetNamespace()), client.MatchingLabels(r.OffshootSelectors()))
122+
err = p.PVCLister.List(context.TODO(), &pvcList, client.InNamespace(obj.GetNamespace()), client.MatchingLabels(sel))
123123
if err != nil {
124124
return nil, err
125125
}
@@ -144,6 +144,20 @@ func (p *BillingEventCreator) CreateEvent(obj client.Object) (*api.Event, error)
144144
}, nil
145145
}
146146

147+
func getOffshootSelectorsIfAny(obj client.Object) (map[string]string, bool) {
148+
if r, ok := obj.(Resource); ok {
149+
return r.OffshootSelectors(), true
150+
}
151+
if r, ok := obj.(ResourceExtra); ok {
152+
return r.OffshootSelectors(), true
153+
}
154+
return nil, false
155+
}
156+
147157
type Resource interface {
148158
OffshootSelectors() map[string]string
149159
}
160+
161+
type ResourceExtra interface {
162+
OffshootSelectors(extraSelectors ...map[string]string) map[string]string
163+
}

0 commit comments

Comments
 (0)