Skip to content

Commit 3e3a86b

Browse files
authored
Auto-orphan foreign dependents on deletion (#317)
* auto-orphan foreign dependents on deletion * refactoring * add brackets * bump versions * fix vet error * update makefile
1 parent 26bb588 commit 3e3a86b

File tree

7 files changed

+123
-55
lines changed

7 files changed

+123
-55
lines changed

Makefile

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,70 @@
22
SHELL = /usr/bin/env bash
33
.SHELLFLAGS = -o pipefail -ec
44

5+
.PHONY: all
6+
all: scaffold clm
7+
8+
##@ General
9+
10+
.PHONY: help
11+
help: ## Display this help
12+
@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)
13+
514
##@ Development
615

716
.PHONY: generate
8-
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
9-
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./pkg/..." paths="./internal/..."
17+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations
18+
$(LOCALBIN)/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./pkg/..." paths="./internal/..."
1019

1120
.PHONY: fmt
12-
fmt: ## Run go fmt against code.
21+
fmt: ## Run go fmt against code
1322
go fmt ./...
1423

1524
.PHONY: vet
16-
vet: ## Run go vet against code.
25+
vet: ## Run go vet against code
1726
go vet ./...
1827

1928
.PHONY: test
20-
test:
29+
test: generate fmt vet ## Run tests
2130
go test ./internal/... ./pkg/...
2231

32+
##@ Build
33+
34+
.PHONY: scaffold
35+
scaffold: generate fmt vet ## Build scaffold
36+
GIT_BRANCH=$$(git rev-parse --abbrev-ref @) && \
37+
GIT_COMMIT=$$(git rev-parse @) && \
38+
if out=$$(git status --porcelain) && [ -z "$$out" ]; then GIT_TREE_STATE=clean; else GIT_TREE_STATE=dirty; fi && \
39+
LDFLAGS=" -X \"github.com/sap/component-operator-runtime/internal/version.version=$$GIT_BRANCH\" \
40+
-X \"github.com/sap/component-operator-runtime/internal/version.gitCommit=$$GIT_COMMIT\" \
41+
-X \"github.com/sap/component-operator-runtime/internal/version.gitTreeState=$$GIT_TREE_STATE\"" && \
42+
CGO_ENABLED=0 go build -ldflags "$$LDFLAGS" -o ./bin/scaffold ./scaffold
43+
44+
.PHONY: clm
45+
clm: generate fmt vet ## Build clm
46+
GIT_BRANCH=$$(git rev-parse --abbrev-ref @) && \
47+
GIT_COMMIT=$$(git rev-parse @) && \
48+
if out=$$(git status --porcelain) && [ -z "$$out" ]; then GIT_TREE_STATE=clean; else GIT_TREE_STATE=dirty; fi && \
49+
LDFLAGS=" -X \"github.com/sap/component-operator-runtime/internal/version.version=$$GIT_BRANCH\" \
50+
-X \"github.com/sap/component-operator-runtime/internal/version.gitCommit=$$GIT_COMMIT\" \
51+
-X \"github.com/sap/component-operator-runtime/internal/version.gitTreeState=$$GIT_TREE_STATE\"" && \
52+
CGO_ENABLED=0 go build -ldflags "$$LDFLAGS" -o ./bin/clm ./clm
53+
2354
##@ Build Dependencies
2455

2556
## Location to install dependencies to
2657
LOCALBIN ?= $(shell pwd)/bin
2758
$(LOCALBIN):
2859
mkdir -p $(LOCALBIN)
2960

30-
## Tool Binaries
31-
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
32-
33-
## Tool Versions
34-
CONTROLLER_TOOLS_VERSION ?= v0.14.0
35-
3661
.PHONY: controller-gen
37-
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
38-
$(CONTROLLER_GEN): $(LOCALBIN)
39-
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
62+
controller-gen: $(LOCALBIN) ## Install controller-gen
63+
@go mod download sigs.k8s.io/controller-tools && \
64+
VERSION=$$(go list -m -f '{{.Version}}' sigs.k8s.io/controller-tools) && \
65+
if [ ! -L $(LOCALBIN)/controller-gen ] || [ "$$(readlink $(LOCALBIN)/controller-gen)" != "controller-gen-$$VERSION" ]; then \
66+
echo "Installing controller-gen $$VERSION" && \
67+
rm -f $(LOCALBIN)/controller-gen && \
68+
GOBIN=$(LOCALBIN) go install $$(go list -m -f '{{.Dir}}' sigs.k8s.io/controller-tools)/cmd/controller-gen && \
69+
mv $(LOCALBIN)/controller-gen $(LOCALBIN)/controller-gen-$$VERSION && \
70+
ln -s controller-gen-$$VERSION $(LOCALBIN)/controller-gen; \
71+
fi

