cli: warn on the usage of `linkerd viz stat ts` (#6684)

Part of https://github.com/linkerd/linkerd2/issues/6647

This PR adds a new warning that is displayed when `linkerd viz stat ts`
is used as TrafficSplits without SMI extension will not be supported
from `2.12`

Signed-off-by: Tarun Pothulapati <tarunpothulapati@outlook.com>
This commit is contained in:
Tarun Pothulapati 2021-09-01 15:05:08 +05:30 committed by GitHub
parent d611af3647
commit bc0cb4ea61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apimachinery/pkg/api/errors"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/version"
@ -197,7 +198,7 @@ func (kubeAPI *KubernetesAPI) GetNamespaceWithExtensionLabel(ctx context.Context
return &ns, err
}
}
return nil, fmt.Errorf("could not find the %s extension", value)
return nil, errors.NewNotFound(corev1.Resource("namespace"), value)
}
// GetPodStatus receives a pod and returns the pod status, based on `kubectl` logic.

View File

@ -33,6 +33,9 @@ type statTsRow struct {
}
func parseStatTsRow(out string, expectedRowCount, expectedColumnCount int) (map[string]*statTsRow, error) {
// remove extra warning when parsing stat ts output
out = strings.TrimSuffix(out, "\n")
out = strings.Join(strings.Split(out, "\n")[2:], "\n")
rows, err := testutil.CheckRowCount(out, expectedRowCount)
if err != nil {
return nil, err

View File

@ -839,9 +839,23 @@ func buildStatSummaryRequests(resources []string, options *statOptions) ([]*pb.S
}
requests = append(requests, req)
}
if containsTS(targets) {
fmt.Printf("Starting in 2.12, the SMI extension will be required for traffic splitting. Please follow the SMI extension getting started guide from https://linkerd.io/2.10/tasks/linkerd-smi\n\n")
}
return requests, nil
}
func containsTS(resources []*pb.Resource) bool {
for _, resource := range resources {
if resource.Type == k8s.TrafficSplit {
return true
}
}
return false
}
func sortStatsKeys(stats map[string]*row) []string {
var sortedKeys []string
for key := range stats {