Skip to content

Commit ba6dc3c

Browse files
committed
Populated.
1 parent 8e056a3 commit ba6dc3c

Some content is hidden

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

88 files changed

+19415
-2
lines changed

Dockerfile

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM registry.access.redhat.com/ubi8/go-toolset:1.16.12 as builder
2+
ENV GOPATH=$APP_ROOT
3+
COPY --chown=1001:0 . .
4+
RUN make docker
5+
6+
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.4
7+
COPY --from=builder /opt/app-root/src/bin/hub /usr/local/bin/tackle-hub
8+
ENTRYPOINT ["/usr/local/bin/tackle-hub"]
9+
10+
LABEL name="konveyor/tackle2-hub" \
11+
description="Konveyor Tackle - Hub" \
12+
help="For more information visit https://konveyor.io" \
13+
license="Apache License 2.0" \
14+
15+
summary="Konveyor Tackle - Hub" \
16+
url="https://quay.io/repository/konveyor/tackle2-hub" \
17+
usage="podman run konveyor/tackle2-hub:latest" \
18+
com.redhat.component="konveyor-tackle-hub-container" \
19+
io.k8s.display-name="Tackle Hub" \
20+
io.k8s.description="Konveyor Tackle - Hub" \
21+
io.openshift.expose-services="" \
22+
io.openshift.tags="konveyor,tackle,hub" \
23+
io.openshift.min-cpu="100m" \
24+
io.openshift.min-memory="350Mi"

Makefile

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
GOBIN ?= ${GOPATH}/bin
2+
3+
PKG = ./addon/... \
4+
./api/... \
5+
./cmd/... \
6+
./encryption/... \
7+
./importer/... \
8+
./k8s/... \
9+
./model/... \
10+
./settings/... \
11+
./task/...
12+
13+
BUILD = --tags json1 -o bin/hub github.com/konveyor/tackle2-hub/cmd
14+
15+
# Build ALL commands.
16+
cmd: hub addon
17+
18+
# Run go fmt against code
19+
fmt:
20+
go fmt ${PKG}
21+
22+
# Run go vet against code
23+
vet:
24+
go vet ${PKG}
25+
26+
# Build hub
27+
hub: generate fmt vet
28+
go build ${BUILD}
29+
30+
# Build manager binary with compiler optimizations disabled
31+
debug: generate fmt vet
32+
go build -gcflags=all="-N -l" ${BUILD}
33+
34+
docker: vet
35+
go build ${BUILD}
36+
37+
# Run against the configured Kubernetes cluster in ~/.kube/config
38+
run: fmt vet
39+
go run ./cmd/main.go
40+
41+
# Generate manifests e.g. CRD, Webhooks
42+
manifests: controller-gen
43+
${CONTROLLER_GEN} ${CRD_OPTIONS} \
44+
crd rbac:roleName=manager-role \
45+
paths="./..." output:crd:artifacts:config=generated/crd/bases output:crd:dir=generated/crd
46+
47+
# Generate code
48+
generate: controller-gen
49+
${CONTROLLER_GEN} object:headerFile="./generated/boilerplate" paths="./..."
50+
51+
# Find or download controller-gen.
52+
controller-gen:
53+
ifeq (, $(shell which controller-gen))
54+
@{ \
55+
set -e ;\
56+
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
57+
cd $$CONTROLLER_GEN_TMP_DIR ;\
58+
go mod init tmp ;\
59+
go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
60+
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
61+
}
62+
CONTROLLER_GEN=$(GOBIN)/controller-gen
63+
else
64+
CONTROLLER_GEN=$(shell which controller-gen)
65+
endif
66+
67+
# Build SAMPLE ADDON
68+
addon: fmt vet
69+
go build -o bin/addon github.com/konveyor/tackle2-hub/hack/cmd/addon

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# tackle2-hub
2-
Tackle (2nd generation) hub component.
1+
# tackle-hub
2+
3+
<img src="https://github.com/mansam/tackle-hub/blob/main/tackle-hub.png" width="850" height="600">

