Skip to content

Commit e765e9c

Browse files
Merge pull request #16019 from mfojtik/codegen-expansion-tags
Automatic merge from submit-queue Allow to extend generated clients with custom verbs We need this in order to generate client calls like `.Instantiate()` or `.Secrets()` (for image stream secrets). In upstream, this will allow to generate `UpdateStatus` which is currently "guessed" by checking for the presence of ".Status" field in the resource. It also allows to generate custom `.Scale(...)` in autoscaler. Additionally this allows to send requests to sub-resources but also allows to override the input and result types for existing client calls or for extended client calls. The extended client calls are generated to the main client interface. The final syntax is: ``` //+genclient:method=Instantiate,verb=create,subresource=instantiate,input=DeploymentRequest,output=DeploymentConfig ``` (the input/result types will allow to provide full import path, see the checklist) #### TODO - [x] Finalize the tag syntax - [x] Allow cross-group type references for input/result type overrides - [x] Fix the fake generator - [x] Move this PR upstream and demonstrate this on `.Scale()` and `.UpdateStatus()`
2 parents a213e8c + c087b7d commit e765e9c

File tree

17 files changed

+921
-65
lines changed

17 files changed

+921
-65
lines changed

pkg/deploy/apis/apps/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ const (
123123
)
124124

125125
// +genclient
126+
// +genclient:method=Instantiate,verb=create,subresource=instantiate,input=DeploymentRequest
127+
// +genclient:method=GetScale,verb=get,subresource=scale,result=k8s.io/kubernetes/pkg/apis/extensions/v1beta1.Scale
128+
// +genclient:method=UpdateScale,verb=update,subresource=scale,input=k8s.io/kubernetes/pkg/apis/extensions/v1beta1.Scale,result=k8s.io/kubernetes/pkg/apis/extensions/v1beta1.Scale
126129

127130
// DeploymentConfig represents a configuration for a single deployment (represented as a
128131
// ReplicationController). It also contains details about changes which resulted in the current

pkg/deploy/apis/apps/v1/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import (
99
)
1010

1111
// +genclient
12+
// +genclient:method=Instantiate,verb=create,subresource=instantiate,input=DeploymentRequest
13+
// +genclient:method=GetScale,verb=get,subresource=scale,result=k8s.io/kubernetes/pkg/apis/extensions/v1beta1.Scale
14+
// +genclient:method=UpdateScale,verb=update,subresource=scale,input=k8s.io/kubernetes/pkg/apis/extensions/v1beta1.Scale,result=k8s.io/kubernetes/pkg/apis/extensions/v1beta1.Scale
1215

1316
// Deployment Configs define the template for a pod and manages deploying new images or configuration changes.
1417
// A single deployment configuration is usually analogous to a single micro-service. Can support many different

pkg/deploy/generated/clientset/typed/apps/v1/deploymentconfig.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
types "k8s.io/apimachinery/pkg/types"
88
watch "k8s.io/apimachinery/pkg/watch"
99
rest "k8s.io/client-go/rest"
10+
v1beta1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
1011
)
1112

1213
// DeploymentConfigsGetter has a method to return a DeploymentConfigInterface.
@@ -26,6 +27,10 @@ type DeploymentConfigInterface interface {
2627
List(opts meta_v1.ListOptions) (*v1.DeploymentConfigList, error)
2728
Watch(opts meta_v1.ListOptions) (watch.Interface, error)
2829
Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.DeploymentConfig, err error)
30+
Instantiate(deploymentConfigName string, deploymentRequest *v1.DeploymentRequest) (*v1.DeploymentConfig, error)
31+
GetScale(deploymentConfigName string, options meta_v1.GetOptions) (*v1beta1.Scale, error)
32+
UpdateScale(deploymentConfigName string, scale *v1beta1.Scale) (*v1beta1.Scale, error)
33+
2934
DeploymentConfigExpansion
3035
}
3136

