diff --git a/api/v1alpha1/devicelink_conditions.go b/api/v1alpha1/devicelink_conditions.go index d6f8689c..b7ded377 100644 --- a/api/v1alpha1/devicelink_conditions.go +++ b/api/v1alpha1/devicelink_conditions.go @@ -62,8 +62,8 @@ 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() { @@ -71,9 +71,9 @@ func (in *DeviceLink) SucceedOnModelExisted() { 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() { diff --git a/api/v1alpha1/devicelink_types.go b/api/v1alpha1/devicelink_types.go index 8f8df0a1..ab9ab014 100644 --- a/api/v1alpha1/devicelink_types.go +++ b/api/v1alpha1/devicelink_types.go @@ -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 diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index d8ca5ed1..45901ca0 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -21,6 +21,7 @@ package v1alpha1 import ( "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" ) @@ -298,7 +299,11 @@ func (in *DeviceLinkStatus) DeepCopyInto(out *DeviceLinkStatus) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - out.Model = in.Model + if in.Model != nil { + in, out := &in.Model, &out.Model + *out = new(metav1.TypeMeta) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeviceLinkStatus. diff --git a/deploy/e2e/all_in_one.yaml b/deploy/e2e/all_in_one.yaml index 85afea4e..5506f3a1 100644 --- a/deploy/e2e/all_in_one.yaml +++ b/deploy/e2e/all_in_one.yaml @@ -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: diff --git a/deploy/manifests/crd/base/edge.cattle.io_devicelinks.yaml b/deploy/manifests/crd/base/edge.cattle.io_devicelinks.yaml index 9c7e9680..9a598ce2 100644 --- a/deploy/manifests/crd/base/edge.cattle.io_devicelinks.yaml +++ b/deploy/manifests/crd/base/edge.cattle.io_devicelinks.yaml @@ -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: diff --git a/pkg/brain/predicate/devicelink_changed.go b/pkg/brain/predicate/devicelink_changed.go index f3001830..0cdd837b 100644 --- a/pkg/brain/predicate/devicelink_changed.go +++ b/pkg/brain/predicate/devicelink_changed.go @@ -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 } diff --git a/pkg/limb/controller/devicelink.go b/pkg/limb/controller/devicelink.go index bf524469..632537bf 100644 --- a/pkg/limb/controller/devicelink.go +++ b/pkg/limb/controller/devicelink.go @@ -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 } @@ -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") diff --git a/pkg/limb/controller/devicelink_connection.go b/pkg/limb/controller/devicelink_connection.go index 3b6fc8a6..e8764502 100644 --- a/pkg/limb/controller/devicelink_connection.go +++ b/pkg/limb/controller/devicelink_connection.go @@ -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 diff --git a/pkg/suctioncup/neurons.go b/pkg/suctioncup/neurons.go index 0aab24cd..08212156 100644 --- a/pkg/suctioncup/neurons.go +++ b/pkg/suctioncup/neurons.go @@ -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 {