Skip to content

Commit

Permalink
Merge branch 'main' into release_1.28
Browse files Browse the repository at this point in the history
  • Loading branch information
nesmabadr authored Jan 24, 2025
2 parents df82b6f + df076fe commit fbe67d7
Show file tree
Hide file tree
Showing 52 changed files with 1,328 additions and 867 deletions.
10 changes: 3 additions & 7 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/Masterminds/semver/v3 v3.3.1
github.com/stretchr/testify v1.10.0
k8s.io/apimachinery v0.32.1
sigs.k8s.io/controller-runtime v0.19.4
sigs.k8s.io/controller-runtime v0.20.0
)

require github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand All @@ -26,7 +26,6 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand All @@ -35,8 +34,6 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sys v0.28.0 // indirect
Expand All @@ -46,9 +43,8 @@ require (
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.31.2 // indirect
k8s.io/apiextensions-apiserver v0.31.2 // indirect
k8s.io/client-go v0.31.2 // indirect
k8s.io/api v0.32.0 // indirect
k8s.io/client-go v0.32.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
Expand Down
20 changes: 8 additions & 12 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db h1:097atOisP2aRj7vFgY
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
Expand Down Expand Up @@ -87,8 +85,6 @@ go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand Down Expand Up @@ -136,22 +132,22 @@ gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.31.2 h1:3wLBbL5Uom/8Zy98GRPXpJ254nEFpl+hwndmk9RwmL0=
k8s.io/api v0.31.2/go.mod h1:bWmGvrGPssSK1ljmLzd3pwCQ9MgoTsRCuK35u6SygUk=
k8s.io/apiextensions-apiserver v0.31.2 h1:W8EwUb8+WXBLu56ser5IudT2cOho0gAKeTOnywBLxd0=
k8s.io/apiextensions-apiserver v0.31.2/go.mod h1:i+Geh+nGCJEGiCGR3MlBDkS7koHIIKWVfWeRFiOsUcM=
k8s.io/api v0.32.0 h1:OL9JpbvAU5ny9ga2fb24X8H6xQlVp+aJMFlgtQjR9CE=
k8s.io/api v0.32.0/go.mod h1:4LEwHZEf6Q/cG96F3dqR965sYOfmPM7rq81BLgsE0p0=
k8s.io/apiextensions-apiserver v0.32.0 h1:S0Xlqt51qzzqjKPxfgX1xh4HBZE+p8KKBq+k2SWNOE0=
k8s.io/apiextensions-apiserver v0.32.0/go.mod h1:86hblMvN5yxMvZrZFX2OhIHAuFIMJIZ19bTvzkP+Fmw=
k8s.io/apimachinery v0.32.1 h1:683ENpaCBjma4CYqsmZyhEzrGz6cjn1MY/X2jB2hkZs=
k8s.io/apimachinery v0.32.1/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE=
k8s.io/client-go v0.31.2 h1:Y2F4dxU5d3AQj+ybwSMqQnpZH9F30//1ObxOKlTI9yc=
k8s.io/client-go v0.31.2/go.mod h1:NPa74jSVR/+eez2dFsEIHNa+3o09vtNaWwWwb1qSxSs=
k8s.io/client-go v0.32.0 h1:DimtMcnN/JIKZcrSrstiwvvZvLjG0aSxy8PxN8IChp8=
k8s.io/client-go v0.32.0/go.mod h1:boDWvdM1Drk4NJj/VddSLnx59X3OPgwrOo0vGbtq9+8=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f h1:GA7//TjRY9yWGy1poLzYYJJ4JRdzg3+O6e8I+e+8T5Y=
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f/go.mod h1:R/HEjbvWI0qdfb8viZUeVZm0X6IZnxAydC7YU42CMw4=
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 h1:M3sRQVHv7vB20Xc2ybTt7ODCeFj6JSWYFzOFnYeS6Ro=
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
sigs.k8s.io/controller-runtime v0.19.4 h1:SUmheabttt0nx8uJtoII4oIP27BVVvAKFvdvGFwV/Qo=
sigs.k8s.io/controller-runtime v0.19.4/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4=
sigs.k8s.io/controller-runtime v0.20.0 h1:jjkMo29xEXH+02Md9qaVXfEIaMESSpy3TBWPrsfQkQs=
sigs.k8s.io/controller-runtime v0.20.0/go.mod h1:BrP3w158MwvB3ZbNpaAcIKkHQ7YGpYnzpoSTZ8E14WU=
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7npUVDpVXUUOFfW6CgAqE=
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg=
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 h1:MdmvkGuXi/8io6ixD5wud3vOLwc1rj0aNqRlpuvjmwA=
Expand Down
6 changes: 4 additions & 2 deletions api/v1beta2/modulereleasemeta_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ type ModuleReleaseMetaSpec struct {
Channels []ChannelVersionAssignment `json:"channels"`

// Beta indicates if the module is in beta state. Beta modules are only available for beta Kymas.
// +optional
// +kubebuilder:default:=false
Beta bool `json:"beta,omitempty"`
Beta bool `json:"beta"`

// Internal indicates if the module is internal. Internal modules are only available for internal Kymas.
// +optional
// +kubebuilder:default:=false
Internal bool `json:"internal,omitempty"`
Internal bool `json:"internal"`
}

// +kubebuilder:object:root=true
Expand Down
50 changes: 24 additions & 26 deletions api/v1beta2/moduletemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,39 +223,27 @@ func (m *ModuleTemplate) IsInternal() bool {
return false
}

var ErrInvalidVersion = errors.New("can't find valid semantic version")

// getVersionLegacy() returns the version of the ModuleTemplate from the annotation on the object.
// Remove once shared.ModuleVersionAnnotation is removed.
func (m *ModuleTemplate) getVersionLegacy() (string, error) {
if m.Annotations != nil {
moduleVersion, found := m.Annotations[shared.ModuleVersionAnnotation]
if found {
return moduleVersion, nil
}
// https://github.com/kyma-project/lifecycle-manager/issues/2096
// Refactor this function to drop the label fallback after the migration to the new ModuleTemplate format is completed.
func (m *ModuleTemplate) GetVersion() string {
version := m.Spec.Version
if version == "" {
version = m.Annotations[shared.ModuleVersionAnnotation]
}
return "", ErrInvalidVersion
return version
}

// GetVersion returns the declared version of the ModuleTemplate from it's Spec.
func (m *ModuleTemplate) GetVersion() (*semver.Version, error) {
var versionValue string
var err error

if m.Spec.Version == "" {
versionValue, err = m.getVersionLegacy()
if err != nil {
return nil, err
}
} else {
versionValue = m.Spec.Version
}
var ErrInvalidVersion = errors.New("can't find valid semantic version")

version, err := semver.NewVersion(versionValue)
// GetSemanticVersion returns the declared version of the ModuleTemplate as semantic version.
func (m *ModuleTemplate) GetSemanticVersion() (*semver.Version, error) {
version := m.GetVersion()

semanticVersion, err := semver.NewVersion(version)
if err != nil {
return nil, fmt.Errorf("%w: %s", ErrInvalidVersion, err.Error())
}
return version, nil
return semanticVersion, nil
}

// https://github.com/kyma-project/lifecycle-manager/issues/2096
Expand All @@ -279,3 +267,13 @@ func (m *ModuleTemplate) HasSyncDisabled() bool {
}
return false
}

// https://github.com/kyma-project/lifecycle-manager/issues/2096
// Refactor this function to drop the label fallback after the migration to the new ModuleTemplate format is completed.
func (m *ModuleTemplate) GetModuleName() string {
moduleName := m.Spec.ModuleName
if moduleName == "" {
moduleName = m.Labels[shared.ModuleName]
}
return moduleName
}
131 changes: 120 additions & 11 deletions api/v1beta2/moduletemplate_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
apimetav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

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

func Test_GetVersion(t *testing.T) {
func Test_GetSemanticVersion(t *testing.T) {
const testVersion = "1.0.1"
const otherVersion = "0.0.1"
tests := []struct {
Expand All @@ -20,7 +21,7 @@ func Test_GetVersion(t *testing.T) {
expectedErr string
}{
{
name: "Test GetVersion() by annotation (legacy)",
name: "Test GetSemanticVersion() by annotation (legacy)",
m: &v1beta2.ModuleTemplate{
ObjectMeta: apimetav1.ObjectMeta{
Annotations: map[string]string{
Expand All @@ -31,7 +32,7 @@ func Test_GetVersion(t *testing.T) {
expectedVersion: testVersion,
},
{
name: "Test GetVersion() by explicit version in Spec",
name: "Test GetSemanticVersion() by explicit version in Spec",
m: &v1beta2.ModuleTemplate{
Spec: v1beta2.ModuleTemplateSpec{
Version: testVersion,
Expand All @@ -40,7 +41,7 @@ func Test_GetVersion(t *testing.T) {
expectedVersion: testVersion,
},
{
name: "Test GetVersion() with both version in Spec and annotation",
name: "Test GetSemanticVersion() with both version in Spec and annotation",
m: &v1beta2.ModuleTemplate{
ObjectMeta: apimetav1.ObjectMeta{
Annotations: map[string]string{
Expand Down Expand Up @@ -75,32 +76,140 @@ func Test_GetVersion(t *testing.T) {
}
for _, testCase := range tests {
t.Run(testCase.name, func(t *testing.T) {
actualVersion, err := testCase.m.GetVersion()
actualVersion, err := testCase.m.GetSemanticVersion()
if err != nil {
if actualVersion != nil {
t.Errorf("GetVersion(): Returned version should be nil when error is not nil")
t.Errorf("GetSemanticVersion(): Returned version should be nil when error is not nil")
}
if testCase.expectedErr == "" {
t.Errorf("GetVersion(): Unexpected error: %v", err)
t.Errorf("GetSemanticVersion(): Unexpected error: %v", err)
}
if !strings.Contains(err.Error(), testCase.expectedErr) {
t.Errorf("GetVersion(): Actual error = %v, expected error: %v", err, testCase.expectedErr)
t.Errorf("GetSemanticVersion(): Actual error = %v, expected error: %v", err, testCase.expectedErr)
}
return
}

if actualVersion == nil {
t.Errorf("GetVersion(): Returned version should not be nil when error is nil")
t.Errorf("GetSemanticVersion(): Returned version should not be nil when error is nil")
}

if testCase.expectedVersion == "" {
t.Errorf("GetVersion(): Expected version is empty but non-nil version is returned")
t.Errorf("GetSemanticVersion(): Expected version is empty but non-nil version is returned")
}

if actualVersion != nil && actualVersion.String() != testCase.expectedVersion {
t.Errorf("GetVersion(): actual version = %v, expected version: %v", actualVersion.String(),
t.Errorf("GetSemanticVersion(): actual version = %v, expected version: %v", actualVersion.String(),
testCase.expectedVersion)
}
})
}
}

//nolint:dupl // similar but not duplicate
func Test_GetVersion(t *testing.T) {
tests := []struct {
name string
m *v1beta2.ModuleTemplate
expectedVersion string
}{
{
name: "Test GetVersion() by annotation (legacy)",
m: &v1beta2.ModuleTemplate{
ObjectMeta: apimetav1.ObjectMeta{
Annotations: map[string]string{
shared.ModuleVersionAnnotation: "1.0.0-annotated",
},
},
Spec: v1beta2.ModuleTemplateSpec{},
},
expectedVersion: "1.0.0-annotated",
},
{
name: "Test GetVersion() by spec.version",
m: &v1beta2.ModuleTemplate{
ObjectMeta: apimetav1.ObjectMeta{
Annotations: map[string]string{},
},
Spec: v1beta2.ModuleTemplateSpec{
Version: "2.0.0-spec",
},
},
expectedVersion: "2.0.0-spec",
},
{
name: "Test GetVersion() spec.moduleName has priority over annotation",
m: &v1beta2.ModuleTemplate{
ObjectMeta: apimetav1.ObjectMeta{
Annotations: map[string]string{
shared.ModuleVersionAnnotation: "1.0.0-annotated",
},
},
Spec: v1beta2.ModuleTemplateSpec{
Version: "2.0.0-spec",
},
},
expectedVersion: "2.0.0-spec",
},
}
for _, testCase := range tests {
t.Run(testCase.name, func(t *testing.T) {
actualVersion := testCase.m.GetVersion()
assert.Equal(t, testCase.expectedVersion, actualVersion)
})
}
}

//nolint:dupl // similar but not duplicate
func Test_GetModuleName(t *testing.T) {
tests := []struct {
name string
m *v1beta2.ModuleTemplate
expectedName string
}{
{
name: "Test GetModuleName() by label",
m: &v1beta2.ModuleTemplate{
ObjectMeta: apimetav1.ObjectMeta{
Labels: map[string]string{
shared.ModuleName: "labelled-module",
},
},
Spec: v1beta2.ModuleTemplateSpec{},
},
expectedName: "labelled-module",
},
{
name: "Test GetModuleName() by spec.moduleName",
m: &v1beta2.ModuleTemplate{
ObjectMeta: apimetav1.ObjectMeta{
Labels: map[string]string{},
},
Spec: v1beta2.ModuleTemplateSpec{
ModuleName: "spec-module",
},
},
expectedName: "spec-module",
},
{
name: "Test GetModuleName() spec.moduleName has priority over label",
m: &v1beta2.ModuleTemplate{
ObjectMeta: apimetav1.ObjectMeta{
Labels: map[string]string{
shared.ModuleName: "labelled-module",
},
},
Spec: v1beta2.ModuleTemplateSpec{
ModuleName: "spec-module",
},
},
expectedName: "spec-module",
},
}
for _, testCase := range tests {
t.Run(testCase.name, func(t *testing.T) {
actualName := testCase.m.GetModuleName()
assert.Equal(t, testCase.expectedName, actualName)
})
}
}
Loading

0 comments on commit fbe67d7

Please sign in to comment.