@@ -154,3 +159,45 @@ func (c *deploymentConfigs) Patch(name string, pt types.PatchType, data []byte,
154159
Into(result)
155160
return
156161
}
162+
163+
// Instantiate takes the representation of a deploymentRequest and creates it. Returns the server's representation of the deploymentConfig, and an error, if there is any.
164+
func (c *deploymentConfigs) Instantiate(deploymentConfigName string, deploymentRequest *v1.DeploymentRequest) (result *v1.DeploymentConfig, err error) {
165+
result = &v1.DeploymentConfig{}
166+
err = c.client.Post().
167+
Namespace(c.ns).
168+
Resource("deploymentconfigs").
169+
Name(deploymentConfigName).
170+
SubResource("instantiate").
171+
Body(deploymentRequest).
172+
Do().
173+
Into(result)
174+
return
175+
}
176+
177+
// GetScale takes name of the deploymentConfig, and returns the corresponding v1beta1.Scale object, and an error if there is any.
178+
func (c *deploymentConfigs) GetScale(deploymentConfigName string, options meta_v1.GetOptions) (result *v1beta1.Scale, err error) {
179+
result = &v1beta1.Scale{}
180+
err = c.client.Get().
181+
Namespace(c.ns).
182+
Resource("deploymentconfigs").
183+
Name(deploymentConfigName).
184+
SubResource("scale").
185+
VersionedParams(&options, scheme.ParameterCodec).
186+
Do().
187+
Into(result)
188+
return
189+
}
190+
191+
// UpdateScale takes the top resource name and the representation of a scale and updates it. Returns the server's representation of the scale, and an error, if there is any.
192+
func (c *deploymentConfigs) UpdateScale(deploymentConfigName string, scale *v1beta1.Scale) (result *v1beta1.Scale, err error) {
193+
result = &v1beta1.Scale{}
194+
err = c.client.Put().
195+
Namespace(c.ns).
196+
Resource("deploymentconfigs").
197+
Name(deploymentConfigName).
198+
SubResource("scale").
199+
Body(scale).
200+
Do().
201+
Into(result)
202+
return
203+
}

pkg/deploy/generated/clientset/typed/apps/v1/fake/fake_deploymentconfig.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
types "k8s.io/apimachinery/pkg/types"
99
watch "k8s.io/apimachinery/pkg/watch"
1010
testing "k8s.io/client-go/testing"
11+
v1beta1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
1112
)
1213

1314
// FakeDeploymentConfigs implements DeploymentConfigInterface
@@ -120,3 +121,36 @@ func (c *FakeDeploymentConfigs) Patch(name string, pt types.PatchType, data []by
120121
}
121122
return obj.(*apps_v1.DeploymentConfig), err
122123
}
124+
125+
// Instantiate takes the representation of a deploymentRequest and creates it. Returns the server's representation of the deploymentConfig, and an error, if there is any.
126+
func (c *FakeDeploymentConfigs) Instantiate(deploymentConfigName string, deploymentRequest *apps_v1.DeploymentRequest) (result *apps_v1.DeploymentConfig, err error) {
127+
obj, err := c.Fake.
128+
Invokes(testing.NewCreateSubresourceAction(deploymentconfigsResource, deploymentConfigName, "instantiate", c.ns, deploymentRequest), &apps_v1.DeploymentRequest{})
129+
130+
if obj == nil {
131+
return nil, err
132+
}
133+
return obj.(*apps_v1.DeploymentConfig), err
134+
}
135+
136+
// GetScale takes name of the deploymentConfig, and returns the corresponding deploymentConfig object, and an error if there is any.
137+
func (c *FakeDeploymentConfigs) GetScale(deploymentConfigName string, options v1.GetOptions) (result *v1beta1.Scale, err error) {
138+
obj, err := c.Fake.
139+
Invokes(testing.NewGetSubresourceAction(deploymentconfigsResource, c.ns, "scale", deploymentConfigName), &v1beta1.Scale{})
140+
141+
if obj == nil {
142+
return nil, err
143+
}
144+
return obj.(*v1beta1.Scale), err
145+
}
146+
147+
// UpdateScale takes the representation of a scale and updates it. Returns the server's representation of the scale, and an error, if there is any.
148+
func (c *FakeDeploymentConfigs) UpdateScale(deploymentConfigName string, scale *v1beta1.Scale) (result *v1beta1.Scale, err error) {
149+
obj, err := c.Fake.
150+
Invokes(testing.NewUpdateSubresourceAction(deploymentconfigsResource, "scale", c.ns, scale), &v1beta1.Scale{})
151+
152+
if obj == nil {
153+
return nil, err
154+
}
155+
return obj.(*v1beta1.Scale), err
156+
}

