Fix: the definition namespace is empty (#3227)

Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
This commit is contained in:
barnettZQG
2022-02-11 19:56:29 +08:00
committed by GitHub
parent f0cbe816a6
commit fee4a3f2b8
2 changed files with 16 additions and 2 deletions
+6
View File
@@ -559,6 +559,9 @@ func RenderApp(ctx context.Context, addon *InstallPackage, config *rest.Config,
if err != nil {
return nil, errors.Wrapf(err, "fail to render definition: %s in cue's format", cueDef.Name)
}
if def.Unstructured.GetNamespace() == "" {
def.Unstructured.SetNamespace(types.DefaultKubeVelaNS)
}
app.Spec.Components = append(app.Spec.Components, common2.ApplicationComponent{
Name: cueDef.Name,
Type: "raw",
@@ -605,6 +608,9 @@ func RenderDefinitions(addon *InstallPackage, config *rest.Config) ([]*unstructu
if err != nil {
return nil, errors.Wrapf(err, "fail to render definition: %s in cue's format", cueDef.Name)
}
if def.GetNamespace() == "" {
def.SetNamespace(types.DefaultKubeVelaNS)
}
defObjs = append(defObjs, &def.Unstructured)
}
}
+10 -2
View File
@@ -134,7 +134,11 @@ func NewAddonEnableCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra.Com
}
addonOrDir := args[0]
var name = addonOrDir
if _, err := os.Stat(addonOrDir); err == nil {
if file, err := os.Stat(addonOrDir); err == nil {
if !file.IsDir() {
return fmt.Errorf("%s is not addon dir", addonOrDir)
}
ioStream.Infof("enable addon by local dir: %s", 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)
@@ -200,7 +204,11 @@ func NewAddonUpgradeCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra.Co
}
addonOrDir := args[0]
var name string
if _, err := os.Stat(addonOrDir); err == nil {
if file, err := os.Stat(addonOrDir); err == nil {
if !file.IsDir() {
return fmt.Errorf("%s is not addon dir", addonOrDir)
}
ioStream.Infof("enable addon by local dir: %s", addonOrDir)
// args[0] is a local path install with local dir
name := filepath.Base(addonOrDir)
_, err = pkgaddon.FetchAddonRelatedApp(context.Background(), k8sClient, name)