// GetInstallPackage get install package which is all needed to enable an addon from addon registry func(r *Registry)GetInstallPackage(meta *SourceMeta, uiData *UIData)(*InstallPackage, error) { ... return GetInstallPackageFromReader(reader, meta, uiData) }
// GetInstallPackageFromReader get install package of addon from Reader, this is used to enable an addon funcGetInstallPackageFromReader(r AsyncReader, meta *SourceMeta, uiData *UIData)(*InstallPackage, error) { addonContentsReader := map[string]func(a *InstallPackage, reader AsyncReader, readPath string)error{ TemplateFileName: readTemplate, ResourcesDirName: readResFile, DefSchemaName: readDefSchemaFile, ViewDirName: readViewFile, } ptItems := ClassifyItemByPattern(meta, r)
// Read the installed data from UI metadata object to reduce network payload var addon = &InstallPackage{ Meta: uiData.Meta, Definitions: uiData.Definitions, CUEDefinitions: uiData.CUEDefinitions, Parameters: uiData.Parameters, }
for contentType, method := range addonContentsReader { items := ptItems[contentType] for _, it := range items { err := method(addon, r, r.RelativePath(it)) ... } }
// GetInstallPackageFromReader get install package of addon from Reader, this is used to enable an addon funcGetInstallPackageFromReader(r AsyncReader, meta *SourceMeta, uiData *UIData)(*InstallPackage, error) { addonContentsReader := map[string]func(a *InstallPackage, reader AsyncReader, readPath string)error{ TemplateFileName: readTemplate, ResourcesDirName: readResFile, DefSchemaName: readDefSchemaFile, ViewDirName: readViewFile, } ptItems := ClassifyItemByPattern(meta, r)
// Read the installed data from UI metadata object to reduce network payload var addon = &InstallPackage{ Meta: uiData.Meta, Definitions: uiData.Definitions, CUEDefinitions: uiData.CUEDefinitions, Parameters: uiData.Parameters, }
for contentType, method := range addonContentsReader { items := ptItems[contentType] for _, it := range items { err := method(addon, r, r.RelativePath(it)) ... } }
func(h *Installer)enableAddon(addon *InstallPackage)error { var err error h.addon = addon
if !h.skipVersionValidate { err = checkAddonVersionMeetRequired(h.ctx, addon.SystemRequirements, h.cli, h.dc) if err != nil { version := h.getAddonVersionMeetSystemRequirement(addon.Name) return VersionUnMatchError{addonName: addon.Name, err: err, userSelectedAddonVersion: addon.Version, availableVersion: version} } }
if err = h.installDependency(addon); err != nil { return err } if err = h.dispatchAddonResource(addon); err != nil { return err } // we shouldn't put continue func into dispatchAddonResource, because the re-apply app maybe already update app and // the suspend will set with false automatically if err := h.continueOrRestartWorkflow(); err != nil { return err } returnnil }
// checkAddonVersionMeetRequired will check the version of cli/ux and kubevela-core-controller whether meet the addon requirement, if not will return an error // please notice that this func is for check production environment which vela cli/ux or vela core is officalVersion // if version is for test or debug eg: latest/commit-id/branch-name this func will return nil error funccheckAddonVersionMeetRequired(ctx context.Context, require *SystemRequirements, k8sClient client.Client, dc *discovery.DiscoveryClient)error { ...
// if not semver version, bypass check cli/ux. eg: {branch name/git commit id/UNKNOWN} if version2.IsOfficialKubeVelaVersion(version2.VelaVersion) { res, err := checkSemVer(version2.VelaVersion, require.VelaVersion) }