Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into utest-usersignup-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
sadlerap authored Aug 1, 2024
2 parents 28a8b0d + fef8677 commit 49a9784
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 67 deletions.
32 changes: 27 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,28 @@ BOOK_PATH = $(PWD)/doc/book
MDBOOK_VERSION ?= v0.4.40
VALE_VERSION := v3.6.0

##@ General

# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)


##@ Book

.PHONY: book
book:
book: ## Build the book.
$(CONTAINER_TOOL) run --rm \
--workdir "/book" \
--name "workspaces-mdbook" \
Expand All @@ -21,21 +41,23 @@ book:
build

.PHONY: lint-book-sync
lint-book-sync:
lint-book-sync: ## Synchronize book's linter vocabularies.
$(CONTAINER_TOOL) run --rm -v $(BOOK_PATH):/book -w /book jdkato/vale:$(VALE_VERSION) sync

.PHONY: lint-book
lint-book: lint-book-sync
lint-book: lint-book-sync ## Lint the book.
$(CONTAINER_TOOL) run --rm -v $(BOOK_PATH):/book -w /book jdkato/vale:$(VALE_VERSION) /book/src

##@ Development

.PHONY: vet
vet:
vet: ## run go vet on all projects. Failures are ignored.
-$(MAKE) -C $(E2E_FOLDER) vet
-$(MAKE) -C $(OPERATOR_FOLDER) vet
-$(MAKE) -C $(SERVER_FOLDER) vet

.PHONY: unit-test
unit-test:
unit-test: ## run go test on all projects.
@printf "%s " $(call text-style, setaf 2 bold, "run Operator's unit tests:")
$(MAKE) -C $(OPERATOR_FOLDER) test
@printf "\n%s " $(call text-style, setaf 2 bold, "run Server's unit tests:")
Expand Down
12 changes: 7 additions & 5 deletions operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@ endif
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

.PHONY: all
all: build

ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

OUTDIR := $(ROOT_DIR)/out
$(OUTDIR):
@mkdir $(OUTDIR)

##@ General

Expand All @@ -45,6 +40,13 @@ $(OUTDIR):
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)


## Local Folder

$(OUTDIR):
@mkdir $(OUTDIR)


##@ Development

.PHONY: manifests
Expand Down
124 changes: 67 additions & 57 deletions server/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
LOCALBIN := $(ROOT_DIR)/bin
$(LOCALBIN):
mkdir $(LOCALBIN)

OUTDIR := $(ROOT_DIR)/out
$(OUTDIR):
@mkdir $(OUTDIR)

GO ?= go
LD_FLAGS ?= -s -w
Expand Down Expand Up @@ -45,35 +41,12 @@ JWKS_URL := https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-c
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Dependencies

.PHONY: kustomize
kustomize: $(KUSTOMIZE)
$(KUSTOMIZE):
test -s $(LOCALBIN)/kustomize || \
$(GO) build \
-modfile $(shell dirname $(ROOT_DIR))/hack/tools/kustomize/go.mod \
-o $(LOCALBIN)/kustomize \
sigs.k8s.io/kustomize/kustomize/v5

.PHONY: mockgen
mockgen: $(MOCKGEN)
$(MOCKGEN): $(LOCALBIN)
@cp hack/tools/mockgen $(LOCALBIN)/

.PHONY: yq
yq: $(YQ)
$(YQ): $(LOCALBIN)
$(GO) build \
-modfile $(shell dirname $(ROOT_DIR))/hack/tools/yq/go.mod \
-o $(LOCALBIN)/yq \
github.com/mikefarah/yq/v4
## Local Folders
$(LOCALBIN):
mkdir $(LOCALBIN)
$(OUTDIR):
@mkdir $(OUTDIR)

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

##@ Development

Expand All @@ -85,61 +58,98 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

.PHONY: clean
clean:
@-rm -r $(LOCALBIN)
@-rm -r $(OUTDIR)

.PHONY: build
build:
@$(GO) build \
-ldflags '$(LD_FLAGS)' \
-trimpath \
-o $(LOCALBIN)/server \
main.go

.PHONY: generate-code
generate-code: mockgen
generate-code: mockgen ## Run go generate on the project.
@echo $(GO) generate ./...
@PATH=$(ROOT_DIR)/bin:${PATH} $(GO) generate ./...

.PHONY: run
run:
$(GO) run main.go
.PHONY: clean
clean: ## Delete local folders.
@-rm -r $(LOCALBIN)
@-rm -r $(OUTDIR)

.PHONY: lint
lint:
lint: ## Run go linter.
$(GOLANG_CI) run ./...

.PHONY: vet
vet:
vet: ## Run go vet against code.
$(GO) vet ./...

.PHONY: fmt
fmt:
fmt: ## Run go fmt against code.
$(GO) fmt ./...

.PHONY: test
test: generate-code
test: generate-code ## Run tests.
$(GO) test ./...

.PHONY: test-with-coverage
test-with-coverage: generate-code
test-with-coverage: generate-code ## Run tests with coverage.
$(GO) test ./... -covermode=atomic -coverprofile cover.out


##@ Build

.PHONY: build
build: ## Build server binary.
@$(GO) build \
-ldflags '$(LD_FLAGS)' \
-trimpath \
-o $(LOCALBIN)/server \
main.go

.PHONY: run
run: ## Run the server from your host.
$(GO) run main.go

.PHONY: docker-build
docker-build:
docker-build: ## Build docker image.
$(IMAGE_BUILDER) build -t ${IMG} -f Dockerfile ..


##@ Deployment

.PHONY: deploy
deploy: kustomize yq
deploy: kustomize yq ## Deploy server.
YQ="$(YQ)" KUSTOMIZE="$(KUSTOMIZE)" ./hack/deploy.sh "$(NAMESPACE)" "$(IMG)"

.PHONY: package
package: kustomize yq $(OUTDIR)
package: kustomize yq $(OUTDIR) ## Package server for release.
JWKS_URL="$(JWKS_URL)" \
TOOLCHAIN_HOST="toolchain-host-operator" \
YQ="$(YQ)" \
KUSTOMIZE="$(KUSTOMIZE)" \
MANIFEST_TARBALL="$(MANIFEST_TARBALL)" \
./hack/deploy.sh "$(NAMESPACE)" "$(IMG)"


##@ Build Dependencies

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be overwritten.
$(KUSTOMIZE):
test -s $(LOCALBIN)/kustomize || \
$(GO) build \
-modfile $(shell dirname $(ROOT_DIR))/hack/tools/kustomize/go.mod \
-o $(LOCALBIN)/kustomize \
sigs.k8s.io/kustomize/kustomize/v5

.PHONY: mockgen
mockgen: $(MOCKGEN) ## Install mockgen locally.
$(MOCKGEN): $(LOCALBIN)
@cp hack/tools/mockgen $(LOCALBIN)/

.PHONY: yq
yq: $(YQ) ## Download yq locally if necessary. If wrong version is installed, it will be overwritten.
$(YQ): $(LOCALBIN)
$(GO) build \
-modfile $(shell dirname $(ROOT_DIR))/hack/tools/yq/go.mod \
-o $(LOCALBIN)/yq \
github.com/mikefarah/yq/v4

0 comments on commit 49a9784

Please sign in to comment.