Skip to content

Commit

Permalink
chore: Reference lifecycle manager api module (kyma-project#1881)
Browse files Browse the repository at this point in the history
* Reference LM api module

* upgrade lm api

* code review comments

* code review comments
  • Loading branch information
nesmabadr authored Dec 13, 2023
1 parent dd09d52 commit 0460fff
Show file tree
Hide file tree
Showing 15 changed files with 396 additions and 499 deletions.
12 changes: 6 additions & 6 deletions cmd/kyma/alpha/create/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"path/filepath"
"strings"

"github.com/kyma-project/lifecycle-manager/api/v1beta2"
"github.com/kyma-project/lifecycle-manager/api/shared"
"github.com/mandelsoft/vfs/pkg/memoryfs"
"github.com/mandelsoft/vfs/pkg/osfs"
"github.com/mandelsoft/vfs/pkg/vfs"
Expand Down Expand Up @@ -447,10 +447,10 @@ func (cmd *command) getModuleTemplateLabels(modCnf *Config) map[string]string {
maps.Copy(labels, modCnf.Labels)

if modCnf.Beta {
labels[v1beta2.BetaLabel] = v1beta2.EnableLabelValue
labels[shared.BetaLabel] = shared.EnableLabelValue
}
if modCnf.Internal {
labels[v1beta2.InternalLabel] = v1beta2.EnableLabelValue
labels[shared.InternalLabel] = shared.EnableLabelValue
}
}

Expand All @@ -468,11 +468,11 @@ func (cmd *command) getModuleTemplateAnnotations(modCnf *Config, crValidator val

isClusterScoped := isCrdClusterScoped(crValidator.GetCrd())
if isClusterScoped {
annotations[v1beta2.IsClusterScopedAnnotation] = v1beta2.EnableLabelValue
annotations[shared.IsClusterScopedAnnotation] = shared.EnableLabelValue
} else {
annotations[v1beta2.IsClusterScopedAnnotation] = v1beta2.DisableLabelValue
annotations[shared.IsClusterScopedAnnotation] = shared.DisableLabelValue
}
annotations["operator.kyma-project.io/module-version"] = moduleVersion
annotations[shared.ModuleVersionAnnotation] = moduleVersion
return annotations
}

Expand Down
34 changes: 18 additions & 16 deletions cmd/kyma/alpha/create/module/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"reflect"
"testing"

"github.com/kyma-project/lifecycle-manager/api/shared"

"github.com/kyma-project/cli/internal/cli"
"github.com/kyma-project/cli/pkg/module"
"github.com/kyma-project/lifecycle-manager/api/v1beta2"
)

//go:embed testdata/clusterScopedCRD.yaml
Expand Down Expand Up @@ -79,9 +80,9 @@ func Test_command_getModuleTemplateLabels(t *testing.T) {
},
},
want: map[string]string{
"label1": "value1",
"label2": "value2",
v1beta2.BetaLabel: v1beta2.EnableLabelValue,
"label1": "value1",
"label2": "value2",
shared.BetaLabel: shared.EnableLabelValue,
},
},
{
Expand All @@ -96,7 +97,7 @@ func Test_command_getModuleTemplateLabels(t *testing.T) {
},
},
want: map[string]string{
v1beta2.InternalLabel: v1beta2.EnableLabelValue,
shared.InternalLabel: shared.EnableLabelValue,
},
},
}
Expand Down Expand Up @@ -147,10 +148,10 @@ func Test_command_getModuleTemplateAnnotations(t *testing.T) {
},
},
want: map[string]string{
"annotation1": "value1",
"annotation2": "value2",
"operator.kyma-project.io/module-version": "1.1.1",
v1beta2.IsClusterScopedAnnotation: v1beta2.DisableLabelValue,
"annotation1": "value1",
"annotation2": "value2",
shared.ModuleVersionAnnotation: "1.1.1",
shared.IsClusterScopedAnnotation: shared.DisableLabelValue,
},
},
{
Expand All @@ -171,10 +172,10 @@ func Test_command_getModuleTemplateAnnotations(t *testing.T) {
},
},
want: map[string]string{
"annotation1": "value1",
"annotation2": "value2",
v1beta2.IsClusterScopedAnnotation: v1beta2.EnableLabelValue,
"operator.kyma-project.io/module-version": "1.1.1",
"annotation1": "value1",
"annotation2": "value2",
shared.IsClusterScopedAnnotation: shared.EnableLabelValue,
shared.ModuleVersionAnnotation: "1.1.1",
},
},
{
Expand All @@ -188,8 +189,8 @@ func Test_command_getModuleTemplateAnnotations(t *testing.T) {
},
},
want: map[string]string{
"operator.kyma-project.io/module-version": "1.0.0",
v1beta2.IsClusterScopedAnnotation: v1beta2.DisableLabelValue,
shared.ModuleVersionAnnotation: "1.0.0",
shared.IsClusterScopedAnnotation: shared.DisableLabelValue,
},
},
}
Expand All @@ -199,7 +200,8 @@ func Test_command_getModuleTemplateAnnotations(t *testing.T) {
Command: tt.fields.Command,
opts: tt.fields.opts,
}
if got := cmd.getModuleTemplateAnnotations(tt.args.modCnf, tt.args.crValidator); !reflect.DeepEqual(got, tt.want) {
if got := cmd.getModuleTemplateAnnotations(tt.args.modCnf, tt.args.crValidator); !reflect.DeepEqual(got,
tt.want) {
t.Errorf("getModuleTemplateAnnotations() = %v, want %v", got, tt.want)
}
})
Expand Down
37 changes: 22 additions & 15 deletions cmd/kyma/alpha/deploy/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ import (
"strings"
"time"

"github.com/kyma-project/lifecycle-manager/api/shared"
"github.com/kyma-project/lifecycle-manager/api/v1beta2"
"golang.org/x/exp/slices"

"github.com/kyma-project/cli/internal/cli"
"github.com/kyma-project/cli/internal/coredns"
"github.com/kyma-project/cli/internal/deploy"
"github.com/kyma-project/cli/internal/nice"
"github.com/kyma-project/cli/pkg/dashboard"
"github.com/spf13/cobra"
"go.uber.org/zap"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/kyma-project/cli/internal/cli"
"github.com/kyma-project/cli/internal/coredns"
"github.com/kyma-project/cli/internal/deploy"
"github.com/kyma-project/cli/internal/nice"
"github.com/kyma-project/cli/pkg/dashboard"
)

