Skip to content

Commit

Permalink
feat: establish the component mechanism of the iot system (openyurtio…
Browse files Browse the repository at this point in the history
…#1650)

* feat: extend manifest to support the component mechanism

Signed-off-by: LavenderQAQ <lavenderqaq.cs@gmail.com>

* feat: read the manifest file when the yurt-manager is started

Signed-off-by: LavenderQAQ <lavenderqaq.cs@gmail.com>

* feat: modified reconciler to support dynamic component mechanism

Signed-off-by: LavenderQAQ <lavenderqaq.cs@gmail.com>

* fix: add common-config-bootstrapper component in minnesota version

Signed-off-by: LavenderQAQ <lavenderqaq.cs@gmail.com>

* rebase: move code to new yurtmanager location

Signed-off-by: LavenderQAQ <lavenderqaq.cs@gmail.com>

---------

Signed-off-by: LavenderQAQ <lavenderqaq.cs@gmail.com>
  • Loading branch information
LavenderQAQ authored Aug 21, 2023
1 parent d15078f commit b6f2ec0
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 72 deletions.
2 changes: 0 additions & 2 deletions charts/yurt-manager/crds/iot.openyurt.io_platformadmins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8421,8 +8421,6 @@ spec:
items:
description: Component defines the components of EdgeX
properties:
image:
type: string
name:
type: string
required:
Expand Down
3 changes: 0 additions & 3 deletions pkg/apis/iot/v1alpha2/platformadmin_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ type PlatformAdminConditionSeverity string
// Component defines the components of EdgeX
type Component struct {
Name string `json:"name"`

// +optional
Image string `json:"image,omitempty"`
}

// PlatformAdminSpec defines the desired state of PlatformAdmin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,40 @@ updated: false
count: 6
latestVersion: minnesota
versions:
- kamakura
- jakarta
- levski
- minnesota
- ireland
- hanoi
- name: kamakura
requiredComponents:
- edgex-core-command
- edgex-core-consul
- edgex-core-metadata
- edgex-redis
- name: jakarta
requiredComponents:
- edgex-core-command
- edgex-core-consul
- edgex-core-metadata
- edgex-redis
- name: levski
requiredComponents:
- edgex-core-command
- edgex-core-consul
- edgex-core-metadata
- edgex-redis
- name: minnesota
requiredComponents:
- edgex-core-command
- edgex-core-consul
- edgex-core-metadata
- edgex-redis
- edgex-core-common-config-bootstrapper
- name: ireland
requiredComponents:
- edgex-core-command
- edgex-core-consul
- edgex-core-metadata
- edgex-redis
- name: hanoi
requiredComponents:
- edgex-core-command
- edgex-core-consul
- edgex-core-metadata
- edgex-redis
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,22 @@ import (
"encoding/json"
"path/filepath"

"gopkg.in/yaml.v3"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/klog/v2"
)

var (
//go:embed EdgeXConfig
EdgeXFS embed.FS
folder = "EdgeXConfig/"
ManifestPath = filepath.Join(folder, "manifest.yaml")
securityFile = filepath.Join(folder, "config.json")
nosectyFile = filepath.Join(folder, "config-nosecty.json")
)

type EdgeXConfig struct {
Versions []*Version `yaml:"versions,omitempty" json:"versions,omitempty"`
}
Expand All @@ -42,20 +53,42 @@ type Component struct {
Deployment *appsv1.DeploymentSpec `yaml:"deployment,omitempty" json:"deployment,omitempty"`
}

var (
//go:embed EdgeXConfig
EdgeXFS embed.FS
ManifestPath = filepath.Join(folder, "manifest.yaml")
)
type Manifest struct {
Updated string `yaml:"updated"`
Count int `yaml:"count"`
LatestVersion string `yaml:"latestVersion"`
Versions []ManifestVersion `yaml:"versions"`
}

var (
folder = "EdgeXConfig/"
securityFile = filepath.Join(folder, "config.json")
nosectyFile = filepath.Join(folder, "config-nosecty.json")
)
type ManifestVersion struct {
Name string `yaml:"name"`
RequiredComponents []string `yaml:"requiredComponents"`
}

func ExtractVersionsName(manifest *Manifest) sets.String {
versionsNameSet := sets.NewString()
for _, version := range manifest.Versions {
versionsNameSet.Insert(version.Name)
}
return versionsNameSet
}

func ExtractRequiredComponentsName(manifest *Manifest, versionName string) sets.String {
requiredComponentSet := sets.NewString()
for _, version := range manifest.Versions {
if version.Name == versionName {
for _, c := range version.RequiredComponents {
requiredComponentSet.Insert(c)
}
break
}
}
return requiredComponentSet
}

// PlatformAdminControllerConfiguration contains elements describing PlatformAdminController.
type PlatformAdminControllerConfiguration struct {
Manifest Manifest
SecurityComponents map[string][]*Component
NoSectyComponents map[string][]*Component
SecurityConfigMaps map[string][]corev1.ConfigMap
Expand All @@ -67,13 +100,20 @@ func NewPlatformAdminControllerConfiguration() *PlatformAdminControllerConfigura
edgexconfig = EdgeXConfig{}
edgexnosectyconfig = EdgeXConfig{}
conf = PlatformAdminControllerConfiguration{
Manifest: Manifest{},
SecurityComponents: make(map[string][]*Component),
NoSectyComponents: make(map[string][]*Component),
SecurityConfigMaps: make(map[string][]corev1.ConfigMap),
NoSectyConfigMaps: make(map[string][]corev1.ConfigMap),
}
)

// Read the EdgeX configuration file
manifestContent, err := EdgeXFS.ReadFile(ManifestPath)
if err != nil {
klog.Errorf("File to open the embed EdgeX manifest file: %v", err)
return nil
}
securityContent, err := EdgeXFS.ReadFile(securityFile)
if err != nil {
klog.Errorf("Fail to open the embed EdgeX security config: %v", err)
Expand All @@ -85,6 +125,11 @@ func NewPlatformAdminControllerConfiguration() *PlatformAdminControllerConfigura
return nil
}

// Unmarshal the EdgeX configuration file
if err := yaml.Unmarshal(manifestContent, &conf.Manifest); err != nil {
klog.Errorf("Error manifest EdgeX configuration file: %v", err)
return nil
}
if err = json.Unmarshal(securityContent, &edgexconfig); err != nil {
klog.Errorf("Fail to unmarshal the embed EdgeX security config: %v", err)
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
utils "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/platformadmin/utils"
)

// NewYurtIoTDockComponent initialize the configuration of yurt-iot-dock component
func NewYurtIoTDockComponent(platformAdmin *iotv1alpha2.PlatformAdmin, platformAdminFramework *PlatformAdminFramework) (*config.Component, error) {
// newYurtIoTDockComponent initialize the configuration of yurt-iot-dock component
func newYurtIoTDockComponent(platformAdmin *iotv1alpha2.PlatformAdmin, platformAdminFramework *PlatformAdminFramework) (*config.Component, error) {
var yurtIotDockComponent config.Component

// If the configuration of the yurt-iot-dock component that customized in the platformAdminFramework
Expand Down
Loading

0 comments on commit b6f2ec0

Please sign in to comment.