addon/adapter.go

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
/*
2+
Tackle hub/addon integration.
3+
*/
4+
5+
package addon
6+
7+
import (
8+
"encoding/json"
9+
"fmt"
10+
"github.com/konveyor/controller/pkg/logging"
11+
"github.com/konveyor/tackle2-hub/settings"
12+
"github.com/konveyor/tackle2-hub/task"
13+
"net/http"
14+
"os"
15+
"strings"
16+
)
17+
18+
var (
19+
Settings = settings.Settings
20+
Log = logging.WithName("addon")
21+
)
22+
23+
//
24+
// Addon An addon adapter configured for a task execution.
25+
var Addon *Adapter
26+
27+
func init() {
28+
err := Settings.Load()
29+
if err != nil {
30+
panic(err)
31+
}
32+
33+
Addon = newAdapter()
34+
}
35+
36+
//
37+
// The Adapter provides hub/addon integration.
38+
type Adapter struct {
39+
// Task API.
40+
Task
41+
// Settings API
42+
Setting Setting
43+
// Application API.
44+
Application Application
45+
// Bucket API.
46+
Bucket Bucket
47+
// Identity API.
48+
Identity Identity
49+
// Proxy API.
50+
Proxy Proxy
51+
// TagType API.
52+
TagType TagType
53+
// Tag API.
54+
Tag Tag
55+
// client A REST client.
56+
client *Client
57+
}
58+
59+
//
60+
// Run addon.
61+
// Reports:
62+
// - Started
63+
// - Succeeded
64+
// - Failed (when addon returns error).
65+
func (h *Adapter) Run(addon func() error) {
66+
var err error
67+
//
68+
// Error handling.
69+
defer func() {
70+
r := recover()
71+
if r != nil {
72+
if pErr, cast := r.(error); cast {
73+
err = pErr
74+
} else {
75+
panic(r)
76+
}
77+
}
78+
if err != nil {
79+
Log.Error(err, "Addon failed.")
80+
h.Failed(err.Error())
81+
os.Exit(1)
82+
}
83+
}()
84+
//
85+
// Report addon started.
86+
h.Started()
87+
//
88+
// Run addon.
89+
err = addon()
90+
if err != nil {
91+
return
92+
}
93+
//
94+
// Report addon succeeded.
95+
h.Succeeded()
96+
}
97+
98+
//
99+
// Client provides the REST client.
100+
func (h *Adapter) Client() *Client {
101+
return h.client
102+
}
103+
104+
//
105+
// newAdapter builds a new Addon Adapter object.
106+
func newAdapter() (adapter *Adapter) {
107+
//
108+
// Load secret.
109+
secret := &task.Secret{}
110+
b, err := os.ReadFile(Settings.Addon.Path.Secret)
111+
if err != nil {
112+
panic(err)
113+
}
114+
err = json.Unmarshal(b, secret)
115+
if err != nil {
116+
panic(err)
117+
}
118+
//
119+
// Build REST client.
120+
client := &Client{
121+
baseURL: Settings.Addon.Hub.URL,
122+
http: &http.Client{},
123+
}
124+
//
125+
// Build Adapter.
126+
adapter = &Adapter{
127+
Task: Task{
128+
client: client,
129+
secret: secret,
130+
},
131+
Setting: Setting{
132+
client: client,
133+
},
134+
Application: Application{
135+
client: client,
136+
},
137+
Bucket: Bucket{
138+
client: client,
139+
},
140+
Identity: Identity{
141+
client: client,
142+
},
143+
Proxy: Proxy{
144+
client: client,
145+
},
146+
TagType: TagType{
147+
client: client,
148+
},
149+
Tag: Tag{
150+
client: client,
151+
},
152+
client: client,
153+
}
154+
155+
Log.Info(
156+
"Addon created.",
157+
"data",
158+
adapter.Data())
159+
160+
return
161+
}
162+
163+
//
164+
// Params mapping.
165+
type Params map[string]interface{}
166+
167+
//
168+
// inject values into path.
169+
func (p Params) inject(path string) (s string) {
170+
in := strings.Split(path, "/")
171+
for i := range in {
172+
if len(in[i]) < 1 {
173+
continue
174+
}
175+
key := in[i][1:]
176+
if v, found := p[key]; found {
177+
in[i] = fmt.Sprintf("%v", v)
178+
}
179+
}
180+
s = strings.Join(in, "/")
181+
return
182+
}

addon/application.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package addon
2+
3+
import (
4+
"github.com/konveyor/tackle2-hub/api"
5+
)
6+
7+
//
8+
// Application API.
9+
type Application struct {
10+
// hub API client.
11+
client *Client
12+
}
13+
14+
//
15+
// Get an application by ID.
16+
func (h *Application) Get(id uint) (r *api.Application, err error) {
17+
r = &api.Application{}
18+
path := Params{api.ID: id}.inject(api.ApplicationRoot)
19+
err = h.client.Get(path, r)
20+
return
21+
}
22+
23+
//
24+
// List applications.
25+
func (h *Application) List() (list []api.Application, err error) {
26+
list = []api.Application{}
27+
err = h.client.Get(api.ApplicationsRoot, &list)
28+
return
29+
}
30+
31+
//
32+
// Update an application by ID.
33+
func (h *Application) Update(r *api.Application) (err error) {
34+
path := Params{api.ID: r.ID}.inject(api.ApplicationRoot)
35+
err = h.client.Put(path, r)
36+
if err == nil {
37+
Log.Info(
38+
"Addon updated: application.",
39+
"id",
40+
r.ID)
41+
}
42+
return
43+
}

0 commit comments

Comments
 (0)