Send only delta of workspace state changes from agentk to Rails
Currently, our agentk
implementation sends all information about existing workspaces with every poll.
This issue implements a mechanism to keep track of state changes on the agentk
side. agentk
will know what are the state changes (listening on informer) and it will keep metadata for each resource version of a workspace. agenk
will also know what's the latest state sent to rails.
The latest design is to keep the state changes in memory. (for more detail see this discussion
We'll keep two types of state in agentk
memory:
-
Workspace state changes - for each resourceVersion of the reosource, we'll keep:
- change type
- full resource state as if exported with
kubectl get -o yaml
. We get this value from the informer. Also, for theupdated
change type, we'll get two states: old and new. We'll use the new.
-
Workspace state synchronization status will be a map where
- The key is the name of the workspace.
- The value is made of two items:
-
PersistedDevWorkspaceResourceVersion
: this is the resource version number already reported to rails. Can be missing if we haven't reported to Rails yet -
PersistedDevWorkspaceRoutingResourceVersion
: this is the reported version of the workspace routing resource
-
Old description for using ConfigMaps
ConfigMaps
UsingWe'll try to keep the state persisted in k8s ConfigMap
(key-value store build into k8s). There will be two types of ConfigMaps:
Workspace state changes
We'll keep all states of the workspace indexed by their resourceVersion.
---
apiVersion: v1
kind: ConfigMap
metadata:
name: workspace-1-1-sqjzzz-states
data:
1: |-
---
changeType: created
resourceState: <full yaml of the resource>
2: |-
---
changeType: updated
resourceState: <full yaml of the resource (new version)>
3: |-
---
changeType: updated
resourceState: <full yaml of the resource (new version)>
4: |-
---
changeType: deleted
- The name of the map is
<workspace name>-states
, e.g.workspace-1-1-sqjzzz-states
- The key is the
metadata.resourceVersion
attribute of the workspace. - The value is a nested YAML with the change type and full resource state as if exported with
kubectl get -o yaml
. We get this value from the informer. Also, forupdated
change type, we'll get two states: old and new. We'll use the new.
Workspace state synchronization status
For each workspace, we'll need to keep track of what state changes we have already sent to Rails.
---
apiVersion: v1
kind: ConfigMap
metadata:
name: agent-1-status-sync
data:
workspace-1-1-sqjzzz: |-
---
workspace-1-3-doyyty: |-
---
PersistedDevWorkspaceResourceVersion: 23
PersistedDevWorkspaceRoutingResourceVersion: 1
workspace-1-10-9adcc2: |-
---
PersistedDevWorkspaceResourceVersion: 2
PersistedDevWorkspaceRoutingResourceVersion:2
- The ConfigMap name is
agent-<agent ID>-status-sync
. E.g.agent-1-status-sync
. - The key is the name of the workspace.
- The value is two values:
-
reported
: this is the resource version number already reported to rails. Can be missing if we haven't reported to Rails yet -
actual
: this is the current resource version
-