From efa3e26f37c6f25829f8b649ff5c6f5c8b70f634 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Wed, 6 Sep 2023 10:20:28 +0200 Subject: [PATCH] Show the architecture for each running component This adds the architecture alongside the version information in "subctl show versions". Signed-off-by: Stephen Kitt --- internal/show/versions.go | 44 +++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/internal/show/versions.go b/internal/show/versions.go index 24c12efb4..213861ea2 100644 --- a/internal/show/versions.go +++ b/internal/show/versions.go @@ -67,13 +67,13 @@ func printDaemonSetVersions(clusterInfo *cluster.Info, printer *table.Printer, c // The name of the function is confusing, it just parses any image repo & version version, repository := images.ParseOperatorImage(daemonSet.Spec.Template.Spec.Containers[0].Image) - runningVersion, err := getVersionForComponent(clusterInfo, component, + runningVersion, arch, err := getVersionAndArchForComponent(clusterInfo, component, labels.SelectorFromSet(daemonSet.Spec.Selector.MatchLabels)) if err != nil { return errors.Wrapf(err, "error retrieving running version for %s", component) } - printer.Add(component, repository, version, runningVersion) + printer.Add(component, repository, version, runningVersion, arch) } return nil @@ -94,43 +94,64 @@ func printDeploymentVersions(clusterInfo *cluster.Info, printer *table.Printer, version, repository := images.ParseOperatorImage(deployment.Spec.Template.Spec.Containers[0].Image) - runningVersion, err := getVersionForComponent(clusterInfo, component, + runningVersion, arch, err := getVersionAndArchForComponent(clusterInfo, component, labels.SelectorFromSet(deployment.Spec.Selector.MatchLabels)) if err != nil { return err } - printer.Add(component, repository, version, runningVersion) + printer.Add(component, repository, version, runningVersion, arch) } return nil } -func getVersionForComponent(clusterInfo *cluster.Info, component string, labelSelector labels.Selector) (string, error) { +func getVersionAndArchForComponent(clusterInfo *cluster.Info, component string, labelSelector labels.Selector) (string, string, error) { podsClient := clusterInfo.ClientProducer.ForKubernetes().CoreV1().Pods(constants.OperatorNamespace) podList, err := podsClient.List(context.TODO(), metav1.ListOptions{LabelSelector: labelSelector.String()}) if err != nil || len(podList.Items) < 1 { - return "", errors.Wrapf(err, "failed to find pods for component %s", component) + return "", "", errors.Wrapf(err, "failed to find pods for component %s", component) } // Try all pods for i := range podList.Items { pod := &podList.Items[i] - podVersion := getVersionFromPodBinary(pod, clusterInfo, component) + arch, err := getArchForPod(clusterInfo, pod) + if err != nil { + return "", "", err + } + + podVersion := getVersionFromPodBinary(pod, clusterInfo, component) if podVersion != "" { - return podVersion, nil + return podVersion, arch, nil } podVersion = getVersionFromPodLogs(pod, podsClient, component) - if podVersion != "" { - return podVersion, nil + return podVersion, arch, nil } } - return "Unavailable", nil + return "Unavailable", "Unavailable", nil +} + +func getArchForPod(clusterInfo *cluster.Info, pod *corev1.Pod) (string, error) { + if pod.Spec.NodeName == "" { + return "", nil + } + + nodesClient := clusterInfo.ClientProducer.ForKubernetes().CoreV1().Nodes() + + node, err := nodesClient.Get(context.TODO(), pod.Spec.NodeName, metav1.GetOptions{}) + if err != nil { + return "", errors.Wrapf(err, "error retrieving node %s", pod.Spec.NodeName) + } + + arch := node.GetLabels()[corev1.LabelArchStable] + + return arch, nil } func getVersionFromPodBinary(pod *corev1.Pod, clusterInfo *cluster.Info, component string) string { @@ -191,6 +212,7 @@ func Versions(clusterInfo *cluster.Info, _ string, status reporter.Interface) er {Name: "REPOSITORY"}, {Name: "CONFIGURED"}, {Name: "RUNNING"}, + {Name: "ARCH"}, }} err := printDaemonSetVersions(clusterInfo, &printer, names.GatewayComponent, names.RouteAgentComponent, names.GlobalnetComponent,