Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for link version #13376

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion multicluster/cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ func multiclusterCategory(hc *healthChecker, wait time.Duration) *healthcheck.Ca
WithHintAnchor("l5d-multicluster-links-are-valid").
Fatal().
WithCheck(func(ctx context.Context) error { return hc.checkLinks(ctx) }))
checkers = append(checkers,
*healthcheck.NewChecker("Link and CLI versions match").
WithHintAnchor("l5d-multicluster-links-version").
Warning().
WithCheck(func(ctx context.Context) error { return hc.checkLinkVersions() }))
checkers = append(checkers,
*healthcheck.NewChecker("remote cluster access credentials are valid").
WithHintAnchor("l5d-smc-target-clusters-access").
Expand Down Expand Up @@ -332,6 +337,30 @@ func (hc *healthChecker) checkLinks(ctx context.Context) error {
return healthcheck.VerboseSuccess{Message: strings.Join(linkNames, "\n")}
}

func (hc *healthChecker) checkLinkVersions() error {
errors := []error{}
links := []string{}
for _, link := range hc.links {
parts := strings.Split(link.CreatedBy, " ")
if len(parts) == 2 && parts[0] == "linkerd/cli" {
if parts[1] == version.Version {
links = append(links, fmt.Sprintf("\t* %s", link.TargetClusterName))
} else {
errors = append(errors, fmt.Errorf("* %s: CLI version is %s but Link version is %s", link.TargetClusterName, version.Version, parts[1]))
}
} else {
errors = append(errors, fmt.Errorf("* %s: unable to determine version", link.TargetClusterName))
}
}
if len(errors) > 0 {
return joinErrors(errors, 2)
}
if len(links) == 0 {
return healthcheck.SkipError{Reason: "no links"}
}
return healthcheck.VerboseSuccess{Message: strings.Join(links, "\n")}
}

func (hc *healthChecker) checkRemoteClusterConnectivity(ctx context.Context) error {
errors := []error{}
links := []string{}
Expand Down Expand Up @@ -668,7 +697,7 @@ func (hc *healthChecker) checkIfMirrorServicesHaveEndpoints(ctx context.Context)

func (hc *healthChecker) checkForOrphanedServices(ctx context.Context) error {
errors := []error{}
selector := fmt.Sprintf("%s, !%s", k8s.MirroredResourceLabel, k8s.MirroredGatewayLabel)
selector := fmt.Sprintf("%s, !%s, %s", k8s.MirroredResourceLabel, k8s.MirroredGatewayLabel, k8s.RemoteClusterNameLabel)
mirrorServices, err := hc.KubeAPIClient().CoreV1().Services(metav1.NamespaceAll).List(ctx, metav1.ListOptions{LabelSelector: selector})
if err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions pkg/multicluster/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type (
Link struct {
Name string
Namespace string
CreatedBy string
TargetClusterName string
TargetClusterDomain string
TargetClusterLinkerdNamespace string
Expand Down Expand Up @@ -177,6 +178,7 @@ func NewLink(u unstructured.Unstructured) (Link, error) {
return Link{
Name: u.GetName(),
Namespace: u.GetNamespace(),
CreatedBy: u.GetAnnotations()[k8s.CreatedByAnnotation],
TargetClusterName: targetClusterName,
TargetClusterDomain: targetClusterDomain,
TargetClusterLinkerdNamespace: targetClusterLinkerdNamespace,
Expand Down Expand Up @@ -260,6 +262,9 @@ func (l Link) ToUnstructured() (unstructured.Unstructured, error) {
"metadata": map[string]interface{}{
"name": l.Name,
"namespace": l.Namespace,
"annotations": map[string]string{
k8s.CreatedByAnnotation: k8s.CreatedByAnnotationValue(),
},
},
"spec": spec,
"status": map[string]interface{}{},
Expand Down
Loading