Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# editor and IDE paraphernalia
.idea
*.iml
*.swp
*.swo
*~
Expand Down
23 changes: 23 additions & 0 deletions pkg/internal/source/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -293,6 +294,28 @@ var _ = Describe("Internal", func() {
}
Expect(kind.String()).Should(Equal("kind source: *v1.Pod"))
})
It("should return kind source underlying type for Unstructured", func() {
kind := internal.Kind[*unstructured.Unstructured, reconcile.Request]{
Type: &unstructured.Unstructured{
Object: map[string]any{
"apiVersion": "apps/v1",
"kind": "Deployment",
},
},
}
Expect(kind.String()).Should(Equal("kind source: *unstructured.Unstructured[apps/v1 Deployment]"))
})
It("should return kind source underlying type for PartialObjectMetadata", func() {
kind := internal.Kind[*metav1.PartialObjectMetadata, reconcile.Request]{
Type: &metav1.PartialObjectMetadata{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Kind: "Deployment",
},
},
}
Expect(kind.String()).Should(Equal("kind source: *v1.PartialObjectMetadata[apps/v1 Deployment]"))
})
})
})

Expand Down
16 changes: 13 additions & 3 deletions pkg/internal/source/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"time"

"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/wait"
toolscache "k8s.io/client-go/tools/cache"
Expand Down Expand Up @@ -116,10 +118,18 @@ func (ks *Kind[object, request]) Start(ctx context.Context, queue workqueue.Type
}

func (ks *Kind[object, request]) String() string {
if !isNil(ks.Type) {
if isNil(ks.Type) {
return "kind source: unknown type"
}

switch v := any(ks.Type).(type) {
case *unstructured.Unstructured, *metav1.PartialObjectMetadata:
gvk := v.(client.Object).GetObjectKind().GroupVersionKind()
gv, kind := gvk.ToAPIVersionAndKind()
return fmt.Sprintf("kind source: %T[%s %s]", v, gv, kind)
default:
return fmt.Sprintf("kind source: %T", ks.Type)
}
return "kind source: unknown type"
}

// WaitForSync implements SyncingSource to allow controllers to wait with starting
Expand All @@ -133,7 +143,7 @@ func (ks *Kind[object, request]) WaitForSync(ctx context.Context) error {
if errors.Is(ctx.Err(), context.Canceled) {
return nil
}
return fmt.Errorf("timed out waiting for cache to be synced for Kind %T", ks.Type)
return fmt.Errorf("timed out waiting for cache to be synced for %s", ks.String())
}
}

Expand Down
Loading