8000 Read the version from image tags pinned with a digest by clain23 · Pull Request #2151 · Altinity/clickhouse-operator · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
3 changes: 3 additions & 0 deletions pkg/controller/chi/worker-reconciler-chi.go
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,9 @@ func (w *worker) reconcileHostTables(ctx context.Context, host *api.Host, opts *
return err
}
version = v
// A new host whose image tag carries no version gets MinVersion from findMinMaxVersions.
// The schemer is built from host.Runtime.Version, so hand it the version the host just reported.
host.Runtime.Version = v
w.a.V(1).
M(host).F().
Info("Check host for ClickHouse availability. Host: %s ClickHouse version available: %s", host.GetName(), version)
Expand Down
8 changes: 7 additions & 1 deletion pkg/model/k8s/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,13 @@ func ContainerGetImageTag(container *core.Container) (string, bool) {
if container == nil {
return "", false
}
parts, err := docker.Parse(container.Image)
// For "name:tag@sha256:..." docker.Parse keeps only the digest, so the tag (and the version in it)
// is lost. Parse the reference without the digest when its name still carries an explicit tag.
image := container.Image
if name, _, found := strings.Cut(image, "@"); found && strings.Contains(path.Base(name), ":") {
image = name
}
parts, err := docker.Parse(image)
if err != nil {
return "", false
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/model/k8s/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ func TestImageGetBaseName(t *testing.T) {
}
}

func TestContainerGetImageTag(t *testing.T) {
for image, want := range map[string]string{
"clickhouse/clickhouse-server:26.8.2.7": "26.8.2.7",
"clickhouse/clickhouse-server:26.8.2.7@sha256:" + sha256Digest: "26.8.2.7",
"registry.example.com:5000/clickhouse/clickhouse-server:26.8.2.7@sha256:" + sha256Digest: "26.8.2.7",
"registry.example.com:5000/clickhouse/clickhouse-server@sha256:" + sha256Digest: "sha256:" + sha256Digest,
"clickhouse/clickhouse-server": "latest",
} {
got, ok := ContainerGetImageTag(&core.Container{Image: image})
require.True(t, ok, image)
require.Equal(t, want, got, image)
}

_, ok := ContainerGetImageTag(nil)
require.False(t, ok)
}

func TestPodSpecContainerGet(t *testing.T) {
spec := &core.PodSpec{Containers: []core.Container{{Name: "sidecar"}, {Name: "clickhouse"}}}

Expand Down
Loading
0