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
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,18 @@ VTAG := $(shell [ -z $(VTAG) ] && echo $(ETAG) || echo $(VTAG))
VERS ?= $(shell git describe --tags --match 'v*' 2>/dev/null)
KVER ?= $(shell git describe --tags --match 'knative-*' 2>/dev/null)

LDFLAGS := -X knative.dev/func/pkg/version.Vers=$(VERS) -X knative.dev/func/pkg/version.Kver=$(KVER) -X knative.dev/func/pkg/version.Hash=$(HASH)
# -X pkg.Var=<empty> clears the Go initializer, so only stamp values that are
# actually set (e.g. VERS/KVER are empty outside of a tagged checkout).
LDFLAGS :=
ifneq ($(VERS),)
LDFLAGS += -X knative.dev/func/pkg/version.Vers=$(VERS)
endif
ifneq ($(KVER),)
LDFLAGS += -X knative.dev/func/pkg/version.Kver=$(KVER)
endif
ifneq ($(HASH),)
LDFLAGS += -X knative.dev/func/pkg/version.Hash=$(HASH)
endif

# Overrides the func-utils image; the default is version.FuncUtilsImage.
FUNC_UTILS_IMG ?=
Expand Down
6 changes: 4 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import (
"knative.dev/func/pkg/config"
fn "knative.dev/func/pkg/functions"
"knative.dev/func/pkg/k8s"
"knative.dev/func/pkg/version"
)

// DefaultVersion when building source directly (bypassing the Makefile)
const DefaultVersion = "v0.0.0+source"
// DefaultVersion when building source directly (bypassing the Makefile).
// Delegates to version.Default so the fallback is defined in one place.
const DefaultVersion = version.Default

// DefaultNamespace is the global static default namespace, and is equivalent
// to the Kubernetes default namespace.
Expand Down
7 changes: 0 additions & 7 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ func runVersion(cmd *cobra.Command, v Version) error {
// Set verbose flag
v.Verbose = verbose

// Initialize the default value to the zero semver with a descriptive
// metadata tag indicating this must have been built from source if
// undefined:
if v.Vers == "" {
v.Vers = DefaultVersion
}

// Kver and Hash are already set from build via ldflags,
// injected into the Version struct at startup (see pkg/app/app.go).
// Populate image fields from k8s package constants
Expand Down
10 changes: 6 additions & 4 deletions pkg/mcp/mcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"sync/atomic"

"github.com/modelcontextprotocol/go-sdk/mcp"
"knative.dev/func/pkg/version"
)

const (
name = "func"
title = "func"
version = "0.1.0"
name = "func"
title = "func"

// EnvMCPWrite is the environment variable that enables write operations
// (deploy, delete, and pushing built images) on the MCP server. Set to
Expand All @@ -30,6 +30,7 @@ const (
type Server struct {
OnInit func(context.Context) // Invoked when the server is initialized
prefix string // Command prefix ("func" or "kn func")
version string // Computed once at construction; used by healthcheck
readonly atomic.Bool // disables mutation tools when true
executor executor
transport mcp.Transport // Transport to use (defaults to StdioTransport)
Expand Down Expand Up @@ -103,6 +104,7 @@ func WithReadonly(readonly bool) Option {
func New(options ...Option) *Server {
s := &Server{
prefix: "func",
version: version.Vers,
transport: &mcp.StdioTransport{},
OnInit: func(_ context.Context) {},
}
Expand All @@ -117,7 +119,7 @@ func New(options ...Option) *Server {
&mcp.Implementation{
Name: name,
Title: title,
Version: version},
Version: s.version},
&mcp.ServerOptions{
Instructions: instructions(s.readonly.Load()),
HasPrompts: true,
Expand Down
2 changes: 1 addition & 1 deletion pkg/mcp/tools_healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (s *Server) healthcheckHandler(ctx context.Context, r *mcp.CallToolRequest,
output = HealthcheckOutput{
Status: "ok",
Message: "The MCP server is running!",
Version: version,
Version: s.version,
}
return
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/mcp/tools_healthcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/modelcontextprotocol/go-sdk/mcp"
"knative.dev/func/pkg/version"
)

// TestTool_Healthcheck verifies the healthcheck tool returns expected output
Expand Down Expand Up @@ -64,7 +65,7 @@ func TestTool_Healthcheck(t *testing.T) {
t.Errorf("expected message to contain 'running', got %q", output.Message)
}

if output.Version == "" {
t.Error("expected non-empty version")
if output.Version != version.Vers {
t.Errorf("healthcheck version = %q, want build stamp %q", output.Version, version.Vers)
}
}
10 changes: 9 additions & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package version

var Vers, Kver, Hash string
// Default is the fallback version used when no build-time version was
// injected (e.g. source builds that bypass the Makefile).
const Default = "v0.0.0+source"

var (
Vers = Default // overwritten by ldflags when make actually has a describe
Kver string
Hash string
)

// FuncUtilsImage is the func-utils image that func runs in the cluster: the
// minor in development on main, X.Y on release-X.Y. Builds can override it
Expand Down
Loading