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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ENV GO111MODULE=on \
WORKDIR /go/src/github.com/open-policy-agent/gatekeeper
COPY . .

RUN go build -mod vendor -a -ldflags "${LDFLAGS:--X github.com/open-policy-agent/gatekeeper/pkg/version.Version=latest}" -o manager
RUN go build -mod vendor -a -ldflags "${LDFLAGS}" -o manager

FROM $BASEIMAGE

Expand Down
10 changes: 3 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ BATS_TESTS_FILE ?= test/bats/test.bats
HELM_VERSION ?= 3.7.2
NODE_VERSION ?= 16-bullseye-slim
YQ_VERSION ?= 4.30.6
FRAMEWORKS_VERSION ?= $(shell go list -f '{{ .Version }}' -m github.com/open-policy-agent/frameworks/constraint)
OPA_VERSION ?= $(shell go list -f '{{ .Version }}' -m github.com/open-policy-agent/opa)

HELM_ARGS ?=
GATEKEEPER_NAMESPACE ?= gatekeeper-system
Expand All @@ -45,9 +43,7 @@ FAKE_SUBSCRIBER_IMAGE ?= fake-subscriber:latest
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
BIN_DIR := $(abspath $(ROOT_DIR)/bin)

LDFLAGS := "-X github.com/open-policy-agent/gatekeeper/pkg/version.Version=$(VERSION) \
-X main.frameworksVersion=$(FRAMEWORKS_VERSION) \
-X main.opaVersion=$(OPA_VERSION)"
LDFLAGS := "-X github.com/open-policy-agent/gatekeeper/v3/pkg/version.Version=$(VERSION)"

PLATFORM ?= linux/amd64
OUTPUT_TYPE ?= type=docker
Expand Down Expand Up @@ -284,11 +280,11 @@ e2e-publisher-deploy:

# Build manager binary
manager: generate
GO111MODULE=on go build -mod vendor -o bin/manager -ldflags $(LDFLAGS) main.go
GO111MODULE=on go build -mod vendor -o bin/manager -ldflags $(LDFLAGS)

# Build manager binary
manager-osx: generate
GO111MODULE=on go build -mod vendor -o bin/manager GOOS=darwin -ldflags $(LDFLAGS) main.go
GO111MODULE=on go build -mod vendor -o bin/manager GOOS=darwin -ldflags $(LDFLAGS)

# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate manifests
Expand Down
15 changes: 8 additions & 7 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ allow_k8s_contexts(settings.get("allowed_contexts", []))
if settings.get("trigger_mode", "auto").lower() == "manual":
trigger_mode(TRIGGER_MODE_MANUAL)

LDFLAGS = "-X github.com/open-policy-agent/gatekeeper/pkg/version.Version=latest"

