Skip to content

Commit 7c8242a

Browse files
Refactor agent followup (#700)
* Add some in-depth documentation about the discovery handler registry Signed-off-by: Nicolas Belouin <[email protected]> * Remove mentions of crictl dependency New slot reconciliation system doesn't need crictl anymore, removing everything related to that Signed-off-by: Nicolas Belouin <[email protected]> * Apply suggestions from code review Signed-off-by: Kate Goldenring <[email protected]> Signed-off-by: Nicolas Belouin <[email protected]> Co-authored-by: Kate Goldenring <[email protected]> * Update patch version Signed-off-by: Nicolas Belouin <[email protected]> * Fix version.sh to account for CRD version not always first item in dict Signed-off-by: Nicolas Belouin <[email protected]> --------- Signed-off-by: Nicolas Belouin <[email protected]> Co-authored-by: Kate Goldenring <[email protected]>
1 parent 3050186 commit 7c8242a

File tree

27 files changed

+116
-105
lines changed

27 files changed

+116
-105
lines changed

Cargo.lock

+21-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agent/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "agent"
3-
version = "0.13.1"
3+
version = "0.13.2"
44
license = "Apache-2.0"
55
authors = ["Kate Goldenring <[email protected]>", "<[email protected]>"]
66
edition = "2021"
@@ -35,6 +35,7 @@ serde = "1.0.104"
3535
serde_derive = "1.0.104"
3636
serde_json = "1.0.45"
3737
serde_yaml = { version = "0.8.11", optional = true }
38+
simple-mermaid = "0.1" # used for docs
3839
thiserror = "1.0.50"
3940
tokio = { version = "1.0", features = ["rt-multi-thread", "time", "fs", "macros", "net"] }
4041
tokio-stream = { version = "0.1", features = ["net", "sync"] }
@@ -65,4 +66,4 @@ default = []
6566
onvif-feat = [ "akri-onvif"]
6667
opcua-feat = ["akri-opcua"]
6768
udev-feat = ["akri-udev"]
68-
agent-full = ["serde_yaml", "akri-debug-echo"]
69+
agent-full = ["serde_yaml", "akri-debug-echo"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
sequenceDiagram
2+
Discovery Handler ->> DiscoveryHandlerRequest: send discovered devices
3+
DiscoveryHandlerRequest ->> DiscoveryHandlerRequest: Updates aggregated list of discovered devices
4+
DiscoveryHandlerRequest -) Device Manager: Notifies and updates list of discovered devices
5+
DiscoveryHandlerRequest -) Configuration Controller: Requests reconciliation of Configuration linked to Request
6+
note over Configuration Controller: The following is Configuration Controller behavior
7+
activate Configuration Controller
8+
Configuration Controller ->> Configuration Controller: Reconcile Configuration
9+
Configuration Controller ->> DiscoveryHandlerRegistry: get_request()
10+
DiscoveryHandlerRegistry ->> Configuration Controller:
11+
Configuration Controller ->> DiscoveryHandlerRequest: get_instances()
12+
DiscoveryHandlerRequest ->> Configuration Controller: Returns list of discovered devices as bare Instances
13+
Configuration Controller ->> Kubernetes API: Apply Instances
14+
deactivate Configuration Controller
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
sequenceDiagram
2+
Configuration Controller -) DiscoveryHandlerRegistry: new_request()
3+
alt a Handler exists for the Request
4+
DiscoveryHandlerRegistry ->> DiscoveryHandlerRequest: Creates with filtered list of endpoints
5+
DiscoveryHandlerRegistry ->> DiscoveryHandlerRegistry: Add request to tracked request list
6+
loop over DiscoveryHandlerEndpoints with this name
7+
DiscoveryHandlerRequest ->>+ Kubernetes API: Solve discovery properties
8+
Kubernetes API ->>- DiscoveryHandlerRequest:
9+
DiscoveryHandlerRequest ->>+ Discovery Handler: query discovery handler
10+
loop
11+
Discovery Handler ->> DiscoveryHandlerRequest: send discovered devices
12+
note over DiscoveryHandlerRequest,DiscoveryHandlerRegistry: See other diagram for what happens here
13+
end
14+
deactivate Discovery Handler
15+
end
16+
else
17+
DiscoveryHandlerRegistry -x Configuration Controller: DiscoveryError::NoHandler
18+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
sequenceDiagram
2+
Discovery Handler ->> Registration endpoint: Registers
3+
Registration endpoint->> DiscoveryHandlerRegistry: register_endpoint()
4+
DiscoveryHandlerRegistry ->> DiscoveryHandlerRegistry: Add endpoint to registered handlers list
5+
DiscoveryHandlerRegistry ->> DiscoveryHandlerRequest: notify all DiscoveryHandlerRequest
6+
alt Discovery Handler name is the same as in Request
7+
DiscoveryHandlerRequest ->>+ Kubernetes API: Solve discovery properties
8+
Kubernetes API ->>- DiscoveryHandlerRequest:
9+
DiscoveryHandlerRequest ->>+ Discovery Handler: query discovery handler
10+
loop
11+
Discovery Handler ->> DiscoveryHandlerRequest: send discovered devices
12+
note over DiscoveryHandlerRequest,DiscoveryHandlerRegistry: See other diagram for what happens here
13+
end
14+
deactivate Discovery Handler
15+
end
16+
break on Discovery Handler connection error
17+
Registration endpoint -x DiscoveryHandlerRegistry: close endpoint
18+
DiscoveryHandlerRegistry ->> DiscoveryHandlerRegistry: Remove endpoint from registered handlers list
19+
note over DiscoveryHandlerRequest,Discovery Handler: The DiscoveryHandlerRequest request will handle termination by itself
20+
end

