diff --git a/charts/yurt-manager/crds/iot.openyurt.io_platformadmins.yaml b/charts/yurt-manager/crds/iot.openyurt.io_platformadmins.yaml index 9b71d04091b..edb4df7fd76 100644 --- a/charts/yurt-manager/crds/iot.openyurt.io_platformadmins.yaml +++ b/charts/yurt-manager/crds/iot.openyurt.io_platformadmins.yaml @@ -8421,8 +8421,6 @@ spec: items: description: Component defines the components of EdgeX properties: - image: - type: string name: type: string required: diff --git a/pkg/apis/iot/v1alpha2/platformadmin_types.go b/pkg/apis/iot/v1alpha2/platformadmin_types.go index 92114e58cde..a9be10a55aa 100644 --- a/pkg/apis/iot/v1alpha2/platformadmin_types.go +++ b/pkg/apis/iot/v1alpha2/platformadmin_types.go @@ -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 diff --git a/pkg/yurtmanager/controller/platformadmin/config/EdgeXConfig/manifest.yaml b/pkg/yurtmanager/controller/platformadmin/config/EdgeXConfig/manifest.yaml index a5f1096515f..cf5bf7c3acb 100644 --- a/pkg/yurtmanager/controller/platformadmin/config/EdgeXConfig/manifest.yaml +++ b/pkg/yurtmanager/controller/platformadmin/config/EdgeXConfig/manifest.yaml @@ -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 diff --git a/pkg/yurtmanager/controller/platformadmin/config/types.go b/pkg/yurtmanager/controller/platformadmin/config/config.go similarity index 70% rename from pkg/yurtmanager/controller/platformadmin/config/types.go rename to pkg/yurtmanager/controller/platformadmin/config/config.go index e3727da1a9c..fa0cf36fbec 100644 --- a/pkg/yurtmanager/controller/platformadmin/config/types.go +++ b/pkg/yurtmanager/controller/platformadmin/config/config.go @@ -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"` } @@ -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 @@ -67,6 +100,7 @@ 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), @@ -74,6 +108,12 @@ func NewPlatformAdminControllerConfiguration() *PlatformAdminControllerConfigura } ) + // 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) @@ -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 diff --git a/pkg/yurtmanager/controller/platformadmin/util.go b/pkg/yurtmanager/controller/platformadmin/iotdock.go similarity index 96% rename from pkg/yurtmanager/controller/platformadmin/util.go rename to pkg/yurtmanager/controller/platformadmin/iotdock.go index 9975c683083..a1f98c1cde1 100644 --- a/pkg/yurtmanager/controller/platformadmin/util.go +++ b/pkg/yurtmanager/controller/platformadmin/iotdock.go @@ -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 diff --git a/pkg/yurtmanager/controller/platformadmin/platformadmin_controller.go b/pkg/yurtmanager/controller/platformadmin/platformadmin_controller.go index c75a161d878..46686d11dab 100644 --- a/pkg/yurtmanager/controller/platformadmin/platformadmin_controller.go +++ b/pkg/yurtmanager/controller/platformadmin/platformadmin_controller.go @@ -31,6 +31,7 @@ import ( kjson "k8s.io/apimachinery/pkg/runtime/serializer/json" "k8s.io/apimachinery/pkg/types" kerrors "k8s.io/apimachinery/pkg/util/errors" + "k8s.io/apimachinery/pkg/util/sets" "k8s.io/client-go/tools/record" "k8s.io/klog/v2" "k8s.io/kubectl/pkg/scheme" @@ -244,7 +245,7 @@ func (r *ReconcilePlatformAdmin) reconcileDelete(ctx context.Context, platformAd klog.V(4).Infof(Format("ReconcileDelete PlatformAdmin %s/%s", platformAdmin.Namespace, platformAdmin.Name)) yas := &appsv1alpha1.YurtAppSet{} - platformAdminFramework, err := r.syncFramework(ctx, platformAdmin) + platformAdminFramework, err := r.readFramework(ctx, platformAdmin) if err != nil { return reconcile.Result{}, errors.Wrapf(err, "unexpected error while synchronizing customize framework for %s", platformAdmin.Namespace+"/"+platformAdmin.Name) } @@ -300,7 +301,7 @@ func (r *ReconcilePlatformAdmin) reconcileNormal(ctx context.Context, platformAd // Note that this configmap is different from the one below, which is used to customize the edgex framework // Sync configmap of edgex confiruation during initialization // This framework pointer is needed to synchronize user-modified edgex configurations - platformAdminFramework, err := r.syncFramework(ctx, platformAdmin) + platformAdminFramework, err := r.readFramework(ctx, platformAdmin) if err != nil { return reconcile.Result{}, errors.Wrapf(err, "unexpected error while synchronizing customize framework for %s", platformAdmin.Namespace+"/"+platformAdmin.Name) } @@ -374,38 +375,48 @@ func (r *ReconcilePlatformAdmin) reconcileConfigmap(ctx context.Context, platfor } func (r *ReconcilePlatformAdmin) reconcileComponent(ctx context.Context, platformAdmin *iotv1alpha2.PlatformAdmin, platformAdminStatus *iotv1alpha2.PlatformAdminStatus, platformAdminFramework *PlatformAdminFramework) (bool, error) { - var desireComponents []*config.Component - needComponents := make(map[string]struct{}) - var readyComponent int32 = 0 - - desireComponents = platformAdminFramework.Components + var ( + readyComponent int32 = 0 + needComponents = make(map[string]struct{}) + ) + // TODO: The additional deployment and service of component is no longer supported in v1beta1. additionalComponents, err := annotationToComponent(platformAdmin.Annotations) if err != nil { return false, err } - desireComponents = append(desireComponents, additionalComponents...) - //TODO: handle PlatformAdmin.Spec.Components + // Users can configure components in the framework, + // or they can choose to configure optional components directly in spec, + // which combines the two approaches and tells the controller if the framework needs to be updated. + needWriteFramework := r.calculateDesiredComponents(platformAdmin, platformAdminFramework, additionalComponents) defer func() { platformAdminStatus.ReadyComponentNum = readyComponent - platformAdminStatus.UnreadyComponentNum = int32(len(desireComponents)) - readyComponent + platformAdminStatus.UnreadyComponentNum = int32(len(platformAdminFramework.Components)) - readyComponent }() - for _, desireComponent := range desireComponents { + // The component in spec that does not exist in the framework, so the framework needs to be updated. + if needWriteFramework { + if err := r.writeFramework(ctx, platformAdmin, platformAdminFramework); err != nil { + return false, err + } + } + + // Update the yurtappsets based on the desired components + for _, desiredComponent := range platformAdminFramework.Components { readyService := false readyDeployment := false - needComponents[desireComponent.Name] = struct{}{} + needComponents[desiredComponent.Name] = struct{}{} - if _, err := r.handleService(ctx, platformAdmin, desireComponent); err != nil { + if _, err := r.handleService(ctx, platformAdmin, desiredComponent); err != nil { return false, err } readyService = true yas := &appsv1alpha1.YurtAppSet{ ObjectMeta: metav1.ObjectMeta{ - Name: desireComponent.Name, + Name: desiredComponent.Name, Namespace: platformAdmin.Namespace, }, } @@ -414,13 +425,13 @@ func (r *ReconcilePlatformAdmin) reconcileComponent(ctx context.Context, platfor ctx, types.NamespacedName{ Namespace: platformAdmin.Namespace, - Name: desireComponent.Name}, + Name: desiredComponent.Name}, yas) if err != nil { if !apierrors.IsNotFound(err) { return false, err } - _, err = r.handleYurtAppSet(ctx, platformAdmin, desireComponent) + _, err = r.handleYurtAppSet(ctx, platformAdmin, desiredComponent) if err != nil { return false, err } @@ -428,7 +439,7 @@ func (r *ReconcilePlatformAdmin) reconcileComponent(ctx context.Context, platfor oldYas := yas.DeepCopy() // Refresh the YurtAppSet according to the user-defined configuration - yas.Spec.WorkloadTemplate.DeploymentTemplate.Spec = *desireComponent.Deployment + yas.Spec.WorkloadTemplate.DeploymentTemplate.Spec = *desiredComponent.Deployment if _, ok := yas.Status.PoolReplicas[platformAdmin.Spec.PoolName]; ok { if yas.Status.ReadyReplicas == yas.Status.Replicas { @@ -488,7 +499,7 @@ func (r *ReconcilePlatformAdmin) reconcileComponent(ctx context.Context, platfor } } - return readyComponent == int32(len(desireComponents)), nil + return readyComponent == int32(len(platformAdminFramework.Components)), nil } func (r *ReconcilePlatformAdmin) handleService(ctx context.Context, platformAdmin *iotv1alpha2.PlatformAdmin, component *config.Component) (*corev1.Service, error) { @@ -648,7 +659,7 @@ func annotationToComponent(annotation map[string]string) ([]*config.Component, e return components, nil } -func (r *ReconcilePlatformAdmin) syncFramework(ctx context.Context, platformAdmin *iotv1alpha2.PlatformAdmin) (*PlatformAdminFramework, error) { +func (r *ReconcilePlatformAdmin) readFramework(ctx context.Context, platformAdmin *iotv1alpha2.PlatformAdmin) (*PlatformAdminFramework, error) { klog.V(6).Infof(Format("Synchronize the customize framework information for PlatformAdmin %s/%s", platformAdmin.Namespace, platformAdmin.Name)) // Try to get the configmap that represents the framework @@ -715,6 +726,43 @@ func (r *ReconcilePlatformAdmin) syncFramework(ctx context.Context, platformAdmi return platformAdminFramework, nil } +func (r *ReconcilePlatformAdmin) writeFramework(ctx context.Context, platformAdmin *iotv1alpha2.PlatformAdmin, platformAdminFramework *PlatformAdminFramework) error { + // For better serialization, the serialization method of the Kubernetes runtime library is used + data, err := runtime.Encode(r.yamlSerializer, platformAdminFramework) + if err != nil { + klog.Errorf(Format("Failed to marshal framework for PlatformAdmin %s/%s", platformAdmin.Namespace, platformAdmin.Name)) + return err + } + + // Check if the configmap that represents framework is found + cm := &corev1.ConfigMap{} + if err := r.Get(ctx, types.NamespacedName{Namespace: platformAdmin.Namespace, Name: platformAdminFramework.name}, cm); err != nil { + if apierrors.IsNotFound(err) { + // If the configmap that represents framework is not found, + // need to create it by standard configuration + err = r.initFramework(ctx, platformAdmin, platformAdminFramework) + if err != nil { + klog.Errorf(Format("Init framework for PlatformAdmin %s/%s error %v", platformAdmin.Namespace, platformAdmin.Name, err)) + return err + } + return nil + } + klog.Errorf(Format("Get framework for PlatformAdmin %s/%s error %v", platformAdmin.Namespace, platformAdmin.Name, err)) + return err + } + + // Creates configmap on behalf of the framework, which is called only once upon creation + _, err = controllerutil.CreateOrUpdate(ctx, r.Client, cm, func() error { + cm.Data["framework"] = string(data) + return controllerutil.SetOwnerReference(platformAdmin, cm, r.Scheme()) + }) + if err != nil { + klog.Errorf(Format("Failed to write framework configmap for PlatformAdmin %s/%s", platformAdmin.Namespace, platformAdmin.Name)) + return err + } + return nil +} + // initFramework initializes the framework information for PlatformAdmin func (r *ReconcilePlatformAdmin) initFramework(ctx context.Context, platformAdmin *iotv1alpha2.PlatformAdmin, platformAdminFramework *PlatformAdminFramework) error { klog.V(6).Infof(Format("Initializes the standard framework information for PlatformAdmin %s/%s", platformAdmin.Namespace, platformAdmin.Name)) @@ -723,13 +771,13 @@ func (r *ReconcilePlatformAdmin) initFramework(ctx context.Context, platformAdmi platformAdminFramework.security = platformAdmin.Spec.Security if platformAdminFramework.security { platformAdminFramework.ConfigMaps = r.Configration.SecurityConfigMaps[platformAdmin.Spec.Version] - platformAdminFramework.Components = r.Configration.SecurityComponents[platformAdmin.Spec.Version] + r.calculateDesiredComponents(platformAdmin, platformAdminFramework, nil) } else { platformAdminFramework.ConfigMaps = r.Configration.NoSectyConfigMaps[platformAdmin.Spec.Version] - platformAdminFramework.Components = r.Configration.NoSectyComponents[platformAdmin.Spec.Version] + r.calculateDesiredComponents(platformAdmin, platformAdminFramework, nil) } - yurtIotDock, err := NewYurtIoTDockComponent(platformAdmin, platformAdminFramework) + yurtIotDock, err := newYurtIoTDockComponent(platformAdmin, platformAdminFramework) if err != nil { return err } @@ -761,8 +809,65 @@ func (r *ReconcilePlatformAdmin) initFramework(ctx context.Context, platformAdmi return controllerutil.SetOwnerReference(platformAdmin, cm, r.Scheme()) }) if err != nil { - klog.Errorf(Format("Failed to create or update framework configmap for PlatformAdmin %s/%s", platformAdmin.Namespace, platformAdmin.Name)) + klog.Errorf(Format("Failed to init framework configmap for PlatformAdmin %s/%s", platformAdmin.Namespace, platformAdmin.Name)) return err } return nil } + +// calculateDesiredComponents calculates the components that need to be added and determines whether the framework needs to be rewritten +func (r *ReconcilePlatformAdmin) calculateDesiredComponents(platformAdmin *iotv1alpha2.PlatformAdmin, platformAdminFramework *PlatformAdminFramework, additionalComponents []*config.Component) bool { + needWriteFramework := false + desiredComponents := []*config.Component{} + + // Find all the required components from spec and manifest + requiredComponentSet := config.ExtractRequiredComponentsName(&r.Configration.Manifest, platformAdmin.Spec.Version) + for _, component := range platformAdmin.Spec.Components { + requiredComponentSet.Insert(component.Name) + } + + // Find all existing components and filter removed components + frameworkComponentSet := sets.NewString() + for _, component := range platformAdminFramework.Components { + if requiredComponentSet.Has(component.Name) { + frameworkComponentSet.Insert(component.Name) + desiredComponents = append(desiredComponents, component) + } else { + needWriteFramework = true + } + } + + // Calculate all the components that need to be added or removed and determine whether need to rewrite the framework + addedComponentSet := sets.NewString() + for _, componentName := range requiredComponentSet.List() { + if !frameworkComponentSet.Has(componentName) { + addedComponentSet.Insert(componentName) + needWriteFramework = true + } + } + + // If a component needs to be added, + // check whether the corresponding template exists in the standard configuration library + if platformAdmin.Spec.Security { + for _, component := range r.Configration.SecurityComponents[platformAdmin.Spec.Version] { + if addedComponentSet.Has(component.Name) { + desiredComponents = append(desiredComponents, component) + } + } + } else { + for _, component := range r.Configration.NoSectyComponents[platformAdmin.Spec.Version] { + if addedComponentSet.Has(component.Name) { + desiredComponents = append(desiredComponents, component) + } + } + } + + // TODO: In order to be compatible with v1alpha1, we need to add the component from annotation translation here + if additionalComponents != nil { + desiredComponents = append(desiredComponents, additionalComponents...) + } + + platformAdminFramework.Components = desiredComponents + + return needWriteFramework +} diff --git a/pkg/yurtmanager/webhook/platformadmin/v1alpha1/platformadmin_handler.go b/pkg/yurtmanager/webhook/platformadmin/v1alpha1/platformadmin_handler.go index 7dc5b2e6170..670e9234f4d 100644 --- a/pkg/yurtmanager/webhook/platformadmin/v1alpha1/platformadmin_handler.go +++ b/pkg/yurtmanager/webhook/platformadmin/v1alpha1/platformadmin_handler.go @@ -26,16 +26,9 @@ import ( "github.com/openyurtio/openyurt/pkg/apis/iot/v1alpha1" "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/platformadmin/config" - "github.com/openyurtio/openyurt/pkg/yurtmanager/webhook/util" + webhookutil "github.com/openyurtio/openyurt/pkg/yurtmanager/webhook/util" ) -type Manifest struct { - Updated string `yaml:"updated"` - Count int `yaml:"count"` - LatestVersion string `yaml:"latestVersion"` - Versions []string `yaml:"versions"` -} - // SetupWebhookWithManager sets up Cluster webhooks. func (webhook *PlatformAdminHandler) SetupWebhookWithManager(mgr ctrl.Manager) (string, string, error) { // init @@ -50,8 +43,8 @@ func (webhook *PlatformAdminHandler) SetupWebhookWithManager(mgr ctrl.Manager) ( return "", "", err } - return util.GenerateMutatePath(gvk), - util.GenerateValidatePath(gvk), + return webhookutil.GenerateMutatePath(gvk), + webhookutil.GenerateValidatePath(gvk), ctrl.NewWebhookManagedBy(mgr). For(&v1alpha1.PlatformAdmin{}). WithDefaulter(webhook). @@ -60,7 +53,7 @@ func (webhook *PlatformAdminHandler) SetupWebhookWithManager(mgr ctrl.Manager) ( } func (webhook *PlatformAdminHandler) initManifest() error { - webhook.Manifests = &Manifest{} + webhook.Manifests = &config.Manifest{} manifestContent, err := config.EdgeXFS.ReadFile(config.ManifestPath) if err != nil { @@ -79,7 +72,7 @@ func (webhook *PlatformAdminHandler) initManifest() error { // Cluster implements a validating and defaulting webhook for Cluster. type PlatformAdminHandler struct { Client client.Client - Manifests *Manifest + Manifests *config.Manifest } var _ webhook.CustomDefaulter = &PlatformAdminHandler{} diff --git a/pkg/yurtmanager/webhook/platformadmin/v1alpha2/platformadmin_handler.go b/pkg/yurtmanager/webhook/platformadmin/v1alpha2/platformadmin_handler.go index aa707e3e879..547e9149385 100644 --- a/pkg/yurtmanager/webhook/platformadmin/v1alpha2/platformadmin_handler.go +++ b/pkg/yurtmanager/webhook/platformadmin/v1alpha2/platformadmin_handler.go @@ -26,16 +26,9 @@ import ( "github.com/openyurtio/openyurt/pkg/apis/iot/v1alpha2" "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/platformadmin/config" - "github.com/openyurtio/openyurt/pkg/yurtmanager/webhook/util" + webhookutil "github.com/openyurtio/openyurt/pkg/yurtmanager/webhook/util" ) -type Manifest struct { - Updated string `yaml:"updated"` - Count int `yaml:"count"` - LatestVersion string `yaml:"latestVersion"` - Versions []string `yaml:"versions"` -} - // SetupWebhookWithManager sets up Cluster webhooks. func (webhook *PlatformAdminHandler) SetupWebhookWithManager(mgr ctrl.Manager) (string, string, error) { // init @@ -50,8 +43,8 @@ func (webhook *PlatformAdminHandler) SetupWebhookWithManager(mgr ctrl.Manager) ( return "", "", err } - return util.GenerateMutatePath(gvk), - util.GenerateValidatePath(gvk), + return webhookutil.GenerateMutatePath(gvk), + webhookutil.GenerateValidatePath(gvk), ctrl.NewWebhookManagedBy(mgr). For(&v1alpha2.PlatformAdmin{}). WithDefaulter(webhook). @@ -60,7 +53,7 @@ func (webhook *PlatformAdminHandler) SetupWebhookWithManager(mgr ctrl.Manager) ( } func (webhook *PlatformAdminHandler) initManifest() error { - webhook.Manifests = &Manifest{} + webhook.Manifests = &config.Manifest{} manifestContent, err := config.EdgeXFS.ReadFile(config.ManifestPath) if err != nil { @@ -82,7 +75,7 @@ func (webhook *PlatformAdminHandler) initManifest() error { // Cluster implements a validating and defaulting webhook for Cluster. type PlatformAdminHandler struct { Client client.Client - Manifests *Manifest + Manifests *config.Manifest } var _ webhook.CustomDefaulter = &PlatformAdminHandler{} diff --git a/pkg/yurtmanager/webhook/platformadmin/v1alpha2/platformadmin_validation.go b/pkg/yurtmanager/webhook/platformadmin/v1alpha2/platformadmin_validation.go index 8525c13db6d..3f5d422cd46 100644 --- a/pkg/yurtmanager/webhook/platformadmin/v1alpha2/platformadmin_validation.go +++ b/pkg/yurtmanager/webhook/platformadmin/v1alpha2/platformadmin_validation.go @@ -28,6 +28,7 @@ import ( unitv1alpha1 "github.com/openyurtio/openyurt/pkg/apis/apps/v1alpha1" "github.com/openyurtio/openyurt/pkg/apis/iot/v1alpha2" + "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/platformadmin/config" util "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/platformadmin/utils" ) @@ -94,13 +95,13 @@ func (webhook *PlatformAdminHandler) validatePlatformAdminSpec(platformAdmin *v1 // Verify that it is a supported platformadmin version for _, version := range webhook.Manifests.Versions { - if platformAdmin.Spec.Version == version { + if platformAdmin.Spec.Version == version.Name { return nil } } return field.ErrorList{ - field.Invalid(field.NewPath("spec", "version"), platformAdmin.Spec.Version, "must be one of"+strings.Join(webhook.Manifests.Versions, ",")), + field.Invalid(field.NewPath("spec", "version"), platformAdmin.Spec.Version, "must be one of"+strings.Join(config.ExtractVersionsName(webhook.Manifests).List(), ",")), } }