pkg/deploy/generated/internalclientset/typed/apps/internalversion/deploymentconfig.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
types "k8s.io/apimachinery/pkg/types"
88
watch "k8s.io/apimachinery/pkg/watch"
99
rest "k8s.io/client-go/rest"
10+
v1beta1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
1011
)
1112

1213
// DeploymentConfigsGetter has a method to return a DeploymentConfigInterface.
@@ -26,6 +27,10 @@ type DeploymentConfigInterface interface {
2627
List(opts v1.ListOptions) (*apps.DeploymentConfigList, error)
2728
Watch(opts v1.ListOptions) (watch.Interface, error)
2829
Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *apps.DeploymentConfig, err error)
30+
Instantiate(deploymentConfigName string, deploymentRequest *apps.DeploymentRequest) (*apps.DeploymentConfig, error)
31+
GetScale(deploymentConfigName string, options v1.GetOptions) (*v1beta1.Scale, error)
32+
UpdateScale(deploymentConfigName string, scale *v1beta1.Scale) (*v1beta1.Scale, error)
33+
2934
DeploymentConfigExpansion
3035
}
3136

@@ -154,3 +159,45 @@ func (c *deploymentConfigs) Patch(name string, pt types.PatchType, data []byte,
154159
Into(result)
155160
return
156161
}
162+
163+
// Instantiate takes the representation of a deploymentRequest and creates it. Returns the server's representation of the deploymentConfig, and an error, if there is any.
164+
func (c *deploymentConfigs) Instantiate(deploymentConfigName string, deploymentRequest *apps.DeploymentRequest) (result *apps.DeploymentConfig, err error) {
165+
result = &apps.DeploymentConfig{}
166+
err = c.client.Post().
167+
Namespace(c.ns).
168+
Resource("deploymentconfigs").
169+
Name(deploymentConfigName).
170+
SubResource("instantiate").
171+
Body(deploymentRequest).
172+
Do().
173+
Into(result)
174+
return
175+
}
176+
177+
// GetScale takes name of the deploymentConfig, and returns the corresponding v1beta1.Scale object, and an error if there is any.
178+
func (c *deploymentConfigs) GetScale(deploymentConfigName string, options v1.GetOptions) (result *v1beta1.Scale, err error) {
179+
result = &v1beta1.Scale{}
180+
err = c.client.Get().
181+
Namespace(c.ns).
182+
Resource("deploymentconfigs").
183+
Name(deploymentConfigName).
184+
SubResource("scale").
185+
VersionedParams(&options, scheme.ParameterCodec).
186+
Do().
187+
Into(result)
188+
return
189+
}
190+
191+
// UpdateScale takes the top resource name and the representation of a scale and updates it. Returns the server's representation of the scale, and an error, if there is any.
192+
func (c *deploymentConfigs) UpdateScale(deploymentConfigName string, scale *v1beta1.Scale) (result *v1beta1.Scale, err error) {
193+
result = &v1beta1.Scale{}
194+
err = c.client.Put().
195+
Namespace(c.ns).
196+
Resource("deploymentconfigs").
197+
Name(deploymentConfigName).
198+
SubResource("scale").
199+
Body(scale).
200+
Do().
201+
Into(result)
202+
return
203+
}

pkg/deploy/generated/internalclientset/typed/apps/internalversion/fake/fake_deploymentconfig.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
types "k8s.io/apimachinery/pkg/types"
99
watch "k8s.io/apimachinery/pkg/watch"
1010
testing "k8s.io/client-go/testing"
11+
v1beta1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
1112
)
1213

