Skip to content

Commit 5aa1051

Browse files
Merge pull request #178 from georgettica/georgettica/servicelog-fixes
fix(servicelog): bulk commands
2 parents db3f15c + ebd8d80 commit 5aa1051

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

cmd/servicelog/common.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func createConnection() *sdk.Connection {
3636

3737
// generateQuery returns an OCM search query to retrieve all clusters matching an expression (ie- "foo%")
3838
func generateQuery(clusterIdentifier string) string {
39-
return strings.TrimSpace(fmt.Sprintf("id like '%[1]s' or external_id like '%[1]s' or display_name like '%[1]s'", clusterIdentifier))
39+
return strings.TrimSpace(fmt.Sprintf("(id like '%[1]s' or external_id like '%[1]s' or display_name like '%[1]s')", clusterIdentifier))
4040
}
4141

4242
// getFilteredClusters retrieves clusters in OCM which match the filters given
@@ -51,6 +51,9 @@ func applyFilters(ocmClient *sdk.Connection, filters []string) ([]*v1.Cluster, e
5151

5252
requestSize := 50
5353
full_filters := strings.Join(filters, " and ")
54+
55+
log.Infof(`running the command: 'ocm list clusters --parameter=search="%s"'`, full_filters)
56+
5457
request := ocmClient.ClustersMgmt().V1().Clusters().List().Search(full_filters).Size(requestSize)
5558
response, err := request.Send()
5659
if err != nil {

cmd/servicelog/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var listCmd = &cobra.Command{
2020
Args: cobra.ArbitraryArgs,
2121
SilenceErrors: true,
2222
RunE: func(cmd *cobra.Command, args []string) error {
23-
if len(args) != 1 {
23+
if len(args) == 0 {
2424
cmd.Help()
2525
return fmt.Errorf("cluster-identifier was not provided. please provide a cluster id, UUID, or name")
2626
}

cmd/servicelog/post.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var postCmd = &cobra.Command{
5151
readFilterFile() // parse the ocm filters in file provided via '-f' flag
5252
readTemplate() // parse the given JSON template provided via '-t' flag
5353

54-
if len(args) < 1 && filtersFromFile == "" && clustersFile == "" {
54+
if len(args) == 0 && len(filterParams) == 0 && clustersFile == "" {
5555
log.Fatalf("No cluster identifier has been found.")
5656
}
5757

@@ -108,7 +108,7 @@ var postCmd = &cobra.Command{
108108
cluster := ClustersFile.Clusters[i]
109109
query = append(query, generateQuery(cluster))
110110
}
111-
filterParams = query
111+
filterParams = append(filterParams, strings.Join(query, " or "))
112112
}
113113

114114
clusters, err := applyFilters(ocmClient, filterParams)
@@ -180,7 +180,7 @@ func init() {
180180
postCmd.Flags().StringArrayVarP(&filterParams, "query", "q", filterParams, "Specify a search query (eg. -q \"name like foo\") for a bulk-post to matching clusters.")
181181
postCmd.Flags().BoolVarP(&skipPrompts, "yes", "y", false, "Skips all prompts.")
182182
postCmd.Flags().StringArrayVarP(&filterFiles, "query-file", "f", filterFiles, "File containing search queries to apply. All lines in the file will be concatenated into a single query. If this flag is called multiple times, every file's search query will be combined with logical AND.")
183-
postCmd.Flags().StringVarP(&clustersFile, "clusters-file", "c", clustersFile, "Read a list of clusters to post the servicelog to")
183+
postCmd.Flags().StringVarP(&clustersFile, "clusters-file", "c", clustersFile, `Read a list of clusters to post the servicelog to. the format of the file is: {"clusters":["$CLUSTERID"]}`)
184184
}
185185

186186
// parseUserParameters parse all the '-p FOO=BAR' parameters and checks for syntax errors

0 commit comments

Comments
 (0)