Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
feat: support to reference resource in devicelink
Browse files Browse the repository at this point in the history
- reference the same Namespace's configmap/secret
- reference the downward API for devicelink
- adjust the related docs
  • Loading branch information
Frank Mai authored and guangbochen committed Jun 9, 2020
1 parent 50061b6 commit 771d8de
Show file tree
Hide file tree
Showing 26 changed files with 1,786 additions and 80 deletions.
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Octopus is an edge device management system based on Kubernetes, it is very ligh
- [Idea](#idea)
- [Workflow](#workflow)
- [Walkthrough](#walkthrough)
+ [Deploy Octopus](#deploy-octopus)
+ [Deploy Device Model & Device Adaptor](#deploy-device-model--device-adaptor)
+ [Create DeviceLink](#create-devicelink)
+ [Manage Device](#manage-device)
- [Documentation](#documentation)
- [License](#license)

Expand Down Expand Up @@ -79,7 +83,7 @@ In this walkthrough, we try to use Octopus to manage a dummy device. We will per

1. Deploy Octopus
1. Deploy Device Model & Device Adaptor
1. Create Device Link
1. Create DeviceLink
1. Manage Device

### Deploy Octopus
Expand Down Expand Up @@ -257,15 +261,17 @@ octopus-adaptor-dummy-manager-rolebinding 43s
```

### Create Device Link
### Create DeviceLink

Next, we are going to connect a device via `DeviceLink`. A link consists of 3 parts: `Adaptor`, `Model` and `Device spec`:
Next, we are going to connect a device via `DeviceLink`. A link mainly consists of 3 fields: `adaptor`, `model` and `template(device spec)`:

- `Adaptor` describes how to access the device, this connection process calls adaptation. In order to connect a device, we should indicate the name of the adaptor, the name of the device-connectable node and the parameters of this connection.
- `Model` describes the model of device, it is the [TypeMeta](https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/v1/types.go) of the device model CRD.
- `Device spec` describes the desired status of device, it is determined by the device model CRD.
- `adaptor` describes how to access the device, this accessing process calls **Adaptation**. In order to adapt a device, we need to indicate the name of the adaptor and the name of the device-connectable node.
- `model` describes the model of device, it is the [TypeMeta](https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/v1/types.go) of the device model CRD.
- `template(device spec)` describes the desired status of device, it is determined by the device model CRD.

We can imagine that there is a device named `living-room-fan` on the `edge-worker` node, we can try to connect it in.
In addition, we can also use the `references` field to refer the [ConfigMap](https://kubernetes.io/docs/concepts/configuration/configmap/) and [Secret](https://kubernetes.io/docs/concepts/configuration/secret/) under the same Namespace, even use the downward API to fetch the information in `DeviceLink`.

We can imagine that there is a device named `living-room-fan` on the `edge-worker` node, and then we can connect it by Octopus:

```yaml
apiVersion: edge.cattle.io/v1alpha1
Expand All @@ -292,7 +298,7 @@ spec:
```

There are [several states](./docs/octopus/state_of_devicelink.md) of a link, if we found the **DeviceConnected** `PHASE` is on **Healthy** `STATUS`, we can query the same name instance of device model CRD, now the device is in our cluster:
After deployed the above `DeviceLink` into a cluster, we could find that there are [several states](./docs/octopus/state_of_devicelink.md) of a link. If the **DeviceConnected** `PHASE` is on **Healthy** `STATUS`, we can query the same name instance of device model CRD, now the device is in our cluster:

```shell script
$ kubectl get devicelink living-room-fan -n default
Expand Down
83 changes: 81 additions & 2 deletions api/v1alpha1/devicelink_types.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,96 @@
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

// DeviceLinkReferenceSecretSource defines the source of a same name Secret instance.
type DeviceLinkReferenceSecretSource struct {
// Specifies the name of the Secret in the same Namespace to use.
// +kubebuilder:validation:Required
Name string `json:"name"`

// Specifies the key of the Secret's data.
// If not specified, all keys of the Secret will be projected into the parameter values.
// If specified, the listed keys will be projected into the parameter value.
// If a key is specified which is not present in the Secret,
// the connection will error unless it is marked optional.
// +optional
Items []string `json:"items,omitempty"`
}

// DeviceLinkReferenceConfigMapSource defines the source of a same name ConfigMap instance.
type DeviceLinkReferenceConfigMapSource struct {
// Specifies the name of the ConfigMap in the same Namespace to use.
// +kubebuilder:validation:Required
Name string `json:"name"`

// Specifies the key of the ConfigMap's data.
// If not specified, all keys of the ConfigMap will be projected into the parameter values.
// If specified, the listed keys will be projected into the parameter value.
// If a key is specified which is not present in the ConfigMap,
// the connection will error unless it is marked optional.
// +optional
Items []string `json:"items,omitempty"`
}

// DeviceLinkReferenceDownwardAPISourceItem defines the downward API item for projecting the DeviceLink.
type DeviceLinkReferenceDownwardAPISourceItem struct {
// Specifies the key of the downward API's data.
// +kubebuilder:validation:Required
Name string `json:"name"`

// Specifies that how to select a field of the DeviceLink,
// only annotations, labels, name, namespace and status are supported.
// +kubebuilder:validation:Required
FieldRef *corev1.ObjectFieldSelector `json:"fieldRef"`
}

// DeviceLinkReferenceDownwardAPISource defines the downward API for projecting the DeviceLink.
type DeviceLinkReferenceDownwardAPISource struct {
// Specifies a list of downward API.
// +kubebuilder:validation:MinItems=1
Items []DeviceLinkReferenceDownwardAPISourceItem `json:"items"`
}

// DeviceLinkReferenceSource defines the parameter source.
type DeviceLinkReferenceSource struct {
// Secret represents a Secret of the same Namespace that should populate this connection.
// +optional
Secret *DeviceLinkReferenceSecretSource `json:"secret,omitempty"`

// ConfigMap represents a ConfigMap of the same Namespace that should populate this connection.
// +optional
ConfigMap *DeviceLinkReferenceConfigMapSource `json:"configMap,omitempty"`

// DownwardAPI represents the downward API about the DeviceLink.¬
// +optional
DownwardAPI *DeviceLinkReferenceDownwardAPISource `json:"downwardAPI,omitempty"`
}

// DeviceLinkReference defines the parameter that should be passed to the adaptor during connecting.
type DeviceLinkReference struct {
DeviceLinkReferenceSource `json:",inline"`

// Specifies the name of the parameter.
Name string `json:"name,omitempty"`
}

// DeviceAdaptor defines the properties of device adaptor
type DeviceAdaptor struct {
// Specifies the node of adaptor to be matched.
// +optional
Node string `json:"node,omitempty"`

// Specifies the name of adaptor to be used.
// +optional
// +kubebuilder:validation:Required
Name string `json:"name,omitempty"`

// Specifies the parameter of adaptor to be used.
// [Deprecated] Specifies the parameter of adaptor to be used.
// This field has been deprecated, it should define the connection parameter
// as a part of device model.
// +kubebuilder:pruning:PreserveUnknownFields
// +optional
Parameters *runtime.RawExtension `json:"parameters,omitempty"`
Expand Down Expand Up @@ -96,6 +171,10 @@ type DeviceLinkSpec struct {
// +kubebuilder:validation:Required
Model metav1.TypeMeta `json:"model"`

// Specifies the references of device to be used.
// +optional
References []DeviceLinkReference `json:"references,omitempty"`

// Describe the device that will be created.
// +kubebuilder:validation:Required
Template DeviceTemplateSpec `json:"template"`
Expand Down
136 changes: 136 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 771d8de

Please sign in to comment.