@@ -32,52 +32,69 @@ import (
32
32
"github.com/spf13/cobra"
33
33
)
34
34
35
+ var pipelinesNamespace string
36
+ var pipelinesRuntime string
37
+
35
38
// pipelinesCmd represents the pipelines command
36
39
var pipelinesCmd = & cobra.Command {
37
40
Use : "pipelines" ,
38
41
Short : "Collect data for the Codefresh Pipelines Runtime" ,
39
42
Long : `Collect data for the Codefresh Pipelines Runtime` ,
40
43
Run : func (cmd * cobra.Command , args []string ) {
41
44
const RuntimeType = "Codefresh Pipelines Runtime"
45
+ var runtimes []map [string ]interface {}
46
+ var reSpec map [string ]interface {}
47
+
42
48
dirPath := fmt .Sprintf ("./codefresh-support-%d" , time .Now ().Unix ())
49
+
43
50
cfConfig , err := codefresh .GetCodefreshCreds ()
44
51
if err != nil {
45
52
cmd .PrintErrln ("Error getting Codefresh credentials:" , err )
46
- return
47
53
}
48
54
49
- runtimes , err := codefresh .AccountRuntimes (cfConfig )
50
- if err != nil {
51
- cmd .PrintErrln ("Error getting Codefresh runtimes:" , err )
52
- return
53
- }
55
+ if cfConfig != nil {
56
+ if pipelinesRuntime != "" {
57
+ reSpec , err = codefresh .SingleRuntime (cfConfig , pipelinesRuntime )
58
+ if err != nil {
59
+ cmd .PrintErrln ("Error getting Codefresh runtimes:" , err )
60
+ }
54
61
55
- var pipelinesNamespace string
56
- var reSpec map [string ]interface {}
62
+ } else {
63
+ runtimes , err = codefresh .AccountRuntimes (cfConfig )
64
+ if err != nil {
65
+ cmd .PrintErrln ("Error getting Codefresh runtimes:" , err )
66
+ }
57
67
58
- if len (runtimes ) != 0 {
59
- var selection int
60
- for index , runtime := range runtimes {
61
- cmd .Printf ("%d. %s\n " , index + 1 , runtime ["metadata" ].(map [string ]interface {})["name" ])
62
- }
63
- for {
64
- cmd .Print ("\n Please select the runtime to gather data from (Number): " )
65
- _ , err := fmt .Scanf ("%d" , & selection )
66
- if err != nil || selection < 1 || selection > len (runtimes ) {
67
- cmd .PrintErrln ("Invalid selection. Please enter a number corresponding to one of the listed runtimes." )
68
- continue
68
+ if len (runtimes ) != 0 {
69
+ var selection int
70
+ for index , runtime := range runtimes {
71
+ cmd .Printf ("%d. %s\n " , index + 1 , runtime ["metadata" ].(map [string ]interface {})["name" ])
72
+ }
73
+ for {
74
+ cmd .Print ("\n Please select the runtime to gather data from (Number): " )
75
+ _ , err := fmt .Scanf ("%d" , & selection )
76
+ if err != nil || selection < 1 || selection > len (runtimes ) {
77
+ cmd .PrintErrln ("Invalid selection. Please enter a number corresponding to one of the listed runtimes." )
78
+ continue
79
+ }
80
+ break
81
+
82
+ }
83
+ reSpec = runtimes [selection - 1 ]
69
84
}
70
- break
71
85
72
86
}
73
- reSpec = runtimes [selection - 1 ]
74
- pipelinesNamespace = reSpec ["runtimeScheduler" ].(map [string ]interface {})["cluster" ].(map [string ]interface {})["namespace" ].(string )
75
- } else {
76
- cmd .Println ("No runtimes found in Codefresh account." )
77
- pipelinesNamespace , err = k8s .SelectNamespace (RuntimeType )
78
- if err != nil {
79
- cmd .PrintErrf ("error getting Kubernetes namespace: %v" , err )
80
- return
87
+ }
88
+
89
+ if pipelinesNamespace == "" {
90
+ if reSpec != nil {
91
+ pipelinesNamespace = reSpec ["runtimeScheduler" ].(map [string ]interface {})["cluster" ].(map [string ]interface {})["namespace" ].(string )
92
+ } else {
93
+ pipelinesNamespace , err = k8s .SelectNamespace (RuntimeType )
94
+ if err != nil {
95
+ cmd .PrintErrf ("error getting Kubernetes namespace: %v" , err )
96
+ return
97
+ }
81
98
}
82
99
}
83
100
@@ -119,4 +136,6 @@ func init() {
119
136
// Cobra supports local flags which will only run when this command
120
137
// is called directly, e.g.:
121
138
// pipelinesCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
139
+ pipelinesCmd .Flags ().StringVarP (& pipelinesNamespace , "namespace" , "n" , "" , "The namespace where the Runtime is installed" )
140
+ pipelinesCmd .Flags ().StringVarP (& pipelinesRuntime , "runtime" , "re" , "" , "The name of the Pipelines Runtime" )
122
141
}
0 commit comments