Repository: istio/istio
File: istioctl/pkg/writer/pilot/status.go (Go)

Code before:
		case xdsresource.EndpointType:
			eds = formatStatus(config)
		case xdsresource.ExtensionConfigurationType:
			ecds = formatStatus(config)
		default:
			log.Infof("GenericXdsConfig unexpected type %s\n", xdsresource.GetShortType(cfgType))
		}
	}
	return
}

func handleAndGetXdsConfigs(clientConfig *xdsstatus.ClientConfig) []*xdsstatus.ClientConfig_GenericXdsConfig {
	configs := make([]*xdsstatus.ClientConfig_GenericXdsConfig, 0)
	if clientConfig.GetGenericXdsConfigs() != nil {
		configs = clientConfig.GetGenericXdsConfigs()
		return configs
	}

	// FIXME: currently removing the deprecated code below may result in functions not working
	// if there is a mismatch of versions between istiod and istioctl
	// nolint: staticcheck
	for _, config := range clientConfig.GetXdsConfig() {
		var typeURL string
		switch config.PerXdsConfig.(type) {
		case *xdsstatus.PerXdsConfig_ListenerConfig:
			typeURL = xdsresource.ListenerType
		case *xdsstatus.PerXdsConfig_ClusterConfig:
			typeURL = xdsresource.ClusterType
		case *xdsstatus.PerXdsConfig_RouteConfig:
			typeURL = xdsresource.RouteType
		case *xdsstatus.PerXdsConfig_EndpointConfig:
			typeURL = xdsresource.EndpointType
		}

		if typeURL != "" {
			configs = append(configs, &xdsstatus.ClientConfig_GenericXdsConfig{
				TypeUrl:      typeURL,
				ConfigStatus: config.Status,
			})
		}
	}

	return configs
}


Review comment (bug):
Wanted to call out that there's a behavior change here which breaks foreign tooling calling `istioctl`, not sure if it was intentional or not. Before this patch:
```
istioctl version && istioctl proxy-status && echo $?
client version: 1.26.2
control plane version: 1.26.2
data plane version: none
NAME     CLUSTER     CDS     LDS     EDS     RDS     ECDS     ISTIOD     VERSION
0
```

With this patch:
```
./istioctl version && ./istioctl proxy-status || echo $?
client version: 1.27.0
control plane version: 1.26.2
data plane version: none
Error: failed to setup status print: no proxies found (checked 1 istiods)
1
```

Code after:
			// Skip if namespace filter is set and doesn't match
			if s.Namespace != "" && meta.Namespace != s.Namespace {
				continue
			}

			// Process XDS configs
			configs := handleAndGetXdsConfigs(&clientConfig)
			typeStatus := make(map[string]string, len(configs))
			for _, config := range configs {
				typeURL := config.GetTypeUrl()
				allTypesSet[typeURL] = struct{}{}
				typeStatus[typeURL] = formatStatus(config)
			}

			fullStatus = append(fullStatus, &xdsWriterStatus{
				proxyID:       clientConfig.GetNode().GetId(),
				clusterID:     meta.ClusterID.String(),
				istiodID:      multixds.CpInfo(dr).ID,
				istiodVersion: meta.IstioVersion,
				typeStatus:    typeStatus,
			})
		}
	}

	if len(fullStatus) == 0 {
		return nil, nil, nil, fmt.Errorf("no proxies found (checked %d istiods)", len(drs))
	}

	// Sort types for consistent output, preserving legacy order for core types
	coreOrder := []string{
		xdsresource.ClusterType,  // CDS
		xdsresource.ListenerType, // LDS
		xdsresource.EndpointType, // EDS
		xdsresource.RouteType,    // RDS
	}
	var allTypes []string
	added := map[string]bool{}
	for _, t := range coreOrder {
		if _, ok := allTypesSet[t]; ok {
			allTypes = append(allTypes, t)
			added[t] = true
		}
	}
	// Add any extra types in sorted order
	var extras []string
	for t := range allTypesSet {
		if !added[t] {
			extras = append(extras, t)
		}
	}
	sort.Strings(extras)