Skip to content

Commit

Permalink
define constants for common defaults
Browse files Browse the repository at this point in the history
Also, start using build tags to make it easier to
change defaults for downstream builds.

Signed-off-by: Joe Lanford <[email protected]>
  • Loading branch information
joelanford authored and tylerslaton committed Sep 21, 2022
1 parent d60b6f0 commit 0191183
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 22 deletions.
6 changes: 6 additions & 0 deletions .goreleaser.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ builds:
- id: unpack
main: ./cmd/unpack
binary: unpack
tags: $GO_BUILD_TAGS
goos:
- linux
goarch:
Expand All @@ -23,6 +24,7 @@ builds:
- id: helm
main: ./cmd/helm
binary: helm
tags: $GO_BUILD_TAGS
goos:
- linux
goarch:
Expand All @@ -35,6 +37,7 @@ builds:
- id: core
main: ./cmd/core
binary: core
tags: $GO_BUILD_TAGS
goos:
- linux
goarch:
Expand All @@ -47,6 +50,7 @@ builds:
- id: webhooks
main: ./cmd/webhooks
binary: webhooks
tags: $GO_BUILD_TAGS
goos:
- linux
goarch:
Expand All @@ -59,6 +63,7 @@ builds:
- id: crdvalidator
main: ./cmd/crdvalidator
binary: crdvalidator
tags: $GO_BUILD_TAGS
goos:
- linux
goarch:
Expand All @@ -71,6 +76,7 @@ builds:
- id: rukpakctl
main: ./cmd/rukpakctl
binary: rukpakctl
tags: $GO_BUILD_TAGS
goos:
- linux
goarch:
Expand Down
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ORG := github.com/operator-framework
PKG := $(ORG)/rukpak
export IMAGE_REPO ?= quay.io/operator-framework/rukpak
export IMAGE_TAG ?= latest
export GO_BUILD_TAGS ?= upstream
IMAGE?=$(IMAGE_REPO):$(IMAGE_TAG)
KIND_CLUSTER_NAME ?= rukpak
BIN_DIR := bin
Expand Down Expand Up @@ -52,7 +53,7 @@ help: ## Show this help screen
##@ code management:

lint: golangci-lint ## Run golangci linter
$(Q)$(GOLANGCI_LINT) run
$(Q)$(GOLANGCI_LINT) run --build-tags $(GO_BUILD_TAGS)

tidy: ## Update dependencies
$(Q)go mod tidy
Expand Down Expand Up @@ -91,11 +92,11 @@ test: test-unit test-e2e ## Run the tests
ENVTEST_VERSION = $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/')
UNIT_TEST_DIRS=$(shell go list ./... | grep -v /test/)
test-unit: setup-envtest ## Run the unit tests
eval $$($(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION)) && go test -count=1 -short $(UNIT_TEST_DIRS)
eval $$($(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION)) && go test -tags $(GO_BUILD_TAGS) -count=1 -short $(UNIT_TEST_DIRS)

FOCUS := $(if $(TEST),-v -focus "$(TEST)")
test-e2e: ginkgo ## Run the e2e tests
$(GINKGO) -trace -progress $(FOCUS) test/e2e
$(GINKGO) --tags $(GO_BUILD_TAGS) -trace -progress $(FOCUS) test/e2e

e2e: KIND_CLUSTER_NAME=rukpak-e2e
e2e: rukpakctl run image-registry kind-load-bundles registry-load-bundles test-e2e kind-cluster-cleanup ## Run e2e tests against an ephemeral kind cluster
Expand Down Expand Up @@ -154,10 +155,10 @@ VERSION_FLAGS=-ldflags "-X $(VERSION_PATH).GitCommit=$(GIT_COMMIT)"
build: $(BINARIES)

$(LINUX_BINARIES):
CGO_ENABLED=0 GOOS=linux go build $(VERSION_FLAGS) -o $(BIN_DIR)/$@ ./cmd/$(notdir $@)
CGO_ENABLED=0 GOOS=linux go build -tags $(GO_BUILD_TAGS) $(VERSION_FLAGS) -o $(BIN_DIR)/$@ ./cmd/$(notdir $@)

$(BINARIES):
CGO_ENABLED=0 go build $(VERSION_FLAGS) -o $(BIN_DIR)/$@ ./cmd/$@
CGO_ENABLED=0 go build -tags $(GO_BUILD_TAGS) $(VERSION_FLAGS) -o $(BIN_DIR)/$@ ./cmd/$@

