Skip to content

Commit 36ca448

Browse files
dhaiducekopenshift-merge-bot[bot]
authored andcommitted
Clean up Makefile in favor of common Makefile
Signed-off-by: Dale Haiducek <[email protected]>
1 parent 1e94ca6 commit 36ca448

File tree

6 files changed

+11
-97
lines changed

6 files changed

+11
-97
lines changed

Makefile

Lines changed: 2 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,8 @@ REGISTRY ?= quay.io/open-cluster-management
7373
TAG ?= latest
7474
IMAGE_NAME_AND_VERSION ?= $(REGISTRY)/$(IMG)
7575

76-
# go-get-tool will 'go install' any package $1 and install it to LOCAL_BIN.
77-
define go-get-tool
78-
@set -e ;\
79-
echo "Checking installation of $(1)" ;\
80-
GOBIN=$(LOCAL_BIN) go install $(1)
81-
endef
82-
8376
include build/common/Makefile.common.mk
8477

85-
############################################################
86-
# work section
87-
############################################################
88-
89-
$(GOBIN):
90-
@mkdir -p $(GOBIN)
91-
92-
$(LOCAL_BIN):
93-
@mkdir -p $(LOCAL_BIN)
94-
9578
############################################################
9679
# clean section
9780
############################################################
@@ -109,42 +92,15 @@ clean:
10992
# format section
11093
############################################################
11194

112-
.PHONY: fmt-dependencies
113-
fmt-dependencies:
114-
$(call go-get-tool,github.com/daixiang0/[email protected])
115-
$(call go-get-tool,mvdan.cc/[email protected])
116-
117-
# All available format: format-go format-protos format-python
118-
# Default value will run all formats, override these make target with your requirements:
119-
# eg: fmt: format-go format-protos
12095
.PHONY: fmt
121-
fmt: fmt-dependencies
122-
find . -not \( -path "./.go" -prune \) -name "*.go" | xargs gofmt -s -w
123-
find . -not \( -path "./.go" -prune \) -name "*.go" | xargs gofumpt -l -w
124-
find . -not \( -path "./.go" -prune \) -name "*.go" | xargs gci write -s standard -s default -s "prefix($(shell cat go.mod | head -1 | cut -d " " -f 2))"
125-
126-
############################################################
127-
# check section
128-
############################################################
129-
130-
.PHONY: check
131-
check: lint
132-
133-
.PHONY: lint-dependencies
134-
lint-dependencies:
135-
$(call go-get-tool,github.com/golangci/golangci-lint/cmd/[email protected])
96+
fmt:
13697

13798
.PHONY: lint
13899
lint:
139100

140101
############################################################
141102
# test section
142103
############################################################
143-
GOSEC = $(LOCAL_BIN)/gosec
144-
KUBEBUILDER = $(LOCAL_BIN)/kubebuilder
145-
ENVTEST = $(LOCAL_BIN)/setup-envtest
146-
KBVERSION = 3.12.0
147-
ENVTEST_K8S_VERSION = 1.26.x
148104

149105
.PHONY: test
150106
test: test-dependencies
@@ -157,26 +113,6 @@ test-coverage: test
157113
.PHONY: test-dependencies
158114
test-dependencies: envtest kubebuilder
159115