agent/src/discovery_handler_manager/discovery_handler_registry.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
//! This module is the heart of the discovery process handled by the agent, it is based around the [DiscoveryHandlerRegistry]
2+
//! and uses several other structure to represent and help handle discovery related operations.
3+
//!
4+
//! The [DiscoveryHandlerRegistry] keeps track of registered discovery handlers. Note, multiple endpoints/instances of a given
5+
//! handler can be registered at the same time.
6+
//!
7+
//! The [DiscoveryHandlerRegistry] also keeps track of ongoing discovery requests against those discovery handlers. There is one discovery request (a [DiscoveryHandlerRequest] object) per Configuration.
8+
//!
9+
//! Here are some simple diagrams showing how the components interact with each other in different situations:
10+
//!
11+
//! A new DiscoverHandler gets registered (after it connects to and registers with the agent registration Unix socket):
12+
#![doc=simple_mermaid::mermaid!("diagrams/dh_registration.mmd")]
13+
//!
14+
//! A new query is made by the Configuration Controller:
15+
#![doc=simple_mermaid::mermaid!("diagrams/dh_query.mmd")]
16+
//!
17+
//! A Discovery Handler's instance/endpoint sends a new list of discovered devices for a Request:
18+
#![doc=simple_mermaid::mermaid!("diagrams/dh_device.mmd")]
19+
120
use std::collections::HashMap;
221
use std::sync::Arc;
322

build/containers/Dockerfile.rust

+1-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ ARG AKRI_COMPONENT
2424
RUN PROFILE=$(echo "${EXTRA_CARGO_ARGS}" | grep -q -- --release && echo "release" || echo "debug"); \
2525
xx-verify ./target/$(xx-cargo --print-target-triple)/${PROFILE}/${AKRI_COMPONENT}\
2626
&& cp ./target/$(xx-cargo --print-target-triple)/${PROFILE}/${AKRI_COMPONENT} /build/bin/akri
27-
# Prepare crictl for agent
28-
RUN VERSION=v1.25.0; if [ "x${AKRI_COMPONENT}" = "xagent" ]; then wget \
29-
"https://github.com/kubernetes-sigs/cri-tools/releases/download/$VERSION/crictl-$VERSION-linux-$(xx-info arch).tar.gz" -O crictl.tar.gz\
30-
&& tar zxvf crictl.tar.gz -C /build/bin; fi
27+
3128

3229

3330
FROM scratch

controller/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "controller"
3-
version = "0.13.1"
3+
version = "0.13.2"
44
license = "Apache-2.0"
55
66
edition = "2021"

deployment/helm/Chart.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ type: application
1616
# This is the chart version. This version number should be incremented each time you make changes
1717
# to the chart and its templates, including the app version.
1818
# Versions are expected to follow Semantic Versioning (https://semver.org/)
19-
version: 0.13.1
19+
version: 0.13.2
2020

2121
# This is the version number of the application being deployed. This version number should be
2222
# incremented each time you make changes to the application. Versions are not expected to
2323
# follow Semantic Versioning. They should reflect the version the application is using.
24-
appVersion: 0.13.1
24+
appVersion: 0.13.2

deployment/helm/templates/agent.yaml

