Fix: registry don't have enough info to build a reader (#3237)

Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
This commit is contained in:
barnettZQG
2022-02-14 18:04:34 +08:00
committed by GitHub
parent 65522cabdb
commit 4a29776e8e
4 changed files with 30 additions and 3 deletions

View File

@@ -951,6 +951,26 @@ func (h *Installer) installDependency(addon *InstallPackage) error {
return nil
}
// checkDependency checks if addon's dependency
func (h *Installer) checkDependency(addon *InstallPackage) ([]string, error) {
var app v1beta1.Application
var needEnable []string
for _, dep := range addon.Dependencies {
err := h.cli.Get(h.ctx, client.ObjectKey{
Namespace: types.DefaultKubeVelaNS,
Name: Convert2AppName(dep.Name),
}, &app)
if err == nil {
continue
}
if !apierrors.IsNotFound(err) {
return nil, err
}
needEnable = append(needEnable, dep.Name)
}
return needEnable, nil
}
func (h *Installer) dispatchAddonResource(addon *InstallPackage) error {
app, err := RenderApp(h.ctx, addon, h.config, h.cli, h.args)
if err != nil {

View File

@@ -92,6 +92,14 @@ func EnableAddonByLocalDir(ctx context.Context, name string, dir string, cli cli
return err
}
h := NewAddonInstaller(ctx, cli, applicator, config, &Registry{Name: LocalAddonRegistryName}, args, nil)
needEnableAddonNames, err := h.checkDependency(pkg)
if err != nil {
return err
}
if len(needEnableAddonNames) > 0 {
return fmt.Errorf("you must first enable dependencies: %v", needEnableAddonNames)
}
err = h.enableAddon(pkg)
if err != nil {
return err

View File

@@ -169,7 +169,6 @@ func (r *Registry) BuildReader() (AsyncReader, error) {
return NewAsyncReader(g.URL, "", g.Path, g.Token, gitType)
}
return nil, errors.New("registry don't have enough info to build a reader")
}
// GetUIData get UIData of an addon

View File

@@ -140,7 +140,7 @@ func NewAddonEnableCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra.Com
if !file.IsDir() {
return fmt.Errorf("%s is not addon dir", addonOrDir)
}
ioStream.Infof("enable addon by local dir: %s", addonOrDir)
ioStream.Infof("enable addon by local dir: %s \n", addonOrDir)
// args[0] is a local path install with local dir, use base dir name as addonName
name = filepath.Base(addonOrDir)
err = enableAddonByLocal(ctx, name, addonOrDir, k8sClient, config, addonArgs)
@@ -210,7 +210,7 @@ func NewAddonUpgradeCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra.Co
if !file.IsDir() {
return fmt.Errorf("%s is not addon dir", addonOrDir)
}
ioStream.Infof("enable addon by local dir: %s", addonOrDir)
ioStream.Infof("enable addon by local dir: %s \n", addonOrDir)
// args[0] is a local path install with local dir
name := filepath.Base(addonOrDir)
_, err = pkgaddon.FetchAddonRelatedApp(context.Background(), k8sClient, name)