Skip to content

Commit

Permalink
Merge pull request #1066 from rancher/minimal-build
Browse files Browse the repository at this point in the history
fix minimal build issue
  • Loading branch information
dbason authored Feb 14, 2023
2 parents 9d3717b + f548755 commit 6abf4a2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 34 deletions.
34 changes: 0 additions & 34 deletions pkg/opni/commands/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package commands

import (
"fmt"
"github.com/rancher/opni/plugins/metrics/pkg/apis/remoteread"
"os"
"strings"
"time"
Expand Down Expand Up @@ -211,36 +210,3 @@ func completeBootstrapTokens(cmd *cobra.Command, args []string, toComplete strin
}
return comps, cobra.ShellCompDirectiveNoFileComp
}

func completeImportTargets(cmd *cobra.Command, args []string, toComplete string, _ ...func(token *corev1.BootstrapToken) bool) ([]string, cobra.ShellCompDirective) {
if err := importPreRunE(cmd, nil); err != nil {
return nil, cobra.ShellCompDirectiveError | cobra.ShellCompDirectiveNoFileComp
}

var cluster string
if len(args) >= 1 {
cluster = args[1]
}

targetList, err := remoteReadClient.ListTargets(cmd.Context(), &remoteread.TargetListRequest{
ClusterId: cluster,
})
if err != nil {
return nil, cobra.ShellCompDirectiveNoFileComp
}

var targets []string
for _, target := range targetList.Targets {
name := target.Meta.Name

if slices.Contains(args, name) {
continue
}

if strings.HasPrefix(name, toComplete) {
targets = append(targets, name)
}
}

return targets, cobra.ShellCompDirectiveNoFileComp
}
44 changes: 44 additions & 0 deletions pkg/opni/commands/completion_plugins.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//go:build !noplugins

package commands

import (
corev1 "github.com/rancher/opni/pkg/apis/core/v1"
"github.com/rancher/opni/plugins/metrics/pkg/apis/remoteread"
"github.com/spf13/cobra"
"golang.org/x/exp/slices"
"strings"
)

func completeImportTargets(cmd *cobra.Command, args []string, toComplete string, _ ...func(token *corev1.BootstrapToken) bool) ([]string, cobra.ShellCompDirective) {
if err := importPreRunE(cmd, nil); err != nil {
return nil, cobra.ShellCompDirectiveError | cobra.ShellCompDirectiveNoFileComp
}

var cluster string
if len(args) >= 1 {
cluster = args[1]
}

targetList, err := remoteReadClient.ListTargets(cmd.Context(), &remoteread.TargetListRequest{
ClusterId: cluster,
})
if err != nil {
return nil, cobra.ShellCompDirectiveNoFileComp
}

var targets []string
for _, target := range targetList.Targets {
name := target.Meta.Name

if slices.Contains(args, name) {
continue
}

if strings.HasPrefix(name, toComplete) {
targets = append(targets, name)
}
}

return targets, cobra.ShellCompDirectiveNoFileComp
}
2 changes: 2 additions & 0 deletions pkg/opni/commands/import_progress.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !noplugins

package commands

import (
Expand Down

0 comments on commit 6abf4a2

Please sign in to comment.