Skip to content

Disable update checks unless it's a published release #728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions .github/workflows/image-build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ jobs:
uses: sigstore/cosign-installer@3454372f43399081ed03b604cb2d021dabca52bb # v3.8.2

- name: Build and Push Image to GHCR
env:
GOFLAGS: "-ldflags=-s -w -X github.com/stacklok/toolhive/pkg/versions.Version=${{ steps.version-string.outputs.tag }} -X github.com/stacklok/toolhive/pkg/versions.Commit=${{ github.sha }} -X github.com/stacklok/toolhive/pkg/versions.BuildDate=${{ github.event.head_commit.timestamp }} -X github.com/stacklok/toolhive/pkg/versions.BuildType=release"
run: |
TAG=$(echo "${{ steps.version-string.outputs.tag }}" | sed 's/+/_/g')
TAGS="-t $TAG"
Expand Down Expand Up @@ -209,6 +211,8 @@ jobs:
uses: sigstore/cosign-installer@3454372f43399081ed03b604cb2d021dabca52bb # v3.8.2

- name: Build and Push Image to GHCR
env:
GOFLAGS: "-ldflags=-s -w -X github.com/stacklok/toolhive/pkg/versions.Version=${{ steps.version-string.outputs.tag }} -X github.com/stacklok/toolhive/pkg/versions.Commit=${{ github.sha }} -X github.com/stacklok/toolhive/pkg/versions.BuildDate=${{ github.event.head_commit.timestamp }} -X github.com/stacklok/toolhive/pkg/versions.BuildType=release"
run: |
TAG=$(echo "${{ steps.version-string.outputs.tag }}" | sed 's/+/_/g')
TAGS="-t $TAG"
Expand Down
1 change: 1 addition & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ builds:
- "-X github.com/stacklok/toolhive/pkg/versions.Version={{ .Env.VERSION }}"
- "-X github.com/stacklok/toolhive/pkg/versions.Commit={{ .Env.COMMIT }}"
- "-X github.com/stacklok/toolhive/pkg/versions.BuildDate={{ .Date }}"
- "-X github.com/stacklok/toolhive/pkg/versions.BuildType=release"
goos:
- linux
- windows
Expand Down
17 changes: 10 additions & 7 deletions cmd/thv-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/stacklok/toolhive/cmd/thv-operator/controllers"
"github.com/stacklok/toolhive/pkg/logger"
"github.com/stacklok/toolhive/pkg/operator/telemetry"
"github.com/stacklok/toolhive/pkg/versions"
)

var (
Expand Down Expand Up @@ -92,13 +93,15 @@ func main() {
os.Exit(1)
}

// Set up telemetry service - only runs when elected as leader
telemetryService := telemetry.NewService(mgr.GetClient(), "")
if err := mgr.Add(&telemetry.LeaderTelemetryRunnable{
TelemetryService: telemetryService,
}); err != nil {
setupLog.Error(err, "unable to add telemetry runnable")
os.Exit(1)
// Set up telemetry service - only runs when elected as leader and BuildType is "release"
if versions.BuildType == "release" {
telemetryService := telemetry.NewService(mgr.GetClient(), "")
if err := mgr.Add(&telemetry.LeaderTelemetryRunnable{
TelemetryService: telemetryService,
}); err != nil {
setupLog.Error(err, "unable to add telemetry runnable")
os.Exit(1)
}
}

setupLog.Info("starting manager")
Expand Down
6 changes: 4 additions & 2 deletions cmd/thv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import (
"github.com/stacklok/toolhive/cmd/thv/app"
"github.com/stacklok/toolhive/pkg/container"
"github.com/stacklok/toolhive/pkg/logger"
"github.com/stacklok/toolhive/pkg/versions"
)

func main() {
// Initialize the logger
logger.Initialize()

// Skip update check for completion command or if we are running in kubernetes
if err := app.NewRootCmd(!app.IsCompletionCommand(os.Args) && !container.IsKubernetesRuntime()).Execute(); err != nil {
// Skip update check for completion command, if we are running in kubernetes, or if BuildType is not "release"
enableUpdates := !app.IsCompletionCommand(os.Args) && !container.IsKubernetesRuntime() && versions.BuildType == "release"
if err := app.NewRootCmd(enableUpdates).Execute(); err != nil {
os.Exit(1)
}
}
17 changes: 11 additions & 6 deletions pkg/updates/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"fmt"
"io"
"net/http"
"os"
"time"

"github.com/stacklok/toolhive/pkg/versions"
)

// VersionClient is an interface for calling the update service API.
Expand Down Expand Up @@ -49,14 +50,18 @@ func (d *defaultVersionClient) GetLatestVersion(instanceID string, currentVersio
}

// Set headers
userAgent := fmt.Sprintf("toolhive/%s", currentVersion)
// Determine user agent based on build type
var userAgent string
if versions.BuildType == "release" {
userAgent = fmt.Sprintf("toolhive/%s", currentVersion)
} else {
userAgent = fmt.Sprintf("toolhive/development-%s", currentVersion)
}

// Add suffix
if d.userAgentSuffix != "" {
userAgent += " " + d.userAgentSuffix
}
// Add `dev` to the user agent for Stacklok devs.
if os.Getenv("TOOLHIVE_DEV") != "" {
userAgent += " dev"
}
req.Header.Set(instanceIDHeader, instanceID)
req.Header.Set(userAgentHeader, userAgent)

Expand Down
3 changes: 3 additions & 0 deletions pkg/versions/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ var (
// BuildDate is the date when the binary was built
// nolint:goconst // This is a placeholder for the build date
BuildDate = unknownStr
// BuildType indicates if this is a release build.
// Set to "release" only in official release builds, everything else is considered "development".
BuildType = "development"
)

// VersionInfo represents the version information
Expand Down
Loading