-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamer.go
40 lines (30 loc) · 1.09 KB
/
streamer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// SPDX-License-Identifier: AGPL-3.0-only
package apihelpers
import (
"context"
"fmt"
"io"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apiserver/pkg/registry/rest"
)
type inputStreamFn = func(ctx context.Context, apiVersion, acceptHeader string) (stream io.ReadCloser, flush bool, contentType string, err error)
type SubresourceStreamer struct {
fn inputStreamFn
}
var _ rest.ResourceStreamer = (*SubresourceStreamer)(nil)
func (s *SubresourceStreamer) SetInputStream(fn inputStreamFn) {
s.fn = fn
}
func (s *SubresourceStreamer) GetObjectKind() schema.ObjectKind {
return schema.EmptyObjectKind
}
func (s *SubresourceStreamer) DeepCopyObject() runtime.Object {
panic("SubresourceStreamer does not implement DeepCopyObject")
}
func (s *SubresourceStreamer) InputStream(ctx context.Context, apiVersion, acceptHeader string) (stream io.ReadCloser, flush bool, contentType string, err error) {
if s.fn == nil {
return nil, false, "", fmt.Errorf("subresource streamer not initialized with input stream function")
}
return s.fn(ctx, apiVersion, acceptHeader)
}