Skip to content

Commit

Permalink
bug: don't assume kind/apiversion are set on object
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Oct 25, 2024
1 parent 096ce85 commit 9ff4a5c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pkg/router/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ func (f FinalizerHandler) Handle(req Request, resp Response) error {
}

for _, respObj := range newResp.Objs {
if isObjectForRequest(req, respObj) {
if ok, err := isObjectForRequest(req, respObj); err != nil {
return err
} else if ok {
newObj = respObj
}
resp.Objects(respObj)
Expand Down
2 changes: 1 addition & 1 deletion pkg/router/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (m *HandlerSet) onChange(gvk schema.GroupVersionKind, key string, runtimeOb
err = m.backend.Get(m.ctx, kclient.ObjectKey{Name: name, Namespace: ns}, obj.(kclient.Object))
if err == nil {
runtimeObject = obj
} else if err != nil && !apierror.IsNotFound(err) {
} else if !apierror.IsNotFound(err) {
return nil, err
}

Expand Down
10 changes: 7 additions & 3 deletions pkg/router/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import (
kclient "sigs.k8s.io/controller-runtime/pkg/client"
)

func isObjectForRequest(req Request, obj kclient.Object) bool {
func isObjectForRequest(req Request, obj kclient.Object) (bool, error) {
gvk, err := req.Client.GroupVersionKindFor(obj)
if err != nil {
return false, err
}
return obj.GetName() == req.Name &&
obj.GetNamespace() == req.Namespace &&
obj.GetObjectKind().GroupVersionKind() == req.GVK
gvk == req.GVK, nil
}

type handlers struct {
Expand Down Expand Up @@ -53,7 +57,7 @@ func (h *handlers) Handle(req Request, resp *response) error {
}
newObjects := make([]kclient.Object, 0, len(resp.objects))
for _, obj := range resp.objects {
if isObjectForRequest(req, obj) {
if ok, err := isObjectForRequest(req, obj); err != nil {

Check failure on line 60 in pkg/router/handlers.go

View workflow job for this annotation

GitHub Actions / test

declared and not used: ok (typecheck)

Check failure on line 60 in pkg/router/handlers.go

View workflow job for this annotation

GitHub Actions / test

declared and not used: ok) (typecheck)

Check failure on line 60 in pkg/router/handlers.go

View workflow job for this annotation

GitHub Actions / test

declared and not used: ok) (typecheck)

Check failure on line 60 in pkg/router/handlers.go

View workflow job for this annotation

GitHub Actions / test

declared and not used: ok) (typecheck)
req.Object = obj
} else {
newObjects = append(newObjects, obj)
Expand Down

0 comments on commit 9ff4a5c

Please sign in to comment.