Skip to content

Commit fa90a77

Browse files
authored
chore: update resource selector references and add examples (#383)
* chore: update resource selector references and add examples * chore: fix lint errors * chore: make resource selector resources conditional * chore: hide unwanted resource selector resources in k8s check
1 parent 7123efe commit fa90a77

File tree

4 files changed

+156
-145
lines changed

4 files changed

+156
-145
lines changed

canary-checker/docs/reference/1-catalog.mdx

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ sidebar_position: 0
55
sidebar_custom_props:
66
icon: config-db
77
---
8+
import ResourceSelector from '@site/docs/snippets/\_resource-selector.mdx';
89

910
# <Icon name="config-db">Config DB</Icon>
1011

@@ -21,32 +22,32 @@ Runs a [config-db](https://github.com/flanksource/config-db) query.
2122
},
2223
]}/>
2324

24-
25-
## Resource Selectors
26-
27-
28-
| Field | Description | Scheme | Required |
29-
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------- | -------- |
30-
| `id` | ID of the component | `string` | No |
31-
| `name` | Name of the component/config | `string` | No |
32-
| `namespace` | Select resources in this namespace only, if empty find resources in all namespaces | `string` | No |
33-
| `types` | Match any of the types specified | `[]string` | No |
34-
| `statuses` | Match any of the statuses specified | `[]string` | No |
35-
| `labelSelector` | Kubernetes Style Label Selector | [LabelSelector](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/) | No |
36-
| `fieldSelector` | Kubernetes Style Field Selector Property fields of the component in kubernetes format (or database columns: owner, topology_id, parent_id) | [FieldSelector](https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/) | No |
37-
| `agent` | Select resources created on this agent, Defaults to `local` | `uuid`, `{name}`, `local` or `all` | No |
38-
| `cache` | Cache settings to use for the results, expensive selectors or selectors that are used often should be cached for longer periods. Defaults to `max-age=10m` | `no-cache`, `no-store` or `max-age={duration}` | No |
39-
| `search` | Search for resources via key value pairs using parsing expression grammar | [Search](#search) | No |
40-
41-
## Search
42-
43-
The query syntax is `field1=value1 field2>value2 field3=value3* field4=*value4`. `*` is for prefix and suffix matching.
44-
45-
Supported operators:
46-
47-
| Operator | Syntax | Types |
48-
| -------- | -------------------------------- | --------------------- |
49-
| `=` | `field=value` | `string` `int` `json` |
50-
| `!=` | `field!=value` | `string` `int` `json` |
51-
| `*` | `field=*value` or `field=value*` | `string` `int` |
52-
| `>` `<` | `field>value` or `field<value` | `datetime` `int` |
25+
## Resource Selector
26+
27+
<ResourceSelector hideComponent={true} hideCheck={true} />
28+
29+
### Examples
30+
31+
```yaml title="catalog-pod-check.yaml"
32+
apiVersion: canaries.flanksource.com/v1
33+
kind: Canary
34+
metadata:
35+
name: k8s-checks
36+
spec:
37+
schedule: '@every 30s'
38+
catalog:
39+
- name: pod-catalog-check
40+
selector:
41+
- labelSelector: 'kubernetes.io/app=notification-listener'
42+
types:
43+
- Kubernetes::Pod
44+
test:
45+
expr: "size(results) > 0"
46+
47+
# Only namespace starting with kube should be kube-system, kube-public and kube-node-lease
48+
- name: namespace-search-check
49+
selector:
50+
- search: 'kube-* type=Kubernetes::Namespace'
51+
test:
52+
expr: "size(results) == 3"
53+
```

canary-checker/docs/reference/1-kubernetes.mdx

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ sidebar_custom_props:
55
icon: k8s
66
---
77
import ReactMarkdown from 'react-markdown';
8+
import ResourceSelector from '@site/docs/snippets/\_resource-selector.mdx';
89

910
# <Icon name="k8s" /> Kubernetes
1011

@@ -31,31 +32,26 @@ The Kubernetes check performs requests on Kubernetes resources such as Pods to g
3132
]}/>
3233

3334

34-
3535
## Resource Selector
3636

37+
<ResourceSelector hideComponent={true} hideCheck={true} />
3738

