Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pkg/docker/image.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package docker

import (
"errors"
"fmt"
"regexp"
"strings"
Expand Down Expand Up @@ -146,3 +147,20 @@ func AllToRepository(images []*Image, repo string) (list []*Image) {
}
return list
}

var errInvalidVersion = errors.New("invalid image version")

// ImageRepoAndTag returns the Repo and tag from a container image.
//
// e.g. `dtr.efzp.com:9026/mirantis/ucp-agent:3.8.10` => `dtr.efzp.com:9026/mirantis/ucp-agent`, `3.8.10`
func ImageRepoAndTag(image string) (string, string, error) {
vparts := strings.Split(image, ":")
vpartslen := len(vparts)
if vpartslen < 2 || vpartslen > 3 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that these are the right boundaries? Perhaps just >2 is needed.

Copy link
Contributor

@pgedara pgedara Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it support images without a specific tag? I mean the latest tag.

return "", "", fmt.Errorf("%w: malformed version output: %s", errInvalidVersion, image)
}

repo := strings.Join(vparts[0:vpartslen-1], ":")
version := vparts[vpartslen-1]
return repo, version, nil
}
14 changes: 14 additions & 0 deletions pkg/docker/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,17 @@ registry.ci.mirantis.com/mirantiseng/ucp-auth-store:3.8.7`
require.Equal(t, "registry.ci.mirantis.com/mirantiseng/ucp-alertmanager:3.8.7", images[1].String())
require.Equal(t, "registry.ci.mirantis.com/mirantiseng/ucp-auth-store:3.8.7", images[2].String())
}

func TestImageVersions(t *testing.T) {
repo, tag, err := docker.ImageRepoAndTag("mirantis/ucp-proxy:3.8.8")
require.Nil(t, err, "SwarmMKEVersion gave unexpected error from valid version string")
require.Equal(t, "mirantis/ucp-proxy", repo, "SwarmMKEVersion gave wrong repo value")
require.Equal(t, "3.8.8", tag, "SwarmMKEVersion gave wrong repo value")
}

func TestImageVersionsWithColon(t *testing.T) {
repo, tag, err := docker.ImageRepoAndTag("dtr.efzp.com:9026/mirantis/ucp-agent:3.8.10")
require.Nil(t, err, "SwarmMKEVersion gave unexpected error from valid version string")
require.Equal(t, "dtr.efzp.com:9026/mirantis/ucp-agent", repo, "SwarmMKEVersion gave wrong repo value")
require.Equal(t, "3.8.10", tag, "SwarmMKEVersion gave wrong repo value")
}
15 changes: 6 additions & 9 deletions pkg/mke/mke.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

"github.com/Mirantis/launchpad/pkg/constant"
"github.com/Mirantis/launchpad/pkg/docker"
commonconfig "github.com/Mirantis/launchpad/pkg/product/common/config"
mkeconfig "github.com/Mirantis/launchpad/pkg/product/mke/config"
"github.com/hashicorp/go-version"
Expand All @@ -40,8 +41,6 @@ type Credentials struct {
Password string `json:"password,omitempty"`
}

var errInvalidVersion = errors.New("invalid version")

// CollectFacts gathers the current status of installed mke setup.
func CollectFacts(swarmLeader *mkeconfig.Host, mkeMeta *mkeconfig.MKEMetadata) error {
output, err := swarmLeader.ExecOutput(swarmLeader.Configurer.DockerCommandf(`inspect --format '{{.Config.Image}}' ucp-proxy`))
Expand All @@ -51,15 +50,13 @@ func CollectFacts(swarmLeader *mkeconfig.Host, mkeMeta *mkeconfig.MKEMetadata) e
return nil
}

vparts := strings.Split(output, ":")
if len(vparts) != 2 {
return fmt.Errorf("%w: malformed version output: %s", errInvalidVersion, output)
repo, tag, verr := docker.ImageRepoAndTag(output)
if verr != nil {
return fmt.Errorf("%w: malformed version output: %s", verr, output)
}
repo := vparts[0][:strings.LastIndexByte(vparts[0], '/')]

mkeMeta.Installed = true
mkeMeta.InstalledVersion = vparts[1]
mkeMeta.InstalledBootstrapImage = fmt.Sprintf("%s:/ucp:%s", repo, vparts[1])
mkeMeta.InstalledVersion = tag
mkeMeta.InstalledBootstrapImage = fmt.Sprintf("%s:/ucp:%s", repo, tag)

// Find out calico data plane by inspecting the calico container's env variables
cmd := swarmLeader.Configurer.DockerCommandf(`ps --filter label=name="Calico node" --format {{.ID}}`)
Expand Down