Skip to content

Commit edfec45

Browse files
authored
Adding index for mcio.users.principalIds (#1018)
* Adding index for mcio.users.principalIds * Adding integration tests for filtering on the newly indexed field
1 parent 920defb commit edfec45

File tree

5 files changed

+158
-0
lines changed

5 files changed

+158
-0
lines changed

pkg/sqlcache/informer/listoption_indexer.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,12 @@ func (l *ListOptionIndexer) addIndexFields(key string, obj any, tx db.TxClient)
384384
args = append(args, fmt.Sprint(typedValue))
385385
case []string:
386386
args = append(args, strings.Join(typedValue, "|"))
387+
case []interface{}:
388+
var s []string
389+
for _, v := range typedValue {
390+
s = append(s, fmt.Sprint(v))
391+
}
392+
args = append(args, strings.Join(s, "|"))
387393
default:
388394
err2 := fmt.Errorf("field %v has a non-supported type value: %v", field, value)
389395
return err2

pkg/stores/sqlproxy/proxy_store.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ var (
192192
gvkKey("management.cattle.io", "v3", "RoleTemplate"): {
193193
{"context"},
194194
},
195+
gvkKey("management.cattle.io", "v3", "User"): {
196+
{"principalIds"},
197+
},
195198
gvkKey("networking.k8s.io", "v1", "Ingress"): {
196199
{"spec", "rules", "host"},
197200
{"spec", "ingressClassName"},
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
annotations:
5+
controller-gen.kubebuilder.io/version: v0.17.1
6+
name: users.management.cattle.io
7+
spec:
8+
group: management.cattle.io
9+
names:
10+
kind: User
11+
listKind: UserList
12+
plural: users
13+
singular: user
14+
scope: Cluster
15+
versions:
16+
- name: v3
17+
schema:
18+
openAPIV3Schema:
19+
description: User represents a user in Rancher
20+
properties:
21+
apiVersion:
22+
description: |-
23+
APIVersion defines the versioned schema of this representation of an object.
24+
Servers should convert recognized schemas to the latest internal value, and
25+
may reject unrecognized values.
26+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
27+
type: string
28+
description:
29+
description: Description provides a brief summary about the user.
30+
type: string
31+
displayName:
32+
description: DisplayName is the user friendly name shown in the UI.
33+
type: string
34+
enabled:
35+
description: Enabled indicates whether the user account is active.
36+
type: boolean
37+
kind:
38+
description: |-
39+
Kind is a string value representing the REST resource this object represents.
40+
Servers may infer this from the endpoint the client submits requests to.
41+
Cannot be updated.
42+
In CamelCase.
43+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
44+
type: string
45+
me:
46+
description: Deprecated. Only used by /v3 Rancher API.
47+
type: boolean
48+
metadata:
49+
type: object
50+
mustChangePassword:
51+
description: |-
52+
MustChangePassword is a flag that, if true, forces the user to change their
53+
password upon their next login.
54+
type: boolean
55+
password:
56+
description: Deprecated. Password are stored in secrets in the cattle-local-user-passwords
57+
namespace.
58+
type: string
59+
principalIds:
60+
description: |-
61+
PrincipalIDs lists the authentication provider identities (e.g. GitHub, Keycloak or Active Directory)
62+
that are associated with this user account.
63+
items:
64+
type: string
65+
type: array
66+
status:
67+
description: Status contains the most recent observed state of the user.
68+
properties:
69+
conditions:
70+
items:
71+
properties:
72+
lastTransitionTime:
73+
description: Last time the condition transitioned from one status
74+
to another.
75+
type: string
76+
lastUpdateTime:
77+
description: The last time this condition was updated.
78+
type: string
79+
message:
80+
description: Human-readable message indicating details about
81+
last transition
82+
type: string
83+
reason:
84+
description: The reason for the condition's last transition.
85+
type: string
86+
status:
87+
description: Status of the condition, one of True, False, Unknown.
88+
type: string
89+
type:
90+
description: Type of user condition.
91+
type: string
92+
required:
93+
- status
94+
- type
95+
type: object
96+
type: array
97+
type: object
98+
username:
99+
description: Username is the unique login identifier for the user.
100+
type: string
101+
type: object
102+
served: true
103+
storage: true
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: management.cattle.io/v3
2+
kind: User
3+
metadata:
4+
name: user-one
5+
principalIds:
6+
- local://user-one-principal
7+
- local://another-id-for-user1
8+
---
9+
apiVersion: management.cattle.io/v3
10+
kind: User
11+
metadata:
12+
name: user-two
13+
principalIds:
14+
- local://user-two-principal
15+
- local://another-id-for-user2
16+
---
17+
apiVersion: management.cattle.io/v3
18+
kind: User
19+
metadata:
20+
name: admin-user
21+
principalIds:
22+
- local://admin-principal
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
schemaID: management.cattle.io.users
2+
tests:
3+
- description: "Filter by principalId: local://user-one-principal"
4+
query: "filter=principalIds~local://user-one-principal"
5+
expected:
6+
- user-one
7+
- description: "Filter by principalId: local://admin-principal"
8+
query: "filter=principalIds~local://admin-principal"
9+
expected:
10+
- admin-user
11+
- description: "Filter by principalId: local://another-id-for-user2"
12+
query: "filter=principalIds~local://another-id-for-user2"
13+
expected:
14+
- user-two
15+
- description: "Filter by non-existent principalId"
16+
query: "filter=principalIds~local://non-existent-id"
17+
expected: []
18+
- description: "Filter by multiple principalIds (AND logic): local://user-one-principal AND local://another-id-for-user1"
19+
query: "filter=principalIds~local://user-one-principal&filter=principalIds~local://another-id-for-user1"
20+
expected:
21+
- user-one
22+
- description: "Filter by multiple principalIds (AND logic) for different users"
23+
query: "filter=principalIds~local://user-one-principal&filter=principalIds~local://admin-principal"
24+
expected: []

0 commit comments

Comments
 (0)