mirror of
https://github.com/rancher/steve.git
synced 2025-07-01 09:12:12 +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
59 lines
2.0 KiB
Go
59 lines
2.0 KiB
Go
// Package virtual provides functions/resources to define virtual fields (fields which don't exist in k8s
|
|
// but should be visible in the API) on resources
|
|
package virtual
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/rancher/steve/pkg/resources/virtual/clusters"
|
|
"github.com/rancher/steve/pkg/resources/virtual/common"
|
|
"github.com/rancher/steve/pkg/resources/virtual/events"
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
"k8s.io/client-go/tools/cache"
|
|
)
|
|
|
|
// TransformBuilder builds transform functions for specified GVKs through GetTransformFunc
|
|
type TransformBuilder struct {
|
|
defaultFields *common.DefaultFields
|
|
}
|
|
|
|
// NewTransformBuilder returns a TransformBuilder using the given summary cache
|
|
func NewTransformBuilder(cache common.SummaryCache) *TransformBuilder {
|
|
return &TransformBuilder{
|
|
defaultFields: &common.DefaultFields{
|
|
Cache: cache,
|
|
},
|
|
}
|
|
}
|
|
|
|
// GetTransformFunc returns the func to transform a raw object into a fixed object, if needed
|
|
func (t *TransformBuilder) GetTransformFunc(gvk schema.GroupVersionKind) cache.TransformFunc {
|
|
converters := make([]func(*unstructured.Unstructured) (*unstructured.Unstructured, error), 0)
|
|
if gvk.Kind == "Event" && gvk.Group == "" && gvk.Version == "v1" {
|
|
converters = append(converters, events.TransformEventObject)
|
|
} else if gvk.Kind == "Cluster" && gvk.Group == "management.cattle.io" && gvk.Version == "v3" {
|
|
converters = append(converters, clusters.TransformManagedCluster)
|
|
}
|
|
converters = append(converters, t.defaultFields.TransformCommon)
|
|
|
|
return func(raw interface{}) (interface{}, error) {
|
|
obj, isSignal, err := common.GetUnstructured(raw)
|
|
if isSignal {
|
|
// isSignal= true overrides any error
|
|
return raw, err
|
|
}
|
|
if err != nil {
|
|
return nil, fmt.Errorf("GetUnstructured: failed to get underlying object: %w", err)
|
|
}
|
|
// Conversions are run in this loop:
|
|
for _, f := range converters {
|
|
obj, err = f(obj)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return obj, nil
|
|
}
|
|
}
|