From 89978cc719407884f5c2f3c3927e63022c498afe Mon Sep 17 00:00:00 2001 From: Gerrit Date: Tue, 23 Jul 2024 11:43:57 +0200 Subject: [PATCH] Update metal-lib to v0.17.2. (#552) --- cmd/metal-api/internal/datastore/image.go | 6 ++-- .../internal/datastore/image_test.go | 4 +-- cmd/metal-api/internal/metal/filesystem.go | 5 ++-- .../internal/service/image-service.go | 4 +-- cmd/metal-api/internal/utils/utils.go | 29 ------------------- go.mod | 2 +- go.sum | 4 +-- 7 files changed, 13 insertions(+), 41 deletions(-) delete mode 100644 cmd/metal-api/internal/utils/utils.go diff --git a/cmd/metal-api/internal/datastore/image.go b/cmd/metal-api/internal/datastore/image.go index fe761e0de..1ae6927ed 100644 --- a/cmd/metal-api/internal/datastore/image.go +++ b/cmd/metal-api/internal/datastore/image.go @@ -8,7 +8,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/metal-stack/metal-api/cmd/metal-api/internal/metal" - "github.com/metal-stack/metal-api/cmd/metal-api/internal/utils" + metalcommon "github.com/metal-stack/metal-lib/pkg/metal" r "gopkg.in/rethinkdb/rethinkdb-go.v6" ) @@ -201,7 +201,7 @@ func isOrphanImage(image metal.Image, machines metal.Machines) bool { // then the most recent ubuntu image (ubuntu-19.10.20200407) is returned // If patch is specified e.g. ubuntu-20.04.20200502 then this exact image is searched. func (rs *RethinkStore) getMostRecentImageFor(id string, images metal.Images) (*metal.Image, error) { - os, sv, err := utils.GetOsAndSemverFromImage(id) + os, sv, err := metalcommon.GetOsAndSemverFromImage(id) if err != nil { return nil, err } @@ -248,7 +248,7 @@ func (rs *RethinkStore) getMostRecentImageFor(id string, images metal.Images) (* // then all ubuntu images (ubuntu-19.10.*) are returned // If patch is specified e.g. ubuntu-20.04.20200502 then this exact image is searched. func getImagesFor(id string, images metal.Images) ([]metal.Image, error) { - os, sv, err := utils.GetOsAndSemverFromImage(id) + os, sv, err := metalcommon.GetOsAndSemverFromImage(id) if err != nil { return nil, err } diff --git a/cmd/metal-api/internal/datastore/image_test.go b/cmd/metal-api/internal/datastore/image_test.go index 390621135..af23dfd1e 100644 --- a/cmd/metal-api/internal/datastore/image_test.go +++ b/cmd/metal-api/internal/datastore/image_test.go @@ -9,7 +9,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/metal-stack/metal-api/cmd/metal-api/internal/metal" "github.com/metal-stack/metal-api/cmd/metal-api/internal/testdata" - "github.com/metal-stack/metal-api/cmd/metal-api/internal/utils" + metalcommon "github.com/metal-stack/metal-lib/pkg/metal" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -403,7 +403,7 @@ func TestGetOsAndSemver(t *testing.T) { for i := range tests { tt := tests[i] t.Run(tt.name, func(t *testing.T) { - os, version, err := utils.GetOsAndSemverFromImage(tt.id) + os, version, err := metalcommon.GetOsAndSemverFromImage(tt.id) if (err != nil) != tt.wantErr { t.Errorf("GetOsAndSemver() error = %v, wantErr %v", err, tt.wantErr) return diff --git a/cmd/metal-api/internal/metal/filesystem.go b/cmd/metal-api/internal/metal/filesystem.go index 0151d29ef..0934c5d7c 100644 --- a/cmd/metal-api/internal/metal/filesystem.go +++ b/cmd/metal-api/internal/metal/filesystem.go @@ -8,7 +8,8 @@ import ( "strings" "github.com/Masterminds/semver/v3" - "github.com/metal-stack/metal-api/cmd/metal-api/internal/utils" + + metalcommon "github.com/metal-stack/metal-lib/pkg/metal" ) const ( @@ -470,7 +471,7 @@ func (c *FilesystemLayoutConstraints) matches(sizeID, imageID string) bool { } // Size matches for os, versionconstraint := range c.Images { - imageos, version, err := utils.GetOsAndSemverFromImage(imageID) + imageos, version, err := metalcommon.GetOsAndSemverFromImage(imageID) if err != nil { return false } diff --git a/cmd/metal-api/internal/service/image-service.go b/cmd/metal-api/internal/service/image-service.go index b24b8d126..0d6b06a01 100644 --- a/cmd/metal-api/internal/service/image-service.go +++ b/cmd/metal-api/internal/service/image-service.go @@ -11,8 +11,8 @@ import ( "github.com/metal-stack/metal-api/cmd/metal-api/internal/datastore" "github.com/metal-stack/metal-api/cmd/metal-api/internal/metal" v1 "github.com/metal-stack/metal-api/cmd/metal-api/internal/service/v1" - "github.com/metal-stack/metal-api/cmd/metal-api/internal/utils" "github.com/metal-stack/metal-lib/auditing" + metalcommon "github.com/metal-stack/metal-lib/pkg/metal" restfulspec "github.com/emicklei/go-restful-openapi/v2" restful "github.com/emicklei/go-restful/v3" @@ -297,7 +297,7 @@ func (r *imageResource) createImage(request *restful.Request, response *restful. features[ft] = true } - os, v, err := utils.GetOsAndSemverFromImage(requestPayload.ID) + os, v, err := metalcommon.GetOsAndSemverFromImage(requestPayload.ID) if err != nil { r.sendError(request, response, httperrors.BadRequest(err)) return diff --git a/cmd/metal-api/internal/utils/utils.go b/cmd/metal-api/internal/utils/utils.go deleted file mode 100644 index 315996dda..000000000 --- a/cmd/metal-api/internal/utils/utils.go +++ /dev/null @@ -1,29 +0,0 @@ -package utils - -import ( - "errors" - "strings" - - "github.com/Masterminds/semver/v3" -) - -// GetOsAndSemverFromImage parses a imageID to OS and Semver, or returns an error -// the last part must be the semantic version, valid ids are: -// ubuntu-19.04 os: ubuntu version: 19.04 -// ubuntu-19.04.20200408 os: ubuntu version: 19.04.20200408 -// ubuntu-small-19.04.20200408 os: ubuntu-small version: 19.04.20200408 -func GetOsAndSemverFromImage(id string) (string, *semver.Version, error) { - imageParts := strings.Split(id, "-") - if len(imageParts) < 2 { - return "", nil, errors.New("image does not contain a version") - } - - parts := len(imageParts) - 1 - os := strings.Join(imageParts[:parts], "-") - version := strings.Join(imageParts[parts:], "") - v, err := semver.NewVersion(version) - if err != nil { - return "", nil, err - } - return os, v, nil -} diff --git a/go.mod b/go.mod index 09fc15553..885132db2 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/looplab/fsm v1.0.2 github.com/metal-stack/go-ipam v1.14.1 github.com/metal-stack/masterdata-api v0.11.4 - github.com/metal-stack/metal-lib v0.17.1 + github.com/metal-stack/metal-lib v0.17.2 github.com/metal-stack/security v0.8.0 github.com/metal-stack/v v1.0.3 github.com/nsqio/go-nsq v1.1.0 diff --git a/go.sum b/go.sum index c67327fe7..945481014 100644 --- a/go.sum +++ b/go.sum @@ -299,8 +299,8 @@ github.com/metal-stack/go-ipam v1.14.1 h1:kTe4GUvLTNd27sad2uzxZUS5jD7pZfgfr077xo github.com/metal-stack/go-ipam v1.14.1/go.mod h1:0KqCwF1nTB3SZGED+Z+bxdZwXQjP7CiLPcjGDLMKn3s= github.com/metal-stack/masterdata-api v0.11.4 h1:bgRk7PbD5BjYbmAReaV7gTKKKrW5x/ZzCwj98VSWoJk= github.com/metal-stack/masterdata-api v0.11.4/go.mod h1:fD0AtsoNNaOLqRMBeZzDFljiQW9RlrOnxeZ20Pqhxas= -github.com/metal-stack/metal-lib v0.17.1 h1:JLa4wJ62dgxtY9UOLF+QDk10/i/W5vhzrv8RsundDUY= -github.com/metal-stack/metal-lib v0.17.1/go.mod h1:nyNGI4DZFOcWbSoq2Y6V3SHpFxuXBIqYBZHTb6cy//s= +github.com/metal-stack/metal-lib v0.17.2 h1:T1rxCPgagHW/M0wWSrOj4hWsPZMSt1pYw90Z3vBm88Q= +github.com/metal-stack/metal-lib v0.17.2/go.mod h1:nyNGI4DZFOcWbSoq2Y6V3SHpFxuXBIqYBZHTb6cy//s= github.com/metal-stack/security v0.8.0 h1:tVaSDB9m5clwYrnLyaXfPy7mQlJTnmeoHscG+RUy/xo= github.com/metal-stack/security v0.8.0/go.mod h1:7GAcQb+pOgflW30ohJygxpqc3i0dQ2ahGJK1CU5tqa0= github.com/metal-stack/v v1.0.3 h1:Sh2oBlnxrCUD+mVpzfC8HiqL045YWkxs0gpTvkjppqs=