Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more fields - part 6. #485

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ displayed by `kubectl get $TYPE`. For example `secrets` have `"metadata.fields[0
corresponding to `"name"`, `"type"`, `"data"`, and `"age"`. For CRDs, these come from
[Additional printer columns](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#additional-printer-columns)

When matching on array-type fields, the array's values are stored in the database as a single field separated by or-bars (`|`s).=
So searching for those fields needs to do a partial match when a field contains more than one value.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created rancher/rancher#49116 to address this


#### `projectsornamespaces`

Resources can also be filtered by the Rancher projects their namespaces belong
Expand Down
1 change: 1 addition & 0 deletions pkg/sqlcache/informer/listoption_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ func getField(a any, field string) (any, error) {
}
obj = fmt.Sprintf("%v", t[key])
} else if i == len(subFields)-1 {
// If the last layer is an array, return array.map(a => a[subfield])
result := make([]string, len(t))
for index, v := range t {
itemVal, ok := v.(map[string]interface{})
Expand Down
2 changes: 1 addition & 1 deletion pkg/sqlcache/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func NewStore(ctx context.Context, example any, keyFunc cache.KeyFunc, c db.Clie

dbName := db.Sanitize(s.name)

// once multiple informerfactories are needed, this can accept the case where table already exists error is received
// once multiple informer-factories are needed, this can accept the case where table already exists error is received
err := s.WithTransaction(ctx, true, func(tx transaction.Client) error {
createTableQuery := fmt.Sprintf(createTableFmt, dbName)
_, err := tx.Exec(createTableQuery)
Expand Down
18 changes: 18 additions & 0 deletions pkg/stores/sqlproxy/proxy_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,26 @@ var (
gvkKey("", "v1", "Pod"): {
{"spec", "containers", "image"},
{"spec", "nodeName"}},
gvkKey("", "v1", "ReplicationController"): {
{"spec", "template", "spec", "containers", "image"}},
gvkKey("", "v1", "Service"): {
{"spec", "clusterIP"},
{"spec", "type"},
},
gvkKey("apps", "v1", "DaemonSet"): {
{"metadata", "annotations", "field.cattle.io/publicEndpoints"},
{"spec", "template", "spec", "containers", "image"},
},
gvkKey("apps", "v1", "Deployment"): {
{"metadata", "annotations", "field.cattle.io/publicEndpoints"},
{"spec", "template", "spec", "containers", "image"},
},
gvkKey("apps", "v1", "ReplicaSet"): {
{"spec", "template", "spec", "containers", "image"},
},
gvkKey("apps", "v1", "StatefulSet"): {
{"metadata", "annotations", "field.cattle.io/publicEndpoints"},
{"spec", "template", "spec", "containers", "image"},
},
gvkKey("autoscaling", "v2", "HorizontalPodAutoscaler"): {
{"spec", "scaleTargetRef", "name"},
Expand All @@ -105,9 +113,11 @@ var (
},
gvkKey("batch", "v1", "CronJob"): {
{"metadata", "annotations", "field.cattle.io/publicEndpoints"},
{"spec", "jobTemplate", "spec", "template", "spec", "containers", "image"},
},
gvkKey("batch", "v1", "Job"): {
{"metadata", "annotations", "field.cattle.io/publicEndpoints"},
{"spec", "template", "spec", "containers", "image"},
},
gvkKey("catalog.cattle.io", "v1", "App"): {
{"spec", "chart", "metadata", "name"},
Expand All @@ -124,6 +134,8 @@ var (
},
gvkKey("cluster.x-k8s.io", "v1beta1", "Machine"): {
{"spec", "clusterName"}},
gvkKey("cluster.x-k8s.io", "v1beta1", "MachineDeployment"): {
{"spec", "clusterName"}},
gvkKey("management.cattle.io", "v3", "Cluster"): {
{"metadata", "labels", "provider.cattle.io"},
{"spec", "internal"},
Expand All @@ -137,6 +149,8 @@ var (
{"spec", "clusterName"}},
gvkKey("management.cattle.io", "v3", "NodeTemplate"): {
{"spec", "clusterName"}},
gvkKey("management.cattle.io", "v3", "Project"): {
{"spec", "clusterName"}},
gvkKey("networking.k8s.io", "v1", "Ingress"): {
{"spec", "rules", "host"},
{"spec", "ingressClassName"},
Expand All @@ -146,6 +160,10 @@ var (
{"status", "clusterName"},
{"status", "provider"},
},
gvkKey("rke.cattle.io", "v1", "ETCDSnapshot"): {
{"snapshotFile", "createdAt"},
{"spec", "clusterName"},
},
gvkKey("storage.k8s.io", "v1", "StorageClass"): {
{"provisioner"},
{"metadata", "annotations", "storageclass.kubernetes.io/is-default-class"},
Expand Down
Loading