Skip to content

Commit 368bdd3

Browse files
Merge pull request #880 from MateSaary/srep-3857
Add describe-nodes investigation and --params flag to cad run
2 parents e8332d0 + 76d95cf commit 368bdd3

4 files changed

Lines changed: 124 additions & 20 deletions

File tree

cmd/cluster/cad/run.go

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"slices"
7+
"strings"
78

89
"github.com/openshift/osdctl/cmd/setup"
910
"github.com/openshift/osdctl/pkg/k8s"
@@ -34,6 +35,7 @@ var validInvestigations = []string{
3435
"must-gather",
3536
"upgrade-config",
3637
"restart-controlplane",
38+
"describe-nodes",
3739
}
3840

3941
var validEnvironments = []string{
@@ -47,6 +49,7 @@ type cadRunOptions struct {
4749
elevationReason string
4850
environment string
4951
isDryRun bool
52+
params []string
5053
}
5154

5255
func newCmdRun() *cobra.Command {
@@ -66,7 +69,8 @@ Prerequisites:
6669
6770
Available Investigations:
6871
chgm, cmbb, can-not-retrieve-updates, ai, cpd, etcd-quota-low,
69-
insightsoperatordown, machine-health-check, must-gather, upgrade-config
72+
insightsoperatordown, machine-health-check, must-gather, upgrade-config,
73+
restart-controlplane, describe-nodes
7074
7175
Examples:
7276
` + "```bash" + `
@@ -84,6 +88,14 @@ osdctl cluster cad run \
8488
--environment production \
8589
--reason "OHSS-12345" \
8690
--dry-run
91+
92+
# Run describe-nodes on master nodes only
93+
osdctl cluster cad run \
94+
--cluster-id 1a2b3c4d5e6f7g8h9i0j \
95+
--investigation describe-nodes \
96+
--environment production \
97+
--reason "OHSS-12345" \
98+
--params MASTER=true
8799
` + "```" + `
88100
89101
Note:
@@ -105,6 +117,8 @@ osdctl cluster reports list -C <cluster-id> -l 1
105117
runCmd.Flags().StringVarP(&opts.environment, "environment", "e", "", "Environment in which the target cluster runs. Allowed values: \"stage\" or \"production\"")
106118
runCmd.Flags().BoolVarP(&opts.isDryRun, "dry-run", "d", false, "Dry-Run: Run the investigation with the dry-run flag. This will not create a report.")
107119
runCmd.Flags().StringVar(&opts.elevationReason, "reason", "", "Provide a reason for running a manual investigation, used for backplane. Eg: 'OHSS-XXXX', or '#ITN-2024-XXXXX.")
120+
runCmd.Flags().StringArrayVarP(&opts.params, "params", "p", nil,
121+
"Investigation-specific parameters as KEY=VALUE (can be specified multiple times)")
108122

109123
_ = runCmd.MarkFlagRequired("cluster-id")
110124
_ = runCmd.MarkFlagRequired("investigation")
@@ -198,6 +212,13 @@ func (o *cadRunOptions) validate() error {
198212
return fmt.Errorf("elevation reason is required")
199213
}
200214

215+
for _, p := range o.params {
216+
parts := strings.SplitN(p, "=", 2)
217+
if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
218+
return fmt.Errorf("invalid param %q: must be in KEY=VALUE format", p)
219+
}
220+
}
221+
201222
return nil
202223
}
203224

@@ -209,6 +230,28 @@ func (o *cadRunOptions) getCADClusterConfig() (clusterID, namespace string) {
209230
}
210231