38-
| Field | Description | Scheme | Required |
39-
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------- | -------- |
40-
| `name` | Name of the component/config | `string` | No |
41-
| `namespace` | Select resources in this namespace only, if empty find resources in all namespaces | `string` | No | | No |
42-
| `labelSelector` | Kubernetes Style Label Selector | [LabelSelector](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/) | No |
43-
| `fieldSelector` | Kubernetes Style Field Selector Property fields of the component in kubernetes format (or database columns: owner, topology_id, parent_id) | [FieldSelector](https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/) | No |
44-
| `search` | Search for resources via key value pairs using parsing expression grammar | [Search](#search) | No |
45-
46-
### Search
47-
48-
The query syntax is `field1=value1 field2>value2 field3=value3* field4=*value4`. `*` is for prefix and suffix matching.
49-
50-
Supported operators:
51-
52-
| Operator | Syntax | Types |
53-
| -------- | -------------------------------- | --------------------- |
54-
| `=` | `field=value` | `string` `int` `json` |
55-
| `!=` | `field!=value` | `string` `int` `json` |
56-
| `*` | `field=*value` or `field=value*` | `string` `int` |
57-
| `>` `<` | `field>value` or `field<value` | `datetime` `int` |
58-
39+
```yaml title="catalog-pod-check.yaml"
40+
apiVersion: canaries.flanksource.com/v1
41+
kind: Canary
42+
metadata:
43+
name: k8s-checks
44+
spec:
45+
schedule: '@every 30s'
46+
kubernetes:
47+
- name: notification-pod-health-check
48+
selector:
49+
- labelSelector: 'kubernetes.io/app=notification-listener'
50+
types:
51+
- Kubernetes::Pod
52+
test:
53+
expr: dyn(results).all(x, k8s.isHealthy(x))
54+
```
5955
6056
## Healthy
6157
Lines changed: 44 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
---
2-
title: Resource Selectors
3-
sidebar_position: 2
4-
sidebar_custom_props:
5-
icon: stash:search-box-light
6-
---
7-
8-
# Resource Selectors
1+
import Link from '@docusaurus/Link';
92

103
Resource Selectors are used in multiple places including:
114

@@ -24,9 +17,9 @@ Resource Selectors are used in multiple places including:
2417
| `fieldSelector` | Kubernetes Style Field Selector Property fields of the component in kubernetes format (or database columns: owner, topology_id, parent_id) | [FieldSelector](https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/) | No |
2518
| `agent` | Select resources created on this agent, Defaults to `local` | `uuid`, `{name}`, `local` or `all` | No |
2619
| `cache` | Cache settings to use for the results, expensive selectors or selectors that are used often should be cached for longer periods. Defaults to `max-age=10m` | `no-cache`, `no-store` or `max-age={duration}` | No |
27-
| `search` | Search for resources via key value pairs using parsing expression grammar | `#search` | No |
20+
| `search` | Search for resources via key value pairs using parsing expression grammar | [Search](#search) | No |
2821

29-
## Search
22+
### Search
3023

3124
The query syntax is `field1=value1 field2>value2 field3=value3* field4=*value4`. `*` is for prefix and suffix matching.
3225

@@ -59,86 +52,44 @@ Supported fields for:
5952
| `updated_at` | `datetime` |
6053
| `deleted_at` | `datetime` |
6154

62-
- [Components](/reference/topology/components):
63-
64-
| Field | Type |
65-
| ------------- | ---------- |
66-
| `name` | `string` |
67-
| `topology_id` | `string` |
68-
| `namespace` | `string` |
69-
| `type` | `string` |
70-
| `status` | `string` |
71-
| `labels` | `json` |
72-
| `health` | `string` |
73-
| `agent` | `string` |
74-
| `created_at` | `datetime` |
75-
| `updated_at` | `datetime` |
76-
| `deleted_at` | `datetime` |
77-
78-
- [Health Checks](/reference/canary-checker/check):
79-
80-
| Field | Type |
81-
| ------------ | ---------- |
82-
| `name` | `string` |
83-
| `canary_id` | `string` |
84-
| `namespace` | `string` |
85-
| `type` | `string` |
86-
| `status` | `string` |
87-
| `health` | `string` |
88-
| `labels` | `json` |
89-
| `agent` | `string` |
90-
| `created_at` | `datetime` |
91-
| `updated_at` | `datetime` |
92-
| `deleted_at` | `datetime` |
93-
94-
## Examples
95-
96-
### Selecting Components in a Topology
97-
98-
```yaml title="topology-component-selectors.yaml"
99-
kind: Topology
100-
metadata:
101-
name: Example
102-
spec:
103-
components:
104-
- name: Components with healthy status in kube-system namespace of all agents
105-
selectors:
106-
- statuses: ['healthy']
107-
namespace: kube-system
108-
agent: all
109-
110-
- name: Components with Node type with spot instance property labeled with gpu tag
111-
selectors:
112-
- types: ['Kubernetes::Node']
113-
fieldSelector: 'instance-type=spot'
114-
labelSelector: 'sku-type=gpu'
115-
116-
- name: Components with labels of team payments or team orders
117-
# Using multiple selectors to aggregate
118-
selectors:
119-
- labelSelector: 'team=payments'
120-
- labelSelector: 'team=orders'
121-
122-
- name: Kubernetes components which start with kafka created in last 24h
123-
# Suffix and Prefix matches are supported using *
124-
selectors:
125-
- search: name=kafka* type=Kubernetes* created_at>now-24h
126-
127-
- name: All components updated between a specific interval
128-
selectors:
129-
- search: updated_at>2024-10-10 updated_at<2024-10-17
130-
131-
- name: Component with name httpbin-service
132-
# Not giving any key will do a name lookup (ie name=httpbin-service)
133-
selectors:
134-
- search: httpbin-service
135-
136-
- name: Components with label cluster
137-
# JSON lookups are also supported
138-
selectors:
139-
- search: labels.cluster=prod
140-
141-
- name: Link configs which have logistics-api image
142-
configs:
143-
- search: config.spec.template.spec.containers[0].name=docker.io/example/logistics-api:latest
144-
```
55+
{!props.hideComponent && (
56+
<Link to="/reference/topology/components">Components</Link>
57+
)}
58+
59+
{!props.hideComponent && (
60+
<Fields rows={[
61+
{field: "name", scheme: "string"},
62+
{field: "topology_id", scheme: "string"},
63+
{field: "namespace", scheme: "string"},
64+
{field: "type", scheme: "string"},
65+
{field: "status", scheme: "string"},
66+
{field: "labels", scheme: "json"},
67+
{field: "health", scheme: "string"},
68+
{field: "agent", scheme: "string"},
69+
{field: "created_at", scheme: "datetime"},
70+
{field: "updated_at", scheme: "datetime"},
71+
{field: "deleted_at", scheme: "datetime"},
72+
]}/>
73+
74+
)}
75+
76+
{!props.hideCheck && (
77+
<CommonLink to="/reference/canary-checker/check">Health Checks</CommonLink>
78+
)}
79+
80+
{!props.hideCheck && (
81+
<Fields rows={[
82+
{field: "name", scheme: "string"},
83+
{field: "canary_id", scheme: "string"},
84+
{field: "namespace", scheme: "string"},
85+
{field: "type", scheme: "string"},
86+
{field: "status", scheme: "string"},
87+
{field: "health", scheme: "string"},
88+
{field: "labels", scheme: "json"},
89+
{field: "agent", scheme: "string"},
90+
{field: "created_at", scheme: "datetime"},
91+
{field: "updated_at", scheme: "datetime"},
92+
{field: "deleted_at", scheme: "datetime"},
93+
]}/>
94+
95+
)}

mission-control/docs/reference/resource-selector.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: Resource Selectors
3+
sidebar_position: 2
4+
sidebar_custom_props:
5+
icon: stash:search-box-light
6+
---
7+
8+
import ResourceSelector from '@site/docs/snippets/\_resource-selector.mdx';
9+
10+
# Resource Selectors
11+
12+
<ResourceSelector />
13+
14+
## Examples
15+
16+
### Selecting Components in a Topology
17+
18+
```yaml title="topology-component-selectors.yaml"
19+
kind: Topology
20+
metadata:
21+
name: Example
22+
spec:
23+
components:
24+
- name: Components with healthy status in kube-system namespace of all agents
25+
selectors:
26+
- statuses: ['healthy']
27+
namespace: kube-system
28+
agent: all
29+
30+
- name: Components with Node type with spot instance property labeled with gpu tag
31+
selectors:
32+
- types: ['Kubernetes::Node']
33+
fieldSelector: 'instance-type=spot'
34+
labelSelector: 'sku-type=gpu'
35+
36+
- name: Components with labels of team payments or team orders
37+
# Using multiple selectors to aggregate
38+
selectors:
39+
- labelSelector: 'team=payments'
40+
- labelSelector: 'team=orders'
41+
42+
- name: Kubernetes components which start with kafka created in last 24h
43+
# Suffix and Prefix matches are supported using *
44+
selectors:
45+
- search: name=kafka* type=Kubernetes* created_at>now-24h
46+
47+
- name: All components updated between a specific interval
48+
selectors:
49+
- search: updated_at>2024-10-10 updated_at<2024-10-17
50+
51+
- name: Component with name httpbin-service
52+
# Not giving any key will do a name lookup (ie name=httpbin-service)
53+
selectors:
54+
- search: httpbin-service
55+
56+
- name: Components with label cluster
57+
# JSON lookups are also supported
58+
selectors:
59+
- search: labels.cluster=prod
60+
61+
- name: Link configs which have logistics-api image
62+
configs:
63+
- search: config.spec.template.spec.containers[0].name=docker.io/example/logistics-api:latest
64+
```

0 commit comments

Comments
 (0)