From 867593832e59d05e220802d5a95b2ffe9e09bd08 Mon Sep 17 00:00:00 2001 From: Simon Murray Date: Tue, 29 Oct 2024 13:15:59 +0000 Subject: [PATCH] Improve Applications More Unlock the newest semver library, add in some interfaces to make handing nicer, and remove some cruft. --- charts/core/Chart.yaml | 4 +-- .../unikorn-cloud.org_helmapplications.yaml | 9 +++---- go.mod | 3 +-- go.sum | 6 ++--- .../v1alpha1/helmapplication_helpers.go | 18 ++++++++++--- pkg/apis/unikorn/v1alpha1/types.go | 26 ++++++++++++++++++- .../application/provisioner_test.go | 2 +- 7 files changed, 50 insertions(+), 18 deletions(-) diff --git a/charts/core/Chart.yaml b/charts/core/Chart.yaml index cdbf20b..fafdb66 100644 --- a/charts/core/Chart.yaml +++ b/charts/core/Chart.yaml @@ -4,8 +4,8 @@ description: A Helm chart for deploying Unikorn Core type: application -version: v0.1.78 -appVersion: v0.1.78 +version: v0.1.79 +appVersion: v0.1.79 icon: https://assets.unikorn-cloud.org/images/logos/dark-on-light/icon.svg diff --git a/charts/core/crds/unikorn-cloud.org_helmapplications.yaml b/charts/core/crds/unikorn-cloud.org_helmapplications.yaml index db168a2..50c5298 100644 --- a/charts/core/crds/unikorn-cloud.org_helmapplications.yaml +++ b/charts/core/crds/unikorn-cloud.org_helmapplications.yaml @@ -50,11 +50,6 @@ spec: documentation: description: Documentation defines a URL to 3rd party documentation. type: string - exported: - description: |- - Exported defines whether the application should be exported to - the user visiable application manager. - type: boolean icon: description: Icon is a base64 encoded icon for the application. format: byte @@ -122,6 +117,7 @@ spec: type: array name: description: Name of the application to depend on. + minLength: 1 type: string required: - name @@ -146,9 +142,11 @@ spec: properties: name: description: Name is the name of the parameter. + minLength: 1 type: string value: description: Value is the value of the parameter. + minLength: 1 type: string required: - name @@ -170,6 +168,7 @@ spec: Name of the application to require. That recommendation MUST have a dependency with any constraints on this application. + minLength: 1 type: string required: - name diff --git a/go.mod b/go.mod index 9b53a26..cc4ba70 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,10 @@ module github.com/unikorn-cloud/core go 1.23.2 require ( + github.com/Masterminds/semver/v3 v3.3.0 github.com/getkin/kin-openapi v0.128.0 github.com/go-logr/logr v1.4.2 github.com/go-openapi/jsonpointer v0.21.0 - github.com/masterminds/semver v1.5.0 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.9.0 go.opentelemetry.io/otel v1.31.0 @@ -26,7 +26,6 @@ require ( ) require ( - github.com/Masterminds/semver v1.5.0 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect diff --git a/go.sum b/go.sum index c5f2b8d..78eeced 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= -github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= +github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0= +github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= @@ -81,8 +81,6 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= -github.com/masterminds/semver v1.5.0 h1:hTxJTTY7tjvnWMrl08O6u3G6BLlKVwxSz01lVac9P8U= -github.com/masterminds/semver v1.5.0/go.mod h1:s7KNT9fnd7edGzwwP7RBX4H0v/CYd5qdOLfkL1V75yg= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= diff --git a/pkg/apis/unikorn/v1alpha1/helmapplication_helpers.go b/pkg/apis/unikorn/v1alpha1/helmapplication_helpers.go index 2bbf642..7d9d47d 100644 --- a/pkg/apis/unikorn/v1alpha1/helmapplication_helpers.go +++ b/pkg/apis/unikorn/v1alpha1/helmapplication_helpers.go @@ -20,6 +20,7 @@ package v1alpha1 import ( "errors" "fmt" + "iter" "strings" ) @@ -33,10 +34,21 @@ func CompareHelmApplication(a, b HelmApplication) int { return strings.Compare(a.Name, b.Name) } +// Versions returns an iterator over versions. +func (a *HelmApplication) Versions() iter.Seq[*HelmApplicationVersion] { + return func(yield func(*HelmApplicationVersion) bool) { + for i := range a.Spec.Versions { + if !yield(&a.Spec.Versions[i]) { + break + } + } + } +} + func (a *HelmApplication) GetVersion(version SemanticVersion) (*HelmApplicationVersion, error) { - for i := range a.Spec.Versions { - if a.Spec.Versions[i].Version.Equal(&version.Version) { - return &a.Spec.Versions[i], nil + for v := range a.Versions() { + if v.Version.Equal(&version) { + return v, nil } } diff --git a/pkg/apis/unikorn/v1alpha1/types.go b/pkg/apis/unikorn/v1alpha1/types.go index dfaf756..0a1d44d 100644 --- a/pkg/apis/unikorn/v1alpha1/types.go +++ b/pkg/apis/unikorn/v1alpha1/types.go @@ -22,7 +22,7 @@ import ( "errors" "net" - "github.com/masterminds/semver" + "github.com/Masterminds/semver/v3" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -43,6 +43,30 @@ type SemanticVersion struct { semver.Version } +func (v SemanticVersion) Compare(o *SemanticVersion) int { + return v.Version.Compare(&o.Version) +} + +func (v SemanticVersion) Equal(o *SemanticVersion) bool { + return v.Version.Equal(&o.Version) +} + +func (v SemanticVersion) GreaterThan(o *SemanticVersion) bool { + return v.Version.GreaterThan(&o.Version) +} + +func (v SemanticVersion) GreaterThanEqual(o *SemanticVersion) bool { + return v.Version.GreaterThanEqual(&o.Version) +} + +func (v SemanticVersion) LessThan(o *SemanticVersion) bool { + return v.Version.LessThan(&o.Version) +} + +func (v SemanticVersion) LessThanEqual(o *SemanticVersion) bool { + return v.Version.LessThanEqual(&o.Version) +} + func (v *SemanticVersion) UnmarshalJSON(b []byte) error { return json.Unmarshal(b, &v.Version) } diff --git a/pkg/provisioners/application/provisioner_test.go b/pkg/provisioners/application/provisioner_test.go index 7e4cc8d..fb8e648 100644 --- a/pkg/provisioners/application/provisioner_test.go +++ b/pkg/provisioners/application/provisioner_test.go @@ -21,7 +21,7 @@ import ( "context" "testing" - "github.com/masterminds/semver" + "github.com/Masterminds/semver/v3" "github.com/stretchr/testify/assert" "go.uber.org/mock/gomock"