From 4046d247901db0dd9ccdcdb25a5dbea9d7b9bf72 Mon Sep 17 00:00:00 2001 From: wangxye <1031989637@qq.com> Date: Sat, 19 Aug 2023 23:47:28 +0800 Subject: [PATCH] update the client of iotdock to deploy edgex according to different versions Signed-off-by: wangxye <1031989637@qq.com> --- cmd/yurt-iot-dock/app/core.go | 15 +++--- cmd/yurt-iot-dock/app/options/options.go | 3 ++ .../clients/edgex-foundry/edgexobject.go | 54 +++++++++++++++++++ .../edgex-foundry/{ => v2}/device_client.go | 2 +- .../{ => v2}/device_client_test.go | 2 +- .../{ => v2}/deviceprofile_client.go | 2 +- .../{ => v2}/deviceprofile_client_test.go | 2 +- .../{ => v2}/deviceservice_client.go | 2 +- .../{ => v2}/deviceservice_client_test.go | 2 +- .../clients/edgex-foundry/{ => v2}/util.go | 2 +- pkg/yurtiotdock/clients/interface.go | 7 +++ .../controllers/device_controller.go | 10 ++-- pkg/yurtiotdock/controllers/device_syncer.go | 10 ++-- .../controllers/deviceprofile_controller.go | 10 ++-- .../controllers/deviceprofile_syncer.go | 10 ++-- .../controllers/deviceservice_controller.go | 10 ++-- .../controllers/deviceservice_syncer.go | 10 ++-- .../controller/platformadmin/iotdock.go | 1 + 18 files changed, 123 insertions(+), 31 deletions(-) rename pkg/yurtiotdock/clients/edgex-foundry/{ => v2}/device_client.go (99%) rename pkg/yurtiotdock/clients/edgex-foundry/{ => v2}/device_client_test.go (99%) rename pkg/yurtiotdock/clients/edgex-foundry/{ => v2}/deviceprofile_client.go (99%) rename pkg/yurtiotdock/clients/edgex-foundry/{ => v2}/deviceprofile_client_test.go (99%) rename pkg/yurtiotdock/clients/edgex-foundry/{ => v2}/deviceservice_client.go (99%) rename pkg/yurtiotdock/clients/edgex-foundry/{ => v2}/deviceservice_client_test.go (99%) rename pkg/yurtiotdock/clients/edgex-foundry/{ => v2}/util.go (99%) diff --git a/cmd/yurt-iot-dock/app/core.go b/cmd/yurt-iot-dock/app/core.go index 3d4aae34219..061dedbfe9e 100644 --- a/cmd/yurt-iot-dock/app/core.go +++ b/cmd/yurt-iot-dock/app/core.go @@ -37,6 +37,7 @@ import ( "github.com/openyurtio/openyurt/cmd/yurt-iot-dock/app/options" "github.com/openyurtio/openyurt/pkg/apis" + edgexclients "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients/edgex-foundry" "github.com/openyurtio/openyurt/pkg/yurtiotdock/controllers" "github.com/openyurtio/openyurt/pkg/yurtiotdock/controllers/util" ) @@ -116,15 +117,17 @@ func Run(opts *options.YurtIoTDockOptions, stopCh <-chan struct{}) { } } + edgexdock := edgexclients.NewEdgexDock(opts.Version, opts.CoreMetadataAddr, opts.CoreCommandAddr) + // setup the DeviceProfile Reconciler and Syncer if err = (&controllers.DeviceProfileReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), - }).SetupWithManager(mgr, opts); err != nil { + }).SetupWithManager(mgr, opts, edgexdock); err != nil { setupLog.Error(err, "unable to create controller", "controller", "DeviceProfile") os.Exit(1) } - dfs, err := controllers.NewDeviceProfileSyncer(mgr.GetClient(), opts) + dfs, err := controllers.NewDeviceProfileSyncer(mgr.GetClient(), opts, edgexdock) if err != nil { setupLog.Error(err, "unable to create syncer", "syncer", "DeviceProfile") os.Exit(1) @@ -139,11 +142,11 @@ func Run(opts *options.YurtIoTDockOptions, stopCh <-chan struct{}) { if err = (&controllers.DeviceReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), - }).SetupWithManager(mgr, opts); err != nil { + }).SetupWithManager(mgr, opts, edgexdock); err != nil { setupLog.Error(err, "unable to create controller", "controller", "Device") os.Exit(1) } - ds, err := controllers.NewDeviceSyncer(mgr.GetClient(), opts) + ds, err := controllers.NewDeviceSyncer(mgr.GetClient(), opts, edgexdock) if err != nil { setupLog.Error(err, "unable to create syncer", "controller", "Device") os.Exit(1) @@ -158,11 +161,11 @@ func Run(opts *options.YurtIoTDockOptions, stopCh <-chan struct{}) { if err = (&controllers.DeviceServiceReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), - }).SetupWithManager(mgr, opts); err != nil { + }).SetupWithManager(mgr, opts, edgexdock); err != nil { setupLog.Error(err, "unable to create controller", "controller", "DeviceService") os.Exit(1) } - dss, err := controllers.NewDeviceServiceSyncer(mgr.GetClient(), opts) + dss, err := controllers.NewDeviceServiceSyncer(mgr.GetClient(), opts, edgexdock) if err != nil { setupLog.Error(err, "unable to create syncer", "syncer", "DeviceService") os.Exit(1) diff --git a/cmd/yurt-iot-dock/app/options/options.go b/cmd/yurt-iot-dock/app/options/options.go index 08d9e37a920..747cbf389ca 100644 --- a/cmd/yurt-iot-dock/app/options/options.go +++ b/cmd/yurt-iot-dock/app/options/options.go @@ -30,6 +30,7 @@ type YurtIoTDockOptions struct { EnableLeaderElection bool Nodepool string Namespace string + Version string CoreDataAddr string CoreMetadataAddr string CoreCommandAddr string @@ -43,6 +44,7 @@ func NewYurtIoTDockOptions() *YurtIoTDockOptions { EnableLeaderElection: false, Nodepool: "", Namespace: "default", + Version: "", CoreDataAddr: "edgex-core-data:59880", CoreMetadataAddr: "edgex-core-metadata:59881", CoreCommandAddr: "edgex-core-command:59882", @@ -63,6 +65,7 @@ func (o *YurtIoTDockOptions) AddFlags(fs *pflag.FlagSet) { fs.BoolVar(&o.EnableLeaderElection, "leader-elect", false, "Enable leader election for controller manager. "+"Enabling this will ensure there is only one active controller manager.") fs.StringVar(&o.Nodepool, "nodepool", "", "The nodePool deviceController is deployed in.(just for debugging)") fs.StringVar(&o.Namespace, "namespace", "default", "The cluster namespace for edge resources synchronization.") + fs.StringVar(&o.Version, "version", "", "The version of edge resources deploymenet.") fs.StringVar(&o.CoreDataAddr, "core-data-address", "edgex-core-data:59880", "The address of edge core-data service.") fs.StringVar(&o.CoreMetadataAddr, "core-metadata-address", "edgex-core-metadata:59881", "The address of edge core-metadata service.") fs.StringVar(&o.CoreCommandAddr, "core-command-address", "edgex-core-command:59882", "The address of edge core-command service.") diff --git a/pkg/yurtiotdock/clients/edgex-foundry/edgexobject.go b/pkg/yurtiotdock/clients/edgex-foundry/edgexobject.go index 4a093bf9834..3ab0beb979c 100644 --- a/pkg/yurtiotdock/clients/edgex-foundry/edgexobject.go +++ b/pkg/yurtiotdock/clients/edgex-foundry/edgexobject.go @@ -16,6 +16,60 @@ limitations under the License. package edgex_foundry +import ( + "fmt" + + "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients" + edgexCliv2 "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients/edgex-foundry/v2" +) + type EdgeXObject interface { IsAddedToEdgeX() bool } + +type EdgexDock struct { + Version string + CoreMetadataAddr string + CoreCommandAddr string +} + +func NewEdgexDock(version string, coreMetadataAddr string, coreCommandAddr string) *EdgexDock { + return &EdgexDock{ + Version: version, + CoreMetadataAddr: coreMetadataAddr, + CoreCommandAddr: coreCommandAddr, + } +} + +func (ep *EdgexDock) CreateDeviceClient() (clients.DeviceInterface, error) { + switch ep.Version { + case "minesota": + return nil, nil + case "levski", "kamakura", "jakarta": + return edgexCliv2.NewEdgexDeviceClient(ep.CoreMetadataAddr, ep.CoreCommandAddr), nil + default: + return nil, fmt.Errorf("unsupported Edgex version: %v", ep.Version) + } +} + +func (ep *EdgexDock) CreateDeviceProfileClient() (clients.DeviceProfileInterface, error) { + switch ep.Version { + case "minesota": + return nil, nil + case "levski", "kamakura", "jakarta": + return edgexCliv2.NewEdgexDeviceProfile(ep.CoreMetadataAddr), nil + default: + return nil, fmt.Errorf("unsupported Edgex version: %v", ep.Version) + } +} + +func (ep *EdgexDock) CreateDeviceServiceClient() (clients.DeviceServiceInterface, error) { + switch ep.Version { + case "minesota": + return nil, nil + case "levski", "kamakura", "jakarta": + return edgexCliv2.NewEdgexDeviceServiceClient(ep.CoreMetadataAddr), nil + default: + return nil, fmt.Errorf("unsupported Edgex version: %v", ep.Version) + } +} diff --git a/pkg/yurtiotdock/clients/edgex-foundry/device_client.go b/pkg/yurtiotdock/clients/edgex-foundry/v2/device_client.go similarity index 99% rename from pkg/yurtiotdock/clients/edgex-foundry/device_client.go rename to pkg/yurtiotdock/clients/edgex-foundry/v2/device_client.go index 72ef381d8fa..771d1659f43 100644 --- a/pkg/yurtiotdock/clients/edgex-foundry/device_client.go +++ b/pkg/yurtiotdock/clients/edgex-foundry/v2/device_client.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package edgex_foundry +package v2 import ( "context" diff --git a/pkg/yurtiotdock/clients/edgex-foundry/device_client_test.go b/pkg/yurtiotdock/clients/edgex-foundry/v2/device_client_test.go similarity index 99% rename from pkg/yurtiotdock/clients/edgex-foundry/device_client_test.go rename to pkg/yurtiotdock/clients/edgex-foundry/v2/device_client_test.go index 5873a540d74..f34d5b76c6a 100644 --- a/pkg/yurtiotdock/clients/edgex-foundry/device_client_test.go +++ b/pkg/yurtiotdock/clients/edgex-foundry/v2/device_client_test.go @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package edgex_foundry +package v2 import ( "context" diff --git a/pkg/yurtiotdock/clients/edgex-foundry/deviceprofile_client.go b/pkg/yurtiotdock/clients/edgex-foundry/v2/deviceprofile_client.go similarity index 99% rename from pkg/yurtiotdock/clients/edgex-foundry/deviceprofile_client.go rename to pkg/yurtiotdock/clients/edgex-foundry/v2/deviceprofile_client.go index 2cd9c9d40c6..8f300278cf5 100644 --- a/pkg/yurtiotdock/clients/edgex-foundry/deviceprofile_client.go +++ b/pkg/yurtiotdock/clients/edgex-foundry/v2/deviceprofile_client.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package edgex_foundry +package v2 import ( "context" diff --git a/pkg/yurtiotdock/clients/edgex-foundry/deviceprofile_client_test.go b/pkg/yurtiotdock/clients/edgex-foundry/v2/deviceprofile_client_test.go similarity index 99% rename from pkg/yurtiotdock/clients/edgex-foundry/deviceprofile_client_test.go rename to pkg/yurtiotdock/clients/edgex-foundry/v2/deviceprofile_client_test.go index 0f32eecf687..ba6e2599021 100644 --- a/pkg/yurtiotdock/clients/edgex-foundry/deviceprofile_client_test.go +++ b/pkg/yurtiotdock/clients/edgex-foundry/v2/deviceprofile_client_test.go @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package edgex_foundry +package v2 import ( "context" diff --git a/pkg/yurtiotdock/clients/edgex-foundry/deviceservice_client.go b/pkg/yurtiotdock/clients/edgex-foundry/v2/deviceservice_client.go similarity index 99% rename from pkg/yurtiotdock/clients/edgex-foundry/deviceservice_client.go rename to pkg/yurtiotdock/clients/edgex-foundry/v2/deviceservice_client.go index c7cd9f70f24..48d74e223ce 100644 --- a/pkg/yurtiotdock/clients/edgex-foundry/deviceservice_client.go +++ b/pkg/yurtiotdock/clients/edgex-foundry/v2/deviceservice_client.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package edgex_foundry +package v2 import ( "context" diff --git a/pkg/yurtiotdock/clients/edgex-foundry/deviceservice_client_test.go b/pkg/yurtiotdock/clients/edgex-foundry/v2/deviceservice_client_test.go similarity index 99% rename from pkg/yurtiotdock/clients/edgex-foundry/deviceservice_client_test.go rename to pkg/yurtiotdock/clients/edgex-foundry/v2/deviceservice_client_test.go index c00d7b9118e..def719cf836 100644 --- a/pkg/yurtiotdock/clients/edgex-foundry/deviceservice_client_test.go +++ b/pkg/yurtiotdock/clients/edgex-foundry/v2/deviceservice_client_test.go @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package edgex_foundry +package v2 import ( "context" diff --git a/pkg/yurtiotdock/clients/edgex-foundry/util.go b/pkg/yurtiotdock/clients/edgex-foundry/v2/util.go similarity index 99% rename from pkg/yurtiotdock/clients/edgex-foundry/util.go rename to pkg/yurtiotdock/clients/edgex-foundry/v2/util.go index 8fbf276ab30..40753cda5bd 100644 --- a/pkg/yurtiotdock/clients/edgex-foundry/util.go +++ b/pkg/yurtiotdock/clients/edgex-foundry/v2/util.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package edgex_foundry +package v2 import ( "fmt" diff --git a/pkg/yurtiotdock/clients/interface.go b/pkg/yurtiotdock/clients/interface.go index 93ffc3574bd..92f2839d27e 100644 --- a/pkg/yurtiotdock/clients/interface.go +++ b/pkg/yurtiotdock/clients/interface.go @@ -91,3 +91,10 @@ type DeviceProfileInterface interface { Get(ctx context.Context, name string, options GetOptions) (*iotv1alpha1.DeviceProfile, error) List(ctx context.Context, options ListOptions) ([]iotv1alpha1.DeviceProfile, error) } + +// IoTDock defines the interfaces which used to create deviceclient, deviceprofileclient, deviceserviceclient +type IoTDock interface { + CreateDeviceClient() (DeviceInterface, error) + CreateDeviceProfileClient() (DeviceProfileInterface, error) + CreateDeviceServiceClient() (DeviceServiceInterface, error) +} diff --git a/pkg/yurtiotdock/controllers/device_controller.go b/pkg/yurtiotdock/controllers/device_controller.go index 662feb3632d..444759de006 100644 --- a/pkg/yurtiotdock/controllers/device_controller.go +++ b/pkg/yurtiotdock/controllers/device_controller.go @@ -34,7 +34,7 @@ import ( "github.com/openyurtio/openyurt/cmd/yurt-iot-dock/app/options" iotv1alpha1 "github.com/openyurtio/openyurt/pkg/apis/iot/v1alpha1" "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients" - edgexCli "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients/edgex-foundry" + edgexobj "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients/edgex-foundry" util "github.com/openyurtio/openyurt/pkg/yurtiotdock/controllers/util" ) @@ -109,8 +109,12 @@ func (r *DeviceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr } // SetupWithManager sets up the controller with the Manager. -func (r *DeviceReconciler) SetupWithManager(mgr ctrl.Manager, opts *options.YurtIoTDockOptions) error { - r.deviceCli = edgexCli.NewEdgexDeviceClient(opts.CoreMetadataAddr, opts.CoreCommandAddr) +func (r *DeviceReconciler) SetupWithManager(mgr ctrl.Manager, opts *options.YurtIoTDockOptions, edgexdock *edgexobj.EdgexDock) error { + deviceclient, err := edgexdock.CreateDeviceClient() + if err != nil { + return err + } + r.deviceCli = deviceclient r.NodePool = opts.Nodepool r.Namespace = opts.Namespace diff --git a/pkg/yurtiotdock/controllers/device_syncer.go b/pkg/yurtiotdock/controllers/device_syncer.go index 501ba6101dc..64e30c8dc36 100644 --- a/pkg/yurtiotdock/controllers/device_syncer.go +++ b/pkg/yurtiotdock/controllers/device_syncer.go @@ -29,7 +29,7 @@ import ( "github.com/openyurtio/openyurt/cmd/yurt-iot-dock/app/options" iotv1alpha1 "github.com/openyurtio/openyurt/pkg/apis/iot/v1alpha1" edgeCli "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients" - efCli "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients/edgex-foundry" + edgexobj "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients/edgex-foundry" "github.com/openyurtio/openyurt/pkg/yurtiotdock/controllers/util" ) @@ -46,10 +46,14 @@ type DeviceSyncer struct { } // NewDeviceSyncer initialize a New DeviceSyncer -func NewDeviceSyncer(client client.Client, opts *options.YurtIoTDockOptions) (DeviceSyncer, error) { +func NewDeviceSyncer(client client.Client, opts *options.YurtIoTDockOptions, edgexdock *edgexobj.EdgexDock) (DeviceSyncer, error) { + devicelient, err := edgexdock.CreateDeviceClient() + if err != nil { + return DeviceSyncer{}, err + } return DeviceSyncer{ syncPeriod: time.Duration(opts.EdgeSyncPeriod) * time.Second, - deviceCli: efCli.NewEdgexDeviceClient(opts.CoreMetadataAddr, opts.CoreCommandAddr), + deviceCli: devicelient, Client: client, NodePool: opts.Nodepool, Namespace: opts.Namespace, diff --git a/pkg/yurtiotdock/controllers/deviceprofile_controller.go b/pkg/yurtiotdock/controllers/deviceprofile_controller.go index 459f39156b3..3ea4f321918 100644 --- a/pkg/yurtiotdock/controllers/deviceprofile_controller.go +++ b/pkg/yurtiotdock/controllers/deviceprofile_controller.go @@ -32,7 +32,7 @@ import ( "github.com/openyurtio/openyurt/cmd/yurt-iot-dock/app/options" iotv1alpha1 "github.com/openyurtio/openyurt/pkg/apis/iot/v1alpha1" "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients" - edgexclis "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients/edgex-foundry" + edgexobj "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients/edgex-foundry" "github.com/openyurtio/openyurt/pkg/yurtiotdock/controllers/util" ) @@ -87,8 +87,12 @@ func (r *DeviceProfileReconciler) Reconcile(ctx context.Context, req ctrl.Reques } // SetupWithManager sets up the controller with the Manager. -func (r *DeviceProfileReconciler) SetupWithManager(mgr ctrl.Manager, opts *options.YurtIoTDockOptions) error { - r.edgeClient = edgexclis.NewEdgexDeviceProfile(opts.CoreMetadataAddr) +func (r *DeviceProfileReconciler) SetupWithManager(mgr ctrl.Manager, opts *options.YurtIoTDockOptions, edgexdock *edgexobj.EdgexDock) error { + deviceprofileclient, err := edgexdock.CreateDeviceProfileClient() + if err != nil { + return err + } + r.edgeClient = deviceprofileclient r.NodePool = opts.Nodepool r.Namespace = opts.Namespace diff --git a/pkg/yurtiotdock/controllers/deviceprofile_syncer.go b/pkg/yurtiotdock/controllers/deviceprofile_syncer.go index 72d67729b47..5ae3390f8e5 100644 --- a/pkg/yurtiotdock/controllers/deviceprofile_syncer.go +++ b/pkg/yurtiotdock/controllers/deviceprofile_syncer.go @@ -29,7 +29,7 @@ import ( "github.com/openyurtio/openyurt/cmd/yurt-iot-dock/app/options" iotv1alpha1 "github.com/openyurtio/openyurt/pkg/apis/iot/v1alpha1" devcli "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients" - edgexclis "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients/edgex-foundry" + edgexobj "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients/edgex-foundry" "github.com/openyurtio/openyurt/pkg/yurtiotdock/controllers/util" ) @@ -45,10 +45,14 @@ type DeviceProfileSyncer struct { } // NewDeviceProfileSyncer initialize a New DeviceProfileSyncer -func NewDeviceProfileSyncer(client client.Client, opts *options.YurtIoTDockOptions) (DeviceProfileSyncer, error) { +func NewDeviceProfileSyncer(client client.Client, opts *options.YurtIoTDockOptions, edgexdock *edgexobj.EdgexDock) (DeviceProfileSyncer, error) { + edgeclient, err := edgexdock.CreateDeviceProfileClient() + if err != nil { + return DeviceProfileSyncer{}, err + } return DeviceProfileSyncer{ syncPeriod: time.Duration(opts.EdgeSyncPeriod) * time.Second, - edgeClient: edgexclis.NewEdgexDeviceProfile(opts.CoreMetadataAddr), + edgeClient: edgeclient, Client: client, NodePool: opts.Nodepool, Namespace: opts.Namespace, diff --git a/pkg/yurtiotdock/controllers/deviceservice_controller.go b/pkg/yurtiotdock/controllers/deviceservice_controller.go index b924d789c5c..c277220f564 100644 --- a/pkg/yurtiotdock/controllers/deviceservice_controller.go +++ b/pkg/yurtiotdock/controllers/deviceservice_controller.go @@ -33,7 +33,7 @@ import ( "github.com/openyurtio/openyurt/cmd/yurt-iot-dock/app/options" iotv1alpha1 "github.com/openyurtio/openyurt/pkg/apis/iot/v1alpha1" "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients" - edgexCli "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients/edgex-foundry" + edgexobj "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients/edgex-foundry" util "github.com/openyurtio/openyurt/pkg/yurtiotdock/controllers/util" ) @@ -107,8 +107,12 @@ func (r *DeviceServiceReconciler) Reconcile(ctx context.Context, req ctrl.Reques } // SetupWithManager sets up the controller with the Manager. -func (r *DeviceServiceReconciler) SetupWithManager(mgr ctrl.Manager, opts *options.YurtIoTDockOptions) error { - r.deviceServiceCli = edgexCli.NewEdgexDeviceServiceClient(opts.CoreMetadataAddr) +func (r *DeviceServiceReconciler) SetupWithManager(mgr ctrl.Manager, opts *options.YurtIoTDockOptions, edgexdock *edgexobj.EdgexDock) error { + deviceserviceclient, err := edgexdock.CreateDeviceServiceClient() + if err != nil { + return err + } + r.deviceServiceCli = deviceserviceclient r.NodePool = opts.Nodepool r.Namespace = opts.Namespace diff --git a/pkg/yurtiotdock/controllers/deviceservice_syncer.go b/pkg/yurtiotdock/controllers/deviceservice_syncer.go index 78949c55069..30a6e59b5c4 100644 --- a/pkg/yurtiotdock/controllers/deviceservice_syncer.go +++ b/pkg/yurtiotdock/controllers/deviceservice_syncer.go @@ -28,7 +28,7 @@ import ( "github.com/openyurtio/openyurt/cmd/yurt-iot-dock/app/options" iotv1alpha1 "github.com/openyurtio/openyurt/pkg/apis/iot/v1alpha1" iotcli "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients" - edgexCli "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients/edgex-foundry" + edgexobj "github.com/openyurtio/openyurt/pkg/yurtiotdock/clients/edgex-foundry" "github.com/openyurtio/openyurt/pkg/yurtiotdock/controllers/util" ) @@ -42,10 +42,14 @@ type DeviceServiceSyncer struct { Namespace string } -func NewDeviceServiceSyncer(client client.Client, opts *options.YurtIoTDockOptions) (DeviceServiceSyncer, error) { +func NewDeviceServiceSyncer(client client.Client, opts *options.YurtIoTDockOptions, edgexdock *edgexobj.EdgexDock) (DeviceServiceSyncer, error) { + deviceserviceclient, err := edgexdock.CreateDeviceServiceClient() + if err != nil { + return DeviceServiceSyncer{}, err + } return DeviceServiceSyncer{ syncPeriod: time.Duration(opts.EdgeSyncPeriod) * time.Second, - deviceServiceCli: edgexCli.NewEdgexDeviceServiceClient(opts.CoreMetadataAddr), + deviceServiceCli: deviceserviceclient, Client: client, NodePool: opts.Nodepool, Namespace: opts.Namespace, diff --git a/pkg/yurtmanager/controller/platformadmin/iotdock.go b/pkg/yurtmanager/controller/platformadmin/iotdock.go index a1f98c1cde1..15ffaffd7b9 100644 --- a/pkg/yurtmanager/controller/platformadmin/iotdock.go +++ b/pkg/yurtmanager/controller/platformadmin/iotdock.go @@ -76,6 +76,7 @@ func newYurtIoTDockComponent(platformAdmin *iotv1alpha2.PlatformAdmin, platformA "--metrics-bind-address=127.0.0.1:8080", "--leader-elect=false", fmt.Sprintf("--namespace=%s", ns), + fmt.Sprintf("--version=%s", platformAdmin.Spec.Version), }, LivenessProbe: &corev1.Probe{ InitialDelaySeconds: 15,