-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
611 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package module | ||
|
||
import ( | ||
"github.com/kyma-project/cli.v3/internal/clierror" | ||
"github.com/kyma-project/cli.v3/internal/cmdcommon" | ||
"github.com/kyma-project/cli.v3/internal/kube/resources" | ||
"github.com/kyma-project/cli.v3/internal/modules" | ||
"github.com/spf13/cobra" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
) | ||
|
||
type enableConfig struct { | ||
*cmdcommon.KymaConfig | ||
|
||
module string | ||
channel string | ||
crPath string | ||
defaultCR bool | ||
} | ||
|
||
func newEnableCMD(kymaConfig *cmdcommon.KymaConfig) *cobra.Command { | ||
cfg := enableConfig{ | ||
KymaConfig: kymaConfig, | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "enable <module>", | ||
Short: "Enable module.", | ||
Long: "Use this command to enable module.", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cfg.module = args[0] | ||
clierror.Check(runEnable(&cfg)) | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVar(&cfg.channel, "channel", "", "Name of the Kyma channel to use for the module") | ||
cmd.Flags().StringVar(&cfg.crPath, "cr-path", "", "Path to the custom resource file") | ||
cmd.Flags().BoolVar(&cfg.defaultCR, "default-cr", false, "Use this flag to deploy module with default cr") | ||
|
||
cmd.MarkFlagsMutuallyExclusive("cr-path", "default-cr") | ||
|
||
return cmd | ||
} | ||
|
||
func runEnable(cfg *enableConfig) clierror.Error { | ||
client, clierr := cfg.GetKubeClientWithClierr() | ||
if clierr != nil { | ||
return clierr | ||
} | ||
|
||
crs, clierr := loadCustomCRs(cfg.crPath) | ||
if clierr != nil { | ||
return clierr | ||
} | ||
|
||
return modules.Enable(cfg.Ctx, client, cfg.module, cfg.channel, cfg.defaultCR, crs...) | ||
} | ||
|
||
func loadCustomCRs(crPath string) ([]unstructured.Unstructured, clierror.Error) { | ||
if crPath == "" { | ||
// skip if not set | ||
return nil, nil | ||
} | ||
|
||
crs, err := resources.ReadFromFiles(crPath) | ||
if err != nil { | ||
return nil, clierror.Wrap(err, clierror.New("failed to read object from file")) | ||
} | ||
|
||
return crs, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package fake | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/kyma-project/cli.v3/internal/kube/kyma" | ||
) | ||
|
||
type FakeEnabledModule struct { | ||
Name string | ||
Channel string | ||
CustomResourcePolicy string | ||
} | ||
|
||
type KymaClient struct { | ||
// outputs | ||
ReturnErr error | ||
ReturnGetModuleInfoErr error | ||
ReturnDisableModuleErr error | ||
ReturnGetModuleTemplateErr error | ||
ReturnWaitForModuleErr error | ||
ReturnModuleReleaseMetaList kyma.ModuleReleaseMetaList | ||
ReturnModuleTemplateList kyma.ModuleTemplateList | ||
ReturnModuleReleaseMeta kyma.ModuleReleaseMeta | ||
ReturnModuleTemplate kyma.ModuleTemplate | ||
ReturnDefaultKyma kyma.Kyma | ||
ReturnModuleInfo kyma.KymaModuleInfo | ||
|
||
// input arguments | ||
UpdateDefaultKymas []kyma.Kyma | ||
DisabledModules []string | ||
EnabledModules []FakeEnabledModule | ||
} | ||
|
||
func (c *KymaClient) ListModuleReleaseMeta(_ context.Context) (*kyma.ModuleReleaseMetaList, error) { | ||
return &c.ReturnModuleReleaseMetaList, c.ReturnErr | ||
} | ||
|
||
func (c *KymaClient) ListModuleTemplate(_ context.Context) (*kyma.ModuleTemplateList, error) { | ||
return &c.ReturnModuleTemplateList, c.ReturnErr | ||
} | ||
|
||
func (c *KymaClient) GetModuleReleaseMetaForModule(_ context.Context, _ string) (*kyma.ModuleReleaseMeta, error) { | ||
return &c.ReturnModuleReleaseMeta, c.ReturnErr | ||
} | ||
|
||
func (c *KymaClient) GetModuleTemplateForModule(_ context.Context, _, _ string) (*kyma.ModuleTemplate, error) { | ||
return &c.ReturnModuleTemplate, c.ReturnGetModuleTemplateErr | ||
} | ||
|
||
func (c *KymaClient) GetDefaultKyma(_ context.Context) (*kyma.Kyma, error) { | ||
return &c.ReturnDefaultKyma, c.ReturnErr | ||
} | ||
|
||
func (c *KymaClient) UpdateDefaultKyma(_ context.Context, kyma *kyma.Kyma) error { | ||
c.UpdateDefaultKymas = append(c.UpdateDefaultKymas, *kyma) | ||
return c.ReturnErr | ||
} | ||
|
||
func (c *KymaClient) GetModuleInfo(_ context.Context, _ string) (*kyma.KymaModuleInfo, error) { | ||
return &c.ReturnModuleInfo, c.ReturnGetModuleInfoErr | ||
} | ||
|
||
func (c *KymaClient) WaitForModuleState(_ context.Context, _ string, _ ...string) error { | ||
return c.ReturnWaitForModuleErr | ||
} | ||
|
||
func (c *KymaClient) EnableModule(_ context.Context, module string, channel string, customResourcePolicy string) error { | ||
c.EnabledModules = append(c.EnabledModules, FakeEnabledModule{ | ||
Name: module, | ||
Channel: channel, | ||
CustomResourcePolicy: customResourcePolicy, | ||
}) | ||
return c.ReturnErr | ||
} | ||
|
||
func (c *KymaClient) DisableModule(_ context.Context, module string) error { | ||
c.DisabledModules = append(c.DisabledModules, module) | ||
return c.ReturnDisableModuleErr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package fake | ||
|
||
import ( | ||
"context" | ||
|
||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
) | ||
|
||
type RootlessDynamicClient struct { | ||
// outputs | ||
ReturnErr error | ||
ReturnGetErr error | ||
ReturnRemoveErr error | ||
ReturnGetObj unstructured.Unstructured | ||
ReturnListObjs *unstructured.UnstructuredList | ||
|
||
// inputs summary | ||
GetObjs []unstructured.Unstructured | ||
ListObjs []unstructured.Unstructured | ||
RemovedObjs []unstructured.Unstructured | ||
ApplyObjs []unstructured.Unstructured | ||
} | ||
|
||
func (m *RootlessDynamicClient) Apply(_ context.Context, obj *unstructured.Unstructured) error { | ||
m.ApplyObjs = append(m.ApplyObjs, *obj) | ||
return m.ReturnErr | ||
} | ||
|
||
func (m *RootlessDynamicClient) ApplyMany(_ context.Context, objs []unstructured.Unstructured) error { | ||
m.ApplyObjs = append(m.ApplyObjs, objs...) | ||
return m.ReturnErr | ||
} | ||
|
||
func (m *RootlessDynamicClient) Get(_ context.Context, obj *unstructured.Unstructured) (*unstructured.Unstructured, error) { | ||
m.GetObjs = append(m.GetObjs, *obj) | ||
return &m.ReturnGetObj, m.ReturnGetErr | ||
} | ||
|
||
func (m *RootlessDynamicClient) List(_ context.Context, obj *unstructured.Unstructured) (*unstructured.UnstructuredList, error) { | ||
m.ListObjs = append(m.ListObjs, *obj) | ||
return m.ReturnListObjs, m.ReturnErr | ||
} | ||
|
||
func (m *RootlessDynamicClient) Remove(_ context.Context, obj *unstructured.Unstructured) error { | ||
m.RemovedObjs = append(m.RemovedObjs, *obj) | ||
return m.ReturnRemoveErr | ||
} | ||
|
||
func (m *RootlessDynamicClient) RemoveMany(_ context.Context, objs []unstructured.Unstructured) error { | ||
m.RemovedObjs = append(m.RemovedObjs, objs...) | ||
return m.ReturnRemoveErr | ||
} |
Oops, something went wrong.