Skip to content

Commit

Permalink
multi-addon tasks.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel committed Feb 22, 2024
1 parent 03c2d0e commit 1674814
Show file tree
Hide file tree
Showing 20 changed files with 1,217 additions and 309 deletions.
7 changes: 4 additions & 3 deletions api/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/gin-gonic/gin"
crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1"
core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
k8s "sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -94,12 +95,12 @@ func (h AddonHandler) List(ctx *gin.Context) {

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

// With model.
func (r *Addon) With(m *crd.Addon) {
r.Name = m.Name
r.Image = m.Spec.Image
r.Container = m.Spec.Container
}
1 change: 0 additions & 1 deletion api/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func All() []Handler {
&ImportHandler{},
&JobFunctionHandler{},
&IdentityHandler{},
&ProviderHandler{},
&ProxyHandler{},
&ReviewHandler{},
&RuleSetHandler{},
Expand Down
106 changes: 0 additions & 106 deletions api/provider.go

This file was deleted.

59 changes: 7 additions & 52 deletions api/task.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package api

import (
"context"
"encoding/json"
"io/ioutil"
"net/http"
Expand All @@ -11,16 +10,12 @@ import (
"time"

"github.com/gin-gonic/gin"
liberr "github.com/jortel/go-utils/error"
crd "github.com/konveyor/tackle2-hub/k8s/api/tackle/v1alpha1"
"github.com/konveyor/tackle2-hub/model"
tasking "github.com/konveyor/tackle2-hub/task"
"gorm.io/gorm"
"gorm.io/gorm/clause"
core "k8s.io/api/core/v1"
k8serr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/utils/strings/slices"
k8s "sigs.k8s.io/controller-runtime/pkg/client"
)

// Routes
Expand Down Expand Up @@ -522,12 +517,12 @@ type TaskError struct {
// Task REST resource.
type Task struct {
Resource `yaml:",inline"`
Kind string `json:"kind"`
Name string `json:"name"`
Locator string `json:"locator,omitempty" yaml:",omitempty"`
Priority int `json:"priority,omitempty" yaml:",omitempty"`
Policy string `json:"policy,omitempty" yaml:",omitempty"`
TTL *TTL `json:"ttl,omitempty" yaml:",omitempty"`
Addon string `json:"addon,omitempty" binding:"required" yaml:",omitempty"`
Data interface{} `json:"data" swaggertype:"object" binding:"required"`
Application *Ref `json:"application,omitempty" yaml:",omitempty"`
State string `json:"state"`
Expand All @@ -547,9 +542,8 @@ type Task struct {
// With updates the resource with the model.
func (r *Task) With(m *model.Task) {
r.Resource.With(&m.Model)
r.Kind = m.Kind
r.Name = m.Name
r.Image = m.Image
r.Addon = m.Addon
r.Locator = m.Locator
r.Priority = m.Priority
r.Policy = m.Policy
Expand All @@ -568,12 +562,15 @@ func (r *Task) With(m *model.Task) {
if m.Errors != nil {
_ = json.Unmarshal(m.Errors, &r.Errors)
}
if m.Attached != nil {
_ = json.Unmarshal(m.Attached, &r.Attached)
}
if m.Report != nil {
report := &TaskReport{}
report.With(m.Report)
r.Activity = report.Activity
r.Errors = append(report.Errors, r.Errors...)
r.Attached = report.Attached
r.Attached = append(report.Attached, r.Attached...)
switch r.State {
case tasking.Succeeded:
switch report.Status {
Expand All @@ -587,8 +584,8 @@ func (r *Task) With(m *model.Task) {
// Model builds a model.
func (r *Task) Model() (m *model.Task) {
m = &model.Task{
Kind: r.Kind,
Name: r.Name,
Addon: r.Addon,
Locator: r.Locator,
Priority: r.Priority,
Policy: r.Policy,
Expand Down Expand Up @@ -712,45 +709,3 @@ type Attachment struct {
// activity entry. Zero(0) indicates not associated.
Activity int `json:"activity,omitempty" yaml:",omitempty"`
}

// data:
//
// providers:
// - java
// - xml
func init() {
variant := func(
client k8s.Client,
task *model.Task,
pod *core.PodSpec) (err error) {
type Data struct {
Providers []string `json:"providers"`
}
d := &Data{}
err = json.Unmarshal(task.Data, d)
if err != nil {
err = liberr.Wrap(err)
return
}
for _, name := range d.Providers {
p := &crd.Provider{}
err = client.Get(
context.TODO(),
k8s.ObjectKey{
Namespace: Settings.Hub.Namespace,
Name: name,
},
p)
if err != nil {
err = liberr.Wrap(err)
return
}
pod.Containers = append(
pod.Containers,
p.Spec.Container)
}

return
}
tasking.Variants["analyzer"] = variant
}
6 changes: 3 additions & 3 deletions api/taskgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ func (h TaskGroupHandler) BucketDelete(ctx *gin.Context) {
// TaskGroup REST resource.
type TaskGroup struct {
Resource `yaml:",inline"`
Kind string `json:"kind"`
Name string `json:"name"`
Addon string `json:"addon"`
Data interface{} `json:"data" swaggertype:"object" binding:"required"`
Bucket *Ref `json:"bucket,omitempty"`
State string `json:"state"`
Expand All @@ -366,8 +366,8 @@ type TaskGroup struct {
// With updates the resource with the model.
func (r *TaskGroup) With(m *model.TaskGroup) {
r.Resource.With(&m.Model)
r.Kind = m.Kind
r.Name = m.Name
r.Addon = m.Addon
r.State = m.State
r.Bucket = r.refPtr(m.BucketID, m.Bucket)
r.Tasks = []Task{}
Expand All @@ -390,7 +390,7 @@ func (r *TaskGroup) With(m *model.TaskGroup) {
func (r *TaskGroup) Model() (m *model.TaskGroup) {
m = &model.TaskGroup{
Name: r.Name,
Addon: r.Addon,
Kind: r.Kind,
State: r.State,
}
m.ID = r.ID
Expand Down
15 changes: 8 additions & 7 deletions k8s/api/tackle/v1alpha1/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ package v1alpha1
import (
core "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

// AddonSpec defines the desired state of Addon
type AddonSpec struct {
// Addon fqin.
Image string `json:"image"`
// ImagePullPolicy an optional image pull policy.
// +kubebuilder:default=IfNotPresent
// +kubebuilder:validation:Enum=IfNotPresent;Always;Never
ImagePullPolicy core.PullPolicy `json:"imagePullPolicy,omitempty"`
// Addon kind.
// +kubebuilder:default=command
// +kubebuilder:validation:Enum=init;daemon;command
Kind string `json:"kind,omitempty"`
// Addon container.
Container core.Container `json:"container,omitempty"`
// Resource requirements.
Resources core.ResourceRequirements `json:"resources,omitempty"`
Configuration map[string]runtime.RawExtension `json:"configuration,omitempty"`
}

// AddonStatus defines the observed state of Addon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,26 @@ limitations under the License.
package v1alpha1

import (
core "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ProviderSpec defines the desired state of Provider
type ProviderSpec struct {
// Container fqin.
Container core.Container `json:"container"`
type Tag struct {
Category string `json:"category"`
Label string `json:"label"`
}

// ProviderStatus defines the observed state of Provider
type ProviderStatus struct {
type Match struct {
Tag []Tag `json:"tag,omitempty"`
}

// TaskSpec defines the desired state of Task
type TaskSpec struct {
// Task kind.
Match Match `json:"match,omitempty"`
}

// TaskStatus defines the observed state of Task
type TaskStatus struct {
// The most recent generation observed by the controller.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Expand All @@ -40,20 +48,20 @@ type ProviderStatus struct {
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="READY",type=string,JSONPath=".status.conditions[?(@.type=='Ready')].status"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
type Provider struct {
type Task struct {
meta.TypeMeta `json:",inline"`
meta.ObjectMeta `json:"metadata,omitempty"`
Spec ProviderSpec `json:"spec,omitempty"`
Status ProviderStatus `json:"status,omitempty"`
Spec TaskSpec `json:"spec,omitempty"`
Status TaskStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ProviderList struct {
type TaskList struct {
meta.TypeMeta `json:",inline"`
meta.ListMeta `json:"metadata,omitempty"`
Items []Provider `json:"items"`
Items []Task `json:"items"`
}

func init() {
SchemeBuilder.Register(&Provider{}, &ProviderList{})
SchemeBuilder.Register(&Task{}, &TaskList{})
}
Loading

0 comments on commit 1674814

Please sign in to comment.