Skip to content

Commit

Permalink
Merge pull request #79 from cl2017/dmi-chenlin-rebase
Browse files Browse the repository at this point in the history
add implement dmi interface
  • Loading branch information
kubeedge-bot authored Jan 17, 2023
2 parents 0a45c58 + 9e82f0a commit 1a172d8
Show file tree
Hide file tree
Showing 40 changed files with 4,540 additions and 180 deletions.
104 changes: 104 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
Copyright 2022 The KubeEdge Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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 config

import (
"errors"
"io/ioutil"
"os"
"strings"

"github.com/spf13/pflag"
"gopkg.in/yaml.v2"
"k8s.io/klog/v2"

"github.com/kubeedge/mappers-go/pkg/common"
)

// ErrConfigCert error of certification configuration.
var ErrConfigCert = errors.New("Both certification and private key must be provided")

var defaultConfigFile = "./config.yaml"

// Config is the common mapper configuration.
type Config struct {
GrpcServer GRPCServer `yaml:"grpc_server"`
Common Common `yaml:"common"`
DevInit DevInit `yaml:"dev_init"`
}

type GRPCServer struct {
SocketPath string `yaml:"socket_path"`
}

type Common struct {
Name string `yaml:"name"`
Version string `yaml:"version"`
APIVersion string `yaml:"api_version"`
Protocol string `yaml:"protocol"`
Address string `yaml:"address"`
EdgeCoreSock string `yaml:"edgecore_sock"`
}

type DevInit struct {
Mode string `yaml:"mode"`
Configmap string `yaml:"configmap"`
}

// Parse the configuration file. If failed, return error.
func (c *Config) Parse() error {
var level klog.Level
var loglevel string
var configFile string

pflag.StringVar(&loglevel, "v", "1", "log level")
pflag.StringVar(&configFile, "config-file", defaultConfigFile, "Config file name")

cf, err := ioutil.ReadFile(configFile)
if err != nil {
return err
}
if err = yaml.Unmarshal(cf, c); err != nil {
return err
}
if err = level.Set(loglevel); err != nil {
return err
}

switch c.DevInit.Mode {
case common.DevInitModeConfigmap:
if readFile, err := ioutil.ReadFile(c.DevInit.Configmap); err != nil {
if !os.IsNotExist(err) {
return err
}
c.DevInit.Configmap = strings.TrimSpace(os.Getenv("DEVICE_PROFILE"))
} else {
c.DevInit.Configmap = string(readFile)
}
if strings.TrimSpace(c.DevInit.Configmap) == "" {
return errors.New("can not parse configmap")
}
case common.DevInitModeRegister:
case "": // if mode is nil, use meta server mode
c.DevInit.Mode = common.DevInitModeRegister
fallthrough
default:
return errors.New("unsupported dev init mode " + c.DevInit.Mode)
}

return nil
}
12 changes: 12 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
grpc_server:
socket_path: /tmp/a.sock
common:
name: mapper-test
version: v1.0.0
api_version: v1.0.0
protocol: modbus
address: 127.0.0.1
edgecore_sock: /tmp/edgecore.sock
dev_init:
mode: register #register/configmap
configmap: /opt/kubeedge/deviceProfile.json
17 changes: 17 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package config

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestParse(t *testing.T) {
config := Config{}
if err := config.Parse(); err != nil {
t.Log(err)
t.FailNow()
}

assert.Equal(t, "/opt/kubeedge/deviceProfile.json", config.DevInit.Configmap)
}
88 changes: 73 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,39 +1,92 @@
module github.com/kubeedge/mappers-go

go 1.14
go 1.17

