Skip to content

Conversation

@IfSentient
Copy link
Contributor

Introduce resource.PartialObject and k8s.DeferredNegotiatedSerializer to allow for deferring more expensive unmarshaling for a given kind. This is an experimental feature to see if this accelerates initial start-up processing of large numbers of objects in CPU-constrained environments, and may be removed in a future release if not effective.

Includes changes from not-yet-merged #1023 to allow specifying the negotiated serializer using k8s.ClientConfig.

@IfSentient IfSentient requested a review from a team as a code owner October 15, 2025 15:19
Copy link
Contributor

@radiohead radiohead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of minor comments, but also, could we add a benchmark? Something like:

// resource/partialobject_test.go
func BenchmarkPartialObjectUnmarshal(b *testing.B) {
    data := []byte(`{"apiVersion":"v1","kind":"Pod","metadata":{"name":"test","namespace":"default"},"spec":{"containers":[...]}}`)
    for i := 0; i < b.N; i++ {
        var obj PartialObject
        _ = json.Unmarshal(data, &obj)
    }
}

func BenchmarkTypedObjectUnmarshal(b *testing.B) {
    data := []byte(`{"apiVersion":"v1","kind":"Pod","metadata":{"name":"test","namespace":"default"},"spec":{"containers":[...]}}`)
    for i := 0; i < b.N; i++ {
        var obj TypedSpecObject[PodSpec]
        _ = json.Unmarshal(data, &obj)
    }
}

func NewApp(config AppConfig) (*App, error) {
clients := config.ClientGenerator
if clients == nil {
k8s.NewClientRegistry(config.KubeConfig, k8s.DefaultClientConfig())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
k8s.NewClientRegistry(config.KubeConfig, k8s.DefaultClientConfig())
clients = k8s.NewClientRegistry(config.KubeConfig, k8s.DefaultClientConfig())

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, that this should go away after syncing with main, since #1023 was merged.

Comment on lines +37 to +38
p.TypeMeta = *md.TypeMeta
p.ObjectMeta = *md.ObjectMeta
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could be nil, couldn't they?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants