Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👻 Go 1.20 #595

Merged
merged 10 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 36 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
GOBIN ?= ${GOPATH}/bin
GOPATH ?= $(HOME)/go
GOBIN ?= $(GOPATH)/bin
GOIMPORTS = $(GOBIN)/goimports
CONTROLLERGEN = $(GOBIN)/controller-gen
IMG ?= tackle2-hub:latest
HUB_BASE_URL ?= http://localhost:8080

PKG = ./addon/... \
./api/... \
./assessment/... \
./auth/... \
./binding/... \
./controller/... \
./cmd/... \
./database/... \
./encryption/... \
Expand All @@ -14,41 +19,47 @@ PKG = ./addon/... \
./metrics/... \
./migration/... \
./model/... \
./nas/... \
./reaper/... \
./seed/... \
./settings/... \
./controller/... \
./tar/... \
./task/... \
./test/... \
./tracker/...

PKGDIR = $(subst /...,,$(PKG))

BUILD = --tags json1 -o bin/hub github.com/konveyor/tackle2-hub/cmd

# Build ALL commands.
cmd: hub addon

# Run go fmt against code
fmt:
go fmt ${PKG}
# Format the code.
fmt: $(GOIMPORTS)
$(GOIMPORTS) -w $(PKGDIR)

# Run go vet against code
vet:
go vet ${PKG}
go vet $(PKG)

# Build hub
hub: generate fmt vet
go build ${BUILD}
go build $(BUILD)

# Build image
docker-build:
docker build -t ${IMG} .
docker build -t $(IMG) .

podman-build:
podman build -t ${IMG} .
podman build -t $(IMG) .

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

docker: vet
go build ${BUILD}
go build $(BUILD)

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

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

# Generate code
generate: controller-gen
controller-gen object:headerFile="./generated/boilerplate" paths="./..."

# Find or download controller-gen.
controller-gen:
if [ "$(shell which controller-gen)" = "" ]; then \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go install sigs.k8s.io/controller-tools/cmd/[email protected] ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
fi ;\
generate: $(CONTROLLERGEN)
$(CONTROLLERGEN) object:headerFile="./generated/boilerplate" paths="./..."

# Ensure controller-gen installed.
$(CONTROLLERGEN):
go install sigs.k8s.io/controller-tools/cmd/[email protected]

# Ensure goimports installed.
$(GOIMPORTS):
go install golang.org/x/tools/cmd/goimports@latest

# Build SAMPLE ADDON
addon: fmt vet
Expand All @@ -86,7 +94,7 @@ docs: docs-html docs-openapi3 docs-binding

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

# Build OpenAPI 3.0 docs
docs-openapi3: docs-swagger
Expand Down Expand Up @@ -135,7 +143,7 @@ test:

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

# Run Hub test suite.
test-all: test-unit test-api
Expand Down
17 changes: 5 additions & 12 deletions addon/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ Tackle hub/addon integration.
package addon

import (
"os"

logapi "github.com/go-logr/logr"
"github.com/jortel/go-utils/logr"
"github.com/konveyor/tackle2-hub/binding"
"github.com/konveyor/tackle2-hub/settings"
"github.com/konveyor/tackle2-hub/task"
"golang.org/x/sys/unix"
"os"
)

var (
Settings = &settings.Settings
Log = logr.WithName("addon")
)

//
// Addon An addon adapter configured for a task execution.
var Addon *Adapter

Expand All @@ -33,20 +33,17 @@ func init() {
Addon = newAdapter()
}

//
// Client
type Client = binding.Client
type Params = binding.Params
type Param = binding.Param
type Path = binding.Path

//
// Error
type ResetError = binding.RestError
type Conflict = binding.Conflict
type NotFound = binding.NotFound

//
// Handler
type Application = binding.Application
type Bucket = binding.Bucket
Expand All @@ -59,11 +56,9 @@ type Setting = binding.Setting
type Tag = binding.Tag
type TagCategory = binding.TagCategory

//
// Filter
type Filter = binding.Filter

//
// The Adapter provides hub/addon integration.
type Adapter struct {
// Task API.
Expand All @@ -90,12 +85,11 @@ type Adapter struct {
client *Client
}

//
// Run addon.
// Reports:
// - Started
// - Succeeded
// - Failed (when addon returns error).
// - Started
// - Succeeded
// - Failed (when addon returns error).
func (h *Adapter) Run(addon func() error) {
var err error
//
Expand Down Expand Up @@ -134,7 +128,6 @@ func (h *Adapter) Run(addon func() error) {
}
}

//
// newAdapter builds a new Addon Adapter object.
func newAdapter() (adapter *Adapter) {
richClient := binding.New(Settings.Addon.Hub.URL)
Expand Down
1 change: 0 additions & 1 deletion addon/error.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package addon

//
// SoftError A "soft" anticipated error.
// Deprecated:
type SoftError struct {
Expand Down
24 changes: 2 additions & 22 deletions addon/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package addon
import (
"encoding/json"
"fmt"
"strings"

"github.com/konveyor/tackle2-hub/api"
"github.com/konveyor/tackle2-hub/binding"
"github.com/konveyor/tackle2-hub/task"
"strings"
)

//
// Task API.
type Task struct {
richClient *binding.RichClient
Expand All @@ -19,7 +19,6 @@ type Task struct {
report api.TaskReport
}

//
// Load a task by ID.
func (h *Task) Load() {
var err error
Expand All @@ -32,7 +31,6 @@ func (h *Task) Load() {
return
}

//
// Application returns the application associated with the task.
func (h *Task) Application() (r *api.Application, err error) {
appRef := h.task.Application
Expand All @@ -44,28 +42,24 @@ func (h *Task) Application() (r *api.Application, err error) {
return
}

//
// Data returns the addon data.
func (h *Task) Data() (d map[string]interface{}) {
d = h.task.Data.(map[string]interface{})
return
}

//
// DataWith populates the addon data object.
func (h *Task) DataWith(object interface{}) (err error) {
b, _ := json.Marshal(h.task.Data)
err = json.Unmarshal(b, object)
return
}

//
// Variant returns the task variant.
func (h *Task) Variant() string {
return h.task.Variant
}

//
// Started report addon started.
func (h *Task) Started() {
h.deleteReport()
Expand All @@ -75,7 +69,6 @@ func (h *Task) Started() {
return
}

//
// Succeeded report addon succeeded.
func (h *Task) Succeeded() {
h.report.Status = task.Succeeded
Expand All @@ -85,7 +78,6 @@ func (h *Task) Succeeded() {
return
}

//
// Failed report addon failed.
// The reason can be a printf style format.
func (h *Task) Failed(reason string, v ...interface{}) {
Expand All @@ -101,7 +93,6 @@ func (h *Task) Failed(reason string, v ...interface{}) {
return
}

//
// Errorf report addon error.
func (h *Task) Errorf(severity, description string, v ...interface{}) {
h.Error(api.TaskError{
Expand All @@ -110,7 +101,6 @@ func (h *Task) Errorf(severity, description string, v ...interface{}) {
})
}

//
// Error report addon error.
func (h *Task) Error(error ...api.TaskError) {
h.report.Status = task.Failed
Expand All @@ -127,7 +117,6 @@ func (h *Task) Error(error ...api.TaskError) {
return
}

//
// Activity report addon activity.
// The description can be a printf style format.
func (h *Task) Activity(entry string, v ...interface{}) {
Expand All @@ -151,7 +140,6 @@ func (h *Task) Activity(entry string, v ...interface{}) {
return
}

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

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

//
// Total report addon total items.
func (h *Task) Total(n int) {
h.report.Total = n
Expand All @@ -203,7 +189,6 @@ func (h *Task) Total(n int) {
return
}

//
// Increment report addon completed (+1) items.
func (h *Task) Increment() {
h.report.Completed++
Expand All @@ -215,7 +200,6 @@ func (h *Task) Increment() {
return
}

//
// Completed report addon completed (N) items.
func (h *Task) Completed(n int) {
h.report.Completed = n
Expand All @@ -224,14 +208,12 @@ func (h *Task) Completed(n int) {
return
}

//
// Bucket returns the bucket API.
func (h *Task) Bucket() (b *binding.BucketContent) {
b = h.richClient.Task.Bucket(h.task.ID)
return
}

//
// Result report addon result.
func (h *Task) Result(object interface{}) {
h.report.Result = object
Expand All @@ -240,7 +222,6 @@ func (h *Task) Result(object interface{}) {
return
}

//
// deleteReport deletes the task report.
func (h *Task) deleteReport() {
params := Params{
Expand All @@ -253,7 +234,6 @@ func (h *Task) deleteReport() {
}
}

//
// pushReport create/update the task report.
func (h *Task) pushReport() {
var err error
Expand Down
Loading
Loading