clm/cmd/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func newDeleteCmd() *cobra.Command {
6464
if ok, msg, err := reconciler.IsDeletionAllowed(context.TODO(), &release.Inventory, ownerId); err != nil {
6565
return err
6666
} else if !ok {
67-
return fmt.Errorf(msg)
67+
return fmt.Errorf("%s", msg)
6868
}
6969

7070
if err := releaseClient.Delete(context.TODO(), release); err != nil {

go.mod

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/sap/component-operator-runtime
22

3-
go 1.24.4
3+
go 1.25.0
44

55
require (
66
github.com/Masterminds/sprig/v3 v3.3.0
@@ -25,6 +25,7 @@ require (
2525
k8s.io/kube-aggregator v0.33.2
2626
sigs.k8s.io/cli-utils v0.37.2
2727
sigs.k8s.io/controller-runtime v0.21.0
28+
sigs.k8s.io/controller-tools v0.18.0
2829
sigs.k8s.io/kustomize/api v0.19.0
2930
sigs.k8s.io/kustomize/kyaml v0.19.0
3031
sigs.k8s.io/structured-merge-diff/v6 v6.1.0
@@ -43,13 +44,15 @@ require (
4344
github.com/emicklei/go-restful/v3 v3.11.2 // indirect
4445
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
4546
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
47+
github.com/fatih/color v1.18.0 // indirect
4648
github.com/fsnotify/fsnotify v1.7.0 // indirect
4749
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
4850
github.com/go-errors/errors v1.5.1 // indirect
4951
github.com/go-openapi/jsonpointer v0.21.0 // indirect
5052
github.com/go-openapi/jsonreference v0.20.4 // indirect
5153
github.com/go-openapi/swag v0.23.0 // indirect
5254
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
55+
github.com/gobuffalo/flect v1.0.3 // indirect
5356
github.com/gogo/protobuf v1.3.2 // indirect
5457
github.com/google/btree v1.1.3 // indirect
5558
github.com/google/gnostic-models v0.6.9 // indirect
@@ -66,6 +69,8 @@ require (
6669
github.com/json-iterator/go v1.1.12 // indirect
6770
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
6871
github.com/mailru/easyjson v0.7.7 // indirect
72+
github.com/mattn/go-colorable v0.1.13 // indirect
73+
github.com/mattn/go-isatty v0.0.20 // indirect
6974
github.com/mitchellh/copystructure v1.2.0 // indirect
7075
github.com/mitchellh/reflectwalk v1.0.2 // indirect
7176
github.com/moby/term v0.5.0 // indirect
@@ -87,22 +92,26 @@ require (
8792
go.yaml.in/yaml/v2 v2.4.2 // indirect
8893
go.yaml.in/yaml/v3 v3.0.3 // indirect
8994
golang.org/x/crypto v0.37.0 // indirect
95+
golang.org/x/mod v0.24.0 // indirect
9096
golang.org/x/net v0.39.0 // indirect
9197
golang.org/x/oauth2 v0.27.0 // indirect
9298
golang.org/x/sync v0.13.0 // indirect
9399
golang.org/x/sys v0.32.0 // indirect
94100
golang.org/x/term v0.31.0 // indirect
95101
golang.org/x/text v0.24.0 // indirect
96102
golang.org/x/time v0.11.0 // indirect
97-
golang.org/x/tools v0.31.0 // indirect
103+
golang.org/x/tools v0.32.0 // indirect
98104
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
99105
google.golang.org/protobuf v1.36.5 // indirect
100106
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
101107
gopkg.in/inf.v0 v0.9.1 // indirect
102108
gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect
103109
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
104110
gopkg.in/warnings.v0 v0.1.2 // indirect
111+
gopkg.in/yaml.v2 v2.4.0 // indirect
105112
gopkg.in/yaml.v3 v3.0.1 // indirect
113+
k8s.io/code-generator v0.33.2 // indirect
114+
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 // indirect
106115
k8s.io/klog/v2 v2.130.1 // indirect
107116
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
108117
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect

0 commit comments

Comments
 (0)