require (
github.com/beevik/etree v1.1.0
github.com/currantlabs/ble v0.0.0-20171229162446-c1d21c164cf8
github.com/eclipse/paho.mqtt.golang v1.3.0
github.com/go-resty/resty/v2 v2.7.0
github.com/goburrow/modbus v0.1.0
github.com/goburrow/serial v0.1.0
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/gopcua/opcua v0.1.13
github.com/gorilla/mux v1.8.0 // indirect
github.com/kubeedge/kubeedge v1.5.0
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mgutz/logxi v0.0.0-20161027140823-aebf8a7d67ab // indirect
github.com/onsi/ginkgo v1.15.0
github.com/onsi/gomega v1.10.5
github.com/gorilla/mux v1.8.0
github.com/kubeedge/kubeedge v1.12.0-beta.0
github.com/onsi/ginkgo v1.16.4
github.com/onsi/gomega v1.19.0
github.com/pkg/errors v0.9.1
github.com/sailorvii/goav v0.1.4
github.com/sailorvii/modbus v0.1.2
github.com/spf13/cobra v1.0.0
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.6.1
github.com/stretchr/testify v1.7.0
github.com/tbrandon/mbserver v0.0.0-20210320091329-a1f8ae952881
github.com/use-go/onvif v0.0.1
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb
google.golang.org/protobuf v1.25.0 // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
google.golang.org/grpc v1.47.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.19.3
k8s.io/api v0.24.1
k8s.io/apimachinery v0.24.1
k8s.io/klog v1.0.0
k8s.io/klog/v2 v2.4.0
k8s.io/klog/v2 v2.60.1
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
)

require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/elgs/gostrgen v0.0.0-20161222160715-9d61ae07eeae // indirect
github.com/emicklei/go-restful v2.9.6+incompatible // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-logr/logr v0.4.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gofrs/uuid v3.2.0+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kubeedge/viaduct v0.0.0 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mgutz/logxi v0.0.0-20161027140823-aebf8a7d67ab // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo/v2 v2.1.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/client-go v0.24.1 // indirect
k8s.io/component-base v0.22.6 // indirect
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

replace (
github.com/kubeedge/beehive v0.0.0 => github.com/kubeedge/beehive v0.0.0-20201125122335-cd19bca6e436
github.com/kubeedge/beehive v0.0.0 => github.com/kubeedge/beehive v1.7.0
github.com/kubeedge/viaduct v0.0.0 => github.com/kubeedge/viaduct v0.0.0-20201130063818-e33931917980
k8s.io/api v0.0.0 => k8s.io/api v0.19.3
k8s.io/apiextensions-apiserver v0.0.0 => k8s.io/apiextensions-apiserver v0.19.3
Expand All @@ -45,6 +98,8 @@ replace (
k8s.io/cluster-bootstrap v0.0.0 => k8s.io/cluster-bootstrap v0.19.3
k8s.io/code-generator v0.0.0 => k8s.io/code-generator v0.19.3
k8s.io/component-base v0.0.0 => k8s.io/component-base v0.19.3
k8s.io/component-helpers v0.0.0 => k8s.io/component-helpers v0.22.6
k8s.io/controller-manager v0.0.0 => k8s.io/controller-manager v0.22.6
k8s.io/cri-api v0.0.0 => k8s.io/cri-api v0.19.3
k8s.io/csi-api v0.0.0 => k8s.io/csi-api v0.19.3
k8s.io/csi-translation-lib v0.0.0 => k8s.io/csi-translation-lib v0.19.3
Expand All @@ -60,8 +115,11 @@ replace (
k8s.io/kubelet v0.0.0 => k8s.io/kubelet v0.19.3
k8s.io/legacy-cloud-providers v0.0.0 => k8s.io/legacy-cloud-providers v0.19.3
k8s.io/metrics v0.0.0 => k8s.io/metrics v0.19.3
k8s.io/mount-utils v0.0.0 => k8s.io/mount-utils v0.22.6
k8s.io/node-api v0.0.0 => k8s.io/node-api v0.19.3
k8s.io/pod-security-admission v0.0.0 => k8s.io/pod-security-admission v0.22.6
k8s.io/repo-infra v0.0.0 => k8s.io/repo-infra v0.19.3
k8s.io/sample-apiserver v0.0.0 => k8s.io/sample-apiserver v0.19.3
k8s.io/utils v0.0.0 => k8s.io/utils v0.19.3
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.0 => sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.27
)
Loading

0 comments on commit 1a172d8

Please sign in to comment.