Skip to content

Commit

Permalink
implemented bugfix for #47 in apirequestcount resource
Browse files Browse the repository at this point in the history
  • Loading branch information
gmeghnag committed May 5, 2022
1 parent 647dc25 commit 5e6737c
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions cmd/get/openshift/apiserver/apirequestcount.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type ApiRequestCountsItems struct {
Items []v1.APIRequestCount `json:"items"`
}

func getAPIRequestCount(currentContextPath string, namespace string, resourceName string, allNamespacesFlag bool, outputFlag string, showLabels bool, jsonPathTemplate string) bool {
func getAPIRequestCount(currentContextPath string, namespace string, resourcesNames []string, allNamespacesFlag bool, outputFlag string, showLabels bool, jsonPathTemplate string) bool {

apirequestcountsFolderPath := currentContextPath + "/cluster-scoped-resources/apiserver.openshift.io/apirequestcounts/"
_apirequestcounts, _ := ioutil.ReadDir(apirequestcountsFolderPath)
Expand All @@ -59,7 +59,7 @@ func getAPIRequestCount(currentContextPath string, namespace string, resourceNam
if !helpers.MatchLabels(labels, vars.LabelSelectorStringVar) {
continue
}
if resourceName != "" && resourceName != APIRequestCount.Name {
if len(resourcesNames) != 0 && !helpers.StringInSlice(APIRequestCount.Name, resourcesNames) {
continue
}

Expand Down Expand Up @@ -120,11 +120,7 @@ func getAPIRequestCount(currentContextPath string, namespace string, resourceNam
return false
}
var resource interface{}
if resourceName != "" {
resource = _ApiRequestCountsList.Items[0]
} else {
resource = _ApiRequestCountsList
}
resource = _ApiRequestCountsList
if outputFlag == "yaml" {
y, _ := yaml.Marshal(resource)
fmt.Println(string(y))
Expand All @@ -144,11 +140,8 @@ var APIRequestCount = &cobra.Command{
Aliases: []string{"apirequestcounts", "apirequestcount.apiserver.openshift.io"},
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
resourceName := ""
if len(args) == 1 {
resourceName = args[0]
}
resourcesNames := args
jsonPathTemplate := helpers.GetJsonTemplate(vars.OutputStringVar)
getAPIRequestCount(vars.MustGatherRootPath, vars.Namespace, resourceName, vars.AllNamespaceBoolVar, vars.OutputStringVar, vars.ShowLabelsBoolVar, jsonPathTemplate)
getAPIRequestCount(vars.MustGatherRootPath, vars.Namespace, resourcesNames, vars.AllNamespaceBoolVar, vars.OutputStringVar, vars.ShowLabelsBoolVar, jsonPathTemplate)
},
}

0 comments on commit 5e6737c

Please sign in to comment.