1314
// FakeDeploymentConfigs implements DeploymentConfigInterface
@@ -120,3 +121,36 @@ func (c *FakeDeploymentConfigs) Patch(name string, pt types.PatchType, data []by
120121
}
121122
return obj.(*apps.DeploymentConfig), err
122123
}
124+
125+
// Instantiate takes the representation of a deploymentRequest and creates it. Returns the server's representation of the deploymentConfig, and an error, if there is any.
126+
func (c *FakeDeploymentConfigs) Instantiate(deploymentConfigName string, deploymentRequest *apps.DeploymentRequest) (result *apps.DeploymentConfig, err error) {
127+
obj, err := c.Fake.
128+
Invokes(testing.NewCreateSubresourceAction(deploymentconfigsResource, deploymentConfigName, "instantiate", c.ns, deploymentRequest), &apps.DeploymentRequest{})
129+
130+
if obj == nil {
131+
return nil, err
132+
}
133+
return obj.(*apps.DeploymentConfig), err
134+
}
135+
136+
// GetScale takes name of the deploymentConfig, and returns the corresponding deploymentConfig object, and an error if there is any.
137+
func (c *FakeDeploymentConfigs) GetScale(deploymentConfigName string, options v1.GetOptions) (result *v1beta1.Scale, err error) {
138+
obj, err := c.Fake.
139+
Invokes(testing.NewGetSubresourceAction(deploymentconfigsResource, c.ns, "scale", deploymentConfigName), &v1beta1.Scale{})
140+
141+
if obj == nil {
142+
return nil, err
143+
}
144+
return obj.(*v1beta1.Scale), err
145+
}
146+
147+
// UpdateScale takes the representation of a scale and updates it. Returns the server's representation of the scale, and an error, if there is any.
148+
func (c *FakeDeploymentConfigs) UpdateScale(deploymentConfigName string, scale *v1beta1.Scale) (result *v1beta1.Scale, err error) {
149+
obj, err := c.Fake.
150+
Invokes(testing.NewUpdateSubresourceAction(deploymentconfigsResource, "scale", c.ns, scale), &v1beta1.Scale{})
151+
152+
if obj == nil {
153+
return nil, err
154+
}
155+
return obj.(*v1beta1.Scale), err
156+
}

pkg/image/apis/image/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ type ImageStreamList struct {
197197
}
198198

199199
// +genclient
200+
// +genclient:method=Secrets,verb=list,subresource=secrets,result=k8s.io/kubernetes/pkg/api.Secret
200201

201202
// ImageStream stores a mapping of tags to images, metadata overrides that are applied
202203
// when images are tagged in a stream, and an optional reference to a Docker image

pkg/image/apis/image/v1/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ type ImageStreamList struct {
152152
}
153153

154154
// +genclient
155+
// +genclient:method=Secrets,verb=list,subresource=secrets,result=k8s.io/kubernetes/pkg/api/v1.Secret
155156

156157
// ImageStream stores a mapping of tags to images, metadata overrides that are applied
157158
// when images are tagged in a stream, and an optional reference to a Docker image

pkg/image/generated/clientset/typed/image/v1/fake/fake_imagestream.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
types "k8s.io/apimachinery/pkg/types"
99
watch "k8s.io/apimachinery/pkg/watch"
1010
testing "k8s.io/client-go/testing"
11+
api_v1 "k8s.io/kubernetes/pkg/api/v1"
1112
)
1213

1314
// FakeImageStreams implements ImageStreamInterface
@@ -120,3 +121,14 @@ func (c *FakeImageStreams) Patch(name string, pt types.PatchType, data []byte, s
120121
}
121122
return obj.(*image_v1.ImageStream), err
122123
}
124+
125+
// Secrets takes label and field selectors, and returns the list of Secrets that match those selectors.
126+
func (c *FakeImageStreams) Secrets(imageStreamName string, opts v1.ListOptions) (result *api_v1.SecretList, err error) {
127+
obj, err := c.Fake.
128+
Invokes(testing.NewListSubresourceAction(imagestreamsResource, imageStreamName, "secrets", imagestreamsKind, c.ns, opts), &api_v1.SecretList{})
129+
130+
if obj == nil {
131+
return nil, err
132+
}
133+
return obj.(*api_v1.SecretList), err
134+
}

pkg/image/generated/clientset/typed/image/v1/imagestream.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
types "k8s.io/apimachinery/pkg/types"
88
watch "k8s.io/apimachinery/pkg/watch"
99
rest "k8s.io/client-go/rest"
10+
api_v1 "k8s.io/kubernetes/pkg/api/v1"
1011
)
1112