211232
func (o *cadRunOptions) pipelineRunTemplate(cadNamespace string) *unstructured.Unstructured {
233+
pipelineParams := []map[string]interface{}{
234+
{
235+
"name": "cluster-id",
236+
"value": o.clusterID,
237+
},
238+
{
239+
"name": "investigation",
240+
"value": o.investigation,
241+
},
242+
{
243+
"name": "dry-run",
244+
"value": o.isDryRun,
245+
},
246+
}
247+
248+
if len(o.params) > 0 {
249+
pipelineParams = append(pipelineParams, map[string]interface{}{
250+
"name": "investigation-params",
251+
"value": strings.Join(o.params, ","),
252+
})
253+
}
254+
212255
u := unstructured.Unstructured{}
213256
u.Object = map[string]interface{}{
214257
"apiVersion": "tekton.dev/v1beta1",
@@ -218,23 +261,8 @@ func (o *cadRunOptions) pipelineRunTemplate(cadNamespace string) *unstructured.U
218261
"namespace": cadNamespace,
219262
},
220263
"spec": map[string]interface{}{
221-
"params": []map[string]interface{}{
222-
{
223-
"name": "cluster-id",
224-
"value": o.clusterID,
225-
},
226-
{
227-
"name": "investigation",
228-
"value": o.investigation,
229-
},
230-
{
231-
"name": "dry-run",
232-
"value": o.isDryRun,
233-
},
234-
},
235-
"pipelineRef": map[string]interface{}{
236-
"name": "cad-manual-investigation-pipeline",
237-
},
264+
"params": pipelineParams,
265+
"pipelineRef": map[string]interface{}{"name": "cad-manual-investigation-pipeline"},
238266
"serviceAccountName": "cad-sa",
239267
"timeout": "30m",
240268
},

cmd/cluster/cad/run_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,62 @@ import (
88
"github.com/stretchr/testify/assert"
99
)
1010

11+
func TestValidateParams(t *testing.T) {
12+
base := cadRunOptions{
13+
clusterID: "test-cluster",
14+
investigation: "chgm",
15+
environment: "production",
16+
elevationReason: "OHSS-12345",
17+
}
18+
19+
tests := []struct {
20+
name string
21+
params []string
22+
wantErr string
23+
}{
24+
{
25+
name: "valid params",
26+
params: []string{"KEY=value", "MASTER=true"},
27+
},
28+
{
29+
name: "no params",
30+
params: nil,
31+
},
32+
{
33+
name: "missing value",
34+
params: []string{"foo"},
35+
wantErr: `invalid param "foo": must be in KEY=VALUE format`,
36+
},
37+
{
38+
name: "empty key",
39+
params: []string{"=bar"},
40+
wantErr: `invalid param "=bar": must be in KEY=VALUE format`,
41+
},
42+
{
43+
name: "empty value",
44+
params: []string{"KEY="},
45+
wantErr: `invalid param "KEY=": must be in KEY=VALUE format`,
46+
},
47+
{
48+
name: "value containing equals sign",
49+
params: []string{"KEY=val=ue"},
50+
},
51+
}
52+
53+
for _, tt := range tests {
54+
t.Run(tt.name, func(t *testing.T) {
55+
opts := base
56+
opts.params = tt.params
57+
err := opts.validate()
58+
if tt.wantErr != "" {
59+
assert.EqualError(t, err, tt.wantErr)
60+
} else {
61+
assert.NoError(t, err)
62+
}
63+
})
64+
}
65+
}
66+
1167
func TestGetCADClusterConfig(t *testing.T) {
1268
tests := []struct {
1369
name string

docs/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,8 @@ Prerequisites:
13531353

13541354
Available Investigations:
13551355
chgm, cmbb, can-not-retrieve-updates, ai, cpd, etcd-quota-low,
1356-
insightsoperatordown, machine-health-check, must-gather, upgrade-config
1356+
insightsoperatordown, machine-health-check, must-gather, upgrade-config,
1357+
restart-controlplane, describe-nodes
13571358

13581359
Examples:
13591360
```bash
@@ -1371,6 +1372,14 @@ osdctl cluster cad run \
13711372
--environment production \
13721373
--reason "OHSS-12345" \
13731374
--dry-run
1375+
1376+
# Run describe-nodes on master nodes only
1377+
osdctl cluster cad run \
1378+
--cluster-id 1a2b3c4d5e6f7g8h9i0j \
1379+
--investigation describe-nodes \
1380+
--environment production \
1381+
--reason "OHSS-12345" \
1382+
--params MASTER=true
13741383
```
13751384

13761385
Note:
@@ -1399,6 +1408,7 @@ osdctl cluster cad run [flags]
13991408
-i, --investigation string Investigation name
14001409
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
14011410
-o, --output string Valid formats are ['', 'json', 'yaml', 'env']
1411+
-p, --params stringArray Investigation-specific parameters as KEY=VALUE (can be specified multiple times)
14021412
--reason string Provide a reason for running a manual investigation, used for backplane. Eg: 'OHSS-XXXX', or '#ITN-2024-XXXXX.
14031413
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
14041414
-s, --server string The address and port of the Kubernetes API server

docs/osdctl_cluster_cad_run.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Prerequisites:
1515

1616
Available Investigations:
1717
chgm, cmbb, can-not-retrieve-updates, ai, cpd, etcd-quota-low,
18-
insightsoperatordown, machine-health-check, must-gather, upgrade-config
18+
insightsoperatordown, machine-health-check, must-gather, upgrade-config,
19+
restart-controlplane, describe-nodes
1920

2021
Examples:
2122
```bash
@@ -33,6 +34,14 @@ osdctl cluster cad run \
3334
--environment production \
3435
--reason "OHSS-12345" \
3536
--dry-run
37+
38+
# Run describe-nodes on master nodes only
39+
osdctl cluster cad run \
40+
--cluster-id 1a2b3c4d5e6f7g8h9i0j \
41+
--investigation describe-nodes \
42+
--environment production \
43+
--reason "OHSS-12345" \
44+
--params MASTER=true
3645
```
3746

3847
Note:
@@ -55,6 +64,7 @@ osdctl cluster cad run [flags]
5564
-e, --environment string Environment in which the target cluster runs. Allowed values: "stage" or "production"
5665
-h, --help help for run
5766
-i, --investigation string Investigation name
67+
-p, --params stringArray Investigation-specific parameters as KEY=VALUE (can be specified multiple times)
5868
--reason string Provide a reason for running a manual investigation, used for backplane. Eg: 'OHSS-XXXX', or '#ITN-2024-XXXXX.
5969
```
6070

0 commit comments

Comments
 (0)