Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
Update deviceController to reconcile the device between the openyurt …
Browse files Browse the repository at this point in the history
…and edge
  • Loading branch information
qclc committed Sep 18, 2021
1 parent e764d4b commit 7d47bfa
Show file tree
Hide file tree
Showing 21 changed files with 1,435 additions and 399 deletions.
2 changes: 1 addition & 1 deletion PROJECT
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
domain: openyurt.io
layout: go.kubebuilder.io/v3
projectName: device-controller
repo: github.com/charleszheng44/device-controller
repo: github.com/openyurtio/device-controller
resources:
- api:
crdVersion: v1
Expand Down
41 changes: 36 additions & 5 deletions api/v1alpha1/device_types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 The Kubernetes authors.
Copyright 2021 The OpenYurt Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,15 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
)

const (
DeviceFinalizer = "v1alpha1.device.finalizer"
// DeviceSyncedCondition indicates that the device exists in both OpenYurt and edge platform
DeviceSyncedCondition clusterv1.ConditionType = "DeviceSynced"
// DeviceManagingCondition indicates that the device is being managed by cloud and its properties are being reconciled
DeviceManagingCondition clusterv1.ConditionType = "DeviceManaging"
)

type AdminState string
Expand All @@ -38,6 +47,7 @@ type ProtocolProperties map[string]string

// DeviceSpec defines the desired state of Device
type DeviceSpec struct {
// Information describing the device
Description string `json:"description,omitempty"`
// Admin state (locked/unlocked)
AdminState AdminState `json:"adminState,omitempty"`
Expand All @@ -54,9 +64,15 @@ type DeviceSpec struct {
Service string `json:"service"`
// Associated Device Profile - Describes the device
Profile string `json:"profile"`
// True means device is managed by cloud, cloud can update the related fields
// False means cloud can't update the fields
Managed bool `json:"managed,omitempty"`
// NodePool indicates which nodePool the device comes from
NodePool string `json:"nodePool,omitempty"`
// TODO support the following field
// A list of auto-generated events coming from the device
// AutoEvents []AutoEvent `json:"autoEvents"`
// DeviceProperties represents the expected state of the device's properties
DeviceProperties map[string]DesiredPropertyState `json:"deviceProperties,omitempty"`
}

Expand All @@ -80,11 +96,18 @@ type DeviceStatus struct {
// Time (milliseconds) that the device reported data to the core
// microservice
LastReported int64 `json:"lastReported,omitempty"`
// AddedToEdgeX indicates whether the object has been successfully
// created on EdgeX Foundry
AddedToEdgeX bool `json:"addedToEdgeX,omitempty"`
// Synced indicates whether the device already exists on both OpenYurt and edge platform
Synced bool `json:"synced,omitempty"`
// it represents the actual state of the device's properties
DeviceProperties map[string]ActualPropertyState `json:"deviceProperties,omitempty"`
Id string `json:"id,omitempty"`
EdgeId string `json:"edgeId,omitempty"`
// Admin state (locked/unlocked)
AdminState AdminState `json:"adminState,omitempty"`
// Operating state (enabled/disabled)
OperatingState OperatingState `json:"operatingState,omitempty"`
// current device state
// +optional
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
}

//+kubebuilder:object:root=true
Expand All @@ -99,6 +122,14 @@ type Device struct {
Status DeviceStatus `json:"status,omitempty"`
}

func (d *Device) SetConditions(conditions clusterv1.Conditions) {
d.Status.Conditions = conditions
}

func (d *Device) GetConditions() clusterv1.Conditions {
return d.Status.Conditions
}

//+kubebuilder:object:root=true

// DeviceList contains a list of Device
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/edgexobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ func (dp *DeviceProfile) IsAddedToEdgeX() bool {
}

func (d *Device) IsAddedToEdgeX() bool {
return d.Status.AddedToEdgeX
return d.Status.Synced
}
12 changes: 10 additions & 2 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 7d47bfa

Please sign in to comment.