160-
.PHONY: kubebuilder
161-
kubebuilder:
162-
@if [ "$$($(KUBEBUILDER) version 2>/dev/null | grep -o KubeBuilderVersion:\"[0-9]*\.[0-9]\.[0-9]*\")" != "KubeBuilderVersion:\"$(KBVERSION)\"" ]; then \
163-
echo "Installing Kubebuilder"; \
164-
curl -L https://github.com/kubernetes-sigs/kubebuilder/releases/download/v$(KBVERSION)/kubebuilder_$(GOOS)_$(GOARCH) -o $(KUBEBUILDER); \
165-
chmod +x $(KUBEBUILDER); \
166-
fi
167-
168-
.PHONY: envtest
169-
envtest:
170-
$(call go-get-tool,sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
171-
172-
.PHONY: gosec
173-
gosec:
174-
$(call go-get-tool,github.com/securego/gosec/v2/cmd/[email protected])
175-
176-
.PHONY: gosec-scan
177-
gosec-scan: gosec
178-
$(GOSEC) -fmt sonarqube -out gosec.json -stdout -exclude-dir=.go -exclude-dir=test ./...
179-
180116
############################################################
181117
# build section
182118
############################################################
@@ -201,13 +137,10 @@ build-images:
201137
.PHONY: deploy
202138
deploy: generate-operator-yaml
203139
kubectl apply -f deploy/operator.yaml -n $(KIND_NAMESPACE) --kubeconfig=$(MANAGED_CONFIG)_e2e
204-
205140

206141
############################################################
207142
# Generate manifests
208143
############################################################
209-
CONTROLLER_GEN = $(LOCAL_BIN)/controller-gen
210-
KUSTOMIZE = $(LOCAL_BIN)/kustomize
211144

212145
.PHONY: manifests
213146
manifests: controller-gen
@@ -221,18 +154,9 @@ generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and
221154
generate-operator-yaml: kustomize manifests
222155
$(KUSTOMIZE) build deploy/manager > deploy/operator.yaml
223156

224-
.PHONY: controller-gen
225-
controller-gen: ## Download controller-gen locally if necessary.
226-
$(call go-get-tool,sigs.k8s.io/controller-tools/cmd/[email protected])
227-
228-
.PHONY: kustomize
229-
kustomize: ## Download kustomize locally if necessary.
230-
$(call go-get-tool,sigs.k8s.io/kustomize/kustomize/[email protected])
231-
232157
############################################################
233158
# e2e test section
234159
############################################################
235-
GINKGO = $(LOCAL_BIN)/ginkgo
236160

237161
.PHONY: kind-bootstrap-cluster
238162
kind-bootstrap-cluster: kind-bootstrap-cluster-dev kind-deploy-controller
@@ -293,10 +217,6 @@ install-resources:
293217
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper/v3.11.0/deploy/gatekeeper.yaml --kubeconfig=$(MANAGED_CONFIG)_e2e; \
294218
fi
295219

296-
.PHONY: e2e-dependencies
297-
e2e-dependencies:
298-
$(call go-get-tool,github.com/onsi/ginkgo/v2/ginkgo@$(shell awk '/github.com\/onsi\/ginkgo\/v2/ {print $$2}' go.mod))
299-
300220
.PHONY: e2e-test
301221
e2e-test: e2e-dependencies
302222
$(GINKGO) -v --fail-fast $(E2E_TEST_ARGS) test/e2e
@@ -355,12 +275,8 @@ e2e-debug:
355275
############################################################
356276
# test coverage
357277
############################################################
358-
GOCOVMERGE = $(LOCAL_BIN)/gocovmerge
359-
.PHONY: coverage-dependencies
360-
coverage-dependencies:
361-
$(call go-get-tool,github.com/wadey/[email protected])
362-
363278
COVERAGE_FILE = coverage.out
279+
364280
.PHONY: coverage-merge
365281
coverage-merge: coverage-dependencies
366282
@echo Merging the coverage reports into $(COVERAGE_FILE)

controllers/secretsync/secret_sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ func (r *SecretReconciler) Reconcile(ctx context.Context, request reconcile.Requ
109109
}
110110

111111
managedEncryptionSecret := &corev1.Secret{}
112+
112113
err = r.ManagedClient.Get(
113114
ctx, types.NamespacedName{Namespace: r.TargetNamespace, Name: request.Name}, managedEncryptionSecret,
114115
)
115-
116116
if err != nil {
117117
if !errors.IsNotFound(err) {
118118
reqLogger.Error(err, "Failed to get the replicated Secret. Requeueing the request.")

controllers/specsync/policy_spec_sync.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
116116
}
117117

118118
managedPlc := &policiesv1.Policy{}
119-
err = r.ManagedClient.Get(ctx, types.NamespacedName{Namespace: r.TargetNamespace, Name: request.Name}, managedPlc)
120119

120+
err = r.ManagedClient.Get(ctx, types.NamespacedName{Namespace: r.TargetNamespace, Name: request.Name}, managedPlc)
121121
if err != nil {
122122
if errors.IsNotFound(err) {
123123
// not found on managed cluster, create it
@@ -132,8 +132,8 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
132132

133133
managedPlc.SetOwnerReferences(nil)
134134
managedPlc.SetResourceVersion("")
135-
err = r.ManagedClient.Create(ctx, managedPlc)
136135

136+
err = r.ManagedClient.Create(ctx, managedPlc)
137137
if err != nil {
138138
reqLogger.Error(err, "Failed to create policy on managed...")
139139

controllers/statussync/policy_status_sync.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
102102
// The replicated policy on the managed cluster was deleted.
103103
// check if it was deleted by user by checking if it still exists on hub
104104
hubInstance := &policiesv1.Policy{}
105+
105106
err = r.HubClient.Get(
106107
ctx, types.NamespacedName{Namespace: r.ClusterNamespaceOnHub, Name: request.Name}, hubInstance,
107108
)
108-
109109
if err != nil {
110110
if errors.IsNotFound(err) {
111111
// confirmed deleted on hub, doing nothing
@@ -139,10 +139,11 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
139139

140140
return reconcile.Result{}, err
141141
}
142+
142143
// get hub policy
143144
hubPlc := &policiesv1.Policy{}
144-
err = r.HubClient.Get(ctx, types.NamespacedName{Namespace: r.ClusterNamespaceOnHub, Name: request.Name}, hubPlc)
145145

146+
err = r.HubClient.Get(ctx, types.NamespacedName{Namespace: r.ClusterNamespaceOnHub, Name: request.Name}, hubPlc)
146147
if err != nil {
147148
// hub policy not found, it has been deleted
148149
if errors.IsNotFound(err) {
@@ -178,8 +179,8 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
178179

179180
// plc matches hub plc, then get events
180181
eventList := &corev1.EventList{}
181-
err = r.ManagedClient.List(ctx, eventList, client.InNamespace(instance.GetNamespace()))
182182

183+
err = r.ManagedClient.List(ctx, eventList, client.InNamespace(instance.GetNamespace()))
183184
if err != nil {
184185
// there is an error to list events, requeue
185186
reqLogger.Error(err, "Error listing events, will requeue the request")
@@ -395,7 +396,6 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
395396
reqLogger.Info("status mismatch on managed, update it")
396397

397398
err = r.ManagedClient.Status().Update(ctx, instance)
398-
399399
if err != nil {
400400
reqLogger.Error(err, "Failed to get update policy status on managed")
401401

@@ -420,8 +420,8 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
420420
reqLogger.Info("status not in sync, update the hub")
421421

422422
hubPlc.Status = instance.Status
423-
err = r.HubClient.Status().Update(ctx, hubPlc)
424423

424+
err = r.HubClient.Status().Update(ctx, hubPlc)
425425
if err != nil {
426426
reqLogger.Error(err, "Failed to update policy status on hub")
427427

controllers/templatesync/template_sync.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,9 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
484484
}
485485

486486
res = dClient.Resource(rsrc).Namespace(resourceNs)
487-
488487
tObjectUnstructured := &unstructured.Unstructured{}
489-
err = json.Unmarshal(policyT.ObjectDefinition.Raw, tObjectUnstructured)
490488

489+
err = json.Unmarshal(policyT.ObjectDefinition.Raw, tObjectUnstructured)
491490
if err != nil {
492491
resultError = err
493492
errMsg := fmt.Sprintf("Failed to unmarshal the policy template: %s", err)

main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,6 @@ func addControllers(ctx context.Context, hubCfg *rest.Config, hubMgr manager.Man
766766
hubClient, err = client.New(
767767
hubCfg, client.Options{Scheme: scheme, Cache: &client.CacheOptions{Reader: hubCache}},
768768
)
769-
770769
if err != nil {
771770
log.Error(err, "Failed to generate a client to the hub cluster")
772771
os.Exit(1)

0 commit comments

Comments
 (0)