type command struct {
Expand Down Expand Up @@ -222,7 +225,8 @@ func (cmd *command) deploy(ctx context.Context) error {
deployStep := cmd.NewStep("Deploying Kustomizations")
deployStep.Start()
hasKyma, err := deploy.Bootstrap(
ctx, cmd.opts.Kustomizations, cmd.K8s, cmd.opts.Filters, cmd.opts.WildcardPermissions, cmd.opts.Force, false, isInKcpMode,
ctx, cmd.opts.Kustomizations, cmd.K8s, cmd.opts.Filters, cmd.opts.WildcardPermissions, cmd.opts.Force, false,
isInKcpMode,
)
if err != nil {
deployStep.Failuref("Failed to deploy Kustomizations %s: %s", cmd.opts.Kustomizations, err.Error())
Expand All @@ -245,7 +249,8 @@ func (cmd *command) deploy(ctx context.Context) error {

if len(cmd.opts.AdditionalTemplates) > 0 {
modStep := cmd.NewStep("Deploying additional module templates")
if err := deploy.ModuleTemplates(ctx, cmd.K8s, cmd.opts.AdditionalTemplates, cmd.opts.Target, cmd.opts.Force, false); err != nil {
if err := deploy.ModuleTemplates(ctx, cmd.K8s, cmd.opts.AdditionalTemplates, cmd.opts.Target, cmd.opts.Force,
false); err != nil {
modStep.Failuref("Failed to deploy additional module templates")
return err
}
Expand Down Expand Up @@ -301,7 +306,8 @@ func (cmd *command) dryRun(ctx context.Context, isInKcpMode bool) error {
}

hasKyma, err := deploy.Bootstrap(
ctx, cmd.opts.Kustomizations, cmd.K8s, cmd.opts.Filters, cmd.opts.WildcardPermissions, cmd.opts.Force, true, isInKcpMode,
ctx, cmd.opts.Kustomizations, cmd.K8s, cmd.opts.Filters, cmd.opts.WildcardPermissions, cmd.opts.Force, true,
isInKcpMode,
)
if err != nil {
return err
Expand All @@ -312,7 +318,8 @@ func (cmd *command) dryRun(ctx context.Context, isInKcpMode bool) error {
}

if len(cmd.opts.AdditionalTemplates) > 0 {
if err := deploy.ModuleTemplates(ctx, cmd.K8s, cmd.opts.AdditionalTemplates, cmd.opts.Target, cmd.opts.Force, true); err != nil {
if err := deploy.ModuleTemplates(ctx, cmd.K8s, cmd.opts.AdditionalTemplates, cmd.opts.Target, cmd.opts.Force,
true); err != nil {
return err
}
}
Expand All @@ -329,9 +336,9 @@ func (cmd *command) openDashboard(ctx context.Context) error {

kymas, err := cmd.K8s.Dynamic().Resource(
schema.GroupVersionResource{
Group: "operator.kyma-project.io",
Version: "v1beta2",
Resource: "kymas",
Group: shared.OperatorGroup,
Version: v1beta2.GroupVersion.Version,
Resource: shared.KymaKind.Plural(),
},
).List(ctx, v1.ListOptions{})
if err != nil {
Expand Down Expand Up @@ -382,9 +389,9 @@ func (cmd *command) handleTimeoutErr(err error) error {

func (cmd *command) detectManagedKyma(ctx context.Context) error {
kymaResource := schema.GroupVersionResource{
Group: "operator.kyma-project.io",
Version: "v1beta2",
Resource: "kymas",
Group: shared.OperatorGroup,
Version: v1beta2.GroupVersion.Version,
Resource: shared.KymaKind.Plural(),
}

deployedKymaCRs, err := cmd.K8s.Dynamic().Resource(kymaResource).List(ctx, v1.ListOptions{})
Expand Down
17 changes: 10 additions & 7 deletions cmd/kyma/alpha/deploy/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package deploy

import (
"context"
"github.com/kyma-project/cli/internal/cli"
"github.com/kyma-project/cli/internal/kube/mocks"
"github.com/kyma-project/cli/pkg/step"
"testing"

"github.com/kyma-project/lifecycle-manager/api/shared"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
fakedynamic "k8s.io/client-go/dynamic/fake"
"k8s.io/client-go/kubernetes/scheme"
"testing"

"github.com/kyma-project/cli/internal/cli"
"github.com/kyma-project/cli/internal/kube/mocks"
"github.com/kyma-project/cli/pkg/step"
)

func Test_command_detectManagedKyma(t *testing.T) {
Expand All @@ -24,7 +27,7 @@ func Test_command_detectManagedKyma(t *testing.T) {
// Managed Kyma
managedKymaMock := &mocks.KymaKube{}
managedKyma := &unstructured.Unstructured{}
managedKyma.SetKind("Kyma")
managedKyma.SetKind(string(shared.KymaKind))
managedKyma.SetAPIVersion("operator.kyma-project.io/v1beta2")
managedKyma.SetManagedFields([]metav1.ManagedFieldsEntry{
{
Expand All @@ -38,7 +41,7 @@ func Test_command_detectManagedKyma(t *testing.T) {
// Unmanaged Kyma
unmanagedKymaMock := &mocks.KymaKube{}
unmanagedKyma := &unstructured.Unstructured{}
unmanagedKyma.SetKind("Kyma")
unmanagedKyma.SetKind(string(shared.KymaKind))
unmanagedKyma.SetAPIVersion("operator.kyma-project.io/v1beta2")
unmanagedKyma.SetManagedFields([]metav1.ManagedFieldsEntry{
{
Expand All @@ -52,7 +55,7 @@ func Test_command_detectManagedKyma(t *testing.T) {
// kyma with no managed fields
noManagedFieldsMock := &mocks.KymaKube{}
noManagedFields := &unstructured.Unstructured{}
noManagedFields.SetKind("Kyma")
noManagedFields.SetKind(string(shared.KymaKind))
noManagedFields.SetAPIVersion("operator.kyma-project.io/v1beta2")
noManagedFieldsDynamic := fakedynamic.NewSimpleDynamicClient(scheme.Scheme, noManagedFields)
noManagedFieldsMock.On("Dynamic").Return(noManagedFieldsDynamic)
Expand Down
23 changes: 13 additions & 10 deletions cmd/kyma/alpha/list/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import (
"text/template"
"time"

"github.com/kyma-project/cli/internal/cli"
"github.com/kyma-project/cli/internal/clusterinfo"
"github.com/kyma-project/cli/internal/kube"
"github.com/kyma-project/lifecycle-manager/api/shared"
"github.com/kyma-project/lifecycle-manager/api/v1beta2"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -25,21 +24,25 @@ import (
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/restmapper"
"sigs.k8s.io/yaml"

"github.com/kyma-project/cli/internal/cli"
"github.com/kyma-project/cli/internal/clusterinfo"
"github.com/kyma-project/cli/internal/kube"
)

//go:embed list.tmpl
var moduleTemplates string

var moduleTemplateResource = schema.GroupVersionResource{
Group: "operator.kyma-project.io",
Version: "v1beta2",
Resource: "moduletemplates",
Group: shared.OperatorGroup,
Version: v1beta2.GroupVersion.Version,
Resource: shared.ModuleTemplateKind.Plural(),
}

var kymaResource = schema.GroupVersionResource{
Group: "operator.kyma-project.io",
Version: "v1beta2",
Resource: "kymas",
Group: shared.OperatorGroup,
Version: v1beta2.GroupVersion.Version,
Resource: shared.KymaKind.Plural(),
}

type command struct {
Expand Down Expand Up @@ -268,7 +271,7 @@ func (cmd *command) printModuleTemplatesTable(templates *unstructured.Unstructur
tabWriter := tabwriter.NewWriter(os.Stdout, 0, 8, 2, '\t', 0)
if !cmd.opts.NoHeaders {
headers := []string{
"operator.kyma-project.io/module-name",
shared.ModuleName,
"Domain Name (FQDN)",
"Channel",
"Version",
Expand Down
Loading

0 comments on commit 0460fff

Please sign in to comment.