-
Notifications
You must be signed in to change notification settings - Fork 2
/
injection.go
68 lines (55 loc) · 2.4 KB
/
injection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package crontrigger
import (
"context"
"github.com/tsundata/flowline/pkg/api/client"
"github.com/tsundata/flowline/pkg/api/meta"
)
// jobControlInterface is an interface that knows how to add or delete jobs
// created as an interface to allow testing.
type jobControlInterface interface {
// GetJob retrieves a Job.
GetJob(name string) (*meta.Job, error)
// CreateJob creates new Jobs according to the spec.
CreateJob(job *meta.Job) (*meta.Job, error)
// UpdateJob updates a Job.
UpdateJob(job *meta.Job) (*meta.Job, error)
// PatchJob patches a Job.
PatchJob(name string, pt string, data []byte, subresources ...string) (*meta.Job, error)
// DeleteJob deletes the Job identified by name.
DeleteJob(name string) error
}
type realJobControl struct {
Client client.Interface
}
var _ jobControlInterface = &realJobControl{}
func (r *realJobControl) GetJob(name string) (*meta.Job, error) {
return r.Client.CoreV1().Job().Get(context.Background(), name, meta.GetOptions{})
}
func (r *realJobControl) CreateJob(job *meta.Job) (*meta.Job, error) {
return r.Client.CoreV1().Job().Create(context.Background(), job, meta.CreateOptions{})
}
func (r *realJobControl) UpdateJob(job *meta.Job) (*meta.Job, error) {
return r.Client.CoreV1().Job().Update(context.Background(), job, meta.UpdateOptions{})
}
func (r *realJobControl) PatchJob(name string, pt string, data []byte, subresources ...string) (*meta.Job, error) {
return r.Client.CoreV1().Job().Patch(context.Background(), name, pt, data, meta.PatchOptions{}, subresources...)
}
func (r *realJobControl) DeleteJob(name string) error {
return r.Client.CoreV1().Job().Delete(context.Background(), name, meta.DeleteOptions{})
}
// cjControlInterface is an interface that knows how to update CronJob status
// created as an interface to allow testing.
type cjControlInterface interface {
UpdateStatus(ctx context.Context, cj *meta.Workflow) (*meta.Workflow, error)
// GetWorkflow retrieves a CronJob.
GetWorkflow(ctx context.Context, name string) (*meta.Workflow, error)
}
type realCJControl struct {
Client client.Interface
}
func (r *realCJControl) UpdateStatus(ctx context.Context, cj *meta.Workflow) (*meta.Workflow, error) {
return r.Client.CoreV1().Workflow().UpdateStatus(ctx, cj, meta.UpdateOptions{})
}
func (r *realCJControl) GetWorkflow(ctx context.Context, name string) (*meta.Workflow, error) {
return r.Client.CoreV1().Workflow().Get(ctx, name, meta.GetOptions{})
}