-25
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ spec:
6767
- name: DEBUG_ECHO_INSTANCES_SHARED
6868
value: {{ .Values.debugEcho.configuration.shared | quote }}
6969
{{- end }}
70-
- name: HOST_CRICTL_PATH
71-
value: /usr/local/bin/crictl
72-
- name: HOST_RUNTIME_ENDPOINT
73-
value: unix:///host/run/containerd/containerd.sock
74-
- name: HOST_IMAGE_ENDPOINT
75-
value: unix:///host/run/containerd/containerd.sock
7670
- name: AGENT_NODE_NAME
7771
valueFrom:
7872
fieldRef:
@@ -86,8 +80,6 @@ spec:
8680
mountPath: /var/lib/kubelet/device-plugins
8781
- name: pod-resources
8882
mountPath: /var/lib/kubelet/pod-resources
89-
- name: var-run-dockershim
90-
mountPath: /host/run/containerd/containerd.sock
9183
{{- if .Values.agent.host.udev }}
9284
- name: devices
9385
mountPath: /run/udev
@@ -111,23 +103,6 @@ spec:
111103
- name: pod-resources
112104
hostPath:
113105
path: "{{ .Values.agent.host.kubeletPodResources }}"
114-
- name: var-run-dockershim
115-
hostPath:
116-
{{- if ne "" .Values.agent.host.containerRuntimeSocket }}
117-
path: {{.Values.agent.host.containerRuntimeSocket }}
118-
{{- else if eq .Values.kubernetesDistro "microk8s" }}
119-
path: "/var/snap/microk8s/common/run/containerd.sock"
120-
{{- else if eq .Values.kubernetesDistro "k3s" }}
121-
path: "/run/k3s/containerd/containerd.sock"
122-
{{- else if eq .Values.kubernetesDistro "k8s" }}
123-
path: "/run/containerd/containerd.sock"
124-
{{- else }}
125-
# Please set container runtime socket by either selecting the appropriate K8s distro `kubernetesDistro=<k8s|k3s|microk8s>`
126-
# or setting `agent.host.containerRuntimeSocket=/container/runtime.sock`.
127-
# See https://docs.akri.sh/user-guide/cluster-setup for more information.
128-
# Using K8s default "/run/containerd/containerd.sock" for now.
129-
path: "/run/containerd/containerd.sock"
130-
{{- end }}
131106
{{- if .Values.agent.host.udev }}
132107
- name: devices
133108
hostPath:

deployment/helm/values.yaml

-9
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ useDevelopmentContainers: true
1616
# This can be set from the helm command line using `--set imagePullSecrets[0].name="mysecret"`
1717
imagePullSecrets: []
1818

19-
# kubernetesDistro describes the Kubernetes distro Akri is running on. It is used to conditionally set
20-
# distribution specific values such as container runtime socket. Options: microk8s | k3s | k8s
21-
kubernetesDistro: ""
22-
2319
# generalize references to `apiGroups` and `apiVersion` values for Akri CRDs
2420
crds:
2521
group: akri.sh
@@ -109,11 +105,6 @@ agent:
109105
kubeletDevicePlugins: /var/lib/kubelet/device-plugins
110106
# kubeletPodResources is the location of the kubelet pod-resources socket
111107
kubeletPodResources: /var/lib/kubelet/pod-resources
112-
# containerRuntimeSocket is the default node path of the container runtime socket.
113-
# For MicroK8s, set to "/var/snap/microk8s/common/run/containerd.sock"
114-
# For K3s, set to "/run/k3s/containerd/containerd.sock"
115-
# For standard K8s, set to "/run/containerd/containerd.sock"
116-
containerRuntimeSocket: ""
117108
# udev is the node path of udev, usually at `/run/udev`
118109
udev:
119110
# allowDebugEcho dictates whether the Akri Agent will allow DebugEcho Configurations

discovery-handler-modules/debug-echo-discovery-handler/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "debug-echo-discovery-handler"
3-
version = "0.13.1"
3+
version = "0.13.2"
44
license = "Apache-2.0"
55
authors = ["Kate Goldenring <[email protected]>"]
66
edition = "2021"

discovery-handler-modules/onvif-discovery-handler/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "onvif-discovery-handler"
3-
version = "0.13.1"
3+
version = "0.13.2"
44
license = "Apache-2.0"
55
authors = ["Kate Goldenring <[email protected]>"]
66
edition = "2021"

discovery-handler-modules/opcua-discovery-handler/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "opcua-discovery-handler"
3-
version = "0.13.1"
3+
version = "0.13.2"
44
license = "Apache-2.0"
55
authors = ["Kate Goldenring <[email protected]>"]
66
edition = "2021"

discovery-handler-modules/udev-discovery-handler/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "udev-discovery-handler"
3-
version = "0.13.1"
3+
version = "0.13.2"
44
license = "Apache-2.0"
55
authors = ["Kate Goldenring <[email protected]>"]
66
edition = "2021"

discovery-handlers/debug-echo/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "akri-debug-echo"
3-
version = "0.13.1"
3+
version = "0.13.2"
44
license = "Apache-2.0"
55
authors = ["Kate Goldenring <[email protected]>"]
66
edition = "2021"

discovery-handlers/onvif/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "akri-onvif"
3-
version = "0.13.1"
3+
version = "0.13.2"
44
license = "Apache-2.0"
55
authors = ["Kate Goldenring <[email protected]>"]
66
edition = "2021"

0 commit comments

Comments
 (0)