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

Commit

Permalink
refactor: adjust devicelink status
Browse files Browse the repository at this point in the history
- remove `deviceTemplateGeneration` field of status, which is used for observing the
  template generation of the devices.
- change `model` field of status to pointer type.

BREAKING CHANGE:
- Remove `DeviceTemplateGeneration` field from DeviceLink's status.
- `Model` field of DeviceLink's status is invisible when `ModelExisited`
  condition is checking or failed.
  • Loading branch information
Frank Mai authored and guangbochen committed Jul 6, 2020
1 parent 2235d62 commit c1984f0
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 23 deletions.
8 changes: 4 additions & 4 deletions api/v1alpha1/devicelink_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ func (in *DeviceLink) FailOnModelExisted(message string) {
return
}
in.Status.Conditions = deviceLinkConditions(in.Status.Conditions).
did(DeviceLinkModelExisted, metav1.ConditionFalse, "NotFound", message, in.Status.Model != in.Spec.Model)
in.Status.Model = metav1.TypeMeta{}
did(DeviceLinkModelExisted, metav1.ConditionFalse, "NotFound", message, in.Status.Model == nil || *in.Status.Model != in.Spec.Model)
in.Status.Model = nil
}

func (in *DeviceLink) SucceedOnModelExisted() {
if in == nil {
return
}
in.Status.Conditions = deviceLinkConditions(in.Status.Conditions).
did(DeviceLinkModelExisted, metav1.ConditionTrue, "Found", "", in.Status.Model != in.Spec.Model).
did(DeviceLinkModelExisted, metav1.ConditionTrue, "Found", "", in.Status.Model == nil || *in.Status.Model != in.Spec.Model).
next(DeviceLinkAdaptorExisted, "Confirming", "verify if there is a suitable adaptor to access")
in.Status.Model = in.Spec.Model
in.Status.Model = &in.Spec.Model
}

func (in *DeviceLink) ToCheckModelExisted() {
Expand Down
6 changes: 1 addition & 5 deletions api/v1alpha1/devicelink_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,11 @@ type DeviceLinkStatus struct {

// Represents the observed model of the device.
// +optional
Model metav1.TypeMeta `json:"model,omitempty"`
Model *metav1.TypeMeta `json:"model,omitempty"`

// Represents the observed adaptor name of the device.
// +optional
AdaptorName string `json:"adaptorName,omitempty"`

// Represents the observed template generation of the device.
// +optional
DeviceTemplateGeneration int64 `json:"deviceTemplateGeneration,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
7 changes: 6 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

4 changes: 0 additions & 4 deletions deploy/e2e/all_in_one.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,6 @@ spec:
- type
type: object
type: array
deviceTemplateGeneration:
description: Represents the observed template generation of the device.
format: int64
type: integer
model:
description: Represents the observed model of the device.
properties:
Expand Down
4 changes: 0 additions & 4 deletions deploy/manifests/crd/base/edge.cattle.io_devicelinks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,6 @@ spec:
- type
type: object
type: array
deviceTemplateGeneration:
description: Represents the observed template generation of the device.
format: int64
type: integer
model:
description: Represents the observed model of the device.
properties:
Expand Down
2 changes: 1 addition & 1 deletion pkg/brain/predicate/devicelink_changed.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (p DeviceLinkChangedPredicate) Update(e event.UpdateEvent) bool {
deviceLinkChangedPredicateLog.V(5).Info("Accept UpdateEvent as the node is changed", "object", object.GetNamespacedName(e.MetaOld))
return true
}
if dl.Status.Model != dl.Spec.Model {
if dl.Status.Model == nil || *dl.Status.Model != dl.Spec.Model {
deviceLinkChangedPredicateLog.V(5).Info("Accept UpdateEvent as the model is changed", "object", object.GetNamespacedName(e.MetaOld))
return true
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/limb/controller/devicelink.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (r *DeviceLinkReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error)
// NB(thxCode) we might see this as the `spec.model` has been changed,
// so we need to disconnect the previous connection and
// wait for brain to confirm the next step.
if link.Status.Model != link.Spec.Model {
if link.Status.Model == nil || *link.Status.Model != link.Spec.Model {
r.SuctionCup.Disconnect(&link)
return ctrl.Result{}, nil
}
Expand All @@ -127,7 +127,7 @@ func (r *DeviceLinkReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error)
link.SucceedOnAdaptorExisted()

// validates device
var device, deviceNewErr = modelutil.NewInstanceOfTypeMeta(link.Status.Model)
var device, deviceNewErr = modelutil.NewInstanceOfTypeMeta(*link.Status.Model)
if deviceNewErr != nil {
log.Error(deviceNewErr, "Unable to make device from model")
link.FailOnDeviceCreated("unable to make device from model")
Expand Down
2 changes: 1 addition & 1 deletion pkg/limb/controller/devicelink_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (r *DeviceLinkReconciler) ReceiveConnectionStatus(req suctioncup.RequestCon
}

// validates device
var device, err = modelutil.NewInstanceOfTypeMeta(link.Status.Model)
var device, err = modelutil.NewInstanceOfTypeMeta(*link.Status.Model)
if err != nil {
// NB(thxCode) we don't need to deal with this case as it can be traced by the main logic of limb.
return suctioncup.Response{}, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/suctioncup/neurons.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (m *manager) Connect(referencesData map[string]map[string][]byte, device *u
}
}()

var sendModel = &by.Status.Model
var sendModel = by.Status.Model
var sendDevice []byte
sendDevice, sentErr = device.MarshalJSON()
if sentErr != nil {
Expand Down

0 comments on commit c1984f0

Please sign in to comment.