TILT_DOCKERFILE = """
FROM golang:1.20-bullseye as tilt-helper
# Support live reloading with Tilt
Expand All @@ -36,8 +34,7 @@ COPY bin/manager .
def build_manager():
cmd = [
"make tilt-prepare",
"GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod vendor -a -ldflags \"" +
LDFLAGS + "\" -o .tiltbuild/bin/manager",
"GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod vendor -a -o .tiltbuild/bin/manager",
]
local_resource(
"manager",
Expand Down Expand Up @@ -90,7 +87,8 @@ def deploy_gatekeeper():
name="gatekeeper",
namespace="gatekeeper-system",
values=[".tiltbuild/charts/gatekeeper/values.yaml"],
set=["{}={}".format(k, str(v).lower()) for k, v in helm_values.items()],
set=["{}={}".format(k, str(v).lower())
for k, v in helm_values.items()],
))

# add label to resources
Expand All @@ -102,16 +100,19 @@ def deploy_gatekeeper():
port = int(helm_values["audit.metricsPort"])
k8s_resource(
workload="gatekeeper-audit",
port_forwards=[port_forward(port, name="View metrics", link_path="/metrics")],
port_forwards=[port_forward(
port, name="View metrics", link_path="/metrics")],
)

if "controllerManager.metricsPort" in helm_values:
port = int(helm_values["controllerManager.metricsPort"])
k8s_resource(
workload="gatekeeper-controller-manager",
port_forwards=[port_forward(port, name="View metrics", link_path="/metrics")],
port_forwards=[port_forward(
port, name="View metrics", link_path="/metrics")],
)


build_manager()

build_crds()
Expand Down
14 changes: 3 additions & 11 deletions cmd/gator/gator.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"os"

"github.com/open-policy-agent/gatekeeper/v3/cmd/gator/expand"
Expand All @@ -12,13 +11,6 @@ import (
k8sVersion "sigs.k8s.io/release-utils/version"
)

const state = "beta"

var (
frameworksVersion string
opaVersion string
)

var commands = []*cobra.Command{
verify.Cmd,
test.Cmd,
Expand All @@ -28,12 +20,12 @@ var commands = []*cobra.Command{

func init() {
rootCmd.AddCommand(commands...)
rootCmd.Version = version.GetUserAgent("gator")
}

var rootCmd = &cobra.Command{
Use: "gator subcommand",
Short: "gator is a suite of authorship tools for Gatekeeper",
Version: fmt.Sprintf("%s (Feature State: %s), OPA version: %s, Framework version: %s", version.Version, state, opaVersion, frameworksVersion),
Use: "gator subcommand",
Short: "gator is a suite of authorship tools for Gatekeeper",
}

func main() {
Expand Down
2 changes: 1 addition & 1 deletion gator.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ENV GO111MODULE=on \
COPY . /go/src/github.com/open-policy-agent/gatekeeper
WORKDIR /go/src/github.com/open-policy-agent/gatekeeper/cmd/gator

RUN go build -mod vendor -a -ldflags "${LDFLAGS:--X github.com/open-policy-agent/gatekeeper/pkg/version.Version=latest -X main.frameworksVersion=latest -X main.opaVersion=latest}" -o /gator
RUN go build -mod vendor -a -ldflags "${LDFLAGS}" -o /gator

FROM --platform=$BUILDPLATFORM $BASEIMAGE as build
USER 65532:65532
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ func innerMain() int {
}

config := ctrl.GetConfigOrDie()
config.UserAgent = version.GetUserAgent()
config.UserAgent = version.GetUserAgent("gatekeeper")
setupLog.Info("setting up manager", "user agent", config.UserAgent)

var webhooks []rotator.WebhookInfo
webhooks = webhook.AppendValidationWebhookIfEnabled(webhooks)
Expand Down
38 changes: 33 additions & 5 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ import (
"runtime/debug"
)

const (
gatorState = "beta"
unknown = "unknown"
)

// Version is the gatekeeper version.
var Version string

// GetUserAgent returns a user agent of the format: gatekeeper/<version> (<goos>/<goarch>) <vcsrevision><-vcsdirty>/<vcstimestamp>.
func GetUserAgent() string {
vcsrevision := "unknown"
vcstimestamp := "unknown"
// GetUserAgent returns Gatekeeper and Gator version information.
func GetUserAgent(name string) string {
vcsrevision := unknown
vcstimestamp := unknown
vcsdirty := ""
opaVersion := unknown
frameworksVersion := unknown

if info, ok := debug.ReadBuildInfo(); ok {
for _, v := range info.Settings {
Expand All @@ -28,7 +35,28 @@ func GetUserAgent() string {
vcstimestamp = v.Value
}
}

for _, v := range info.Deps {
switch v.Path {
case "github.com/open-policy-agent/opa":
opaVersion = v.Version
case "github.com/open-policy-agent/frameworks/constraint":
frameworksVersion = v.Version
}
}
}

// OPA and Frameworks version used by Gatekeeper and Gator
opaFrameworksVersion := fmt.Sprintf("opa/%s, frameworks/%s", opaVersion, frameworksVersion)

// if LDFLAGS are not set, use revision info
if Version == "" {
Version = fmt.Sprintf("devel (%s)", vcsrevision)
}

if name == "gator" {
return fmt.Sprintf("%s (Feature State: %s), %s", Version, gatorState, opaFrameworksVersion)
}

return fmt.Sprintf("gatekeeper/%s (%s/%s) %s%s/%s", Version, runtime.GOOS, runtime.GOARCH, vcsrevision, vcsdirty, vcstimestamp)
return fmt.Sprintf("%s/%s (%s/%s) %s%s/%s, %s", name, Version, runtime.GOOS, runtime.GOARCH, vcsrevision, vcsdirty, vcstimestamp, opaFrameworksVersion)
}