Skip to content

Commit 1fcb411

Browse files
committed
dev: rework version checker
1 parent a2284dc commit 1fcb411

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

pkg/controller/chi/worker-app-version.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@ package chi
1616

1717
import (
1818
"context"
19-
"fmt"
20-
2119
api "github.com/altinity/clickhouse-operator/pkg/apis/clickhouse.altinity.com/v1"
2220
"github.com/altinity/clickhouse-operator/pkg/apis/swversion"
2321
"github.com/altinity/clickhouse-operator/pkg/controller/common/poller/domain"
2422
)
2523

26-
var errUnknownVersion = fmt.Errorf("unknown version")
27-
2824
func (w *worker) getTagBasedVersion(host *api.Host) *swversion.SoftWareVersion {
2925
// Fetch tag from the image
3026
var tagBasedVersion *swversion.SoftWareVersion
@@ -35,30 +31,24 @@ func (w *worker) getTagBasedVersion(host *api.Host) *swversion.SoftWareVersion {
3531
}
3632

3733
// getHostClickHouseVersion gets host ClickHouse version
38-
func (w *worker) getHostClickHouseVersion(ctx context.Context, host *api.Host) (*swversion.SoftWareVersion, error) {
34+
func (w *worker) getHostClickHouseVersion(ctx context.Context, host *api.Host) *swversion.SoftWareVersion {
3935
version, err := w.ensureClusterSchemer(host).HostClickHouseVersion(ctx, host)
4036
if err != nil {
41-
w.a.V(1).M(host).F().Warning("Failed to get ClickHouse version on host: %s", host.GetName())
42-
return nil, err
37+
w.a.V(1).M(host).F().Warning("Failed to get ClickHouse version on host: %s err: %v", host.GetName(), err)
38+
return nil
4339
}
4440

4541
w.a.V(1).M(host).F().Info("Get ClickHouse version on host: %s version: %s", host.GetName(), version)
46-
v := swversion.NewSoftWareVersion(version)
47-
if v.IsUnknown() {
48-
return nil, errUnknownVersion
49-
}
50-
51-
return v, nil
42+
return swversion.NewSoftWareVersion(version)
5243
}
5344

5445
func (w *worker) pollHostForClickHouseVersion(ctx context.Context, host *api.Host) (version *swversion.SoftWareVersion, err error) {
5546
err = domain.PollHost(
5647
ctx,
5748
host,
5849
func(_ctx context.Context, _host *api.Host) bool {
59-
var e error
60-
version, e = w.getHostClickHouseVersion(_ctx, _host)
61-
if e == nil {
50+
version = w.getHostClickHouseVersion(_ctx, _host)
51+
if version.IsKnown() {
6252
return true
6353
}
6454
w.a.V(1).M(host).F().Warning("Host is NOT alive: %s ", host.GetName())

pkg/controller/chi/worker-reconciler-helper.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,28 @@ func (w *worker) getHostSoftwareVersion(ctx context.Context, host *api.Host) *sw
4343
if tagBasedOnly, description := opts.tagBasedOnly(host); tagBasedOnly {
4444
return swversion.MinVersion().SetDescription("set min version cause unable to parse from the tag: '%s' via '%s'", tagBasedVersion.GetOriginal(), description)
4545
}
46-
w.a.V(1).M(host).F().Info("Fallback to host-detected version. Tag: '%s' Host: %s ", tagBasedVersion.GetOriginal(), host.GetName())
46+
w.a.V(1).M(host).F().Info("Fallback to app-based version. Tag: '%s' Host: %s ", tagBasedVersion.GetOriginal(), host.GetName())
4747
}
4848

4949
// Try to report version from the app
50-
if appBasedVersion, err := w.getHostClickHouseVersion(ctx, host); err == nil {
50+
if appBasedVersion := w.getHostClickHouseVersion(ctx, host); appBasedVersion.IsKnown() {
5151
// Able to fetch version from the app - report version
5252
return appBasedVersion.SetDescription("fetched from the host")
5353
}
5454

5555
// Unable to acquire any version - report min one
56-
return swversion.MinVersion().SetDescription("min - unable to acquire neither from the tag nor from the host")
56+
return swversion.MinVersion().SetDescription("min - unable to acquire neither from the tag nor from the app")
5757
}
5858

5959
func (w *worker) isHostSoftwareAbleToRespond(ctx context.Context, host *api.Host) error {
6060
// Check whether the software is able to respond its version
61-
version, err := w.getHostClickHouseVersion(ctx, host)
62-
if err != nil {
63-
w.a.V(1).M(host).F().Info("Host software is not alive - version NOT detected. Host: %s Err: %v", host.GetName(), err)
61+
version := w.getHostClickHouseVersion(ctx, host)
62+
if version.IsKnown() {
63+
w.a.V(1).M(host).F().Info("Host software is alive - version detected. Host: %s version: %s", host.GetName(), version)
64+
} else {
65+
w.a.V(1).M(host).F().Info("Host software is not alive - version NOT detected. Host: %s ", host.GetName())
6466
}
6567

66-
w.a.V(1).M(host).F().Info("Host software is alive - version detected. Host: %s version: %s", host.GetName(), version)
6768
return nil
6869
}
6970

0 commit comments

Comments
 (0)