Skip to content

Commit

Permalink
Implement kyma client (#2190)
Browse files Browse the repository at this point in the history
  • Loading branch information
pPrecel authored Jul 15, 2024
1 parent cbb07b0 commit 43b8905
Show file tree
Hide file tree
Showing 10 changed files with 357 additions and 336 deletions.
27 changes: 1 addition & 26 deletions internal/cmd/alpha/add/managed/managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package managed
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/kyma"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -42,29 +41,5 @@ func NewManagedCMD(kymaConfig *cmdcommon.KymaConfig) *cobra.Command {
}

func runAddManaged(config *managedConfig) error {
kymaCR, err := kyma.GetDefaultKyma(config.Ctx, config.KubeClient)
if err != nil {
return err
}

kymaCR = enableModule(kymaCR, config.module, config.channel)

return kyma.UpdateDefaultKyma(config.Ctx, config.KubeClient, kymaCR)
}

func enableModule(kymaCR *kyma.Kyma, moduleName, moduleChannel string) *kyma.Kyma {
for i, m := range kymaCR.Spec.Modules {
if m.Name == moduleName {
// module already exists, update channel
kymaCR.Spec.Modules[i].Channel = moduleChannel
return kymaCR
}
}

kymaCR.Spec.Modules = append(kymaCR.Spec.Modules, kyma.Module{
Name: moduleName,
Channel: moduleChannel,
})

return kymaCR
return config.KubeClient.Kyma().EnableModule(config.Ctx, config.module, config.channel)
}
168 changes: 0 additions & 168 deletions internal/cmd/alpha/add/managed/managed_test.go

This file was deleted.

20 changes: 1 addition & 19 deletions internal/cmd/alpha/remove/managed/managed.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package managed

import (
"slices"

"github.com/kyma-project/cli.v3/internal/clierror"
"github.com/kyma-project/cli.v3/internal/cmdcommon"
"github.com/kyma-project/cli.v3/internal/kube/kyma"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -42,20 +39,5 @@ func NewManagedCMD(kymaConfig *cmdcommon.KymaConfig) *cobra.Command {
}

func runRemoveManaged(config *managedConfig) error {
kymaCR, err := kyma.GetDefaultKyma(config.Ctx, config.KubeClient)
if err != nil {
return err
}

kymaCR = disableModule(kymaCR, config.module)

return kyma.UpdateDefaultKyma(config.Ctx, config.KubeClient, kymaCR)
}

func disableModule(kymaCR *kyma.Kyma, moduleName string) *kyma.Kyma {
kymaCR.Spec.Modules = slices.DeleteFunc(kymaCR.Spec.Modules, func(m kyma.Module) bool {
return m.Name == moduleName
})

return kymaCR
return config.KubeClient.Kyma().DisableModule(config.Ctx, config.module)
}
92 changes: 0 additions & 92 deletions internal/cmd/alpha/remove/managed/managed_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/communitymodules/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func ManagedModules(client cmdcommon.KubeClientConfig, cfg cmdcommon.KymaConfig)

// getManagedList gets a list of all managed modules from the Kyma CR
func getManagedList(client cmdcommon.KubeClientConfig, cfg cmdcommon.KymaConfig) ([]kyma.ModuleStatus, clierror.Error) {
kyma, err := kyma.GetDefaultKyma(cfg.Ctx, client.KubeClient)
kyma, err := client.KubeClient.Kyma().GetDefaultKyma(cfg.Ctx)
if err != nil && !errors.IsNotFound(err) {
return nil, clierror.Wrap(err, clierror.New("while getting Kyma CR"))
}
Expand Down
5 changes: 3 additions & 2 deletions internal/communitymodules/modules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/kyma-project/cli.v3/internal/cmdcommon"
kube_fake "github.com/kyma-project/cli.v3/internal/kube/fake"
"github.com/kyma-project/cli.v3/internal/kube/kyma"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
v1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -116,7 +117,7 @@ func Test_ManagedModules(t *testing.T) {
dynamic := dynamic_fake.NewSimpleDynamicClient(scheme, testKyma)
kubeClient := &kube_fake.FakeKubeClient{
TestKubernetesInterface: nil,
TestDynamicInterface: dynamic,
TestKymaInterface: kyma.NewClient(dynamic),
}

kymaConfig := cmdcommon.KymaConfig{
Expand All @@ -140,7 +141,7 @@ func Test_ManagedModules(t *testing.T) {
dynamic := dynamic_fake.NewSimpleDynamicClient(scheme)
kubeClient := &kube_fake.FakeKubeClient{
TestKubernetesInterface: nil,
TestDynamicInterface: dynamic,
TestKymaInterface: kyma.NewClient(dynamic),
}

kymaConfig := cmdcommon.KymaConfig{
Expand Down
Loading

0 comments on commit 43b8905

Please sign in to comment.