Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ add payload for manifestwork #269

Merged

Conversation

skeeey
Copy link
Member

@skeeey skeeey commented Aug 29, 2023

Summary

add cloudevents payload for manifestwork

@openshift-ci openshift-ci bot requested review from deads2k and mdelder August 29, 2023 01:20
@skeeey
Copy link
Member Author

skeeey commented Aug 29, 2023

/assign @qiujian16

@skeeey
Copy link
Member Author

skeeey commented Aug 29, 2023

/assign @morvencao

}

// SingleManifest represents the data in a cloudevent, it contains a single manifest.
type SingleManifest struct {
Copy link
Member

Choose a reason for hiding this comment

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

nit: do we need 'single', 'Manifest' is more simpler and straightforward?

Copy link
Member Author

Choose a reason for hiding this comment

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

Use Manifest as the struct name

@@ -19,6 +19,14 @@ const (
SourceAll = ""
)

const (
// CloudEventsDataTypeAnnotationKey is the key of the cloudevents data type annotation.
CloudEventsDataTypeAnnotationKey = "cloudevents.open-cluster-management.io/datatype"
Copy link
Member

Choose a reason for hiding this comment

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

what's this annotation for?

Copy link
Member Author

Choose a reason for hiding this comment

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

this will be used by work-agent to distinguish a manifestwork's event data type, move to work package

@skeeey skeeey force-pushed the cloudevents-mw branch 2 times, most recently from 7351025 to 379ee7d Compare August 29, 2023 07:35
Copy link
Member

@qiujian16 qiujian16 left a comment

Choose a reason for hiding this comment

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

shouldn't we have a implementation of workv1client.ManifestWorkInterface

Status *workv1.ManifestCondition `json:"status,omitempty"`
}

type ManifestConfigOption struct {
Copy link
Member

Choose a reason for hiding this comment

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

why not use ManifestConfigOption in work api? because of the resourcemeta field?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, it is, for a single manifest, I think we alreay have a certain type resource, so we may not set the resourcemeta outside

)

// ManifestWorkLister list the ManifestWorks from a ManifestWorkInformer's local cache.
type ManifestWorkLister struct {
Copy link
Member

Choose a reason for hiding this comment

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

how does this lister get initiated?

Copy link
Member Author

@skeeey skeeey Aug 30, 2023

Choose a reason for hiding this comment

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

when we build the work clients for cloud events, we use inform store to initiate it

Copy link
Member

Choose a reason for hiding this comment

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

if it is from informer, why we not use lister directly but using cache.store?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, a lister can be used here, I will use lister instead of store

return func(action types.ResourceAction, work *workv1.ManifestWork) error {
switch action {
case types.Added:
_, err := workClient.Create(ctx, work, metav1.CreateOptions{})
Copy link
Member

Choose a reason for hiding this comment

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

this is not clear to me, why the resource handler finally creates a manifestwork using a client? I thought you are going to put it in the cache.Store.

Copy link
Member Author

@skeeey skeeey Aug 30, 2023

Choose a reason for hiding this comment

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

yes, it will be put in the store finally, we will have a new client, it implements the ManifestWorkInterface, the client will put the manifestwork to the sore, the logic will be same with here, so I used the client to handle this

Copy link
Member

Choose a reason for hiding this comment

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

it is confusing I think, if it is a certain type client, we should use that as the input instead of the interface.

Copy link
Member Author

Choose a reason for hiding this comment

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

hrm... I do not introduce the new client in this pr yet, I will add the implementation, and use a certain type client

@skeeey
Copy link
Member Author

skeeey commented Aug 30, 2023

shouldn't we have a implementation of workv1client.ManifestWorkInterface

Yes, we need, I will open a new pr to implement the interface after this pr

will add it

@skeeey skeeey force-pushed the cloudevents-mw branch 2 times, most recently from ebf6c0c to 4558fdd Compare August 30, 2023 07:19
klog.V(4).Infof("deleting manifestwork %s", name)
work, err := c.lister.Get(name)
if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

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

should ignore isnotfound?

return err
}

c.watcher.Receive(watch.Event{Type: watch.Modified, Object: work})
Copy link
Member

Choose a reason for hiding this comment

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

what is the intension of this? and I do not think agent should have the permission to delete?

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch, we don't need the delete function for agent, we just need mark the manifest has the deletiontimestamp, this should be finished by update function

return mw.watcher, nil
}

func (mw *ManifestWorksAgentClient) Patch(ctx context.Context, name string, pt kubetypes.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *workv1.ManifestWork, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

we have starting to use patch a lot in ocm repo.

Copy link
Member Author

@skeeey skeeey Aug 30, 2023

Choose a reason for hiding this comment

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

add todo

need to implement this function


func (c *ManifestWorksAgentClient) List(ctx context.Context, opts metav1.ListOptions) (*workv1.ManifestWorkList, error) {
klog.V(4).Infof("sync manifestworks")
// send resync request to fetch manifestworks from source
Copy link
Member

Choose a reason for hiding this comment

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

this is tricky, we only use list to resync?

Copy link
Member Author

Choose a reason for hiding this comment

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

this only happens when the agent starts, if we want to resync in other time, I think we need call cloudevents resync function, or we don't do resync here? we provide a way to do resync when we build the clients


var manifestWorkGR = schema.GroupResource{Group: workv1.GroupName, Resource: "manifestworks"}

// ManifestWorkWatcher implements the ManifestWorkInterface. It receives manifestworks spec from source by
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// ManifestWorkWatcher implements the ManifestWorkInterface. It receives manifestworks spec from source by
// ManifestWorksAgentClient implements the ManifestWorkInterface. It receives manifestworks spec from source by

@skeeey skeeey force-pushed the cloudevents-mw branch 5 times, most recently from c45a1f1 to ebe455c Compare August 30, 2023 10:31
@skeeey
Copy link
Member Author

skeeey commented Aug 30, 2023

now ManifestWorkResourceHandler send kube events to handle the works in local and ManifestWorksAgentClient sends works status to source

@skeeey skeeey force-pushed the cloudevents-mw branch 3 times, most recently from 0096aa9 to 41b79d8 Compare August 30, 2023 13:57
Signed-off-by: Wei Liu <liuweixa@redhat.com>
@qiujian16
Copy link
Member

/approve
/lgtm

@openshift-ci openshift-ci bot added the lgtm label Aug 31, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 31, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qiujian16, skeeey

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit c7abb65 into open-cluster-management-io:main Aug 31, 2023
10 checks passed
@skeeey skeeey deleted the cloudevents-mw branch September 4, 2023 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants