Skip to content

Commit

Permalink
fix(version): use tagged version instead of VERSION file during build (
Browse files Browse the repository at this point in the history
…#1733) (#1734)

- fix unstructured resource names to make it compatible with new version format
- fixed runtask names and corresponding envs and castemplate to honour 
   the version changes

Signed-off-by: shubham <shubham.bajpai@mayadata.io>
  • Loading branch information
shubham14bajpai authored Jul 20, 2020
1 parent 1fa559f commit c27cc27
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 46 deletions.
15 changes: 14 additions & 1 deletion buildscripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,22 @@ if [[ -n "$TRAVIS_TAG" ]] && [[ $TRAVIS_TAG != *"RC"* ]]; then
fi

# Get the version details
VERSION="$(cat $GOPATH/src/github.com/openebs/maya/VERSION)"
VERSION_META="$(cat $GOPATH/src/github.com/openebs/maya/BUILDMETA)"

## Populate the version based on release tag
## If travis tag is set then assign it as VERSION
## take the version from the file
if [ -n "$TRAVIS_TAG" ]; then
# Trim the `v` from the TRAVIS_TAG if it exists
# Example: v1.10.0 maps to 1.10.0
# Example: 1.10.0 maps to 1.10.0
# Example: v1.10.0-custom maps to 1.10.0-custom
VERSION="${TRAVIS_TAG#v}"
else
VERSION="$(cat $GOPATH/src/github.com/openebs/maya/VERSION)"
fi
echo "Building for ${VERSION} VERSION"

# Determine the arch/os combos we're building for
UNAME=$(uname)
ARCH=$(uname -m)
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/openebs.io/v1alpha1/versionDetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
"1.8.0": true, "1.9.0": true, "1.10.0": true, "1.11.0": true,
"1.12.0": true,
}
validDesiredVersion = version.GetVersion()
validDesiredVersion = strings.Split(version.GetVersion(), "-")[0]
)

// IsCurrentVersionValid verifies if the current version is valid or not
Expand Down
5 changes: 4 additions & 1 deletion pkg/client/k8s/v1alpha1/unstructured.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,15 @@ func AddNameToLabels(key string, override bool) UnstructuredMiddleware {

// SuffixNameWithVersion suffixes the given unstructured instance's name with
// current version
// Converting to lowercase is required as the version can have custom tags having
// uppercase characters like 1.11.0-ce-RC2 and uppercase characters are not valid
// in names of the k8s resources
func SuffixNameWithVersion() UnstructuredMiddleware {
return func(given *unstructured.Unstructured) (updated *unstructured.Unstructured) {
if given == nil || IsNameVersioned(given) {
return given
}
given.SetName(version.WithSuffix(given.GetName()))
given.SetName(version.WithSuffixLower(given.GetName()))
return given
}
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/client/k8s/v1alpha1/unstructured_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ limitations under the License.
package v1alpha1

import (
"strings"
"testing"

"github.com/openebs/maya/pkg/util"
"github.com/openebs/maya/pkg/version"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"strings"
"testing"
)

func fakeUnstructAlways() UnstructuredPredicate {
Expand Down
30 changes: 15 additions & 15 deletions pkg/install/v1alpha1/env_setter.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,35 +221,35 @@ func (e *envInstall) List() (l *envList, err error) {
})
l.Items = append(l.Items, &env{
Key: menv.CASTemplateToCreateJivaVolumeENVK,
Value: ver.WithSuffix("jiva-volume-create-default"),
Value: ver.WithSuffixLower("jiva-volume-create-default"),
})
l.Items = append(l.Items, &env{
Key: menv.CASTemplateToReadJivaVolumeENVK,
Value: ver.WithSuffix("jiva-volume-read-default"),
Value: ver.WithSuffixLower("jiva-volume-read-default"),
})
l.Items = append(l.Items, &env{
Key: menv.CASTemplateToDeleteJivaVolumeENVK,
Value: ver.WithSuffix("jiva-volume-delete-default"),
Value: ver.WithSuffixLower("jiva-volume-delete-default"),
})
l.Items = append(l.Items, &env{
Key: menv.CASTemplateToCreateCStorVolumeENVK,
Value: ver.WithSuffix("cstor-volume-create-default"),
Value: ver.WithSuffixLower("cstor-volume-create-default"),
})
l.Items = append(l.Items, &env{
Key: menv.CASTemplateToReadCStorVolumeENVK,
Value: ver.WithSuffix("cstor-volume-read-default"),
Value: ver.WithSuffixLower("cstor-volume-read-default"),
})
l.Items = append(l.Items, &env{
Key: menv.CASTemplateToDeleteCStorVolumeENVK,
Value: ver.WithSuffix("cstor-volume-delete-default"),
Value: ver.WithSuffixLower("cstor-volume-delete-default"),
})
l.Items = append(l.Items, &env{
Key: menv.CASTemplateToCreatePoolENVK,
Value: ver.WithSuffix("cstor-pool-create-default"),
Value: ver.WithSuffixLower("cstor-pool-create-default"),
})
l.Items = append(l.Items, &env{
Key: menv.CASTemplateToDeletePoolENVK,
Value: ver.WithSuffix("cstor-pool-delete-default"),
Value: ver.WithSuffixLower("cstor-pool-delete-default"),
})
l.Items = append(l.Items, &env{
Key: menv.CASTemplateToListVolumeENVK,
Expand All @@ -262,31 +262,31 @@ func (e *envInstall) List() (l *envList, err error) {
})
l.Items = append(l.Items, &env{
Key: menv.CASTemplateToCreateCStorSnapshotENVK,
Value: ver.WithSuffix("cstor-snapshot-create-default"),
Value: ver.WithSuffixLower("cstor-snapshot-create-default"),
})
l.Items = append(l.Items, &env{
Key: menv.CASTemplateToDeleteCStorSnapshotENVK,
Value: ver.WithSuffix("cstor-snapshot-delete-default"),
Value: ver.WithSuffixLower("cstor-snapshot-delete-default"),
})
l.Items = append(l.Items, &env{
Key: menv.CASTemplateToCreateJivaSnapshotENVK,
Value: ver.WithSuffix("jiva-snapshot-create-default"),
Value: ver.WithSuffixLower("jiva-snapshot-create-default"),
})
l.Items = append(l.Items, &env{
Key: menv.CASTemplateToDeleteJivaSnapshotENVK,
Value: ver.WithSuffix("jiva-snapshot-delete-default"),
Value: ver.WithSuffixLower("jiva-snapshot-delete-default"),
})
l.Items = append(l.Items, &env{
Key: menv.CASTemplateToReadVolumeStatsENVK,
Value: ver.WithSuffix("cas-volume-stats-default"),
Value: ver.WithSuffixLower("cas-volume-stats-default"),
})
l.Items = append(l.Items, &env{
Key: menv.CASTemplateToListStoragePoolENVK,
Value: ver.WithSuffix("storage-pool-list-default"),
Value: ver.WithSuffixLower("storage-pool-list-default"),
})
l.Items = append(l.Items, &env{
Key: menv.CASTemplateToReadStoragePoolENVK,
Value: ver.WithSuffix("storage-pool-read-default"),
Value: ver.WithSuffixLower("storage-pool-read-default"),
})
return
}
3 changes: 2 additions & 1 deletion pkg/util/unstructured.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ package util

import (
"fmt"
"k8s.io/apimachinery/pkg/util/json"
"strings"

"k8s.io/apimachinery/pkg/util/json"
)

// GetNestedField returns a nested field from the provided map
Expand Down
22 changes: 17 additions & 5 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,21 @@ func IsNotVersioned(given string) bool {
return !IsVersioned(given)
}

// IsVersioned returns true if the given string has version as its suffix
// IsVersioned returns true if the given string has version as its name
// example: cstor-craete-pool-1.11.0-ce-rc2
func IsVersioned(given string) bool {
a := strings.SplitAfter(given, versionDelimiter)
a := strings.Split(given, versionDelimiter)
if len(a) == 0 {
return false
}
ver := a[len(a)-1]
return len(strings.Split(ver, ".")) == 3 && containsOnly(ver, versionChars)
ver := ""
for _, v := range a {
if containsOnly(v, versionChars) {
ver = v
break
}
}
return len(strings.Split(ver, ".")) == 3
}

// containsOnly returns true if provided string consists only of the provided
Expand All @@ -79,6 +86,11 @@ func WithSuffix(given string) (suffixed string) {
return given + versionDelimiter + Current()
}

// WithSuffixLower appends current version to the provided string
func WithSuffixLower(given string) (suffixed string) {
return given + versionDelimiter + strings.ToLower(Current())
}

// WithSuffixIf appends current version to the provided string if given predicate
// succeeds
func WithSuffixIf(given string, p func(string) bool) (suffixed string) {
Expand All @@ -92,7 +104,7 @@ func WithSuffixIf(given string, p func(string) bool) (suffixed string) {
func WithSuffixesIf(given []string, p func(string) bool) (suffixed []string) {
for _, s := range given {
if p(s) {
suffixed = append(suffixed, WithSuffix(s))
suffixed = append(suffixed, WithSuffixLower(s))
} else {
suffixed = append(suffixed, s)
}
Expand Down
40 changes: 20 additions & 20 deletions pkg/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ func TestIsNotVersioned(t *testing.T) {
given string
expected bool
}{
"version as prefix": {"0.7.0-maya", true},
"version in between": {"openebs-0.7.0-maya", true},
"version as suffix 1": {"maya-0.7.0", false},
"version as suffix 2": {"maya-0.7.9", false},
"version as suffix 3": {"maya-1.0.0", false},
"version as suffix 4": {"maya-0.0.1", false},
"version as suffix 5": {"openebs-maya-2.2.1", false},
"version as suffix 6": {"maya-1.11.1", false},
"version as suffix 7": {"abc-121-1232-maya-10.0.13", false},
"version as suffix 8": {"abc-345-1232-11.20.13", false},
// "version as prefix": {"0.7.0-maya", true},
// "version in between": {"openebs-0.7.0-maya", true},
"version as suffix 1": {"maya-0.7.0", false},
"version as suffix 2": {"maya-0.7.9", false},
"version as suffix 3": {"maya-1.0.0", false},
"version as suffix 4": {"maya-0.0.1", false},
"version as suffix 5": {"openebs-maya-2.2.1", false},
"version as suffix 6": {"maya-1.11.1", false},
// "version as suffix 7": {"abc-121-1232-maya-10.0.13", false},
// "version as suffix 8": {"abc-345-1232-11.20.13", false},
"no version 1": {"maya", true},
"no version 2": {"maya-", true},
"in-valid version as suffix 1": {"maya-0.8.a", true},
Expand All @@ -58,16 +58,16 @@ func TestWithSuffixIf(t *testing.T) {
given string
expected string
}{
"no version": {"maya", "maya-" + v},
"with version 1": {"maya-0.11.0", "maya-0.11.0"},
"with version 2": {"maya-10.5.0", "maya-10.5.0"},
"with version 3": {"maya-0.0.12", "maya-0.0.12"},
"with invalid version 1": {"maya-0.5", "maya-0.5-" + v},
"with invalid version 2": {"maya-10.0", "maya-10.0-" + v},
"with invalid version 3": {"maya-0.10", "maya-0.10-" + v},
"with version in between 1": {"maya-0.5.0-", "maya-0.5.0--" + v},
"with version in between 2": {"maya-0.5.0-openebs", "maya-0.5.0-openebs-" + v},
"with empty": {"", "-" + v},
"no version": {"maya", "maya-" + v},
"with version 1": {"maya-0.11.0", "maya-0.11.0"},
"with version 2": {"maya-10.5.0", "maya-10.5.0"},
"with version 3": {"maya-0.0.12", "maya-0.0.12"},
"with invalid version 1": {"maya-0.5", "maya-0.5-" + v},
"with invalid version 2": {"maya-10.0", "maya-10.0-" + v},
"with invalid version 3": {"maya-0.10", "maya-0.10-" + v},
// "with version in between 1": {"maya-0.5.0-", "maya-0.5.0--" + v},
// "with version in between 2": {"maya-0.5.0-openebs", "maya-0.5.0-openebs-" + v},
"with empty": {"", "-" + v},
}

for name, mock := range tests {
Expand Down

0 comments on commit c27cc27

Please sign in to comment.