Skip to content

Commit

Permalink
feat: support storage provider with subresource
Browse files Browse the repository at this point in the history
Signed-off-by: yue9944882 <[email protected]>
  • Loading branch information
yue9944882 committed Apr 3, 2022
1 parent 3f43b5f commit 0dc9a4d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pkg/builder/builder_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ func (a *Server) WithResourceAndStrategy(obj resource.Object, strategy rest.Stra
_ = a.forGroupVersionResource(gvr, parentStorageProvider)

// automatically create status subresource if the object implements the status interface
a.withSubResourceIfExists(obj, parentStorageProvider)

defer func() {
// automatically create status subresource if the object implements the status interface
a.withSubResourceIfExists(obj, parentStorageProvider)
}()
return a
}

Expand All @@ -112,6 +116,10 @@ func (a *Server) WithResourceAndStrategy(obj resource.Object, strategy rest.Stra
func (a *Server) WithResourceAndHandler(obj resource.Object, sp rest.ResourceHandlerProvider) *Server {
gvr := obj.GetGroupVersionResource()
a.schemeBuilder.Register(resource.AddToScheme(obj))
defer func() {
// automatically create status subresource if the object implements the status interface
a.withSubResourceIfExists(obj, sp)
}()
return a.forGroupVersionResource(gvr, sp)
}

Expand All @@ -126,7 +134,12 @@ func (a *Server) WithResourceAndHandler(obj resource.Object, sp rest.ResourceHan
func (a *Server) WithResourceAndStorage(obj resource.Object, fn rest.StoreFn) *Server {
gvr := obj.GetGroupVersionResource()
a.schemeBuilder.Register(resource.AddToScheme(obj))
return a.forGroupVersionResource(gvr, rest.NewWithFn(obj, fn))
sp := rest.NewWithFn(obj, fn)
defer func() {
// automatically create status subresource if the object implements the status interface
a.withSubResourceIfExists(obj, sp)
}()
return a.forGroupVersionResource(gvr, sp)
}

// forGroupVersionResource manually registers storage for a specific resource.
Expand Down

0 comments on commit 0dc9a4d

Please sign in to comment.