-
Notifications
You must be signed in to change notification settings - Fork 6
/
factory.go
2959 lines (2757 loc) · 88.1 KB
/
factory.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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package om
import (
// Necessary to use go:embed
_ "embed"
"time"
"github.com/spf13/cobra"
"github.com/opensvc/om3/core/monitor"
commands "github.com/opensvc/om3/core/omcmd"
)
var (
//go:embed text/node-events/event-kind
eventKindTemplate string
)
func newCmdAll() *cobra.Command {
return &cobra.Command{
Use: "all",
Short: "manage a mix of objects, tentatively exposing all commands",
}
}
func newCmdCcfg() *cobra.Command {
return &cobra.Command{
Use: "ccfg",
Short: "manage the cluster shared configuration",
Long: `The cluster nodes merge their private configuration
over the cluster shared configuration.
The shared configuration is hosted in a ccfg-kind object, and is
replicated using the same rules as other kinds of object (last write is
eventually replicated).
`,
}
}
func newCmdCfg() *cobra.Command {
return &cobra.Command{
Use: "cfg",
Short: "manage configmaps",
Long: `A configmap is an unencrypted key-value store.
Values can be binary or text.
A key can be installed as a file in a Vol, then exposed to apps
and containers.
A key can be exposed as a environment variable for apps and
containers.
A signal can be sent to consumer processes upon exposed key value
changes.
The key names can include the '/' character, interpreted as a path separator
when installing the key in a volume.`,
}
}
func newCmdSec() *cobra.Command {
return &cobra.Command{
Use: "sec",
Short: "manage secrets",
Long: `A secret is an encrypted key-value store.
Values can be binary or text.
A key can be installed as a file in a Vol, then exposed to apps
and containers.
A key can be exposed as a environment variable for apps and
containers.
A signal can be sent to consumer processes upon exposed key value
changes.
The key names can include the '/' character, interpreted as a path separator
when installing the key in a volume.`,
}
}
func newCmdSVC() *cobra.Command {
return &cobra.Command{
Use: "svc",
Short: "manage services",
Long: `Service objects subsystem.
A service is typically made of ip, app, container and task resources.
They can use support objects like volumes, secrets and configmaps to
isolate lifecycles or to abstract cluster-specific knowledge.
`,
}
}
func newCmdVol() *cobra.Command {
return &cobra.Command{
Use: "vol",
Short: "manage volumes",
Long: `A volume is a persistent data provider.
A volume is made of disk, fs and sync resources. It is created by a pool,
to satisfy a demand from a volume resource in a service.
Volumes and their subdirectories can be mounted inside containers.
A volume can host cfg and sec keys projections.`,
}
}
func newCmdUsr() *cobra.Command {
return &cobra.Command{
Use: "usr",
Short: "manage users",
Long: `A user stores the grants and credentials of user of the agent API.
User objects are not necessary with OpenID authentication, as the
grants are embedded in the trusted bearer tokens.`,
}
}
func newCmdArrayLs() *cobra.Command {
var options commands.CmdArrayLs
cmd := &cobra.Command{
Use: "ls",
Short: "list the cluster-managed storage arrays",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
return cmd
}
func newCmdClusterAbort() *cobra.Command {
var options commands.CmdClusterAbort
cmd := &cobra.Command{
Use: "abort",
Short: "abort the running orchestration",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsAsync(flags, &options.OptsAsync)
addFlagsGlobal(flags, &options.OptsGlobal)
return cmd
}
func newCmdClusterFreeze() *cobra.Command {
var options commands.CmdClusterFreeze
cmd := &cobra.Command{
Use: "freeze",
Short: "block ha automatic start and split action on all nodes",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagsAsync(flags, &options.OptsAsync)
return cmd
}
func newCmdClusterLogs() *cobra.Command {
var options commands.CmdClusterLogs
cmd := &cobra.Command{
Use: "logs",
Aliases: []string{"logs", "log", "lo"},
Short: "show all nodes logs",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagsLogs(flags, &options.OptsLogs)
addFlagNodeSelector(flags, &options.NodeSelector)
return cmd
}
func newCmdClusterThaw() *cobra.Command {
var options commands.CmdClusterUnfreeze
cmd := &cobra.Command{
Use: "thaw",
Hidden: true,
Short: "unblock ha automatic and split action start on all nodes",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagsAsync(flags, &options.OptsAsync)
return cmd
}
func newCmdClusterUnfreeze() *cobra.Command {
var options commands.CmdClusterUnfreeze
cmd := &cobra.Command{
Use: "unfreeze",
Short: "unblock ha automatic and split action start on all nodes",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagsAsync(flags, &options.OptsAsync)
return cmd
}
func newCmdDaemonAuth() *cobra.Command {
var options commands.CmdDaemonAuth
cmd := &cobra.Command{
Use: "auth",
Short: "create new token",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagRoles(flags, &options.Roles)
flags.DurationVar(&options.Duration, "duration", 60*time.Second, "token duration.")
flags.StringSliceVar(&options.Out, "out", []string{"token"}, "the fields to display: [token,expired_at]")
return cmd
}
func newCmdDNSDump() *cobra.Command {
var options commands.CmdDNSDump
cmd := &cobra.Command{
Use: "dump",
Short: "dump the content of the cluster zone",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
return cmd
}
func newCmdDaemonDNSDump() *cobra.Command {
var options commands.CmdDNSDump
cmd := &cobra.Command{
Use: "dump",
Hidden: true,
Short: "dump the content of the cluster zone",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
return cmd
}
func newCmdDaemonJoin() *cobra.Command {
var options commands.CmdDaemonJoin
cmd := &cobra.Command{
Use: "join",
Short: "add this node to a cluster",
Long: "Join the cluster of the node specified by '--node <node>'.\n" +
"The remote node expects the joiner to provide a join token using '--token <base64>'.\n" +
"The join token can be created on the remote node by the 'daemon auth token --role join' command or by getting /auth/token with a user having the joiner or root role.",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
flags.StringVar(&options.Node, "node", "", "the name of the cluster node we want to join")
flags.StringVar(&options.Server, "server", "", "URI of the opensvc api server when custom port is used.")
if err := cmd.MarkFlagRequired("node"); err != nil {
panic(err)
}
flags.StringVar(&options.Token, "token", "", "auth token with 'join' role"+
" (created from 'om daemon auth --role join')")
if err := cmd.MarkFlagRequired("token"); err != nil {
panic(err)
}
flags.DurationVar(&options.Timeout, "timeout", 5*time.Second, "maximum duration to wait for local node added to cluster")
return cmd
}
func newCmdDaemonLeave() *cobra.Command {
var options commands.CmdDaemonLeave
cmd := &cobra.Command{
Use: "leave",
Short: "remove this node from a cluster",
Long: "Inform peer nodes we leave the cluster. Make sure the leaving node is no longer in the objects nodes list.",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
flags.DurationVar(&options.Timeout, "timeout", 5*time.Second, "maximum duration to wait for local node removed from cluster")
return cmd
}
func newCmdDaemonRelayStatus() *cobra.Command {
var options commands.CmdDaemonRelayStatus
cmd := &cobra.Command{
Use: "status",
Short: "show the local daemon relay clients and last data update time",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
return cmd
}
func newCmdDaemonRestart() *cobra.Command {
var options commands.CmdDaemonRestart
cmd := &cobra.Command{
Use: "restart",
Short: "restart the daemon",
Long: "restart the daemon. Operation is asynchronous when node selector is used",
Aliases: []string{"restart"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagNodeSelector(flags, &options.NodeSelector)
return cmd
}
func newCmdDaemonRunning() *cobra.Command {
var options commands.CmdDaemonRunning
cmd := &cobra.Command{
Use: "running",
Short: "test if the daemon is running",
Long: "Exit with code 0 if the daemon is running, else exit with code 1",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagNodeSelector(flags, &options.NodeSelector)
return cmd
}
func newCmdDaemonShutdown() *cobra.Command {
var options commands.CmdDaemonShutdown
cmd := &cobra.Command{
Use: "shutdown",
Short: "Shutdown all local svc and vol objects then shutdown the daemon.",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagDuration(flags, &options.Timeout)
addFlagNodeSelector(flags, &options.NodeSelector)
return cmd
}
func newCmdDaemonStart() *cobra.Command {
var options commands.CmdDaemonStart
cmd := &cobra.Command{
Use: "start",
Short: "start the daemon or a daemon subsystem",
Aliases: []string{"star"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagForeground(flags, &options.Foreground)
addFlagCPUProfile(flags, &options.CPUProfile)
return cmd
}
func newCmdDaemonStatus() *cobra.Command {
var options commands.CmdObjectMonitor
//var options commands.CmdDaemonStatus
cmd := &cobra.Command{
Use: "status",
Short: "print the cluster status",
Long: monitor.CmdLong,
Aliases: []string{"statu"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run("**", "")
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagWatch(flags, &options.Watch)
addFlagOutputSections(flags, &options.Sections)
return cmd
}
func newCmdDaemonStats() *cobra.Command {
var options commands.CmdDaemonStats
cmd := &cobra.Command{
Use: "stats",
Short: "print the resource usage statistics",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
return cmd
}
func newCmdDaemonStop() *cobra.Command {
var options commands.CmdDaemonStop
cmd := &cobra.Command{
Use: "stop",
Short: "stop the daemon",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagNodeSelector(flags, &options.NodeSelector)
return cmd
}
func newCmdKeystoreAdd(kind string) *cobra.Command {
var options commands.CmdKeystoreAdd
cmd := &cobra.Command{
Use: "add",
Short: "add new keys",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run(selectorFlag, kind)
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagsLock(flags, &options.OptsLock)
addFlagKey(flags, &options.Key)
addFlagFrom(flags, &options.From)
addFlagValue(flags, &options.Value)
cmd.MarkFlagsMutuallyExclusive("from", "value")
return cmd
}
func newCmdKeystoreChange(kind string) *cobra.Command {
var options commands.CmdKeystoreChange
cmd := &cobra.Command{
Use: "change",
Short: "change existing keys value",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run(selectorFlag, kind)
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagKey(flags, &options.Key)
addFlagFrom(flags, &options.From)
addFlagValue(flags, &options.Value)
cmd.MarkFlagsMutuallyExclusive("from", "value")
return cmd
}
func newCmdKeystoreDecode(kind string) *cobra.Command {
var options commands.CmdKeystoreDecode
cmd := &cobra.Command{
Use: "decode",
Short: "decode a key value",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run(selectorFlag, kind)
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagKey(flags, &options.Key)
return cmd
}
func newCmdKeystoreInstall(kind string) *cobra.Command {
var options commands.CmdKeystoreInstall
cmd := &cobra.Command{
Use: "install",
Short: "install keys as files in volumes",
Long: "Keys of sec and cfg can be projected to volumes via the configs and secrets keywords of volume resources. When a key value change all projections are automatically refreshed. This command triggers manually the same operations.",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run(selectorFlag, kind)
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagNodeSelector(flags, &options.NodeSelector)
addFlagKey(flags, &options.Key)
return cmd
}
func newCmdKeystoreKeys(kind string) *cobra.Command {
var options commands.CmdKeystoreKeys
cmd := &cobra.Command{
Use: "keys",
Short: "list the keys",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run(selectorFlag, kind)
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagMatch(flags, &options.Match)
return cmd
}
func newCmdKeystoreRemove(kind string) *cobra.Command {
var options commands.CmdKeystoreRemove
cmd := &cobra.Command{
Use: "remove",
Short: "remove a key",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run(selectorFlag, kind)
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagKey(flags, &options.Key)
return cmd
}
func newCmdMonitor() *cobra.Command {
var options commands.CmdObjectMonitor
cmd := &cobra.Command{
Use: "monitor",
Aliases: []string{"m", "mo", "mon", "moni", "monit", "monito"},
Short: "Print the cluster status",
Long: monitor.CmdLong,
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run("*", "")
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagWatch(flags, &options.Watch)
addFlagOutputSections(flags, &options.Sections)
return cmd
}
func newCmdNetworkLs() *cobra.Command {
var options commands.CmdNetworkLs
cmd := &cobra.Command{
Use: "ls",
Short: "list the cluster networks",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
return cmd
}
func newCmdNetworkSetup() *cobra.Command {
var options commands.CmdNetworkSetup
cmd := &cobra.Command{
Use: "setup",
Short: "configure the cluster networks on the node",
Long: "Most cluster network drivers need ip routes, ip rules, tunnels and firewall rules. This command sets them up, the same as done on daemon startup and daemon reconfiguration via configuration change.",
Aliases: []string{"set"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
return cmd
}
func newCmdNetworkIPLs() *cobra.Command {
var options commands.CmdNetworkIPLs
cmd := &cobra.Command{
Use: "ls",
Short: "list the ip in the cluster networks",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagNetworkStatusName(flags, &options.Name)
return cmd
}
func newCmdNodeAbort() *cobra.Command {
var options commands.CmdNodeAbort
cmd := &cobra.Command{
Use: "abort",
Short: "abort the running orchestration",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsAsync(flags, &options.OptsAsync)
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagNodeSelector(flags, &options.NodeSelector)
return cmd
}
func newCmdNodeCapabilitiesList() *cobra.Command {
var options commands.CmdNodeCapabilitiesList
cmd := &cobra.Command{
Use: "list",
Short: "list the node capabilities",
Aliases: []string{"lis", "li", "ls"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagNodeSelector(flags, &options.NodeSelector)
return cmd
}
func newCmdNodeCapabilitiesScan() *cobra.Command {
var options commands.CmdNodeCapabilitiesScan
cmd := &cobra.Command{
Use: "scan",
Short: "scan the node capabilities",
Aliases: []string{"sca", "sc"},
Long: `Scan the node for capabilities.
Capabilities are normally scanned at daemon startup and when the installed
system packages change, so admins only have to use this when they want manually
installed software to be discovered without restarting the daemon.`,
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagNodeSelector(flags, &options.NodeSelector)
return cmd
}
func newCmdNodeChecks() *cobra.Command {
var options commands.CmdNodeChecks
cmd := &cobra.Command{
Use: "checks",
Short: "run the checks, push and print the result",
Aliases: []string{"check", "chec", "che", "ch"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagNodeSelector(flags, &options.NodeSelector)
return cmd
}
func newCmdNodeClear() *cobra.Command {
var options commands.CmdNodeClear
cmd := &cobra.Command{
Use: "clear",
Short: "reset the monitor state to idle",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
return cmd
}
func newCmdNodeCollectorTagAttach() *cobra.Command {
var attachData string
var options commands.CmdNodeCollectorTagAttach
cmd := &cobra.Command{
Use: "attach",
Short: "attach a tag to this node",
Long: "The tag must already exist in the collector.",
Aliases: []string{"atta", "att", "at", "a"},
RunE: func(cmd *cobra.Command, args []string) error {
if cmd.Flag("attach-data").Changed {
options.AttachData = &attachData
}
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
flags.StringVar(&options.Name, "name", "", "the tag name")
flags.StringVar(&attachData, "attach-data", "", "the data stored with the tag attachment")
return cmd
}
func newCmdNodeCollectorTagCreate() *cobra.Command {
var (
data string
exclude string
)
var options commands.CmdNodeCollectorTagCreate
cmd := &cobra.Command{
Use: "create",
Short: "create a new tag",
RunE: func(cmd *cobra.Command, args []string) error {
if cmd.Flag("data").Changed {
options.Data = &data
}
if cmd.Flag("exclude").Changed {
options.Exclude = &exclude
}
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
flags.StringVar(&options.Name, "name", "", "the tag name")
flags.StringVar(&data, "data", "", "the data stored with the tag")
flags.StringVar(&exclude, "exclude", "", "a pattern to prevent attachment of incompatible tags")
return cmd
}
func newCmdNodeCollectorTagDetach() *cobra.Command {
var options commands.CmdNodeCollectorTagDetach
cmd := &cobra.Command{
Use: "detach",
Short: "detach a tag from this node",
Aliases: []string{"deta", "det", "de", "d"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
flags.StringVar(&options.Name, "name", "", "the tag name")
return cmd
}
func newCmdNodeCollectorTagList() *cobra.Command {
var options commands.CmdNodeCollectorTagList
cmd := &cobra.Command{
Use: "list",
Short: "list available tags",
Aliases: []string{"lis", "li", "ls", "l"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
return cmd
}
func newCmdNodeCollectorTagShow() *cobra.Command {
var options commands.CmdNodeCollectorTagShow
cmd := &cobra.Command{
Use: "show",
Short: "show tags attached to this node",
Aliases: []string{"sho", "sh", "s"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
flags.BoolVar(&options.Verbose, "verbose", false, "also show the attach data")
return cmd
}
func newCmdNodeComplianceAttachModuleset() *cobra.Command {
var options commands.CmdNodeComplianceAttachModuleset
cmd := &cobra.Command{
Use: "moduleset",
Short: "attach modulesets to this node",
Long: "Modules of all attached modulesets are checked on schedule.",
Aliases: []string{"modulese", "modules", "module", "modul", "modu", "mod", "mo"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagModuleset(flags, &options.Moduleset)
addFlagNodeSelector(flags, &options.NodeSelector)
return cmd
}
func newCmdNodeComplianceAttachRuleset() *cobra.Command {
var options commands.CmdNodeComplianceAttachRuleset
cmd := &cobra.Command{
Use: "ruleset",
Short: "attach rulesets to this node",
Long: "Rules of attached rulesets are exposed to modules.",
Aliases: []string{"rulese", "rules", "rule", "rul", "ru"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagRuleset(flags, &options.Ruleset)
addFlagNodeSelector(flags, &options.NodeSelector)
return cmd
}
func newCmdNodeComplianceAuto() *cobra.Command {
var options commands.CmdNodeComplianceAuto
cmd := &cobra.Command{
Use: "auto",
Short: "run modules fixes or checks",
Long: "If the module is has the 'autofix' property set, do a fix, else do a check.",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagModule(flags, &options.Module)
addFlagModuleset(flags, &options.Moduleset)
addFlagNodeSelector(flags, &options.NodeSelector)
addFlagComplianceAttach(flags, &options.Attach)
addFlagComplianceForce(flags, &options.Force)
return cmd
}
func newCmdNodeComplianceCheck() *cobra.Command {
var options commands.CmdNodeComplianceCheck
cmd := &cobra.Command{
Use: "check",
Short: "run modules checks",
Aliases: []string{"chec", "che", "ch"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagModule(flags, &options.Module)
addFlagModuleset(flags, &options.Moduleset)
addFlagNodeSelector(flags, &options.NodeSelector)
addFlagComplianceAttach(flags, &options.Attach)
addFlagComplianceForce(flags, &options.Force)
return cmd
}
func newCmdNodeComplianceFix() *cobra.Command {
var options commands.CmdNodeComplianceFix
cmd := &cobra.Command{
Use: "fix",
Short: "run modules fixes",
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagModule(flags, &options.Module)
addFlagModuleset(flags, &options.Moduleset)
addFlagNodeSelector(flags, &options.NodeSelector)
addFlagComplianceAttach(flags, &options.Attach)
addFlagComplianceForce(flags, &options.Force)
return cmd
}
func newCmdNodeComplianceFixable() *cobra.Command {
var options commands.CmdNodeComplianceFixable
cmd := &cobra.Command{
Use: "fixable",
Short: "run modules fixable-tests",
Aliases: []string{"fixabl", "fixab", "fixa"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagModule(flags, &options.Module)
addFlagModuleset(flags, &options.Moduleset)
addFlagNodeSelector(flags, &options.NodeSelector)
addFlagComplianceAttach(flags, &options.Attach)
addFlagComplianceForce(flags, &options.Force)
return cmd
}
func newCmdNodeComplianceDetachModuleset() *cobra.Command {
var options commands.CmdNodeComplianceDetachModuleset
cmd := &cobra.Command{
Use: "moduleset",
Short: "detach modulesets from this node",
Long: "Modules of attached modulesets are checked on schedule.",
Aliases: []string{"modulese", "modules", "module", "modul", "modu", "mod", "mo"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagModuleset(flags, &options.Moduleset)
addFlagNodeSelector(flags, &options.NodeSelector)
return cmd
}
func newCmdNodeComplianceDetachRuleset() *cobra.Command {
var options commands.CmdNodeComplianceDetachRuleset
cmd := &cobra.Command{
Use: "ruleset",
Short: "detach rulesets from this node",
Long: "Rules of attached rulesets are made available to their module.",
Aliases: []string{"rulese", "rules", "rule", "rul", "ru"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagRuleset(flags, &options.Ruleset)
addFlagNodeSelector(flags, &options.NodeSelector)
return cmd
}
func newCmdNodeComplianceEnv() *cobra.Command {
var options commands.CmdNodeComplianceEnv
cmd := &cobra.Command{
Use: "env",
Short: "show the env variables set for modules run",
Aliases: []string{"en"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagModuleset(flags, &options.Moduleset)
addFlagModule(flags, &options.Module)
addFlagNodeSelector(flags, &options.NodeSelector)
return cmd
}
func newCmdNodeComplianceListModules() *cobra.Command {
var options commands.CmdNodeComplianceListModules
cmd := &cobra.Command{
Use: "modules",
Short: "list modules available on this node",
Aliases: []string{"module", "modul", "modu", "mod"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagNodeSelector(flags, &options.NodeSelector)
return cmd
}
func newCmdNodeComplianceListModuleset() *cobra.Command {
var options commands.CmdNodeComplianceListModuleset
cmd := &cobra.Command{
Use: "moduleset",
Short: "list modulesets available to this node",
Aliases: []string{"modulesets"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagModuleset(flags, &options.Moduleset)
addFlagNodeSelector(flags, &options.NodeSelector)
return cmd
}
func newCmdNodeComplianceListRuleset() *cobra.Command {
var options commands.CmdNodeComplianceListRuleset
cmd := &cobra.Command{
Use: "ruleset",
Short: "list rulesets available to this node",
Aliases: []string{"rulese", "rules", "rule", "rul", "ru"},
RunE: func(cmd *cobra.Command, args []string) error {
return options.Run()
},
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
addFlagRuleset(flags, &options.Ruleset)
addFlagNodeSelector(flags, &options.NodeSelector)
return cmd
}
func newCmdNodeComplianceShowModuleset() *cobra.Command {
var options commands.CmdNodeComplianceShowModuleset
cmd := &cobra.Command{
Use: "moduleset",
Short: "show modulesets and modules attached to this node",
Aliases: []string{"modulese", "modules", "module", "modul", "modu", "mod", "mo"},
RunE: func(cmd *cobra.Command, args []string) error {