Skip to content

Commit

Permalink
CLI updates and other minor things
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alpeb committed Jan 20, 2021
1 parent 161ac04 commit f8371c4
Show file tree
Hide file tree
Showing 24 changed files with 89 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 3 additions & 5 deletions bin/fmt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion charts/linkerd2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
13 changes: 9 additions & 4 deletions cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
},
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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{}
Expand Down
2 changes: 1 addition & 1 deletion multicluster/cmd/gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/healthcheck/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions test/integration/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/integration/testdata/check.cni.proxy.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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 √
7 changes: 7 additions & 0 deletions test/integration/testdata/check.proxy.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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 √
14 changes: 13 additions & 1 deletion viz/charts/linkerd-viz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand All @@ -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` | |
Expand Down
11 changes: 6 additions & 5 deletions viz/cmd/edges.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions viz/cmd/edges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down
16 changes: 0 additions & 16 deletions viz/cmd/root.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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
Expand Down Expand Up @@ -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
}
13 changes: 7 additions & 6 deletions viz/cmd/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions viz/cmd/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down
Loading

0 comments on commit f8371c4

Please sign in to comment.