mirror of
https://github.com/rancher/steve.git
synced 2025-07-04 02:26:36 +00:00
* Replace primary/secondary sort fields with an array of sort directives. * Allow more than 2 sort-params in a search query. * Add a virtual 'status.ready' field to clusters. * Rename status.ready -> status.connected * Set virtual field 'spec.internal' <- spec.displayName == 'local' * Need to declare all virtual fields to index. * Ready clusters have condition[type==Ready && status=True] * Update the README to reflect generalized sorting. * Bump lasso to get revised sort directives. * Review-driven changes, mostly comments and drop unneeded code. * Add unit tests to verify sort-order stringification. * Ignore empty-string sort components. * Fix a rebase mishap. * Drop unneeded commented-out code. * Clusters have a 'spec.internal' field, no need to synthesize one. * Added a note on square-brackets for label references. This should be added to the README for filter queries in the PR for 46333. * Bump to latest sqlcache-free lasso
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package clusters
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
)
|
|
|
|
// TransformManagedClusters does special-case handling on <management.cattle.io v3 Cluster>s:
|
|
// creates a new virtual `status.connected` boolean field that looks for `type = "Ready"` in any
|
|
// of the status.conditions records.
|
|
|
|
func TransformManagedCluster(obj *unstructured.Unstructured) (*unstructured.Unstructured, error) {
|
|
conditions, ok, err := unstructured.NestedFieldNoCopy(obj.Object, "status", "conditions")
|
|
if err != nil {
|
|
return obj, err
|
|
}
|
|
if !ok {
|
|
return obj, fmt.Errorf("failed to find status.conditions block in cluster %s", obj.GetName())
|
|
}
|
|
connectedStatus := false
|
|
conditionsAsArray, ok := conditions.([]interface{})
|
|
if !ok {
|
|
return obj, fmt.Errorf("failed to parse status.conditions as array")
|
|
}
|
|
for _, condition := range conditionsAsArray {
|
|
conditionMap, ok := condition.(map[string]interface{})
|
|
if !ok {
|
|
return obj, fmt.Errorf("failed to parse a condition as a map")
|
|
}
|
|
if conditionMap["type"] == "Ready" && conditionMap["status"] == "True" {
|
|
connectedStatus = true
|
|
break
|
|
}
|
|
}
|
|
err = unstructured.SetNestedField(obj.Object, connectedStatus, "status", "connected")
|
|
return obj, err
|
|
}
|