-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_pools.gen.go
435 lines (388 loc) · 12.7 KB
/
resource_pools.gen.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
// Code generated by chronogen; DO NOT EDIT
package configv1
import (
"context"
"fmt"
"github.com/chronosphereio/chronoctl-core/src/cmd/pkg/client"
"github.com/chronosphereio/chronoctl-core/src/cmd/pkg/clienterror"
"github.com/chronosphereio/chronoctl-core/src/cmd/pkg/dry"
"github.com/chronosphereio/chronoctl-core/src/cmd/pkg/file"
"github.com/chronosphereio/chronoctl-core/src/cmd/pkg/groups"
"github.com/chronosphereio/chronoctl-core/src/cmd/pkg/output"
config_v1 "github.com/chronosphereio/chronoctl-core/src/generated/swagger/configv1/client/operations"
"github.com/chronosphereio/chronoctl-core/src/generated/swagger/configv1/models"
"github.com/chronosphereio/chronoctl-core/src/types"
"github.com/spf13/cobra"
)
func init() { types.MustRegisterObject(ResourcePoolsTypeMeta, &ResourcePools{}) }
var _ types.Object = &ResourcePools{}
var ResourcePoolsTypeMeta = types.TypeMeta{
APIVersion: "v1/config",
Kind: "ResourcePools",
}
type ResourcePools struct {
types.TypeMeta `json:",inline"`
Spec *models.Configv1ResourcePools `json:"spec"`
}
func NewResourcePools(spec *models.Configv1ResourcePools) *ResourcePools {
return &ResourcePools{
TypeMeta: ResourcePoolsTypeMeta,
Spec: spec,
}
}
func (e *ResourcePools) Description() string {
return types.TypeDescription(e)
}
func (e *ResourcePools) Identifier() string {
return "ResourcePools"
}
func CreateResourcePools(
ctx context.Context,
client config_v1.ClientService,
entity *ResourcePools,
dryRun bool,
) (*ResourcePools, error) {
res, err := client.CreateResourcePools(&config_v1.CreateResourcePoolsParams{
Context: ctx,
Body: &models.Configv1CreateResourcePoolsRequest{
DryRun: dryRun,
ResourcePools: entity.Spec,
},
})
if err != nil {
return nil, clienterror.Wrap(err)
}
return NewResourcePools(res.Payload.ResourcePools), nil
}
func newResourcePoolsCreateCmd() *cobra.Command {
var (
permissiveParsing bool
dryRunFlags = dry.NewFlags()
clientFlags = client.NewClientFlags()
outputFlags = output.NewFlags(output.WithoutOutputDirectory(), output.WithoutCreateFilePerObject())
fileFlags = file.NewFlags(true /* required */)
)
var (
use string
short string
)
use = "create -f <file>"
short = "Creates a single ResourcePools."
cmd := &cobra.Command{
Use: use,
GroupID: groups.Commands.ID,
Short: short,
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(cmd.Context(), clientFlags.Timeout())
defer cancel()
if err := outputFlags.Validate(); err != nil {
return err
}
defer outputFlags.Close(cmd.OutOrStdout())
stderr := output.NewStderrPrinter(cmd)
client, err := clientFlags.ConfigV1Client()
if err != nil {
return err
}
var resourcePools *ResourcePools
file, err := fileFlags.File()
if err != nil {
return err
}
defer file.Close() //nolint:errcheck
resourcePools, err = types.MustDecodeSingleObject[*ResourcePools](file, permissiveParsing)
if err != nil {
return err
}
if dryRunFlags.DryRun {
stderr.Println("--dry-run is set")
}
fullResourcePools, err := CreateResourcePools(ctx, client, resourcePools, dryRunFlags.DryRun)
if err != nil {
return err
}
if dryRunFlags.DryRun {
stderr.Println("ResourcePools is valid and can be created")
return nil
}
stderr.Printf("ResourcePools created successfully\n")
if err := outputFlags.WriteObject(fullResourcePools, cmd.OutOrStdout()); err != nil {
return err
}
return nil
},
}
dryRunFlags.AddFlags(cmd)
clientFlags.AddFlags(cmd)
outputFlags.AddFlags(cmd)
fileFlags.AddFlags(cmd)
cmd.Flags().BoolVar(&permissiveParsing, "no-strict", false, "If set, manifests with unknown fields are not rejected. Defaults to false.")
return cmd
}
func GetResourcePools(
ctx context.Context,
client config_v1.ClientService,
) (*ResourcePools, error) {
res, err := client.ReadResourcePools(&config_v1.ReadResourcePoolsParams{
Context: ctx,
})
if err != nil {
return nil, clienterror.Wrap(err)
}
return NewResourcePools(res.GetPayload().ResourcePools), nil
}
func newResourcePoolsReadCmd() *cobra.Command {
clientFlags := client.NewClientFlags()
outputFlags := output.NewFlags(output.WithoutOutputDirectory(), output.WithoutCreateFilePerObject())
var (
short string
use string
args cobra.PositionalArgs
)
short = "Reads a ResourcePools singleton"
use = "read"
cmd := &cobra.Command{
Use: use,
GroupID: groups.Commands.ID,
Short: short,
Args: args,
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(cmd.Context(), clientFlags.Timeout())
defer cancel()
if err := outputFlags.Validate(); err != nil {
return err
}
defer outputFlags.Close(cmd.OutOrStdout())
client, err := clientFlags.ConfigV1Client()
if err != nil {
return err
}
entity, err := GetResourcePools(ctx, client)
if err != nil {
return err
}
if err := outputFlags.WriteObject(entity, cmd.OutOrStdout()); err != nil {
return err
}
return nil
},
}
clientFlags.AddFlags(cmd)
outputFlags.AddFlags(cmd)
return cmd
}
func UpdateResourcePools(
ctx context.Context,
client config_v1.ClientService,
entity *ResourcePools,
opts UpdateOptions,
) (*ResourcePools, error) {
res, err := client.UpdateResourcePools(&config_v1.UpdateResourcePoolsParams{
Context: ctx,
Body: &models.Configv1UpdateResourcePoolsRequest{
CreateIfMissing: opts.CreateIfMissing,
DryRun: opts.DryRun,
ResourcePools: entity.Spec,
},
})
if err != nil {
return nil, clienterror.Wrap(err)
}
return NewResourcePools(res.Payload.ResourcePools), nil
}
func newResourcePoolsUpdateCmd() *cobra.Command {
var (
permissiveParsing bool
createIfMissing bool
dryRunFlags = dry.NewFlags()
clientFlags = client.NewClientFlags()
outputFlags = output.NewFlags(output.WithoutOutputDirectory(), output.WithoutCreateFilePerObject())
fileFlags = file.NewFlags(true /* required */)
)
cmd := &cobra.Command{
Use: "update -f <filename>",
GroupID: groups.Commands.ID,
Short: "Updates an existing ResourcePools.",
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(cmd.Context(), clientFlags.Timeout())
defer cancel()
if err := outputFlags.Validate(); err != nil {
return err
}
defer outputFlags.Close(cmd.OutOrStdout())
stderr := output.NewStderrPrinter(cmd)
client, err := clientFlags.ConfigV1Client()
if err != nil {
return err
}
file, err := fileFlags.File()
if err != nil {
return err
}
defer file.Close() //nolint:errcheck
resourcePools, err := types.MustDecodeSingleObject[*ResourcePools](file, permissiveParsing)
if err != nil {
return err
}
updateOpts := UpdateOptions{
DryRun: dryRunFlags.DryRun,
CreateIfMissing: createIfMissing,
}
if dryRunFlags.DryRun {
stderr.Println("--dry-run is set, update not persisted")
}
fullResourcePools, err := UpdateResourcePools(ctx, client, resourcePools, updateOpts)
if err != nil {
return err
}
if dryRunFlags.DryRun {
stderr.Println("ResourcePools is valid and can be updated")
return nil
}
stderr.Printf("ResourcePools applied successfully\n")
if err := outputFlags.WriteObject(fullResourcePools, cmd.OutOrStdout()); err != nil {
return err
}
return nil
},
}
dryRunFlags.AddFlags(cmd)
clientFlags.AddFlags(cmd)
outputFlags.AddFlags(cmd)
fileFlags.AddFlags(cmd)
cmd.Flags().BoolVar(&permissiveParsing, "no-strict", false, "If set, manifests with unknown fields are allowed. Defaults to false.")
cmd.Flags().BoolVar(&createIfMissing, "create-if-missing", false, "If set, creates the ResourcePools if it does not already exist. Defaults to false.")
return cmd
}
func DeleteResourcePools(
ctx context.Context,
client config_v1.ClientService,
) error {
_, err := client.DeleteResourcePools(&config_v1.DeleteResourcePoolsParams{
Context: ctx,
})
if err != nil {
return clienterror.Wrap(err)
}
return nil
}
func newResourcePoolsDeleteCmd() *cobra.Command {
clientFlags := client.NewClientFlags()
outputFlags := output.NewFlags(output.WithoutOutputDirectory(), output.WithoutCreateFilePerObject())
cmd := &cobra.Command{
Use: "delete <slug>",
GroupID: groups.Commands.ID,
Short: "Deletes a single ResourcePools by slug",
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(cmd.Context(), clientFlags.Timeout())
defer cancel()
if err := outputFlags.Validate(); err != nil {
return err
}
defer outputFlags.Close(cmd.OutOrStdout())
client, err := clientFlags.ConfigV1Client()
if err != nil {
return err
}
res, err := client.DeleteResourcePools(&config_v1.DeleteResourcePoolsParams{
Context: ctx,
})
if err != nil {
return clienterror.Wrap(err)
}
_ = res
fmt.Fprintf(cmd.OutOrStdout(), "deleted ResourcePools")
return nil
},
}
clientFlags.AddFlags(cmd)
outputFlags.AddFlags(cmd)
return cmd
}
const ResourcePoolsScaffoldYAML = `api_version: v1/config
kind: ResourcePools
spec:
# Optional pools.
pools:
- # Required name of the pool. Must be unique.
name: <string>
# Required filters which define which metrics map to this pool, where any
# metric which matches at least one filter will map to the pool.
filters:
- # Name of the label to match.
name: <string>
# Glob value of the label to match.
value_glob: <string>
allocation:
# Percentage of the license to allocate to this pool. Must be between 0
# and 100 inclusive. The percent_of_license values across all pools
# (including the default pool) must add up to exactly 100.
percent_of_license: <number>
priorities:
# Required filters which define which metrics are high priority, where any
# metric which matches at least one filter is considered high priority.
# High priority metrics are dropped last when the license limit is exceeded.
high_priority_filters:
- # Name of the label to match.
name: <string>
# Glob value of the label to match.
value_glob: <string>
# Required filters which define which metrics are low priority, where any
# metric which matches at least one filter is considered low priority. Low
# priority metrics are dropped first when the license limit is exceeded.
low_priority_filters:
- # Name of the label to match.
name: <string>
# Glob value of the label to match.
value_glob: <string>
default_pool:
allocation:
# Percentage of the license to allocate to this pool. Must be between 0
# and 100 inclusive. The percent_of_license values across all pools
# (including the default pool) must add up to exactly 100.
percent_of_license: <number>
priorities:
# Required filters which define which metrics are high priority, where any
# metric which matches at least one filter is considered high priority.
# High priority metrics are dropped last when the license limit is exceeded.
high_priority_filters:
- # Name of the label to match.
name: <string>
# Glob value of the label to match.
value_glob: <string>
# Required filters which define which metrics are low priority, where any
# metric which matches at least one filter is considered low priority. Low
# priority metrics are dropped first when the license limit is exceeded.
low_priority_filters:
- # Name of the label to match.
name: <string>
# Glob value of the label to match.
value_glob: <string>
`
func newResourcePoolsScaffoldCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "scaffold",
GroupID: groups.Commands.ID,
Short: "Scaffolds a complete object with placeholder values",
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprint(cmd.OutOrStdout(), ResourcePoolsScaffoldYAML)
},
}
return cmd
}
func NewResourcePoolsCmd() *cobra.Command {
root := &cobra.Command{
Use: "resource-pools",
GroupID: groups.Config.ID,
Short: "All commands for ResourcePools",
}
root.AddGroup(groups.Commands)
root.AddCommand(
newResourcePoolsCreateCmd(),
newResourcePoolsReadCmd(),
newResourcePoolsUpdateCmd(),
newResourcePoolsDeleteCmd(),
newResourcePoolsScaffoldCmd(),
)
return root
}