Skip to content

Commit f1989d5

Browse files
authored
👻 Go 1.20 (#595)
upgrade Go 1.20. Replaces _gofmt_ with _goimports_. Documentation claims it performs the same formatting plus manages/orders imports. Added missing packages in Makefile. Updated the go.mod and ran `go mod tidy`. Simplified controller-gen target. Updated variable syntax with more traditional. closes: #556 NOT FOR 0.3. --------- Signed-off-by: Jeff Ortel <[email protected]>
1 parent 2552233 commit f1989d5

File tree

225 files changed

+462
-1560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

225 files changed

+462
-1560
lines changed

Makefile

+36-28
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
GOBIN ?= ${GOPATH}/bin
1+
GOPATH ?= $(HOME)/go
2+
GOBIN ?= $(GOPATH)/bin
3+
GOIMPORTS = $(GOBIN)/goimports
4+
CONTROLLERGEN = $(GOBIN)/controller-gen
25
IMG ?= tackle2-hub:latest
36
HUB_BASE_URL ?= http://localhost:8080
47

58
PKG = ./addon/... \
69
./api/... \
710
./assessment/... \
811
./auth/... \
12+
./binding/... \
13+
./controller/... \
914
./cmd/... \
1015
./database/... \
1116
./encryption/... \
@@ -14,41 +19,47 @@ PKG = ./addon/... \
1419
./metrics/... \
1520
./migration/... \
1621
./model/... \
22+
./nas/... \
23+
./reaper/... \
24+
./seed/... \
1725
./settings/... \
18-
./controller/... \
26+
./tar/... \
1927
./task/... \
28+
./test/... \
2029
./tracker/...
2130

31+
PKGDIR = $(subst /...,,$(PKG))
32+
2233
BUILD = --tags json1 -o bin/hub github.com/konveyor/tackle2-hub/cmd
2334

2435
# Build ALL commands.
2536
cmd: hub addon
2637

27-
# Run go fmt against code
28-
fmt:
29-
go fmt ${PKG}
38+
# Format the code.
39+
fmt: $(GOIMPORTS)
40+
$(GOIMPORTS) -w $(PKGDIR)
3041

3142
# Run go vet against code
3243
vet:
33-
go vet ${PKG}
44+
go vet $(PKG)
3445

3546
# Build hub
3647
hub: generate fmt vet
37-
go build ${BUILD}
48+
go build $(BUILD)
3849

3950
# Build image
4051
docker-build:
41-
docker build -t ${IMG} .
52+
docker build -t $(IMG) .
4253

4354
podman-build:
44-
podman build -t ${IMG} .
55+
podman build -t $(IMG) .
4556

4657
# Build manager binary with compiler optimizations disabled
4758
debug: generate fmt vet
48-
go build -gcflags=all="-N -l" ${BUILD}
59+
go build -gcflags=all="-N -l" $(BUILD)
4960

5061
docker: vet
51-
go build ${BUILD}
62+
go build $(BUILD)
5263

5364
# Run against the configured Kubernetes cluster in ~/.kube/config
5465
run: fmt vet
@@ -58,25 +69,22 @@ run-addon:
5869
go run ./hack/cmd/addon/main.go
5970

6071
# Generate manifests e.g. CRD, Webhooks
61-
manifests: controller-gen
62-
controller-gen ${CRD_OPTIONS} \
72+
manifests: $(CONTROLLERGEN)
73+
$(CONTROLLERGEN) $(CRD_OPTIONS) \
6374
crd rbac:roleName=manager-role \
6475
paths="./..." output:crd:artifacts:config=generated/crd/bases output:crd:dir=generated/crd
6576

6677
# Generate code
67-
generate: controller-gen
68-
controller-gen object:headerFile="./generated/boilerplate" paths="./..."
69-
70-
# Find or download controller-gen.
71-
controller-gen:
72-
if [ "$(shell which controller-gen)" = "" ]; then \
73-
set -e ;\
74-
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
75-
cd $$CONTROLLER_GEN_TMP_DIR ;\
76-
go mod init tmp ;\
77-
go install sigs.k8s.io/controller-tools/cmd/[email protected] ;\
78-
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
79-
fi ;\
78+
generate: $(CONTROLLERGEN)
79+
$(CONTROLLERGEN) object:headerFile="./generated/boilerplate" paths="./..."
80+
81+
# Ensure controller-gen installed.
82+
$(CONTROLLERGEN):
83+
go install sigs.k8s.io/controller-tools/cmd/[email protected]
84+
85+
# Ensure goimports installed.
86+
$(GOIMPORTS):
87+
go install golang.org/x/tools/cmd/goimports@latest
8088

8189
# Build SAMPLE ADDON
8290
addon: fmt vet
@@ -86,7 +94,7 @@ docs: docs-html docs-openapi3 docs-binding
8694

8795
# Build Swagger API spec into ./docs directory
8896
docs-swagger:
89-
${GOBIN}/swag init -g pkg.go --dir api,assessment
97+
$(GOBIN)/swag init -g pkg.go --dir api,assessment
9098

9199
# Build OpenAPI 3.0 docs
92100
docs-openapi3: docs-swagger
@@ -135,7 +143,7 @@ test:
135143

136144
# Run Hub REST API tests.
137145
test-api:
138-
HUB_BASE_URL=${HUB_BASE_URL} go test -count=1 -p=1 -v ./test/api/...
146+
HUB_BASE_URL=$(HUB_BASE_URL) go test -count=1 -p=1 -v ./test/api/...
139147

140148
# Run Hub test suite.
141149
test-all: test-unit test-api

addon/adapter.go

+5-12
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ Tackle hub/addon integration.
55
package addon
66

77
import (
8+
"os"
9+
810
logapi "github.com/go-logr/logr"
911
"github.com/jortel/go-utils/logr"
1012
"github.com/konveyor/tackle2-hub/binding"
1113
"github.com/konveyor/tackle2-hub/settings"
1214
"github.com/konveyor/tackle2-hub/task"
1315
"golang.org/x/sys/unix"
14-
"os"
1516
)
1617

1718
var (
1819
Settings = &settings.Settings
1920
Log = logr.WithName("addon")
2021
)
2122

22-
//
2323
// Addon An addon adapter configured for a task execution.
2424
var Addon *Adapter
2525

@@ -33,20 +33,17 @@ func init() {
3333
Addon = newAdapter()
3434
}
3535

36-
//
3736
// Client
3837
type Client = binding.Client
3938
type Params = binding.Params
4039
type Param = binding.Param
4140
type Path = binding.Path
4241

43-
//
4442
// Error
4543
type ResetError = binding.RestError
4644
type Conflict = binding.Conflict
4745
type NotFound = binding.NotFound
4846

49-
//
5047
// Handler
5148
type Application = binding.Application
5249
type Bucket = binding.Bucket
@@ -59,11 +56,9 @@ type Setting = binding.Setting
5956
type Tag = binding.Tag
6057
type TagCategory = binding.TagCategory
6158

62-
//
6359
// Filter
6460
type Filter = binding.Filter
6561

66-
//
6762
// The Adapter provides hub/addon integration.
6863
type Adapter struct {
6964
// Task API.
@@ -90,12 +85,11 @@ type Adapter struct {
9085
client *Client
9186
}
9287

93-
//
9488
// Run addon.
9589
// Reports:
96-
// - Started
97-
// - Succeeded
98-
// - Failed (when addon returns error).
90+
// - Started
91+
// - Succeeded
92+
// - Failed (when addon returns error).
9993
func (h *Adapter) Run(addon func() error) {
10094
var err error
10195
//
@@ -134,7 +128,6 @@ func (h *Adapter) Run(addon func() error) {
134128
}
135129
}
136130

137-
//
138131
// newAdapter builds a new Addon Adapter object.
139132
func newAdapter() (adapter *Adapter) {
140133
richClient := binding.New(Settings.Addon.Hub.URL)

addon/error.go

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package addon
22

3-
//
43
// SoftError A "soft" anticipated error.
54
// Deprecated:
65
type SoftError struct {

addon/task.go

+2-22
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package addon
33
import (
44
"encoding/json"
55
"fmt"
6+
"strings"
7+
68
"github.com/konveyor/tackle2-hub/api"
79
"github.com/konveyor/tackle2-hub/binding"
810
"github.com/konveyor/tackle2-hub/task"
9-
"strings"
1011
)
1112

12-
//
1313
// Task API.
1414
type Task struct {
1515
richClient *binding.RichClient
@@ -19,7 +19,6 @@ type Task struct {
1919
report api.TaskReport
2020
}
2121

22-
//
2322
// Load a task by ID.
2423
func (h *Task) Load() {
2524
var err error
@@ -32,7 +31,6 @@ func (h *Task) Load() {
3231
return
3332
}
3433

35-
//
3634
// Application returns the application associated with the task.
3735
func (h *Task) Application() (r *api.Application, err error) {
3836
appRef := h.task.Application
@@ -44,28 +42,24 @@ func (h *Task) Application() (r *api.Application, err error) {
4442
return
4543
}
4644

47-
//
4845
// Data returns the addon data.
4946
func (h *Task) Data() (d map[string]interface{}) {
5047
d = h.task.Data.(map[string]interface{})
5148
return
5249
}
5350

54-
//
5551
// DataWith populates the addon data object.
5652
func (h *Task) DataWith(object interface{}) (err error) {
5753
b, _ := json.Marshal(h.task.Data)
5854
err = json.Unmarshal(b, object)
5955
return
6056
}
6157

62-
//
6358
// Variant returns the task variant.
6459
func (h *Task) Variant() string {
6560
return h.task.Variant
6661
}
6762

68-
//
6963
// Started report addon started.
7064
func (h *Task) Started() {
7165
h.deleteReport()
@@ -75,7 +69,6 @@ func (h *Task) Started() {
7569
return
7670
}
7771

78-
//
7972
// Succeeded report addon succeeded.
8073
func (h *Task) Succeeded() {
8174
h.report.Status = task.Succeeded
@@ -85,7 +78,6 @@ func (h *Task) Succeeded() {
8578
return
8679
}
8780

88-
//
8981
// Failed report addon failed.
9082
// The reason can be a printf style format.
9183
func (h *Task) Failed(reason string, v ...interface{}) {
@@ -101,7 +93,6 @@ func (h *Task) Failed(reason string, v ...interface{}) {
10193
return
10294
}
10395

104-
//
10596
// Errorf report addon error.
10697
func (h *Task) Errorf(severity, description string, v ...interface{}) {
10798
h.Error(api.TaskError{
@@ -110,7 +101,6 @@ func (h *Task) Errorf(severity, description string, v ...interface{}) {
110101
})
111102
}
112103

113-
//
114104
// Error report addon error.
115105
func (h *Task) Error(error ...api.TaskError) {
116106
h.report.Status = task.Failed
@@ -127,7 +117,6 @@ func (h *Task) Error(error ...api.TaskError) {
127117
return
128118
}
129119

130-
//
131120
// Activity report addon activity.
132121
// The description can be a printf style format.
133122
func (h *Task) Activity(entry string, v ...interface{}) {
@@ -151,7 +140,6 @@ func (h *Task) Activity(entry string, v ...interface{}) {
151140
return
152141
}
153142

154-
//
155143
// Attach ensures the file is attached to the report
156144
// associated with the last entry in the activity.
157145
func (h *Task) Attach(f *api.File) {
@@ -160,7 +148,6 @@ func (h *Task) Attach(f *api.File) {
160148
return
161149
}
162150

163-
//
164151
// AttachAt ensures the file is attached to
165152
// the report indexed to the activity.
166153
// The activity is a 1-based index. Zero(0) means NOT associated.
@@ -191,7 +178,6 @@ func (h *Task) AttachAt(f *api.File, activity int) {
191178
return
192179
}
193180

194-
//
195181
// Total report addon total items.
196182
func (h *Task) Total(n int) {
197183
h.report.Total = n
@@ -203,7 +189,6 @@ func (h *Task) Total(n int) {
203189
return
204190
}
205191

206-
//
207192
// Increment report addon completed (+1) items.
208193
func (h *Task) Increment() {
209194
h.report.Completed++
@@ -215,7 +200,6 @@ func (h *Task) Increment() {
215200
return
216201
}
217202

218-
//
219203
// Completed report addon completed (N) items.
220204
func (h *Task) Completed(n int) {
221205
h.report.Completed = n
@@ -224,14 +208,12 @@ func (h *Task) Completed(n int) {
224208
return
225209
}
226210

227-
//
228211
// Bucket returns the bucket API.
229212
func (h *Task) Bucket() (b *binding.BucketContent) {
230213
b = h.richClient.Task.Bucket(h.task.ID)
231214
return
232215
}
233216

234-
//
235217
// Result report addon result.
236218
func (h *Task) Result(object interface{}) {
237219
h.report.Result = object
@@ -240,7 +222,6 @@ func (h *Task) Result(object interface{}) {
240222
return
241223
}
242224

243-
//
244225
// deleteReport deletes the task report.
245226
func (h *Task) deleteReport() {
246227
params := Params{
@@ -253,7 +234,6 @@ func (h *Task) deleteReport() {
253234
}
254235
}
255236

256-
//
257237
// pushReport create/update the task report.
258238
func (h *Task) pushReport() {
259239
var err error

0 commit comments

Comments
 (0)