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

Commit

Permalink
refactor: add dummy protocol device
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Mai authored and guangbochen committed May 27, 2020
1 parent 9f4c704 commit b22fa07
Show file tree
Hide file tree
Showing 15 changed files with 1,190 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ The dummy adaptor installer YAML file is under the [`adaptors/dummy/deploy/e2e`]
```shell script
$ kubectl apply -f https://raw.githubusercontent.com/cnrancher/octopus/master/adaptors/dummy/deploy/e2e/all_in_one.yaml
customresourcedefinition.apiextensions.k8s.io/dummyspecialdevices.devices.edge.cattle.io created
customresourcedefinition.apiextensions.k8s.io/dummyprotocoldevices.devices.edge.cattle.io created
clusterrole.rbac.authorization.k8s.io/octopus-adaptor-dummy-manager-role created
clusterrolebinding.rbac.authorization.k8s.io/octopus-adaptor-dummy-manager-rolebinding created
daemonset.apps/octopus-adaptor-dummy-adaptor created
Expand Down Expand Up @@ -245,7 +246,7 @@ replicaset.apps/octopus-brain-65fdb4ff99 1 1 1 2m27s
```

It is worth noting that we have granted the permission to Octopus for managing `DummySpecialDevice`:
It is worth noting that we have granted the permission to Octopus for managing `DummySpecialDevice`/`DummyProtocolDevice`:

