-
Notifications
You must be signed in to change notification settings - Fork 15
Extract the configurable startup options and update the log tool #17
Conversation
@qclc: GitHub didn't allow me to assign the following users: your_reviewer. Note that only openyurtio members, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@qclc: The label(s) In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: qclc The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
257ddbd
to
9150cb7
Compare
@qclc: The label(s) In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Please take a look. @wawlian |
a9e4c5e
to
4ee720c
Compare
@@ -22,35 +22,29 @@ import ( | |||
"fmt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about moving this file to clients/edgex-foundry?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file has been moved.
@@ -236,7 +227,7 @@ func (efc *EdgexDeviceClient) UpdatePropertyState(ctx context.Context, propertyN | |||
dps.PutURL = putURL | |||
} | |||
// set the device property to desired state | |||
efc.V(5).Info("setting the property to desired value", "property", dps.Name) | |||
klog.V(5).Infof("setting the property %s to desired value", dps.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding device name into the log info may be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The device name has been added.
mgr, err := ctrl.NewManager(cfg, ctrl.Options{ | ||
Scheme: scheme, | ||
MetricsBindAddress: opts.MetricsAddr, | ||
Port: 9443, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yurt-device-controller has't involve any webhook, seems no need to set this Port field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The port field has been removed.
} | ||
} | ||
|
||
func preflightCheck(mgr ctrl.Manager, opts *options.YurtDeviceControllerOptions) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we need to check edgex apis here either.
controllers/device_controller.go
Outdated
// Checking if device already exist on the edge platform | ||
edgeDevice, err := r.deviceCli.Get(nil, edgeDeviceName, iotcli.GetOptions{}) | ||
if err == nil { | ||
// a. If object exists, the status of the device on OpenYurt is updated | ||
log.V(4).Info("Device already exists on edge platform") | ||
klog.V(4).Info("Device already exists on edge platform") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding device name into the log message may be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The device name has been added.
controllers/device_controller.go
Outdated
newDeviceStatus.EdgeId = createdEdgeObj.Status.EdgeId | ||
newDeviceStatus.Synced = true | ||
} | ||
} else { | ||
log.V(4).Info("failed to visit the edge platform") | ||
klog.V(4).Info("failed to visit the edge platform") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps ErrorS may be better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ErrorS is used here.
controllers/device_controller.go
Outdated
// the device has been added to the edge platform, check if each device property are in the desired state | ||
newDeviceStatus := d.Status.DeepCopy() | ||
// This list is used to hold the names of properties that failed to reconcile | ||
var failedPropertyNames []string | ||
|
||
// 1. reconciling the AdminState and OperatingState field of device | ||
log.V(3).Info("reconciling the AdminState and OperatingState field of device") | ||
klog.V(3).Info("reconciling the AdminState and OperatingState field of device") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding device name into log message may be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deviceName has been added.
controllers/device_controller.go
Outdated
@@ -232,16 +215,16 @@ func (r *DeviceReconciler) reconcileUpdateDevice(ctx context.Context, d *devicev | |||
} | |||
|
|||
// 2. reconciling the device properties' value | |||
log.V(3).Info("reconciling the device properties") | |||
klog.V(3).Info("reconciling the device properties") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding device name into log message may be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deviceName has been added.
controllers/device_controller.go
Outdated
} | ||
|
||
d.Status = *newDeviceStatus | ||
|
||
// 3. update the device status on OpenYurt | ||
log.V(3).Info("update the device status") | ||
klog.V(3).Info("update the device status") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding device name into log message may be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deviceName has been added.
controllers/device_controller.go
Outdated
newDeviceStatus := deviceStatus.DeepCopy() | ||
// This list is used to hold the names of properties that failed to reconcile | ||
var failedPropertyNames []string | ||
// 2. reconciling the device properties' value | ||
log.V(3).Info("reconciling the device properties' value") | ||
klog.V(3).Info("reconciling the value of device properties") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding device name into log message may be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deviceName has been added.
controllers/device_controller.go
Outdated
for _, desiredProperty := range d.Spec.DeviceProperties { | ||
if desiredProperty.DesiredValue == "" { | ||
continue | ||
} | ||
propertyName := desiredProperty.Name | ||
// 1.1. gets the actual property value of the current device from edge platform | ||
log.V(4).Info("getting the actual property state", "property", propertyName) | ||
klog.V(4).Infof("getting the actual value of property: %s", propertyName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding device name into log message may be better.
controllers/device_controller.go
Outdated
"property getURL", actualProperty.GetURL, | ||
"property actual value", actualProperty.ActualValue) | ||
klog.V(4).Infof("got the actual property state, {Name: %s, GetURL: %s, ActualValue: %s}", | ||
propertyName, actualProperty.GetURL, actualProperty.ActualValue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding device name into log message may be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deviceName has been added.
controllers/device_controller.go
Outdated
"desired value", desiredProperty.DesiredValue, | ||
"actual value", actualProperty.ActualValue) | ||
klog.V(4).Infof("the desired value and the actual value are different, desired: %s, actual: %s", | ||
desiredProperty.DesiredValue, actualProperty.ActualValue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding device name into log message may be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deviceName has been added.
controllers/device_controller.go
Outdated
if err := r.deviceCli.UpdatePropertyState(nil, propertyName, d, iotcli.UpdateOptions{}); err != nil { | ||
log.V(4).Error(err, "failed to update property", "propertyName", propertyName) | ||
klog.V(4).ErrorS(err, "failed to update property", "propertyName", propertyName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding device name into log message may be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deviceName has been added.
controllers/device_controller.go
Outdated
failedPropertyNames = append(failedPropertyNames, propertyName) | ||
continue | ||
} | ||
|
||
log.V(4).Info("successfully set the property to desired value", "property", propertyName) | ||
klog.V(4).Infof("successfully set the property %s to desired value", propertyName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding device name into log message may be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deviceName has been added.
controllers/device_syncer.go
Outdated
return DeviceSyncer{}, err | ||
} | ||
|
||
func NewDeviceSyncer(client client.Client, opts *options.YurtDeviceControllerOptions, nodepool string) (DeviceSyncer, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function signature can be
func NewDeviceSyncer(client client.Client, opts *options.YurtDeviceControllerOptions) (DeviceSyncer, error)
since nodePool can be retrieved from opts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NodePool has been retrieved from opts.
continue | ||
} | ||
|
||
ds.log.V(1).Info("One round of Device synchronization is complete") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This log may be necessary to indicate whether on round of synchronization completes or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The log has been added.
controllers/deviceprofile_syncer.go
Outdated
if err != nil { | ||
return DeviceProfileSyncer{}, err | ||
} | ||
func NewDeviceProfileSyncer(client client.Client, opts *options.YurtDeviceControllerOptions, nodepool string) (DeviceProfileSyncer, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nodepool can be retrieved from opts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NodePool has been retrieved from opts.
if err := deleteDeviceProfile(ds.log, ds.Client, deleteKDevs); err != nil { | ||
ds.log.Error(err, "fail to delete device profiles") | ||
if err := deleteDeviceProfile(ds.Client, deleteKDevs); err != nil { | ||
klog.V(3).ErrorS(err, "fail to delete device profiles") | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a log line to indicate completion of one synchronization round may be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The log has been added.
@@ -175,34 +169,34 @@ func getKubeNameWithPrefix(edgeName, NodePoolName string) string { | |||
} | |||
|
|||
// createDeviceProfile creates the list of device profiles | |||
func createDeviceProfile(log logr.Logger, cli client.Client, edgeXDevs []devicev1alpha1.DeviceProfile, NodePoolName string) error { | |||
func createDeviceProfile(cli client.Client, edgeXDevs []devicev1alpha1.DeviceProfile, NodePoolName string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NodePoolName can be retrieved from opts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NodePoolName has been retrieved from opts
func (r *DeviceServiceReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
coreMetaCliInfo := edgexCli.ClientURL{Host: "edgex-core-metadata", Port: 48081} | ||
r.deviceServiceCli = edgexCli.NewEdgexDeviceServiceClient(coreMetaCliInfo, r.Log) | ||
func (r *DeviceServiceReconciler) SetupWithManager(mgr ctrl.Manager, opts *options.YurtDeviceControllerOptions, nodepool string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nodepool can be retrieved from opts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NodePool has been retrieved from opts.
return nil | ||
} | ||
} else { | ||
// a. If object exists, the status of the device on OpenYurt is updated | ||
log.V(4).Info("DeviceService already exists on edge platform") | ||
klog.V(4).Info("DeviceService already exists on edge platform") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding deviceservice name into the log message may be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deviceservice name has been added.
@@ -195,19 +181,18 @@ func (r *DeviceServiceReconciler) reconcileCreateDeviceService(ctx context.Conte | |||
addressable := ds.Spec.Addressable | |||
as, err := r.deviceServiceCli.GetAddressable(nil, addressable.Name, edgeInterface.GetOptions{}) | |||
if err == nil { | |||
log.V(4).Info("Addressable already exists on edge platform") | |||
klog.V(4).Info("Addressable already exists on edge platform") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding deviceservice name into the log message may be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deviceservice name has been added.
controllers/deviceservice_syncer.go
Outdated
if err != nil { | ||
return DeviceServiceSyncer{}, err | ||
} | ||
func NewDeviceServiceSyncer(client client.Client, opts *options.YurtDeviceControllerOptions, nodepool string) (DeviceServiceSyncer, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nodepool can be retrieved from opts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nodepool has been retrieved from opts
continue | ||
} | ||
|
||
ds.log.V(1).Info("One round of DeviceService synchronization is complete") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This log line is necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This log has been added.
4ee720c
to
e97cc02
Compare
/lgtm |
@wawlian: changing LGTM is restricted to collaborators In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
What type of PR is this?
/kind enhancement
What this PR does / why we need it:
klog
.Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
/assign @wawlian
Does this PR introduce a user-facing change?
--zap-log-level
to-v (or --v)
--help (or -h)
parameter:other Note