From f8371c4d90bde4597e203c023a1822edd5c61e29 Mon Sep 17 00:00:00 2001 From: Alejandro Pedraza Date: Wed, 20 Jan 2021 11:32:47 -0500 Subject: [PATCH] CLI updates and other minor things Changes to command files under `cli/cmd`: - Updated `endpoints.go` according to new API interface name. - Updated `version.go`, `dashboard` and `uninstall.go` to pull the viz namespace dynamically. Changes to command files under `viz/cmd`: - `edges.go`, `routes.go`, `stat.go` and `top.go`: point to dependencies that were moved from public-api to viz. Other changes to have tests pass: - Added `metrics-api` to list of docker images to build in actions workflows. - In `bin/fmt` exclude protobuf generated files instead of entire directories because directories could contain both generated and non-generated code (case in point: `viz/metrics-api`). - Update Helm readme files. --- .github/workflows/integration_tests.yml | 2 +- .github/workflows/release.yml | 2 +- bin/fmt | 8 +++---- charts/linkerd2/README.md | 1 - cli/cmd/endpoints.go | 2 +- cli/cmd/version.go | 13 +++++++---- multicluster/cmd/gateways.go | 2 +- pkg/healthcheck/healthcheck.go | 2 +- test/integration/install_test.go | 2 ++ .../testdata/check.cni.proxy.golden | 7 ++++++ test/integration/testdata/check.proxy.golden | 7 ++++++ viz/charts/linkerd-viz/README.md | 14 +++++++++++- viz/cmd/edges.go | 11 +++++----- viz/cmd/edges_test.go | 6 ++--- viz/cmd/root.go | 16 -------------- viz/cmd/routes.go | 13 ++++++----- viz/cmd/routes_test.go | 6 ++--- viz/cmd/stat.go | 15 +++++++------ viz/cmd/stat_test.go | 22 +++++++++---------- viz/cmd/testdata/install_default.golden | 3 --- .../install_prometheus_disabled.golden | 3 --- viz/cmd/top.go | 4 ++-- viz/metrics-api/util/api_utils.go | 20 ++--------------- viz/pkg/healthcheck/healthcheck.go | 2 +- 24 files changed, 89 insertions(+), 94 deletions(-) diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index cd8112e27335b..9599f6346241f 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: # Keep in sync with release.yaml matrix build - target: [proxy, controller, web, cni-plugin, debug, cli-bin, grafana, jaeger-webhook] + target: [proxy, controller, metrics-api, web, cni-plugin, debug, cli-bin, grafana, jaeger-webhook] name: Docker build (${{ matrix.target }}) timeout-minutes: 30 steps: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e1af959fd9983..c669c8a321492 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: # Keep in sync with integration_tests.yaml matrix build - target: [proxy, controller, web, cni-plugin, debug, cli-bin, grafana, jaeger-webhook] + target: [proxy, controller, metrics-api, web, cni-plugin, debug, cli-bin, grafana, jaeger-webhook] name: Docker build (${{ matrix.target }}) timeout-minutes: 30 steps: diff --git a/bin/fmt b/bin/fmt index 1109ea7676b3f..a86603243128a 100755 --- a/bin/fmt +++ b/bin/fmt @@ -1,15 +1,13 @@ #!/usr/bin/env bash -set -eu +set -u -# go list will exclude the vendor directory. We use grep to exclude generated -# code. -while IFS= read -r line; do dirs+=("$line"); done <<< "$(go list -f \{\{.Dir\}\} ./... | grep -v controller/gen | grep -v viz/metrics-api/gen )" +while IFS= read -r line; do dirs+=("$line"); done <<< "$(go list -f \{\{.Dir\}\} ./...)" # go list will list all subdirectories and goimports acts recursively. This # results in certain files being reported multiple time. Therefore, we must # dedup them. -files=$(bin/goimports -l "${dirs[@]}" | sort -u) +files=$(bin/goimports -l "${dirs[@]}" | sort -u | grep -v pb.go) if [ -n "$files" ]; then for file in "${files[@]}"; do diff --git a/charts/linkerd2/README.md b/charts/linkerd2/README.md index 79753b68662bf..320da05214753 100644 --- a/charts/linkerd2/README.md +++ b/charts/linkerd2/README.md @@ -153,7 +153,6 @@ Kubernetes: `>=1.13.0-0` | global.namespace | string | `"linkerd"` | Control plane namespace | | global.podAnnotations | object | `{}` | Additional annotations to add to all pods | | global.podLabels | object | `{}` | Additional labels to add to all pods | -| global.prometheusUrl | string | `""` | url of existing prometheus | | global.proxy.cores | int | `0` | The `cpu.limit` and `cores` should be kept in sync. The value of `cores` must be an integer and should typically be set by rounding up from the limit. E.g. if cpu.limit is '1500m', cores should be 2. | | global.proxy.enableExternalProfiles | bool | `false` | Enable service profiles for non-Kubernetes services | | global.proxy.image.name | string | `"ghcr.io/linkerd/proxy"` | Docker image for the proxy | diff --git a/cli/cmd/endpoints.go b/cli/cmd/endpoints.go index f7f7da8657447..f988567c5c1e5 100644 --- a/cli/cmd/endpoints.go +++ b/cli/cmd/endpoints.go @@ -113,7 +113,7 @@ destination.`, return cmd } -func requestEndpointsFromAPI(client public.PublicAPIClient, authorities []string) (endpointsInfo, error) { +func requestEndpointsFromAPI(client public.Client, authorities []string) (endpointsInfo, error) { info := make(endpointsInfo) // buffered channels to avoid blocking events := make(chan *destinationPb.Update, len(authorities)) diff --git a/cli/cmd/version.go b/cli/cmd/version.go index dc42fc10094fd..aa9b0f7e47bf4 100644 --- a/cli/cmd/version.go +++ b/cli/cmd/version.go @@ -13,6 +13,7 @@ import ( api "github.com/linkerd/linkerd2/pkg/public" "github.com/linkerd/linkerd2/pkg/version" pb "github.com/linkerd/linkerd2/viz/metrics-api/gen/viz" + vizApi "github.com/linkerd/linkerd2/viz/pkg/api" "github.com/spf13/cobra" ) @@ -51,7 +52,7 @@ func newCmdVersion() *cobra.Command { } } - configureAndRunVersion(cmd.Context(), k8sAPI, options, os.Stdout, api.RawPublicAPIClient, api.RawVizAPIClient) + configureAndRunVersion(cmd.Context(), k8sAPI, options, os.Stdout, api.RawPublicAPIClient, vizApi.RawClient) return nil }, } @@ -70,7 +71,7 @@ func configureAndRunVersion( options *versionOptions, stdout io.Writer, mkPublicClient func(ctx context.Context, k8sAPI *k8s.KubernetesAPI, controlPlaneNamespace, apiAddr string) (publicPb.ApiClient, error), - mkVizClient func(ctx context.Context, k8sAPI *k8s.KubernetesAPI, controlPlaneNamespace, apiAddr string) (pb.ApiClient, error), + mkVizClient func(ctx context.Context, k8sAPI *k8s.KubernetesAPI, controlPlaneNamespace string) (pb.ApiClient, error), ) { clientVersion := version.Version if options.shortVersion { @@ -99,8 +100,12 @@ func configureAndRunVersion( } if options.proxy { - vizClient, clientErr := mkVizClient(ctx, k8sAPI, controlPlaneNamespace, apiAddr) - if clientErr != nil { + var vizClient pb.ApiClient + vizNs, err := k8sAPI.GetNamespaceWithExtensionLabel(ctx, "linkerd-viz") + if err == nil { + vizClient, err = mkVizClient(ctx, k8sAPI, vizNs.Name) + } + if err != nil { fmt.Fprintln(stdout, "Proxy versions: unavailable") } else { req := &pb.ListPodsRequest{} diff --git a/multicluster/cmd/gateways.go b/multicluster/cmd/gateways.go index f4fde2a7e010b..8e3e2f9afbdb2 100644 --- a/multicluster/cmd/gateways.go +++ b/multicluster/cmd/gateways.go @@ -45,7 +45,7 @@ func newGatewaysCommand() *cobra.Command { vizNs, err := k8sAPI.GetNamespaceWithExtensionLabel(ctx, "linkerd-viz") if err != nil { - return err + return fmt.Errorf("make sure the linkerd-viz extension is installed, using 'linkerd viz install' (%s)", err) } client, err := client.NewExternalClient(ctx, vizNs.Name, k8sAPI) diff --git a/pkg/healthcheck/healthcheck.go b/pkg/healthcheck/healthcheck.go index 67ff10b495708..5038c37640fe5 100644 --- a/pkg/healthcheck/healthcheck.go +++ b/pkg/healthcheck/healthcheck.go @@ -1626,7 +1626,7 @@ func (hc *HealthChecker) PublicAPIClient() public.Client { return hc.apiClient } -// LatestVersions returns the latest from Linkerd release channels +// LatestVersions returns the latest versions from Linkerd release channels func (hc *HealthChecker) LatestVersions() version.Channels { return hc.latestVersions } diff --git a/test/integration/install_test.go b/test/integration/install_test.go index 6a5b440f27326..46ea12e818d18 100644 --- a/test/integration/install_test.go +++ b/test/integration/install_test.go @@ -496,6 +496,7 @@ func TestInstallHelm(t *testing.T) { "--set", "dashboard.image.tag=" + TestHelper.GetVersion(), "--set", "grafana.image.tag=" + TestHelper.GetVersion(), "--set", "tap.image.tag=" + TestHelper.GetVersion(), + "--set", "metricsAPI.image.tag=" + TestHelper.GetVersion(), } // Install Viz Extension Chart if stdout, stderr, err := TestHelper.HelmInstallPlain(vizChart, "l5d-viz", vizArgs...); err != nil { @@ -605,6 +606,7 @@ func TestUpgradeHelm(t *testing.T) { "--set", "dashboard.image.tag=" + TestHelper.GetVersion(), "--set", "grafana.image.tag=" + TestHelper.GetVersion(), "--set", "tap.image.tag=" + TestHelper.GetVersion(), + "--set", "metricsAPI.image.tag=" + TestHelper.GetVersion(), "--wait", } // Install Viz Extension Chart diff --git a/test/integration/testdata/check.cni.proxy.golden b/test/integration/testdata/check.cni.proxy.golden index a006b53acdb22..6b3ea8f1bee8f 100644 --- a/test/integration/testdata/check.cni.proxy.golden +++ b/test/integration/testdata/check.cni.proxy.golden @@ -72,4 +72,11 @@ linkerd-version √ can determine the latest version √ cli is up-to-date +linkerd-data-plane +------------------ +√ data plane namespace exists +√ data plane proxies are ready +√ data plane is up-to-date +√ data plane and cli versions match + Status check results are √ diff --git a/test/integration/testdata/check.proxy.golden b/test/integration/testdata/check.proxy.golden index c4c384365bca5..5e4be31284157 100644 --- a/test/integration/testdata/check.proxy.golden +++ b/test/integration/testdata/check.proxy.golden @@ -60,4 +60,11 @@ linkerd-version √ can determine the latest version √ cli is up-to-date +linkerd-data-plane +------------------ +√ data plane namespace exists +√ data plane proxies are ready +√ data plane is up-to-date +√ data plane and cli versions match + Status check results are √ diff --git a/viz/charts/linkerd-viz/README.md b/viz/charts/linkerd-viz/README.md index 4231f44d2768a..98c87b9568712 100644 --- a/viz/charts/linkerd-viz/README.md +++ b/viz/charts/linkerd-viz/README.md @@ -104,6 +104,18 @@ Kubernetes: `>=1.13.0-0` | installNamespace | bool | `true` | Set to false when installing in a custom namespace. | | linkerdNamespace | string | `"linkerd"` | Namespace of the Linkerd core control-plane install | | linkerdVersion | string | `"linkerdVersionValue"` | control plane version. See Proxy section for proxy version | +| metricsAPI.UID | int | `2103` | | +| metricsAPI.image.name | string | `"metrics-api"` | Docker image name for the metrics-api component | +| metricsAPI.image.pullPolicy | string | `"Always"` | Pull policy for the metrics-api component | +| metricsAPI.image.registry | string | `"ghcr.io/linkerd"` | Docker registry for the metrics-api component | +| metricsAPI.image.tag | string | `"linkerdVersionValue"` | Docker image tag for the metrics-api component | +| metricsAPI.logLevel | string | `"info"` | log level of the metrics-api component | +| metricsAPI.proxy | string | `nil` | | +| metricsAPI.replicas | int | `1` | number of replicas of the metrics-api component | +| metricsAPI.resources.cpu.limit | string | `nil` | Maximum amount of CPU units that the metrics-api container can use | +| metricsAPI.resources.cpu.request | string | `nil` | Amount of CPU units that the metrics-api container requests | +| metricsAPI.resources.memory.limit | string | `nil` | Maximum amount of memory that metrics-api container can use | +| metricsAPI.resources.memory.request | string | `nil` | Amount of memory that the metrics-api container requests | | namespace | string | `"linkerd-viz"` | Namespace in which the Linkerd Viz extension has to be installed | | nodeSelector | object | `{"beta.kubernetes.io/os":"linux"}` | NodeSelector section, See the [K8S documentation](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector) for more information | | prometheus.alertManagers | string | `nil` | Alertmanager instances the Prometheus server sends alerts to configured via the static_configs parameter. | @@ -112,7 +124,7 @@ Kubernetes: `>=1.13.0-0` | prometheus.enabled | bool | `true` | toggle field to enable or disable prometheus | | prometheus.globalConfig | object | `{"evaluation_interval":"10s","scrape_interval":"10s","scrape_timeout":"10s"}` | The global configuration specifies parameters that are valid in all other configuration contexts. | | prometheus.image.name | string | `"prometheus"` | Docker image name for the prometheus instance | -| prometheus.image.pullPolicy | string | `"Always"` | | +| prometheus.image.pullPolicy | string | `"Always"` | Pull policy for the prometheus instance | | prometheus.image.registry | string | `"prom"` | Docker registry for the prometheus instance | | prometheus.image.tag | string | `"v2.19.3"` | Docker image tag for the prometheus instance | | prometheus.proxy | string | `nil` | | diff --git a/viz/cmd/edges.go b/viz/cmd/edges.go index 209c4d21c71f7..9d01ea27dbe07 100644 --- a/viz/cmd/edges.go +++ b/viz/cmd/edges.go @@ -11,11 +11,12 @@ import ( "text/tabwriter" "github.com/fatih/color" - "github.com/linkerd/linkerd2/controller/api/util" + coreUtil "github.com/linkerd/linkerd2/controller/api/util" pkgcmd "github.com/linkerd/linkerd2/pkg/cmd" "github.com/linkerd/linkerd2/pkg/healthcheck" - api "github.com/linkerd/linkerd2/pkg/public" pb "github.com/linkerd/linkerd2/viz/metrics-api/gen/viz" + "github.com/linkerd/linkerd2/viz/metrics-api/util" + "github.com/linkerd/linkerd2/viz/pkg/api" "github.com/spf13/cobra" ) @@ -82,7 +83,7 @@ func NewCmdEdges() *cobra.Command { # Get all edges between pods in all namespaces. linkerd viz edges po --all-namespaces`, Args: cobra.ExactArgs(1), - ValidArgs: util.ValidTargets, + ValidArgs: coreUtil.ValidTargets, RunE: func(cmd *cobra.Command, args []string) error { if options.namespace == "" { options.namespace = pkgcmd.GetDefaultNamespace(kubeconfigPath, kubeContext) @@ -95,7 +96,7 @@ func NewCmdEdges() *cobra.Command { // The gRPC client is concurrency-safe, so we can reuse it in all the following goroutines // /~https://github.com/grpc/grpc-go/issues/682 - client := api.CheckVizAPIClientOrExit(healthcheck.Options{ + client := api.CheckClientOrExit(healthcheck.Options{ ControlPlaneNamespace: controlPlaneNamespace, KubeConfig: kubeconfigPath, Impersonate: impersonate, @@ -159,7 +160,7 @@ func validateEdgesRequestInputs(targets []*pb.Resource, options *edgesOptions) e } func buildEdgesRequests(resources []string, options *edgesOptions) ([]*pb.EdgesRequest, error) { - targets, err := util.BuildResources(options.namespace, resources) + targets, err := coreUtil.BuildResources(options.namespace, resources) if err != nil { return nil, err diff --git a/viz/cmd/edges_test.go b/viz/cmd/edges_test.go index f47c962d4b316..e9312b9ba73fb 100644 --- a/viz/cmd/edges_test.go +++ b/viz/cmd/edges_test.go @@ -3,7 +3,7 @@ package cmd import ( "testing" - "github.com/linkerd/linkerd2/controller/api/public" + api "github.com/linkerd/linkerd2/viz/metrics-api" ) type edgesParamsExp struct { @@ -99,8 +99,8 @@ func TestEdges(t *testing.T) { } func testEdgesCall(exp edgesParamsExp, t *testing.T) { - mockClient := &public.MockAPIClient{} - response := public.GenEdgesResponse(exp.resourceType, "all") + mockClient := &api.MockAPIClient{} + response := api.GenEdgesResponse(exp.resourceType, "all") mockClient.EdgesResponseToReturn = response diff --git a/viz/cmd/root.go b/viz/cmd/root.go index d11fecce3fb9e..46ea7dd734033 100644 --- a/viz/cmd/root.go +++ b/viz/cmd/root.go @@ -1,16 +1,12 @@ package cmd import ( - "context" - "errors" "fmt" "regexp" "github.com/fatih/color" - "github.com/linkerd/linkerd2/pkg/k8s" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) const ( @@ -24,7 +20,6 @@ const ( ) var ( - // special handling for Windows, on all other platforms these resolve to // os.Stdout and os.Stderr, thanks to /~https://github.com/mattn/go-colorable stdout = color.Output @@ -84,14 +79,3 @@ func NewCmdViz() *cobra.Command { return vizCmd } - -func getVizNamespace(ctx context.Context, k8sAPI *k8s.KubernetesAPI) (string, error) { - ns, err := k8sAPI.CoreV1().Namespaces().List(ctx, metav1.ListOptions{LabelSelector: "linkerd.io/extension=linkerd-viz"}) - if err != nil { - return "", err - } - if len(ns.Items) == 0 { - return "", errors.New("linkerd-viz extension not found") - } - return ns.Items[0].Name, nil -} diff --git a/viz/cmd/routes.go b/viz/cmd/routes.go index 81c1893b926dc..23f7ec303f903 100644 --- a/viz/cmd/routes.go +++ b/viz/cmd/routes.go @@ -11,12 +11,13 @@ import ( "text/tabwriter" "time" - "github.com/linkerd/linkerd2/controller/api/util" + coreUtil "github.com/linkerd/linkerd2/controller/api/util" pkgcmd "github.com/linkerd/linkerd2/pkg/cmd" "github.com/linkerd/linkerd2/pkg/healthcheck" "github.com/linkerd/linkerd2/pkg/k8s" - api "github.com/linkerd/linkerd2/pkg/public" pb "github.com/linkerd/linkerd2/viz/metrics-api/gen/viz" + "github.com/linkerd/linkerd2/viz/metrics-api/util" + "github.com/linkerd/linkerd2/viz/pkg/api" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -62,7 +63,7 @@ This command will only display traffic which is sent to a service that has a Ser # Routes for calls from the traffic deployment to the webapp service in the test namespace. linkerd viz routes deploy/traffic -n test --to svc/webapp`, Args: cobra.ExactArgs(1), - ValidArgs: util.ValidTargets, + ValidArgs: coreUtil.ValidTargets, RunE: func(cmd *cobra.Command, args []string) error { if options.namespace == "" { options.namespace = pkgcmd.GetDefaultNamespace(kubeconfigPath, kubeContext) @@ -73,7 +74,7 @@ This command will only display traffic which is sent to a service that has a Ser } output, err := requestRouteStatsFromAPI( - api.CheckVizAPIClientOrExit(healthcheck.Options{ + api.CheckClientOrExit(healthcheck.Options{ ControlPlaneNamespace: controlPlaneNamespace, KubeConfig: kubeconfigPath, Impersonate: impersonate, @@ -353,7 +354,7 @@ func buildTopRoutesRequest(resource string, options *routesOptions) (*pb.TopRout return nil, err } - target, err := util.BuildResource(options.namespace, resource) + target, err := coreUtil.BuildResource(options.namespace, resource) if err != nil { return nil, err } @@ -374,7 +375,7 @@ func buildTopRoutesRequest(resource string, options *routesOptions) (*pb.TopRout if options.toNamespace == "" { options.toNamespace = options.namespace } - toRes, err := util.BuildResource(options.toNamespace, options.toResource) + toRes, err := coreUtil.BuildResource(options.toNamespace, options.toResource) if err != nil { return nil, err } diff --git a/viz/cmd/routes_test.go b/viz/cmd/routes_test.go index 6be49f65c4b40..082af9a358e4f 100644 --- a/viz/cmd/routes_test.go +++ b/viz/cmd/routes_test.go @@ -3,7 +3,7 @@ package cmd import ( "testing" - "github.com/linkerd/linkerd2/controller/api/public" + api "github.com/linkerd/linkerd2/viz/metrics-api" ) type routesParamsExp struct { @@ -48,9 +48,9 @@ func TestRoutes(t *testing.T) { } func testRoutesCall(exp routesParamsExp, t *testing.T) { - mockClient := &public.MockAPIClient{} + mockClient := &api.MockAPIClient{} - response := public.GenTopRoutesResponse(exp.routes, exp.counts, exp.options.toResource != "", "foobar") + response := api.GenTopRoutesResponse(exp.routes, exp.counts, exp.options.toResource != "", "foobar") mockClient.TopRoutesResponseToReturn = response diff --git a/viz/cmd/stat.go b/viz/cmd/stat.go index 656091c4e1115..c9a6e27f8309e 100644 --- a/viz/cmd/stat.go +++ b/viz/cmd/stat.go @@ -11,13 +11,14 @@ import ( "text/tabwriter" "time" - "github.com/linkerd/linkerd2/controller/api/util" + coreUtil "github.com/linkerd/linkerd2/controller/api/util" "github.com/linkerd/linkerd2/pkg/cmd" pkgcmd "github.com/linkerd/linkerd2/pkg/cmd" "github.com/linkerd/linkerd2/pkg/healthcheck" "github.com/linkerd/linkerd2/pkg/k8s" - api "github.com/linkerd/linkerd2/pkg/public" pb "github.com/linkerd/linkerd2/viz/metrics-api/gen/viz" + "github.com/linkerd/linkerd2/viz/metrics-api/util" + "github.com/linkerd/linkerd2/viz/pkg/api" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -166,7 +167,7 @@ If no resource name is specified, displays stats about all resources of the spec # Get all inbound stats to the test namespace. linkerd viz stat ns/test`, Args: cobra.MinimumNArgs(1), - ValidArgs: util.ValidTargets, + ValidArgs: coreUtil.ValidTargets, RunE: func(cmd *cobra.Command, args []string) error { if options.namespace == "" { options.namespace = pkgcmd.GetDefaultNamespace(kubeconfigPath, kubeContext) @@ -179,7 +180,7 @@ If no resource name is specified, displays stats about all resources of the spec // The gRPC client is concurrency-safe, so we can reuse it in all the following goroutines // /~https://github.com/grpc/grpc-go/issues/682 - client := api.CheckVizAPIClientOrExit(healthcheck.Options{ + client := api.CheckClientOrExit(healthcheck.Options{ ControlPlaneNamespace: controlPlaneNamespace, KubeConfig: kubeconfigPath, Impersonate: impersonate, @@ -685,20 +686,20 @@ func getNamePrefix(resourceType string) string { } func buildStatSummaryRequests(resources []string, options *statOptions) ([]*pb.StatSummaryRequest, error) { - targets, err := util.BuildResources(options.namespace, resources) + targets, err := coreUtil.BuildResources(options.namespace, resources) if err != nil { return nil, err } var toRes, fromRes *pb.Resource if options.toResource != "" { - toRes, err = util.BuildResource(options.toNamespace, options.toResource) + toRes, err = coreUtil.BuildResource(options.toNamespace, options.toResource) if err != nil { return nil, err } } if options.fromResource != "" { - fromRes, err = util.BuildResource(options.fromNamespace, options.fromResource) + fromRes, err = coreUtil.BuildResource(options.fromNamespace, options.fromResource) if err != nil { return nil, err } diff --git a/viz/cmd/stat_test.go b/viz/cmd/stat_test.go index 87bcd5dec67a1..d0c8dd0d17a17 100644 --- a/viz/cmd/stat_test.go +++ b/viz/cmd/stat_test.go @@ -3,13 +3,13 @@ package cmd import ( "testing" - "github.com/linkerd/linkerd2/controller/api/public" pkgcmd "github.com/linkerd/linkerd2/pkg/cmd" "github.com/linkerd/linkerd2/pkg/k8s" + api "github.com/linkerd/linkerd2/viz/metrics-api" ) type paramsExp struct { - counts *public.PodCounts + counts *api.PodCounts options *statOptions resNs []string file string @@ -19,7 +19,7 @@ func TestStat(t *testing.T) { options := newStatOptions() t.Run("Returns namespace stats", func(t *testing.T) { testStatCall(paramsExp{ - counts: &public.PodCounts{ + counts: &api.PodCounts{ MeshedPods: 1, RunningPods: 2, FailedPods: 0, @@ -32,7 +32,7 @@ func TestStat(t *testing.T) { t.Run("Returns pod stats", func(t *testing.T) { testStatCall(paramsExp{ - counts: &public.PodCounts{ + counts: &api.PodCounts{ Status: "Running", MeshedPods: 1, RunningPods: 1, @@ -55,7 +55,7 @@ func TestStat(t *testing.T) { options.outputFormat = jsonOutput t.Run("Returns namespace stats (json)", func(t *testing.T) { testStatCall(paramsExp{ - counts: &public.PodCounts{ + counts: &api.PodCounts{ MeshedPods: 1, RunningPods: 2, FailedPods: 0, @@ -78,7 +78,7 @@ func TestStat(t *testing.T) { options.allNamespaces = true t.Run("Returns all namespace stats", func(t *testing.T) { testStatCall(paramsExp{ - counts: &public.PodCounts{ + counts: &api.PodCounts{ MeshedPods: 1, RunningPods: 2, FailedPods: 0, @@ -92,7 +92,7 @@ func TestStat(t *testing.T) { options.outputFormat = jsonOutput t.Run("Returns all namespace stats (json)", func(t *testing.T) { testStatCall(paramsExp{ - counts: &public.PodCounts{ + counts: &api.PodCounts{ MeshedPods: 1, RunningPods: 2, FailedPods: 0, @@ -107,7 +107,7 @@ func TestStat(t *testing.T) { options.outputFormat = "wide" t.Run("Returns TCP stats", func(t *testing.T) { testStatCall(paramsExp{ - counts: &public.PodCounts{ + counts: &api.PodCounts{ MeshedPods: 1, RunningPods: 2, FailedPods: 0, @@ -228,10 +228,10 @@ func TestStat(t *testing.T) { } func testStatCall(exp paramsExp, resourceType string, t *testing.T) { - mockClient := &public.MockAPIClient{} - response := public.GenStatSummaryResponse("emoji", resourceType, exp.resNs, exp.counts, true, true) + mockClient := &api.MockAPIClient{} + response := api.GenStatSummaryResponse("emoji", resourceType, exp.resNs, exp.counts, true, true) if resourceType == k8s.TrafficSplit { - response = public.GenStatTsResponse("foo-split", resourceType, exp.resNs, true, true) + response = api.GenStatTsResponse("foo-split", resourceType, exp.resNs, true, true) } mockClient.StatSummaryResponseToReturn = response diff --git a/viz/cmd/testdata/install_default.golden b/viz/cmd/testdata/install_default.golden index 81afe2dacd5e8..64c386d9fb355 100644 --- a/viz/cmd/testdata/install_default.golden +++ b/viz/cmd/testdata/install_default.golden @@ -424,7 +424,6 @@ metadata: app.kubernetes.io/part-of: Linkerd app.kubernetes.io/version: dev-undefined component: metrics-api - namespace: linkerd-viz name: linkerd-metrics-api namespace: linkerd-viz spec: @@ -433,7 +432,6 @@ spec: matchLabels: linkerd.io/extension: linkerd-viz component: metrics-api - namespace: linkerd-viz template: metadata: annotations: @@ -442,7 +440,6 @@ spec: labels: linkerd.io/extension: linkerd-viz component: metrics-api - namespace: linkerd-viz spec: nodeSelector: beta.kubernetes.io/os: linux diff --git a/viz/cmd/testdata/install_prometheus_disabled.golden b/viz/cmd/testdata/install_prometheus_disabled.golden index 0a1b18de583bb..2f31cba3503ac 100644 --- a/viz/cmd/testdata/install_prometheus_disabled.golden +++ b/viz/cmd/testdata/install_prometheus_disabled.golden @@ -379,7 +379,6 @@ metadata: app.kubernetes.io/part-of: Linkerd app.kubernetes.io/version: dev-undefined component: metrics-api - namespace: linkerd-viz name: linkerd-metrics-api namespace: linkerd-viz spec: @@ -388,7 +387,6 @@ spec: matchLabels: linkerd.io/extension: linkerd-viz component: metrics-api - namespace: linkerd-viz template: metadata: annotations: @@ -397,7 +395,6 @@ spec: labels: linkerd.io/extension: linkerd-viz component: metrics-api - namespace: linkerd-viz spec: nodeSelector: beta.kubernetes.io/os: linux diff --git a/viz/cmd/top.go b/viz/cmd/top.go index b154ef539596e..d4c67078bf608 100644 --- a/viz/cmd/top.go +++ b/viz/cmd/top.go @@ -11,13 +11,13 @@ import ( "time" "github.com/golang/protobuf/ptypes" - "github.com/linkerd/linkerd2/controller/api/public" "github.com/linkerd/linkerd2/controller/api/util" "github.com/linkerd/linkerd2/pkg/addr" pkgcmd "github.com/linkerd/linkerd2/pkg/cmd" "github.com/linkerd/linkerd2/pkg/k8s" "github.com/linkerd/linkerd2/pkg/protohttp" "github.com/linkerd/linkerd2/pkg/tap" + api "github.com/linkerd/linkerd2/viz/metrics-api" pb "github.com/linkerd/linkerd2/viz/metrics-api/gen/viz" runewidth "github.com/mattn/go-runewidth" termbox "github.com/nsf/termbox-go" @@ -544,7 +544,7 @@ func newRow(req topRequest) (tableRow, error) { path := req.reqInit.GetPath() route := req.event.GetRouteMeta().GetLabels()["route"] if route == "" { - route = public.DefaultRouteName + route = api.DefaultRouteName } method := req.reqInit.GetMethod().GetRegistered().String() source := stripPort(addr.PublicAddressToString(req.event.GetSource())) diff --git a/viz/metrics-api/util/api_utils.go b/viz/metrics-api/util/api_utils.go index 8e8fd5a4f74e8..6c37cd4d80506 100644 --- a/viz/metrics-api/util/api_utils.go +++ b/viz/metrics-api/util/api_utils.go @@ -2,7 +2,6 @@ package util import ( "errors" - "strings" "time" "github.com/linkerd/linkerd2/pkg/k8s" @@ -285,29 +284,14 @@ func K8sPodToPublicPod(pod corev1.Pod, ownerKind string, ownerName string) *pb.P controllerComponent := pod.Labels[k8s.ControllerComponentLabel] controllerNS := pod.Labels[k8s.ControllerNSLabel] - proxyReady := false - for _, container := range pod.Status.ContainerStatuses { - if container.Name == k8s.ProxyContainerName { - proxyReady = container.Ready - } - } - - proxyVersion := "" - for _, container := range pod.Spec.Containers { - if container.Name == k8s.ProxyContainerName { - parts := strings.Split(container.Image, ":") - proxyVersion = parts[1] - } - } - item := &pb.Pod{ Name: pod.Namespace + "/" + pod.Name, Status: status, PodIP: pod.Status.PodIP, ControllerNamespace: controllerNS, ControlPlane: controllerComponent != "", - ProxyReady: proxyReady, - ProxyVersion: proxyVersion, + ProxyReady: k8s.GetProxyReady(pod), + ProxyVersion: k8s.GetProxyVersion(pod), ResourceVersion: pod.ResourceVersion, } diff --git a/viz/pkg/healthcheck/healthcheck.go b/viz/pkg/healthcheck/healthcheck.go index 3ec1c8dfbd14b..d0aa5cf41cc9b 100644 --- a/viz/pkg/healthcheck/healthcheck.go +++ b/viz/pkg/healthcheck/healthcheck.go @@ -155,7 +155,7 @@ func (hc *HealthChecker) vizCategory() *healthcheck.Category { return err } - return healthcheck.CheckPodsRunning(pods) + return healthcheck.CheckPodsRunning(pods, "") })) checkers = append(checkers,