Skip to content

Conversation

@djdongjin
Copy link
Member

@djdongjin djdongjin commented Jun 9, 2023

Use a *typeurl.Any and nil pointer to indicate if the marshal result is saved.

Another approach might be just marshal the empty response as part of InitFn? 🤔️

var emptyResponse typeurl.Any
...
		InitFn: func(ic *plugin.InitContext) (interface{}, error) {
                         ...
                         emptyResponse, err = typeurl.MarshalAny(&ptypes.Empty{})
                         if err != nil {
                             return nil, err
                         }
                         ...
			return &service{manager: i.(streaming.StreamManager)}, nil
		},

@k8s-ci-robot
Copy link

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@djdongjin djdongjin marked this pull request as ready for review June 9, 2023 18:36
@djdongjin djdongjin force-pushed the premarshal-empty-resp branch 2 times, most recently from 32fc053 to 1273311 Compare June 13, 2023 16:46
@djdongjin
Copy link
Member Author

cc @dmcgowan PTAL thanks!

@Iceber
Copy link
Member

Iceber commented Jun 14, 2023

Another approach might be just marshal the empty response as part of InitFn? 🤔️

I think this is more concise

In addition, the initialization of emptyResponse is not actually related to InitFn, so it looks fine to put it directly in init, eg

var emptyResponse typeurl.Any

func init () {
       emptyResponse, err = typeurl.MarshalAny(&ptypes.Empty{})
       if err != nil {
               panic(fmt.Sprintf("......: %v", err))
        }

        plugin.Register(&plugin.Registration{
        ....
}

@djdongjin djdongjin force-pushed the premarshal-empty-resp branch from 1273311 to 2abc7b6 Compare June 14, 2023 18:02
@djdongjin djdongjin force-pushed the premarshal-empty-resp branch from 2abc7b6 to e26c97c Compare June 14, 2023 18:03
@djdongjin
Copy link
Member Author

In addition, the initialization of emptyResponse is not actually related to InitFn, so it looks fine to put it directly in init, eg

updated. thanks for the reminder :). I didn't use this approach because not sure if it's okay to panic in plugin init 😅

@Iceber
Copy link
Member

Iceber commented Jun 15, 2023

In addition, the initialization of emptyResponse is not actually related to InitFn, so it looks fine to put it directly in init, eg

updated. thanks for the reminder :). I didn't use this approach because not sure if it's okay to panic in plugin init 😅

T functions such as typeurl.Register and plugin.Register will also cause panic, the difference is that panic is called explicitly here, but of course see what others have suggested

@dcantah
Copy link
Member

dcantah commented Jun 15, 2023

I'd argue if it did panic we likely screwed up typeurl pretty bad 😆. I like @Iceber's suggestion

Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

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

LGTM

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.

6 participants