Skip to content

Conversation

@hasbro17
Copy link
Contributor

Follow up to #8 with the simplified API with Watch.

Again the focus of this PR is mainly how the Watch API is implemented through informers.
According to the 0.1 milestone design there is no dispatcher, and instead every informer invokes the Handle() function in its sync for each Event to get the required Actions.

A lot of things are still TODO, like initializing or creating the SDK, handling the actions, supporting label selector options for Watch etc.

Plus based on some offline discussion I've added a wrapper around the regular context.Context in anticipation of passing additional info to the Handler but it's usage is still unclear this early on.

// last known state.
type Event struct {
Object Object
ObjectExist bool
Copy link
Contributor

@fanminshi fanminshi Feb 14, 2018

Choose a reason for hiding this comment

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

I am curious how does user handle object that's being updated? does the user want also know about old obj too? or that doesn't matter.

Copy link
Contributor

Choose a reason for hiding this comment

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

also would the event be more descriptive if we have enum on what type of event it is?
e.g:

type EventType int

const (
	Added EventType = iota
	Modified
	Deleted
	Error
)

type Event struct {
	EventType
	obj interface
}

Copy link
Contributor

Choose a reason for hiding this comment

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

does the user want also know about old obj too? or that doesn't matter.

Doesn't matter.

also would the event be more descriptive if we have enum on what type of event it is?

That's out of the scope.
For design discussion, please comment on the design doc.

pkg/sdk/api.go Outdated
handler *stub.Handler
}

func NewSDK() SDK {
Copy link

Choose a reason for hiding this comment

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

Just New. It will look like SDK.New( ) outside this package.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably don't define a struct now?
User will call sdk.Watch() and sdk is the package name, not a struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hongchaodeng Yeah I'm a little confused on the implementation of that. There should be some instance of the SDK that is configured by Watch() and Handle() before you call sdk.Run(). That's what the sdk struct was for.

Or is this configuration for the entire pkg and not an instance of the sdk?

pkg/sdk/doc.go Outdated
@@ -0,0 +1,12 @@
package sdk
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this doc?
We will have the example in README.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is the golang idiomatic way to include doc.go for each pkg to describe what the pkg does. e.g https://github.com/coreos/etcd/blob/master/clientv3/doc.go

"k8s.io/apimachinery/pkg/runtime"
)

type Object runtime.Object
Copy link
Contributor

Choose a reason for hiding this comment

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

Add doc

@@ -0,0 +1,20 @@
package stub
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this?
The stub is generated.

// last known state.
type Event struct {
Object Object
ObjectExist bool
Copy link
Contributor

Choose a reason for hiding this comment

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

does the user want also know about old obj too? or that doesn't matter.

Doesn't matter.

also would the event be more descriptive if we have enum on what type of event it is?

That's out of the scope.
For design discussion, please comment on the design doc.

@hasbro17
Copy link
Contributor Author

@hongchaodeng the sdk API is now at the package level. PTAL.

pkg/sdk/api.go Outdated
for _, informer := range informers {
err := informer.Run(ctx, handler)
if err != nil {
panic("TODO")
Copy link
Contributor

Choose a reason for hiding this comment

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

Write a bit more TODO what?

ObjectExist bool
}

// FuncType defines the type of the function of an Action.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you leave these non-watch related changes out of this PR?

@fanminshi fanminshi mentioned this pull request Feb 14, 2018
21 tasks
@hasbro17
Copy link
Contributor Author

Removed non Watch related types like Action and Handler for now.

@hongchaodeng
Copy link
Contributor

LGTM.

@hongchaodeng hongchaodeng merged commit 0ee6048 into operator-framework:master Feb 14, 2018
@hongchaodeng hongchaodeng deleted the haseeb/add-informer-implementation branch February 14, 2018 19:29
VenkatRamaraju referenced this pull request in VenkatRamaraju/operator-sdk Apr 4, 2022
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.

4 participants