Skip to content

Commit

Permalink
Go 1.20.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel committed Jan 18, 2024
1 parent 2552233 commit 0f407ee
Show file tree
Hide file tree
Showing 132 changed files with 33 additions and 914 deletions.
14 changes: 3 additions & 11 deletions addon/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ var (
Log = logr.WithName("addon")
)

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

Expand All @@ -33,20 +32,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 +55,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 +84,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 +127,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
21 changes: 0 additions & 21 deletions addon/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"
)

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

//
// Load a task by ID.
func (h *Task) Load() {
var err error
Expand All @@ -32,7 +30,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 +41,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 +68,6 @@ func (h *Task) Started() {
return
}

//
// Succeeded report addon succeeded.
func (h *Task) Succeeded() {
h.report.Status = task.Succeeded
Expand All @@ -85,7 +77,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 +92,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 +100,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 +116,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 +139,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 +147,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 +177,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 +188,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 +199,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 +207,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 +221,6 @@ func (h *Task) Result(object interface{}) {
return
}

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

//
// pushReport create/update the task report.
func (h *Task) pushReport() {
var err error
Expand Down
5 changes: 0 additions & 5 deletions api/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@ import (
k8s "sigs.k8s.io/controller-runtime/pkg/client"
)

//
// Routes
const (
AddonsRoot = "/addons"
AddonRoot = AddonsRoot + "/:" + Name
)

//
// AddonHandler handles addon routes.
type AddonHandler struct {
BaseHandler
}

//
// AddRoutes adds routes.
func (h AddonHandler) AddRoutes(e *gin.Engine) {
routeGroup := e.Group("/")
Expand Down Expand Up @@ -94,14 +91,12 @@ func (h AddonHandler) List(ctx *gin.Context) {
h.Respond(ctx, http.StatusOK, content)
}

//
// Addon REST resource.
type Addon struct {
Name string `json:"name"`
Image string `json:"image"`
}

//
// With model.
func (r *Addon) With(m *crd.Addon) {
r.Name = m.Name
Expand Down
13 changes: 0 additions & 13 deletions api/adoptionplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"
)

//
// Effort estimates
const (
EffortS = "small"
Expand All @@ -17,19 +16,15 @@ const (
EffortXL = "extra_large"
)

//
// Routes
const (
AdoptionPlansRoot = "/reports/adoptionplan"
)

//
//
type AdoptionPlanHandler struct {
BaseHandler
}

//
// AddRoutes adds routes.
func (h AdoptionPlanHandler) AddRoutes(e *gin.Engine) {
routeGroup := e.Group("/")
Expand Down Expand Up @@ -110,7 +105,6 @@ func (h AdoptionPlanHandler) Graph(ctx *gin.Context) {
h.Respond(ctx, http.StatusOK, sorted)
}

//
// Vertex represents a vertex in the dependency graph.
type Vertex struct {
ID uint `json:"applicationId" yaml:"applicationId"`
Expand All @@ -122,7 +116,6 @@ type Vertex struct {
PositionX int `json:"positionX" yaml:"positionX"`
}

//
// NewDependencyGraph creates an empty dependency graph.
func NewDependencyGraph() (graph DependencyGraph) {
graph.vertices = make(map[uint]*Vertex)
Expand All @@ -132,7 +125,6 @@ func NewDependencyGraph() (graph DependencyGraph) {
return
}

//
// DependencyGraph is an application dependency graph.
type DependencyGraph struct {
// all applications
Expand All @@ -145,27 +137,23 @@ type DependencyGraph struct {
costs map[uint]int
}

//
// AddVertex adds a vertex to the graph.
func (r *DependencyGraph) AddVertex(v *Vertex) {
r.vertices[v.ID] = v
}

//
// HasVertex checks for the presence of a vertex in the graph.
func (r *DependencyGraph) HasVertex(v uint) (ok bool) {
_, ok = r.vertices[v]
return
}

//
// AddEdge adds an edge between two vertices.
func (r *DependencyGraph) AddEdge(v, w uint) {
r.edges[v] = append(r.edges[v], w)
r.incoming[w] = append(r.incoming[w], v)
}

//
// CalculateCost calculates the total cost to reach a given vertex.
// Costs are memoized.
func (r *DependencyGraph) CalculateCost(v uint) (cumulativeCost int) {
Expand All @@ -189,7 +177,6 @@ func (r *DependencyGraph) CalculateCost(v uint) (cumulativeCost int) {
return
}

//
// TopologicalSort sorts the graph such that the vertices
// with fewer dependencies are first, and detects cycles.
func (r *DependencyGraph) TopologicalSort() (sorted []*Vertex, ok bool) {
Expand Down
Loading

0 comments on commit 0f407ee

Please sign in to comment.