build-container: $(LINUX_BINARIES) ## Builds provisioner container image locally
$(CONTAINER_RUNTIME) build -f Dockerfile -t $(IMAGE) $(BIN_DIR)/linux
Expand Down
4 changes: 2 additions & 2 deletions cmd/core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func main() {
flag.StringVar(&httpExternalAddr, "http-external-address", "http://localhost:8080", "The external address at which the http server is reachable.")
flag.StringVar(&bundleCAFile, "bundle-ca-file", "", "The file containing the certificate authority for connecting to bundle content servers.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.StringVar(&systemNamespace, "system-namespace", "rukpak-system", "Configures the namespace that gets used to deploy system resources.")
flag.StringVar(&unpackImage, "unpack-image", "quay.io/operator-framework/rukpak:latest", "Configures the container image that gets used to unpack Bundle contents.")
flag.StringVar(&systemNamespace, "system-namespace", util.DefaultSystemNamespace, "Configures the namespace that gets used to deploy system resources.")
flag.StringVar(&unpackImage, "unpack-image", util.DefaultUnpackImage, "Configures the container image that gets used to unpack Bundle contents.")
flag.StringVar(&baseUploadManagerURL, "base-upload-manager-url", "", "The base URL from which to fetch uploaded bundles.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
Expand Down
4 changes: 2 additions & 2 deletions cmd/helm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func main() {
flag.StringVar(&httpExternalAddr, "http-external-address", "http://localhost:8080", "The external address at which the http server is reachable.")
flag.StringVar(&bundleCAFile, "bundle-ca-file", "", "The file containing the certificate authority for connecting to bundle content servers.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.StringVar(&unpackImage, "unpack-image", "quay.io/operator-framework/rukpak:latest", "Configures the container image that gets used to unpack Bundle contents.")
flag.StringVar(&unpackImage, "unpack-image", util.DefaultUnpackImage, "Configures the container image that gets used to unpack Bundle contents.")
flag.StringVar(&baseUploadManagerURL, "base-upload-manager-url", "", "The base URL from which to fetch uploaded bundles.")
flag.StringVar(&systemNamespace, "system-namespace", "rukpak-system", "Configures the namespace that gets used to deploy system resources.")
flag.StringVar(&systemNamespace, "system-namespace", util.DefaultSystemNamespace, "Configures the namespace that gets used to deploy system resources.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
Expand Down
4 changes: 2 additions & 2 deletions cmd/rukpakctl/cmd/alpha_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ under the management of a rukpak BundleDeployment.'
}
},
}
cmd.Flags().StringVar(&systemNamespace, "system-namespace", "rukpak-system", "Namespace in which the core rukpak provisioners are running.")
cmd.Flags().StringVar(&uploadServiceName, "upload-service-name", "core", "the name of the service of the upload manager.")
cmd.Flags().StringVar(&systemNamespace, "system-namespace", util.DefaultSystemNamespace, "Namespace in which the core rukpak provisioners are running.")
cmd.Flags().StringVar(&uploadServiceName, "upload-service-name", util.DefaultUploadServiceName, "the name of the service of the upload manager.")
cmd.Flags().StringVar(&caSecretName, "ca-secret-name", "rukpak-ca", "the name of the secret in the system namespace containing the root CAs used to authenticate the upload service.")
return cmd
}
3 changes: 2 additions & 1 deletion cmd/rukpakctl/cmd/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
"github.com/operator-framework/rukpak/cmd/rukpakctl/utils"
plain "github.com/operator-framework/rukpak/internal/provisioner/plain/types"
"github.com/operator-framework/rukpak/internal/util"
)

type bundleOptions struct {
Expand Down Expand Up @@ -81,7 +82,7 @@ func newBundleCmd() *cobra.Command {
}
},
}
bundleCmd.Flags().StringVar(&bundleOpt.namespace, "namespace", "rukpak-system", "namespace for target or work resources")
bundleCmd.Flags().StringVar(&bundleOpt.namespace, "namespace", util.DefaultSystemNamespace, "namespace for target or work resources")
return bundleCmd
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/rukpakctl/cmd/bundledeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
"github.com/operator-framework/rukpak/cmd/rukpakctl/utils"
plain "github.com/operator-framework/rukpak/internal/provisioner/plain/types"
"github.com/operator-framework/rukpak/internal/util"
)