```shell script
$ kubectl get clusterrolebinding | grep octopus
Expand Down
80 changes: 80 additions & 0 deletions adaptors/dummy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ This is for experience or testing.
+ [DummySpecialDeviceStatus](#dummyspecialdevicestatus)
+ [DummySpecialDeviceProtocol](#dummyspecialdeviceprotocol)
+ [DummySpecialDeviceGear](#dummyspecialdevicegear)
+ [DummyProtocolDevice](#dummyprotocoldevice)
+ [DummyProtocolDeviceSpec](#dummyprotocoldevicespec)
+ [DummyProtocolDeviceStatus](#dummyprotocoldevicestatus)
+ [DummyProtocolDeviceProtocol](#dummyprotocoldeviceprotocol)
+ [DummyProtocolDeviceSpecProps](#dummyprotocoldevicespecprops)
+ [DummyProtocolDevicesStatusProps](#dummyprotocoldevicestatusprops)
+ [DummyProtocolDevicePropertyType](#dummyprotocoldevicepropertytype)
- [Support Platform](#support-platform)
- [Usage](#Usage)
- [Authority](#authority)
Expand All @@ -28,6 +35,7 @@ This is for experience or testing.
| Kind | Group | Version | Available |
|:---:|:---:|:---:|:---:|
| [`DummySpecialDevice`](#dummyspecialdevice) | `devices.edge.cattle.io` | `v1alpha1` | * |
| [`DummyProtocolDevice`](#dummyprotocoldevice) | `devices.edge.cattle.io` | `v1alpha1` | * |

### DummySpecialDevice

Expand Down Expand Up @@ -70,6 +78,76 @@ DummySpecialDeviceGear defines how fast the dummy special device should be.
| middle | Starts from 100 and increases every two seconds until 200. | string | false |
| fast | Starts from 200 and increases every one second until 300. | string | false |

### DummyProtocolDevice

The `DummyProtocolDevice` can be considered as a chaos protocol robot, it will change its attribute values every two seconds.

| Field | Description | Schema | Required |
|:---|:---|:---|:---:|
| metadata | | [metav1.ObjectMeta](https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/v1/types.go#L110) | false |
| spec | Defines the desired state of DummyProtocolDevice. | [DummyProtocolDeviceSpec](#dummyprotocoldevicespec) | true |
| status | Defines the observed state of DummyProtocolDevice. | [DummyProtocolDeviceStatus](#dummyprotocoldevicestatus) | false |

#### DummyProtocolDeviceSpec

| Field | Description | Schema | Required |
|:---|:---|:---|:---:|
| protocol | Protocol for accessing the dummy protocol device. | [DummyProtocolDeviceProtocol](#dummyprotocoldeviceprotocol) | true |
| props | Describes the desired properties. | map[string][DummyProtocolDeviceSpecProps](#dummyprotocoldevicespecprops) | false |

#### DummyProtocolDeviceStatus

| Field | Description | Schema | Required |
|:---|:---|:---|:---:|
| props | Reports the observed value of the desired properties. | map[string][DummyProtocolDeviceStatusProps](#dummyprotocoldevicestatusprops) | false |

#### DummyProtocolDeviceProtocol

| Field | Description | Schema | Required |
|:---|:---|:---|:---:|
| ip | Specifies where to connect the dummy protocol device. | string | true |

#### DummyProtocolDeviceSpecProps

> `DummyProtocolDeviceSpecObjectOrArrayProps` is the same as `DummyProtocolDeviceSpecProps`.
> The existence of `DummyProtocolDeviceSpecObjectOrArrayProps` is to combat the object circular reference.
| Field | Description | Schema | Required |
|:---|:---|:---|:---:|
| type | Describes the type of property. | [DummyProtocolDevicePropertyType](#dummyprotocoldevicepropertytype) | true |
| description | Outlines the property. | string | false |
| readOnly | Configures the property is readOnly or not. | bool | false |
| arrayProps | Describes item properties of the array type. | *[DummyProtocolDeviceSpecObjectOrArrayProps](#dummyprotocoldevicespecprops) | false |
| objectProps | Describes properties of the object type. | map[string][DummyProtocolDeviceSpecObjectOrArrayProps](#dummyprotocoldevicespecprops) | false |

#### DummyProtocolDeviceStatusProps

> `DummyProtocolDeviceStatusObjectOrArrayProps` is the same as `DummyProtocolDeviceStatusProps`.
> The existence of `DummyProtocolDeviceStatusObjectOrArrayProps` is to combat the object circular reference.
| Field | Description | Schema | Required |
|:---|:---|:---|:---:|
| type | Reports the type of property. | [DummyProtocolDevicePropertyType](#dummyprotocoldevicepropertytype) | true |
| intValue | Reports the value of int type. | *int | false |
| stringValue | Reports the value of string type. | *string | false |
| floatValue | Reports the value of float type. | *[resource.Quantity](https://github.com/kubernetes/apimachinery/blob/master/pkg/api/resource/quantity.go) [kubernetes-sigs/controller-tools/issues#245](https://github.com/kubernetes-sigs/controller-tools/issues/245#issuecomment-550030238) | false |
| booleanValue | Reports the value of bool type. | *bool | false |
| arrayValue | Reports the value of array type. | [][DummyProtocolDeviceStatusObjectOrArrayProps](#dummyprotocoldevicestatusprops) | false |
| objectValue | Reports the value of object type. | map[string][DummyProtocolDeviceStatusObjectOrArrayProps](#dummyprotocoldevicestatusprops) | false |

#### DummyProtocolDevicePropertyType

DummyProtocolDevicePropertyType describes the type of property.

| Field | Description | Schema | Required |
|:---|:---|:---|:---:|
| string | | string | false |
| int | | string | false |
| float | | string | false |
| boolean | | string | false |
| array | | string | false |
| object | | string | false |

## Support Platform

| OS | Arch |
Expand All @@ -91,7 +169,9 @@ Grant permissions to Octopus as below:
```text
Resources Non-Resource URLs Resource Names Verbs
--------- ----------------- -------------- -----
dummyprotocoldevices.devices.edge.cattle.io [] [] [create delete get list patch update watch]
dummyspecialdevices.devices.edge.cattle.io [] [] [create delete get list patch update watch]
dummyprotocoldevices.devices.edge.cattle.io/status [] [] [get patch update]
dummyspecialdevices.devices.edge.cattle.io/status [] [] [get patch update]
```

Expand Down
130 changes: 130 additions & 0 deletions adaptors/dummy/api/v1alpha1/dummyprotocoldevice_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package v1alpha1

import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// DummyProtocolDevicePropertyType describes the type of property.
// +kubebuilder:validation:Enum=string;int;float;boolean;array;object
type DummyProtocolDevicePropertyType string

const (
DummyProtocolDevicePropertyTypeString DummyProtocolDevicePropertyType = "string"
DummyProtocolDevicePropertyTypeInt DummyProtocolDevicePropertyType = "int"
DummyProtocolDevicePropertyTypeFloat DummyProtocolDevicePropertyType = "float"
DummyProtocolDevicePropertyTypeBoolean DummyProtocolDevicePropertyType = "boolean"
DummyProtocolDevicePropertyTypeArray DummyProtocolDevicePropertyType = "array"
DummyProtocolDevicePropertyTypeObject DummyProtocolDevicePropertyType = "object"
)

type DummyProtocolDeviceSpecObjectOrArrayProps struct {
// +kubebuilder:validation:XPreserveUnknownFields
DummyProtocolDeviceSpecProps `json:",inline"`
}

// DummyProtocolDeviceSpecProps defines the property of DummyProtocolDeviceSpec.
type DummyProtocolDeviceSpecProps struct {
// Describes the type of property.
// +kubebuilder:validation:Required
Type DummyProtocolDevicePropertyType `json:"type"`

// Outlines the property.
// +optional
Description string `json:"description,omitempty"`

// Configures the property is readOnly or not.
// +optional
ReadOnly bool `json:"readOnly,omitempty"`

// Describes item properties of the array type.
// +optional
ArrayProps *DummyProtocolDeviceSpecObjectOrArrayProps `json:"arrayProps,omitempty"`

// Describes properties of the object type.
// +optional
ObjectProps map[string]DummyProtocolDeviceSpecObjectOrArrayProps `json:"objectProps,omitempty"`
}

// DummyProtocolDeviceProtocol describes the accessing protocol for dummy protocol device.
type DummyProtocolDeviceProtocol struct {
// Specifies where to connect the dummy protocol device.
IP string `json:"ip"`
}

// DummyProtocolDeviceSpec defines the desired state of DummyProtocolDevice.
type DummyProtocolDeviceSpec struct {
// Protocol for accessing the dummy protocol device.
// +kubebuilder:validation:Required
Protocol DummyProtocolDeviceProtocol `json:"protocol"`

// Describe the desired properties.
// +optional
Props map[string]DummyProtocolDeviceSpecProps `json:"props,omitempty"`
}

type DummyProtocolDeviceStatusObjectOrArrayProps struct {
// +kubebuilder:validation:XPreserveUnknownFields
DummyProtocolDeviceStatusProps `json:",inline"`
}

// DummyProtocolDeviceStatusProps defines the property of DummyProtocolDeviceStatus.
type DummyProtocolDeviceStatusProps struct {
// Reports the type of property.
Type DummyProtocolDevicePropertyType `json:"type"`

// Reports the value of int type.
// +optional
IntValue *int `json:"intValue,omitempty"`

// Reports the value of string type.
// +optional
StringValue *string `json:"stringValue,omitempty"`

// Reports the value of float type.
// +optional
FloatValue *resource.Quantity `json:"floatValue,omitempty"`

// Reports the value of boolean type.
// +optional
BooleanValue *bool `json:"booleanValue,omitempty"`

// Reports the value of array type.
// +optional
ArrayValue []DummyProtocolDeviceStatusObjectOrArrayProps `json:"arrayValue,omitempty"`

// Reports the value of object type.
// +optional
ObjectValue map[string]DummyProtocolDeviceStatusObjectOrArrayProps `json:"objectValue,omitempty"`
}

// DummyProtocolDeviceStatus defines the observed state of DummyProtocolDevice.
type DummyProtocolDeviceStatus struct {
// Reports the observed value of the desired properties.
// +optional
Props map[string]DummyProtocolDeviceStatusProps `json:"props,omitempty"`
}

// +kubebuilder:object:root=true
// +k8s:openapi-gen=true
// +kubebuilder:subresource:status
// DummyProtocolDevice is the Schema for the dummy protocol device API.
type DummyProtocolDevice struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec DummyProtocolDeviceSpec `json:"spec,omitempty"`
Status DummyProtocolDeviceStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true
// DummyProtocolDeviceList contains a list of DummyProtocolDevice
type DummyProtocolDeviceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []DummyProtocolDevice `json:"items"`
}

func init() {
SchemeBuilder.Register(&DummyProtocolDevice{}, &DummyProtocolDeviceList{})
}
Loading

0 comments on commit b22fa07

Please sign in to comment.