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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package market
import (
"context"
"errors"
"time"
exposurev1alpha1 "github.com/johnandersen777/socialweb-computer-kcp/api/exposure/v1alpha1"
"github.com/johnandersen777/socialweb-computer-kcp/api/v1alpha1"
)
const CapabilityIntents = "market.intents"
const (
KindBid = "Bid"
KindComputeVM = "ComputeVM"
KindGuestIdentityGrant = "GuestIdentityGrant"
KindStateSync = "StateSync"
KindComputeContract = "ComputeContract"
KindExposure = "Exposure"
KindMarketIdentity = "MarketIdentity"
)
var (
ErrExists = errors.New("market: the object already exists")
ErrNotFound = errors.New("market: the object does not exist")
)
type Change struct {
Workspace string
Kind string
Name string
Gone bool
Bid *v1alpha1.Bid
ComputeVM *v1alpha1.ComputeVM
StateSync *v1alpha1.StateSync
ComputeContract *v1alpha1.ComputeContract
Exposure *exposurev1alpha1.Exposure
MarketIdentity *v1alpha1.MarketIdentity
}
type Observer interface {
Observe(ctx context.Context, change Change) (time.Duration, error)
}
type Subscription struct {
Kinds []string
Workspaces []string
Observer Observer
Synced func()
}
type Inputs interface {
Subscribe(ctx context.Context, sub Subscription) (func(), error)
}
type BidIntents interface {
CreateBid(ctx context.Context, bid v1alpha1.Bid) error
ApplyBidSpec(ctx context.Context, name string, spec v1alpha1.BidSpec) error
ApplyBidStatus(ctx context.Context, name string, status v1alpha1.BidStatus) error
}
type GuestIntents interface {
CreateComputeVM(ctx context.Context, vm v1alpha1.ComputeVM) error
DeleteComputeVM(ctx context.Context, name string) error
ApplyComputeVMContract(ctx context.Context, name string, contract v1alpha1.ComputeVMContract) error
ApplyComputeVMRelease(ctx context.Context, name string, release v1alpha1.ComputeVMRelease) error
ApplyComputeVMPublished(ctx context.Context, name string, published v1alpha1.ComputeVMPublished) error
CreateGuestIdentityGrant(ctx context.Context, grant v1alpha1.GuestIdentityGrant) error
}
type StateSyncIntents interface {
CreateStateSync(ctx context.Context, sync v1alpha1.StateSync) error
DeleteStateSync(ctx context.Context, name string) error
ApplyStateSyncStatus(ctx context.Context, name string, status v1alpha1.StateSyncStatus) error
SetStateSyncFinalizer(ctx context.Context, name, finalizer string, present bool) error
}
type ContractIntents interface {
CreateComputeContract(ctx context.Context, contract v1alpha1.ComputeContract) error
ReleaseComputeContract(ctx context.Context, name string) error
DeleteComputeContract(ctx context.Context, name string) error
MergeComputeContractStatus(ctx context.Context, name string, status v1alpha1.ComputeContractStatus) error
SetComputeContractPendingEvents(ctx context.Context, name string, events []v1alpha1.ComputeContractEvent) error
}
type Intents interface {
Inputs
BidIntents
GuestIntents
StateSyncIntents
ContractIntents
}