Skip to content

Commit

Permalink
update build logic, update license headers
Browse files Browse the repository at this point in the history
  • Loading branch information
cbarbian-sap committed Jan 6, 2025
1 parent fda14a3 commit 558e29b
Show file tree
Hide file tree
Showing 81 changed files with 412 additions and 2,177 deletions.
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ Disclaimer: The code in this project may include calls to APIs ("API Calls") of
parties the right to use of access any SAP External Product, through API Calls.

Files: **
Copyright: 2024 SAP SE or an SAP affiliate company and project-operator contributors
Copyright: 2025 SAP SE or an SAP affiliate company and project-operator contributors
License: Apache-2.0
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Build the manager binary
FROM --platform=$BUILDPLATFORM golang:1.23.4 as builder
FROM --platform=$BUILDPLATFORM golang:1.23.4 AS builder
ARG TARGETOS
ARG TARGETARCH

WORKDIR /workspace
# Copy the Go Modules manifests
# Copy the go module manifests
COPY go.mod go.mod
COPY go.sum go.sum
# Cache deps before building and copying source so that we don't need to re-download as much
Expand Down Expand Up @@ -34,3 +34,4 @@ COPY --from=builder /workspace/manager .
USER 65532:65532

ENTRYPOINT ["/manager"]

184 changes: 62 additions & 122 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,177 +1,117 @@

# Image URL to use all building/pushing image targets
IMG ?= controller:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.25.0

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
IMG ?= project-operator:latest
# K8s version used by envtest
ENVTEST_K8S_VERSION = 1.30.3

# Set shell to bash
SHELL = /usr/bin/env bash
.SHELLFLAGS = -o pipefail -ec

.PHONY: all
all: build

##@ 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)
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%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Development

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="main.go" paths="./api/..." paths="./controllers/..." paths="./webhooks/..." paths="./pkg/..." paths="./internal/..." output:crd:artifacts:config=config/crd/bases
rm -rf crds && cp -r config/crd/bases crds
manifests: controller-gen ## Generate CustomResourceDefinition objects
$(LOCALBIN)/controller-gen crd paths="./api/..." output:crd:artifacts:config=crds && \
test ! -d chart || test -e chart/crds || ln -s ../crds chart/crds

.PHONY: generate
generate: controller-gen client-gen informer-gen lister-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./api/..."
./hack/gen-typed-client
generate: generate-deepcopy generate-client ## Generate required code pieces

.PHONY: generate-deepcopy
generate-deepcopy: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations
$(LOCALBIN)/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./api/..."

.PHONY: generate-client
generate-client: ## Generate typed client
./hack/genclient.sh

.PHONY: fmt
fmt: ## Run go fmt against code.
fmt: ## Run go fmt against code
go fmt ./...

.PHONY: vet
vet: ## Run go vet against code.
vet: ## Run go vet against code
go vet ./...

##@ Testing

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
test: manifests generate-deepcopy fmt vet envtest ## Run tests
KUBEBUILDER_ASSETS="$(LOCALBIN)/k8s/current" go test ./... -coverprofile cover.out

##@ Build

.PHONY: build
build: generate fmt vet ## Build manager binary.
build: generate-deepcopy fmt vet ## Build manager binary
go build -o bin/manager main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
run: manifests generate-deepcopy fmt vet ## Run a controller from your host
go run ./main.go

# If you wish built the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
# Build docker image in current architecture and tag it as ${IMG}
.PHONY: docker-build
docker-build: test ## Build docker image with the manager.
docker-build: ## Build docker image with the manager
docker build -t ${IMG} .

# Push docker image to the target specified in ${IMG}
.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker-push: ## Push docker image with the manager
docker push ${IMG}

# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> than the export will fail)
# To properly provided solutions that supports more than one platform you should use this option.
# Build and push docker image for all given platforms
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
.PHONY: docker-buildx
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
docker-buildx: ## Build and push docker image for the manager for cross-platform support
- docker buildx create --name project-v3-builder
docker buildx use project-v3-builder
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} .
- docker buildx rm project-v3-builder
rm Dockerfile.cross

##@ Deployment

ifndef ignore-not-found
ignore-not-found = false
endif

.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -

.PHONY: uninstall
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -

.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

##@ Build Dependencies

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
CLIENT_GEN ?= $(shell pwd)/bin/client-gen
INFORMER_GEN ?= $(shell pwd)/bin/informer-gen
LISTER_GEN ?= $(shell pwd)/bin/lister-gen

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
CONTROLLER_TOOLS_VERSION ?= v0.14.0
CODE_GENERATOR_VERSION ?= v0.23.4

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): $(LOCALBIN)
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
@mkdir -p $(LOCALBIN)

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
controller-gen: $(LOCALBIN) ## Install controller-gen
@go mod download sigs.k8s.io/controller-tools && \
VERSION=$$(go list -m -f '{{.Version}}' sigs.k8s.io/controller-tools) && \
if [ ! -L $(LOCALBIN)/controller-gen ] || [ "$$(readlink $(LOCALBIN)/controller-gen)" != "controller-gen-$$VERSION" ]; then \
echo "Installing controller-gen $$VERSION" && \
rm -f $(LOCALBIN)/controller-gen && \
GOBIN=$(LOCALBIN) go install $$(go list -m -f '{{.Dir}}' sigs.k8s.io/controller-tools)/cmd/controller-gen && \
mv $(LOCALBIN)/controller-gen $(LOCALBIN)/controller-gen-$$VERSION && \
ln -s controller-gen-$$VERSION $(LOCALBIN)/controller-gen; \
fi

.PHONY: setup-envtest
setup-envtest: $(LOCALBIN) ## Install setup-envtest
@go mod download sigs.k8s.io/controller-runtime/tools/setup-envtest && \
VERSION=$$(go list -m -f '{{.Version}}' sigs.k8s.io/controller-runtime/tools/setup-envtest) && \
if [ ! -L $(LOCALBIN)/setup-envtest ] || [ "$$(readlink $(LOCALBIN)/setup-envtest)" != "setup-envtest-$$VERSION" ]; then \
echo "Installing setup-envtest $$VERSION" && \
rm -f $(LOCALBIN)/setup-envtest && \
GOBIN=$(LOCALBIN) go install $$(go list -m -f '{{.Dir}}' sigs.k8s.io/controller-runtime/tools/setup-envtest) && \
mv $(LOCALBIN)/setup-envtest $(LOCALBIN)/setup-envtest-$$VERSION && \
ln -s setup-envtest-$$VERSION $(LOCALBIN)/setup-envtest; \
fi

.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
ENVTESTDIR=$$($(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path) ;\
chmod -R u+w $$ENVTESTDIR ;\
rm -f $(LOCALBIN)/k8s/current ;\
envtest: setup-envtest ## Install envtest binaries
@ENVTESTDIR=$$($(LOCALBIN)/setup-envtest use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path) && \
chmod -R u+w $$ENVTESTDIR && \
rm -f $(LOCALBIN)/k8s/current && \
ln -s $$ENVTESTDIR $(LOCALBIN)/k8s/current

.PHONY: client-gen
client-gen: $(CLIENT_GEN) ## Download client-gen
$(CLIENT_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/client-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/client-gen@$(CODE_GENERATOR_VERSION)

.PHONY: informer-gen
informer-gen: $(INFORMER_GEN) ## Download informer-gen
$(INFORMER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/informer-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/informer-gen@$(CODE_GENERATOR_VERSION)

.PHONY: lister-gen
lister-gen: $(LISTER_GEN) ## Download lister-gen
$(LISTER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/lister-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/lister-gen@$(CODE_GENERATOR_VERSION)
18 changes: 0 additions & 18 deletions PROJECT

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ We as members, contributors, and leaders pledge to make participation in our com

## Licensing

Copyright 2024 SAP SE or an SAP affiliate company and project-operator contributors. Please see our [LICENSE](LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/SAP/project-operator).
Copyright 2025 SAP SE or an SAP affiliate company and project-operator contributors. Please see our [LICENSE](LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/SAP/project-operator).
2 changes: 1 addition & 1 deletion api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and project-operator contributors
SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and project-operator contributors
SPDX-License-Identifier: Apache-2.0
*/

Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/project_types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and project-operator contributors
SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and project-operator contributors
SPDX-License-Identifier: Apache-2.0
*/

Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 0 additions & 39 deletions config/certmanager/certificate.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions config/certmanager/kustomization.yaml

This file was deleted.

16 changes: 0 additions & 16 deletions config/certmanager/kustomizeconfig.yaml

This file was deleted.

Loading

0 comments on commit 558e29b

Please sign in to comment.