type bundleDeploymentOptions struct {
Expand Down Expand Up @@ -80,7 +81,7 @@ func newBundleDeploymentCmd() *cobra.Command {
}
},
}
bdCmd.Flags().StringVar(&bundleDeploymentOpt.namespace, "namespace", "rukpak-system", "namespace for target or work resources")
bdCmd.Flags().StringVar(&bundleDeploymentOpt.namespace, "namespace", util.DefaultSystemNamespace, "namespace for target or work resources")
return bdCmd
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/rukpakctl/cmd/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/config"

rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
"github.com/operator-framework/rukpak/internal/util"
)

type options struct {
Expand Down Expand Up @@ -80,7 +81,7 @@ func newContentCmd() *cobra.Command {
}
},
}
contentCmd.Flags().StringVar(&opt.namespace, "namespace", "rukpak-system", "namespace to run content query job.")
contentCmd.Flags().StringVar(&opt.namespace, "namespace", util.DefaultSystemNamespace, "namespace to run content query job.")
return contentCmd
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/rukpakctl/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

plain "github.com/operator-framework/rukpak/internal/provisioner/plain/types"
"github.com/operator-framework/rukpak/internal/rukpakctl"
"github.com/operator-framework/rukpak/internal/util"
)

// newRunCmd creates the run command
Expand Down Expand Up @@ -80,8 +81,8 @@ one version to the next.
}
},
}
cmd.Flags().StringVar(&systemNamespace, "system-namespace", "rukpak-system", "the namespace in which the rukpak controllers are deployed.")
cmd.Flags().StringVar(&uploadServiceName, "upload-service-name", "core", "the name of the service of the upload manager.")
cmd.Flags().StringVar(&systemNamespace, "system-namespace", util.DefaultSystemNamespace, "the namespace in which the rukpak controllers are deployed.")
cmd.Flags().StringVar(&uploadServiceName, "upload-service-name", util.DefaultUploadServiceName, "the name of the service of the upload manager.")
cmd.Flags().StringVar(&caSecretName, "ca-secret-name", "rukpak-ca", "the name of the secret in the system namespace containing the root CAs used to authenticate the upload service.")
cmd.Flags().StringVar(&bundleDeploymentProvisionerClassName, "bundle-deployment-provisioner-class", plain.ProvisionerID, "Provisioner class name to set on bundle deployment.")
cmd.Flags().StringVar(&bundleProvisionerClassName, "bundle-provisioner-class", plain.ProvisionerID, "Provisioner class name to set on bundle.")
Expand Down
2 changes: 1 addition & 1 deletion cmd/webhooks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func main() {
var rukpakVersion bool
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.StringVar(&systemNamespace, "system-namespace", "rukpak-system", "Configures the namespace that gets used to deploy system resources.")
flag.StringVar(&systemNamespace, "system-namespace", util.DefaultSystemNamespace, "Configures the namespace that gets used to deploy system resources.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
Expand Down
9 changes: 9 additions & 0 deletions internal/util/defaults_upstream.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build upstream

package util

const (
DefaultSystemNamespace = "rukpak-system"
DefaultUnpackImage = "quay.io/operator-framework/rukpak:latest"
DefaultUploadServiceName = "core"
)
10 changes: 5 additions & 5 deletions test/e2e/plain_provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import (
)

const (
// TODO: make this is a CLI flag?
defaultSystemNamespace = "rukpak-system"
testdataDir = "../../testdata"
defaultSystemNamespace = util.DefaultSystemNamespace
defaultUploadServiceName = util.DefaultUploadServiceName
testdataDir = "../../testdata"
)

func Logf(f string, v ...interface{}) {
Expand Down Expand Up @@ -1024,7 +1024,7 @@ var _ = Describe("plain provisioner bundle", func() {
Expect(err).To(BeNil())

bu := rukpakctl.BundleUploader{
UploadServiceName: "core",
UploadServiceName: defaultUploadServiceName,
UploadServiceNamespace: defaultSystemNamespace,
Cfg: cfg,
RootCAs: rootCAs,
Expand Down Expand Up @@ -1082,7 +1082,7 @@ var _ = Describe("plain provisioner bundle", func() {
Expect(err).To(BeNil())

bu := rukpakctl.BundleUploader{
UploadServiceName: "core",
UploadServiceName: defaultUploadServiceName,
UploadServiceNamespace: defaultSystemNamespace,
Cfg: cfg,
RootCAs: rootCAs,
Expand Down

0 comments on commit 0191183

Please sign in to comment.