/
client.go
243 lines (210 loc) · 7.51 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*
Copyright 2021 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by injection-gen. DO NOT EDIT.
package client
import (
context "context"
json "encoding/json"
errors "errors"
fmt "fmt"
v1alpha1 "github.com/tektoncd/experimental/workflows/pkg/apis/workflows/v1alpha1"
versioned "github.com/tektoncd/experimental/workflows/pkg/client/clientset/versioned"
typedworkflowsv1alpha1 "github.com/tektoncd/experimental/workflows/pkg/client/clientset/versioned/typed/workflows/v1alpha1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
unstructured "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
runtime "k8s.io/apimachinery/pkg/runtime"
schema "k8s.io/apimachinery/pkg/runtime/schema"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
discovery "k8s.io/client-go/discovery"
dynamic "k8s.io/client-go/dynamic"
rest "k8s.io/client-go/rest"
injection "knative.dev/pkg/injection"
dynamicclient "knative.dev/pkg/injection/clients/dynamicclient"
logging "knative.dev/pkg/logging"
)
func init() {
injection.Default.RegisterClient(withClientFromConfig)
injection.Default.RegisterClientFetcher(func(ctx context.Context) interface{} {
return Get(ctx)
})
injection.Dynamic.RegisterDynamicClient(withClientFromDynamic)
}
// Key is used as the key for associating information with a context.Context.
type Key struct{}
func withClientFromConfig(ctx context.Context, cfg *rest.Config) context.Context {
return context.WithValue(ctx, Key{}, versioned.NewForConfigOrDie(cfg))
}
func withClientFromDynamic(ctx context.Context) context.Context {
return context.WithValue(ctx, Key{}, &wrapClient{dyn: dynamicclient.Get(ctx)})
}
// Get extracts the versioned.Interface client from the context.
func Get(ctx context.Context) versioned.Interface {
untyped := ctx.Value(Key{})
if untyped == nil {
if injection.GetConfig(ctx) == nil {
logging.FromContext(ctx).Panic(
"Unable to fetch github.com/tektoncd/experimental/workflows/pkg/client/clientset/versioned.Interface from context. This context is not the application context (which is typically given to constructors via sharedmain).")
} else {
logging.FromContext(ctx).Panic(
"Unable to fetch github.com/tektoncd/experimental/workflows/pkg/client/clientset/versioned.Interface from context.")
}
}
return untyped.(versioned.Interface)
}
type wrapClient struct {
dyn dynamic.Interface
}
var _ versioned.Interface = (*wrapClient)(nil)
func (w *wrapClient) Discovery() discovery.DiscoveryInterface {
panic("Discovery called on dynamic client!")
}
func convert(from interface{}, to runtime.Object) error {
bs, err := json.Marshal(from)
if err != nil {
return fmt.Errorf("Marshal() = %w", err)
}
if err := json.Unmarshal(bs, to); err != nil {
return fmt.Errorf("Unmarshal() = %w", err)
}
return nil
}
// WorkflowsV1alpha1 retrieves the WorkflowsV1alpha1Client
func (w *wrapClient) WorkflowsV1alpha1() typedworkflowsv1alpha1.WorkflowsV1alpha1Interface {
return &wrapWorkflowsV1alpha1{
dyn: w.dyn,
}
}
type wrapWorkflowsV1alpha1 struct {
dyn dynamic.Interface
}
func (w *wrapWorkflowsV1alpha1) RESTClient() rest.Interface {
panic("RESTClient called on dynamic client!")
}
func (w *wrapWorkflowsV1alpha1) Workflows(namespace string) typedworkflowsv1alpha1.WorkflowInterface {
return &wrapWorkflowsV1alpha1WorkflowImpl{
dyn: w.dyn.Resource(schema.GroupVersionResource{
Group: "workflows.tekton.dev",
Version: "v1alpha1",
Resource: "workflows",
}),
namespace: namespace,
}
}
type wrapWorkflowsV1alpha1WorkflowImpl struct {
dyn dynamic.NamespaceableResourceInterface
namespace string
}
var _ typedworkflowsv1alpha1.WorkflowInterface = (*wrapWorkflowsV1alpha1WorkflowImpl)(nil)
func (w *wrapWorkflowsV1alpha1WorkflowImpl) Create(ctx context.Context, in *v1alpha1.Workflow, opts v1.CreateOptions) (*v1alpha1.Workflow, error) {
in.SetGroupVersionKind(schema.GroupVersionKind{
Group: "workflows.tekton.dev",
Version: "v1alpha1",
Kind: "Workflow",
})
uo := &unstructured.Unstructured{}
if err := convert(in, uo); err != nil {
return nil, err
}
uo, err := w.dyn.Namespace(w.namespace).Create(ctx, uo, opts)
if err != nil {
return nil, err
}
out := &v1alpha1.Workflow{}
if err := convert(uo, out); err != nil {
return nil, err
}
return out, nil
}
func (w *wrapWorkflowsV1alpha1WorkflowImpl) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
return w.dyn.Namespace(w.namespace).Delete(ctx, name, opts)
}
func (w *wrapWorkflowsV1alpha1WorkflowImpl) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
return w.dyn.Namespace(w.namespace).DeleteCollection(ctx, opts, listOpts)
}
func (w *wrapWorkflowsV1alpha1WorkflowImpl) Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.Workflow, error) {
uo, err := w.dyn.Namespace(w.namespace).Get(ctx, name, opts)
if err != nil {
return nil, err
}
out := &v1alpha1.Workflow{}
if err := convert(uo, out); err != nil {
return nil, err
}
return out, nil
}
func (w *wrapWorkflowsV1alpha1WorkflowImpl) List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.WorkflowList, error) {
uo, err := w.dyn.Namespace(w.namespace).List(ctx, opts)
if err != nil {
return nil, err
}
out := &v1alpha1.WorkflowList{}
if err := convert(uo, out); err != nil {
return nil, err
}
return out, nil
}
func (w *wrapWorkflowsV1alpha1WorkflowImpl) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Workflow, err error) {
uo, err := w.dyn.Namespace(w.namespace).Patch(ctx, name, pt, data, opts)
if err != nil {
return nil, err
}
out := &v1alpha1.Workflow{}
if err := convert(uo, out); err != nil {
return nil, err
}
return out, nil
}
func (w *wrapWorkflowsV1alpha1WorkflowImpl) Update(ctx context.Context, in *v1alpha1.Workflow, opts v1.UpdateOptions) (*v1alpha1.Workflow, error) {
in.SetGroupVersionKind(schema.GroupVersionKind{
Group: "workflows.tekton.dev",
Version: "v1alpha1",
Kind: "Workflow",
})
uo := &unstructured.Unstructured{}
if err := convert(in, uo); err != nil {
return nil, err
}
uo, err := w.dyn.Namespace(w.namespace).Update(ctx, uo, opts)
if err != nil {
return nil, err
}
out := &v1alpha1.Workflow{}
if err := convert(uo, out); err != nil {
return nil, err
}
return out, nil
}
func (w *wrapWorkflowsV1alpha1WorkflowImpl) UpdateStatus(ctx context.Context, in *v1alpha1.Workflow, opts v1.UpdateOptions) (*v1alpha1.Workflow, error) {
in.SetGroupVersionKind(schema.GroupVersionKind{
Group: "workflows.tekton.dev",
Version: "v1alpha1",
Kind: "Workflow",
})
uo := &unstructured.Unstructured{}
if err := convert(in, uo); err != nil {
return nil, err
}
uo, err := w.dyn.Namespace(w.namespace).UpdateStatus(ctx, uo, opts)
if err != nil {
return nil, err
}
out := &v1alpha1.Workflow{}
if err := convert(uo, out); err != nil {
return nil, err
}
return out, nil
}
func (w *wrapWorkflowsV1alpha1WorkflowImpl) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
return nil, errors.New("NYI: Watch")
}