Skip to content

Commit

Permalink
remove docker flag from all scout sub-commands (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonhawkharris committed Jun 16, 2023
1 parent 5a99c9b commit 81cb1c9
Show file tree
Hide file tree
Showing 15 changed files with 5 additions and 351 deletions.
5 changes: 2 additions & 3 deletions cmd/src/scout.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ func init() {
The commands are:
resource print all known sourcegraph resources and their allocations
estimate (coming soon) recommend resource allocation for one or many services
usage (coming soon) get CPU, memory and current disk usage
advise (coming soon) recommend lowering or raising resource allocations based on actual usage
usage get CPU, memory and current disk usage
advise recommend lowering or raising resource allocations based on actual usage
Use "src scout [command] -h" for more information about a command.
`
Expand Down
15 changes: 0 additions & 15 deletions cmd/src/scout_advise.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"path/filepath"

"github.com/docker/docker/client"
"github.com/sourcegraph/src-cli/internal/scout/advise"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
Expand Down Expand Up @@ -45,9 +44,7 @@ func init() {
kubeConfig *string
namespace = flagSet.String("namespace", "", "(optional) specify the kubernetes namespace to use")
pod = flagSet.String("pod", "", "(optional) specify a single pod")
container = flagSet.String("container", "", "(optional) specify a single container")
output = flagSet.String("o", "", "(optional) output advice to file")
docker = flagSet.Bool("docker", false, "(optional) using docker deployment")
)

if home := homedir.HomeDir(); home != "" {
Expand Down Expand Up @@ -91,18 +88,6 @@ func init() {
if *output != "" {
options = append(options, advise.WithOutput(*output))
}
if *container != "" || *docker {
if *container != "" {
options = append(options, advise.WithContainer(*container))
}

dockerClient, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
return errors.Wrap(err, "error creating docker client: ")
}

return advise.Docker(context.Background(), *dockerClient, options...)
}

return advise.K8s(
context.Background(),
Expand Down
14 changes: 0 additions & 14 deletions cmd/src/scout_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"path/filepath"

"github.com/docker/docker/client"
"github.com/sourcegraph/sourcegraph/lib/errors"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
Expand All @@ -23,9 +22,6 @@ func init() {
List pods and resource allocations in a Kubernetes deployment:
$ src scout resource
List containers and resource allocations in a Docker deployment:
$ src scout resource --docker
Add namespace if using namespace in a Kubernetes cluster
$ src scout resource --namespace sg
`
Expand All @@ -40,7 +36,6 @@ func init() {
var (
kubeConfig *string
namespace = flagSet.String("namespace", "", "(optional) specify the kubernetes namespace to use")
docker = flagSet.Bool("docker", false, "(optional) using docker deployment")
// TODO: option for getting resource allocation of the Node
// nodes = flagSet.Bool("node", false, "(optional) view resources for node(s)")
)
Expand Down Expand Up @@ -76,15 +71,6 @@ func init() {
options = append(options, resource.WithNamespace(*namespace))
}

if *docker {
dockerClient, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
return errors.Wrap(err, "error creating docker client: ")
}

return resource.Docker(context.Background(), *dockerClient)
}

return resource.K8s(context.Background(), clientSet, config, options...)
}

Expand Down
29 changes: 0 additions & 29 deletions cmd/src/scout_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"path/filepath"

"github.com/docker/docker/client"
"github.com/sourcegraph/sourcegraph/lib/errors"
"github.com/sourcegraph/src-cli/internal/scout/usage"
"k8s.io/client-go/kubernetes"
Expand All @@ -23,20 +22,11 @@ func init() {
List pods and resource usage in a Kubernetes deployment:
$ src scout usage
List containers and resource usage in a Docker deployment:
$ src scout usage --docker
Check usage for specific pod
$ src scout usage --pod <podname>
Check usage for specific container (docker only)
$ src scout usage --container <containername>
Add namespace if using namespace in a Kubernetes cluster
$ src scout usage --namespace <namespace>
Watch usage in real time
$ src scout usage --spy
`

flagSet := flag.NewFlagSet("usage", flag.ExitOnError)
Expand All @@ -50,9 +40,6 @@ func init() {
kubeConfig *string
namespace = flagSet.String("namespace", "", "(optional) specify the kubernetes namespace to use")
pod = flagSet.String("pod", "", "(optional) specify a single pod")
container = flagSet.String("container", "", "(optional) specify a single container")
docker = flagSet.Bool("docker", false, "(optional) using docker deployment")
spy = flagSet.Bool("spy", false, "(optional) see resource usage in real time")
)

if home := homedir.HomeDir(); home != "" {
Expand Down Expand Up @@ -86,28 +73,12 @@ func init() {
}

var options []usage.Option

if *namespace != "" {
options = append(options, usage.WithNamespace(*namespace))
}
if *spy {
options = append(options, usage.WithSpy(true))
}
if *pod != "" {
options = append(options, usage.WithPod(*pod))
}
if *container != "" || *docker {
if *container != "" {
options = append(options, usage.WithContainer(*container))
}

dockerClient, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
return errors.Wrap(err, "error creating docker client: ")
}

return usage.Docker(context.Background(), *dockerClient, options...)
}

return usage.K8s(
context.Background(),
Expand Down
8 changes: 0 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/creack/goselect v0.1.2
github.com/derision-test/glock v0.0.0-20210316032053-f5b74334bb29
github.com/dineshappavoo/basex v0.0.0-20170425072625-481a6f6dc663
github.com/docker/docker v23.0.5+incompatible
github.com/dustin/go-humanize v1.0.1
github.com/gobwas/glob v0.2.3
github.com/google/go-cmp v0.5.9
Expand Down Expand Up @@ -60,7 +59,6 @@ require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/alecthomas/chroma v0.10.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.17.5 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.13 // indirect
Expand All @@ -85,9 +83,6 @@ require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/envoyproxy/protoc-gen-validate v0.9.1 // indirect
github.com/fatih/color v1.13.0 // indirect
Expand Down Expand Up @@ -134,7 +129,6 @@ require (
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
Expand All @@ -143,8 +137,6 @@ require (
github.com/mwitkow/go-proto-validators v0.3.2 // indirect
github.com/nightlyone/lockfile v1.0.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/profile v1.6.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
17 changes: 0 additions & 17 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3Q
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60=
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek=
Expand Down Expand Up @@ -131,14 +129,6 @@ github.com/dineshappavoo/basex v0.0.0-20170425072625-481a6f6dc663/go.mod h1:Kad2
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo=
github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68=
github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v23.0.5+incompatible h1:DaxtlTJjFSnLOXVNUBU1+6kXGz2lpDoEAH6QoxaSg8k=
github.com/docker/docker v23.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
Expand Down Expand Up @@ -405,8 +395,6 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
Expand Down Expand Up @@ -447,10 +435,6 @@ github.com/onsi/ginkgo/v2 v2.9.1 h1:zie5Ly042PD3bsCvsSOPvRnFwyo3rKe64TJlD6nu0mk=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.27.4 h1:Z2AnStgsdSayCMDiCU42qIz+HLqEPcgiOCXjAU/w+8E=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=
github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
Expand Down Expand Up @@ -813,7 +797,6 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
jaytaylor.com/html2text v0.0.0-20200412013138-3577fbdbcff7 h1:mub0MmFLOn8XLikZOAhgLD1kXJq8jgftSrrv7m00xFo=
Expand Down
6 changes: 0 additions & 6 deletions internal/scout/advise/advise.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ func WithPod(podname string) Option {
}
}

func WithContainer(containerName string) Option {
return func(config *scout.Config) {
config.Container = containerName
}
}

func WithOutput(pathToFile string) Option {
return func(config *scout.Config) {
config.Output = pathToFile
Expand Down
40 changes: 0 additions & 40 deletions internal/scout/advise/docker.go

This file was deleted.

7 changes: 1 addition & 6 deletions internal/scout/advise/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"os"


"github.com/sourcegraph/sourcegraph/lib/errors"
"github.com/sourcegraph/src-cli/internal/scout"
"github.com/sourcegraph/src-cli/internal/scout/kube"
Expand All @@ -25,13 +24,9 @@ func K8s(
cfg := &scout.Config{
Namespace: "default",
Pod: "",
Container: "",
Output: "",
Spy: false,
Docker: false,
RestConfig: restConfig,
K8sClient: k8sClient,
DockerClient: nil,
MetricsClient: metricsClient,
}

Expand Down Expand Up @@ -94,7 +89,7 @@ func Advise(ctx context.Context, cfg *scout.Config, pod v1.Pod) error {
if cfg.Output != "" {
outputToFile(ctx, cfg, pod, advice)
} else {
for _, msg := range advice {
for _, msg := range advice {
fmt.Println(msg)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/scout/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ func AddLimits(ctx context.Context, cfg *scout.Config, pod *corev1.Pod, containe
}
containerMetrics.Limits[containerName] = rsrcs
}

return nil
}

Expand Down Expand Up @@ -287,6 +286,7 @@ func GetStorageUsage(
"worker",
}

// if pod is stateless, return 0 for capacity and usage
if scout.Contains(stateless, containerName) {
return storageCapacity, storageUsage, nil
}
Expand Down
Loading

0 comments on commit 81cb1c9

Please sign in to comment.