-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQLite backed cache: Support sorting mgmt clusters on value in a spe…
…cific condition (#447) * 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
- Loading branch information
1 parent
809e927
commit c180569
Showing
14 changed files
with
709 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
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 | ||
} |
Oops, something went wrong.