diff --git a/controllers/update/reconcile.go b/controllers/update/reconcile.go index fa6f0b6..dd08c99 100644 --- a/controllers/update/reconcile.go +++ b/controllers/update/reconcile.go @@ -1,14 +1,12 @@ package update import ( - "errors" "fmt" "strconv" - "strings" - "github.com/Masterminds/semver/v3" v2 "github.com/metal-stack/firewall-controller-manager/api/v2" "github.com/metal-stack/firewall-controller-manager/controllers" + metalcommon "github.com/metal-stack/metal-lib/pkg/metal" "k8s.io/client-go/util/retry" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -31,7 +29,7 @@ func (c *controller) autoUpdateOS(r *controllers.Ctx[*v2.FirewallDeployment]) er // first, let's resolve the latest image from the api - os, version, err := getOsAndSemverFromImage(r.Target.Spec.Template.Spec.Image) + os, version, err := metalcommon.GetOsAndSemverFromImage(r.Target.Spec.Template.Spec.Image) if err != nil { return fmt.Errorf("image version cannot be parsed: %w", err) } @@ -127,20 +125,3 @@ func (c *controller) autoUpdateOS(r *controllers.Ctx[*v2.FirewallDeployment]) er return nil } - -// copied over from metal-api because this is only available in internal package -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 0c1dd39..dd06566 100644 --- a/go.mod +++ b/go.mod @@ -10,10 +10,11 @@ require ( github.com/google/go-cmp v0.6.0 github.com/google/uuid v1.6.0 github.com/metal-stack/metal-go v0.28.4 - github.com/metal-stack/metal-lib v0.16.2 + github.com/metal-stack/metal-lib v0.17.2 github.com/metal-stack/v v1.0.3 github.com/onsi/ginkgo/v2 v2.17.1 github.com/onsi/gomega v1.32.0 + github.com/prometheus/client_golang v1.18.0 github.com/stretchr/testify v1.9.0 k8s.io/api v0.29.3 k8s.io/apimachinery v0.29.3 @@ -89,7 +90,6 @@ require ( github.com/pelletier/go-toml/v2 v2.1.1 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/prometheus/client_golang v1.18.0 // indirect github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.45.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect diff --git a/go.sum b/go.sum index 46e2547..5e9d9f4 100644 --- a/go.sum +++ b/go.sum @@ -218,8 +218,8 @@ github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvls github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= github.com/metal-stack/metal-go v0.28.4 h1:cTI2jZqn59FNw0RkPAD7TYeK5YKJjj94YFJiuRl8eDo= github.com/metal-stack/metal-go v0.28.4/go.mod h1:gYLZX3umsoZLWZ5d4MJdVbnR8eFXUTlLTK7tyx638As= -github.com/metal-stack/metal-lib v0.16.2 h1:RJls/Spai4h5xr3BEmQt9UdWNN4RB9+SOINoZcjYaA8= -github.com/metal-stack/metal-lib v0.16.2/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=