1213
// ImageStreamsGetter has a method to return a ImageStreamInterface.
@@ -26,6 +27,8 @@ type ImageStreamInterface interface {
2627
List(opts meta_v1.ListOptions) (*v1.ImageStreamList, error)
2728
Watch(opts meta_v1.ListOptions) (watch.Interface, error)
2829
Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.ImageStream, err error)
30+
Secrets(imageStreamName string, opts meta_v1.ListOptions) (*api_v1.SecretList, error)
31+
2932
ImageStreamExpansion
3033
}
3134

@@ -154,3 +157,17 @@ func (c *imageStreams) Patch(name string, pt types.PatchType, data []byte, subre
154157
Into(result)
155158
return
156159
}
160+
161+
// Secrets takes v1.ImageStream name, label and field selectors, and returns the list of Secrets that match those selectors.
162+
func (c *imageStreams) Secrets(imageStreamName string, opts meta_v1.ListOptions) (result *api_v1.SecretList, err error) {
163+
result = &api_v1.SecretList{}
164+
err = c.client.Get().
165+
Namespace(c.ns).
166+
Resource("imagestreams").
167+
Name(imageStreamName).
168+
SubResource("secrets").
169+
VersionedParams(&opts, scheme.ParameterCodec).
170+
Do().
171+
Into(result)
172+
return
173+
}

pkg/image/generated/internalclientset/typed/image/internalversion/fake/fake_imagestream.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
types "k8s.io/apimachinery/pkg/types"
99
watch "k8s.io/apimachinery/pkg/watch"
1010
testing "k8s.io/client-go/testing"
11+
api "k8s.io/kubernetes/pkg/api"
1112
)
1213

1314
// FakeImageStreams implements ImageStreamInterface
@@ -120,3 +121,14 @@ func (c *FakeImageStreams) Patch(name string, pt types.PatchType, data []byte, s
120121
}
121122
return obj.(*image.ImageStream), err
122123
}
124+
125+
// Secrets takes label and field selectors, and returns the list of Secrets that match those selectors.
126+
func (c *FakeImageStreams) Secrets(imageStreamName string, opts v1.ListOptions) (result *api.SecretList, err error) {
127+
obj, err := c.Fake.
128+
Invokes(testing.NewListSubresourceAction(imagestreamsResource, imageStreamName, "secrets", imagestreamsKind, c.ns, opts), &api.SecretList{})
129+
130+
if obj == nil {
131+
return nil, err
132+
}
133+
return obj.(*api.SecretList), err
134+
}

pkg/image/generated/internalclientset/typed/image/internalversion/imagestream.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
types "k8s.io/apimachinery/pkg/types"
88
watch "k8s.io/apimachinery/pkg/watch"
99
rest "k8s.io/client-go/rest"
10+
api "k8s.io/kubernetes/pkg/api"
1011
)
1112

1213
// ImageStreamsGetter has a method to return a ImageStreamInterface.
@@ -26,6 +27,8 @@ type ImageStreamInterface interface {
2627
List(opts v1.ListOptions) (*image.ImageStreamList, error)
2728
Watch(opts v1.ListOptions) (watch.Interface, error)
2829
Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *image.ImageStream, err error)
30+
Secrets(imageStreamName string, opts v1.ListOptions) (*api.SecretList, error)
31+
2932
ImageStreamExpansion
3033
}
3134

@@ -154,3 +157,17 @@ func (c *imageStreams) Patch(name string, pt types.PatchType, data []byte, subre
154157
Into(result)
155158
return
156159
}
160+
161+
// Secrets takes image.ImageStream name, label and field selectors, and returns the list of Secrets that match those selectors.
162+
func (c *imageStreams) Secrets(imageStreamName string, opts v1.ListOptions) (result *api.SecretList, err error) {
163+
result = &api.SecretList{}
164+
err = c.client.Get().
165+
Namespace(c.ns).
166+
Resource("imagestreams").
167+
Name(imageStreamName).
168+
SubResource("secrets").
169+
VersionedParams(&opts, scheme.ParameterCodec).
170+
Do().
171+
Into(result)
172+
return
173+
}

0 commit comments

Comments
 (0)