Skip to content

Commit d262e36

Browse files
wip
Signed-off-by: Anisur Rahman <anisur@appscode.com>
1 parent 2f23ce2 commit d262e36

5,527 files changed

Lines changed: 357 additions & 1783498 deletions

File tree

Some content is hidden

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

api/batch/v1alpha1/pendingtask_types.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,9 @@ package v1alpha1
1818

1919
import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/runtime"
2122
)
2223

23-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25-
26-
// PendingTaskSpec defines the desired state of PendingTask.
27-
type PendingTaskSpec struct {
28-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29-
// Important: Run "make" to regenerate code after modifying this file
30-
31-
// Foo is an example field of PendingTask. Edit pendingtask_types.go to remove/update
32-
Foo string `json:"foo,omitempty"`
33-
}
34-
35-
// PendingTaskStatus defines the observed state of PendingTask.
36-
type PendingTaskStatus struct {
37-
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
38-
// Important: Run "make" to regenerate code after modifying this file
39-
}
40-
4124
// +kubebuilder:object:root=true
4225
// +kubebuilder:subresource:status
4326
// +kubebuilder:resource:scope=Cluster
@@ -51,6 +34,22 @@ type PendingTask struct {
5134
Status PendingTaskStatus `json:"status,omitempty"`
5235
}
5336

37+
// PendingTaskSpec defines the desired state of PendingTask.
38+
type PendingTaskSpec struct {
39+
// Task identifies the resource type that the taskQueue is responsible for triggering.
40+
Task UnitTask `json:"task,omitempty"`
41+
42+
// Resource contains the raw YAML/JSON representation of the Kubernetes resource
43+
// to be triggered by the task queue.
44+
Resource runtime.RawExtension `json:"resource,omitempty"`
45+
}
46+
47+
// PendingTaskStatus defines the observed state of PendingTask.
48+
type PendingTaskStatus struct {
49+
// TaskQueueName is the name of the taskQueue that is responsible for triggering this task.
50+
TaskQueueName string `json:"taskQueueName,omitempty"`
51+
}
52+
5453
// +kubebuilder:object:root=true
5554

5655
// PendingTaskList contains a list of PendingTask.

api/batch/v1alpha1/taskqueue_types.go

Lines changed: 77 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,10 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
v1 "k8s.io/api/core/v1"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
)
2223

23-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25-
26-
// TaskQueueSpec defines the desired state of TaskQueue.
27-
type TaskQueueSpec struct {
28-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29-
// Important: Run "make" to regenerate code after modifying this file
30-
31-
// Foo is an example field of TaskQueue. Edit taskqueue_types.go to remove/update
32-
Foo string `json:"foo,omitempty"`
33-
}
34-
35-
// TaskQueueStatus defines the observed state of TaskQueue.
36-
type TaskQueueStatus struct {
37-
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
38-
// Important: Run "make" to regenerate code after modifying this file
39-
}
40-
4124
// +kubebuilder:object:root=true
4225
// +kubebuilder:subresource:status
4326
// +kubebuilder:resource:scope=Cluster
@@ -51,8 +34,83 @@ type TaskQueue struct {
5134
Status TaskQueueStatus `json:"status,omitempty"`
5235
}
5336

54-
// +kubebuilder:object:root=true
37+
// TaskQueueSpec defines the desired state of TaskQueue.
38+
type TaskQueueSpec struct {
39+
// NumberOfConcurrentTasks specifies how many tasks can run concurrently.
40+
// Defaults to 20 if not set.
41+
// +kubebuilder:default=20
42+
// +optional
43+
NumberOfConcurrentTasks int `json:"numberOfConcurrentTasks,omitempty"`
44+
45+
// Tasks represents the lists of tasks that this queue is responsible for processing.
46+
Tasks []UnitTask `json:"tasks,omitempty"`
47+
48+
// Rules defines ObjectPhaseRules. It contains three identification rules of successful phase of the object,
49+
// progressing phase of the object & failed phase of the object.
50+
// Example:
51+
// rules:
52+
// success: `has(self.status.phase) && self.status.phase == 'Successful'`
53+
// inProgress: `has(self.status.phase) && self.status.phase == 'Progressing'`
54+
// failed: `has(self.status.phase) && self.status.phase == 'Failed'`
55+
Rules ObjectPhaseRules `json:"rules"`
5556

57+
// LastTriggeredTasksHistory specifies how many history of triggeredTask will display in the status section.
58+
// Defaults to 20 if not set.
59+
// +kubebuilder:default=20
60+
// +optional
61+
LastTriggeredTasksHistory int `json:"lastTriggeredTasksHistory,omitempty"`
62+
}
63+
64+
// ObjectPhaseRules defines three identification rules of successful phase of the object,
65+
// progressing phase of the object & failed execution of the object.
66+
// To specifies any field of the Operation object, the rule must start with the word `self`.
67+
// Example:
68+
//
69+
// .status.phase -> self.status.phase
70+
// .status.observedGeneration -> self.status.observedGeneration
71+
//
72+
// The rules can be any valid expression supported by CEL(Common Expression Language).
73+
// Ref: https://github.com/google/cel-spec
74+
type ObjectPhaseRules struct {
75+
// Success defines a rule to identify the successful execution of the operation.
76+
// Example:
77+
// success: `has(self.status.phase) && self.status.phase == 'Successful'`
78+
// Here self.status.phase is pointing to .status.phase field of the Operation object.
79+
// When .status.phase field presents and becomes `Successful`, the Success rule will satisfy.
80+
Success string `json:"success"`
81+
82+
// InProgress defines a rule to identify that applied operation is progressing.
83+
// Example:
84+
// inProgress: `has(self.status.phase) && self.status.phase == 'Progressing'`
85+
// Here self.status.phase is pointing to .status.phase field of the Operation object.
86+
// When .status.phase field presents and becomes `Progressing`, the InProgress rule will satisfy.
87+
InProgress string `json:"inProgress"`
88+
89+
// Failed defines a rule to identify that applied operation is failed.
90+
// Example:
91+
// inProgress: `has(self.status.phase) && self.status.phase == 'Failed'`
92+
// Here self.status.phase is pointing to .status.phase field of the Operation object.
93+
// When .status.phase field presents and becomes `Failed`, the Failed rule will satisfy.
94+
Failed string `json:"failed"`
95+
}
96+
97+
// TaskQueueStatus defines the observed state of TaskQueue.
98+
type TaskQueueStatus struct {
99+
// LastExecutionTime indicates when the last task was executed.
100+
// +optional
101+
LastExecutionTime *metav1.Time `json:"lastExecutionTime,omitempty"`
102+
103+
// LastTriggeredTasks contains references to the most recently triggered tasks.
104+
// +optional
105+
LastTriggeredTasks []v1.TypedObjectReference `json:"lastTriggeredTasks,omitempty"`
106+
}
107+
108+
type UnitTask struct {
109+
Kind string `json:"kind,omitempty"`
110+
APIGroup string `json:"apiGroup,omitempty"`
111+
}
112+
113+
// +kubebuilder:object:root=true
56114
// TaskQueueList contains a list of TaskQueue.
57115
type TaskQueueList struct {
58116
metav1.TypeMeta `json:",inline"`

api/ops/v1alpha1/groupversion_info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616

1717
// Package v1alpha1 contains API Schema definitions for the ops.batch v1alpha1 API group.
1818
// +kubebuilder:object:generate=true
19-
// +groupName=ops.batch.k8s.appscode.com
19+
// +groupName=ops.k8s.appscode.com
2020
package v1alpha1
2121

2222
import (
@@ -26,7 +26,7 @@ import (
2626

2727
var (
2828
// GroupVersion is group version used to register these objects.
29-
GroupVersion = schema.GroupVersion{Group: "ops.batch.k8s.appscode.com", Version: "v1alpha1"}
29+
GroupVersion = schema.GroupVersion{Group: "ops.k8s.appscode.com", Version: "v1alpha1"}
3030

3131
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
3232
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDQDCCAiigAwIBAgIIX2NvDbk07VEwDQYJKoZIhvcNAQELBQAwIjEgMB4GA1UE
3+
AwwXbG9jYWxob3N0LWNhQDE3NDY3MDgxOTYwHhcNMjUwNTA4MTE0MzE2WhcNMjYw
4+
NTA4MTE0MzE2WjAfMR0wGwYDVQQDDBRsb2NhbGhvc3RAMTc0N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
y7pezfKYjcUwDO3X
39+
-----END CERTIFICATE-----
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIIEowIBAAKCAQEAz/NW494L56v3ZzhIYn+zD6HuIsBuKoG4urtrAK+zxHFOLaQ8
3+
HdsvV0WIt7L7QVqAF7uSp2imwdoJkr0/t2xp5MfXXGgdk9phldXTjoqz93oLFuew
4+
5Yk/r08O+Uq64Upnwn2kNx6s7xhSNu4tjh780BgQCBDsqSmI2U4VYeET8L89Ui0h
5+
cyA4FG9CMzLnhCuNCcmnhYmGzdou/lD2WyW1QSoYA1bRReQB0oZg/eLScqtfCG89
6+
dNZDyfd9qI495PwiF8KWJnqSW0eoMNNuLPbbIbx6plrf831SyY+cXGd9fV4zJ6qb
7+
1WXvV8MeiskoS8LfrFjgC69BKlU9itY3p/SjJQIDAQABAoIBAAPa8A5zbGcUIhcQ
8+
zQ6+bVRp3R9Zz/ELzJ/xn484sq1+qENiWxb2nE8S4/D76XqRsfQ+rv5Zi1Xms+y7
9+
g3XkFaZ/Kff1mi7Giq6bczueSK3a3l/DVd07iSm33oAyqXpJxdiuOaAn+m7IVaXd
10+
Do0m9+rnt0xe+/Q65+WXdAAHizYYXPRWrrjs/VcXhem/LOccyYDeuF4zASUnmkxl
11+
Ysgk4foS4BiFR+Fj15SSSC1vrbgtFiDX2Dmzz7fNHh2MCZP1oQ9tKYZkG36egofF
12+
CeUr+j+PxW8xwefTnWxUDkUToZaTXjL5xiJPc7FHjTke5rMC7Z6BtzvZiFf79rJo
13+
JJqjy/UCgYEA0oEHEwELZqN8WBgxGXsoI1o+2YpOCuNBJD4tceEtxIejCejs1+O3
14+
ILR82AdvggHc2xh3sEv83vE9gbOFuZ4Oud/+HKsheVTStg2LUOuBF2Zo41M0eVf9
15+
MgcnoUllzwrHYx7WfJvlF8SD6rcLmuh6neL8igMJqrp8jS0S1gsrcO8CgYEA/OUH
16+
6d3POzH6f6U1FCM0ljcvhYSHr0smv1ICZnIIWXObPxzc7n8ZgFGwCmRBWHpUPte+
17+
BBbulgVt8HB4lSI41Vk4ynwOvrFVTzVIL1TfBp7gwrx1mlEDjUgZeXdSB1G6rdQo
18+
zNLE5b+nLqDvhqnx8q698dUTHFU7yPCnkRDMBSsCgYBTW4TRobhCDLtQp0PKM1rR
19+
pQr+WiZNaXCCSZz1W5YkHRIS+onPc/0wlkhZw5gEg3hRyn6a8XxRTHZuxghOWKi8
20+
MlcOQzYeNdi6/uIMSTX1bjhazLga1R0Okoa+97G5KyuJtMx6y8EMiGU0rQeLcEQe
21+
AaS/gjRxxydLQG4VFJc/QQKBgQDKrhQFjsuDOa71lkZP+Vcv/NKNQ4YrKyPGucdK
22+
q6Gdb1XA4zT9v8eEW/OmoGruqjvSkb2sMWTNv1Q5GyrI+0BpXLRzM7HtitpAPQe5
23+
R1/nQnYIHFp0bvFVza789nA7hXkDz8FTRqifKVanvDu7xYAva3S32HkUgAsGJDln
24+
vfqFOQKBgDvfkUiU/gHxmINbhAZWfEKKn5apewqItjbO9NaKYNwoCzo26yrMFwjk
25+
i2IKbvCkooWkuJi/+jHtGha6v4sSNnJSGy342qofGqtDpK4RtZQd+uRj7Pjgzjnl
26+
v2+MxWCtwv7+wbnZ4cqc1o2X+H6x2KVpcyNZtaaHi5qgoQ45V73e
27+
-----END RSA PRIVATE KEY-----

cmd/main.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,23 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"context"
2021
"crypto/tls"
2122
"flag"
23+
"fmt"
2224
"os"
2325
"path/filepath"
24-
2526
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
2627
// to ensure that exec-entrypoint and run can make use of them.
2728
_ "k8s.io/client-go/plugin/pkg/client/auth"
2829

2930
"k8s.io/apimachinery/pkg/runtime"
3031
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3132
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
33+
"k8s.io/client-go/util/workqueue"
3234
ctrl "sigs.k8s.io/controller-runtime"
3335
"sigs.k8s.io/controller-runtime/pkg/certwatcher"
36+
runtime_client "sigs.k8s.io/controller-runtime/pkg/client"
3437
"sigs.k8s.io/controller-runtime/pkg/healthz"
3538
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3639
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
@@ -46,6 +49,7 @@ import (
4649
var (
4750
scheme = runtime.NewScheme()
4851
setupLog = ctrl.Log.WithName("setup")
52+
queue workqueue.Typed[string]
4953
)
5054

5155
func init() {
@@ -204,9 +208,23 @@ func main() {
204208
os.Exit(1)
205209
}
206210

211+
queue, err = func() (workqueue.Typed[string], error) {
212+
wq := workqueue.NewTyped[string]()
213+
pendingTaskList := batchv1alpha1.PendingTaskList{}
214+
if err := mgr.GetClient().List(context.Background(), &pendingTaskList, &runtime_client.ListOptions{}); err != nil {
215+
setupLog.Error(err, "failed to list pendingtasklist")
216+
os.Exit(1)
217+
}
218+
for _, pt := range pendingTaskList.Items {
219+
wq.Add(pt.Name)
220+
}
221+
return *wq, nil
222+
}()
223+
207224
if err = (&batchcontroller.TaskQueueReconciler{
208225
Client: mgr.GetClient(),
209226
Scheme: mgr.GetScheme(),
227+
Queue: &queue,
210228
}).SetupWithManager(mgr); err != nil {
211229
setupLog.Error(err, "unable to create controller", "controller", "TaskQueue")
212230
os.Exit(1)

config/crd/bases/batch.k8s.appscode.com_pendingtasks.yaml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,29 @@ spec:
3939
spec:
4040
description: PendingTaskSpec defines the desired state of PendingTask.
4141
properties:
42-
foo:
43-
description: Foo is an example field of PendingTask. Edit pendingtask_types.go
44-
to remove/update
45-
type: string
42+
resource:
43+
description: |-
44+
Resource contains the raw YAML/JSON representation of the Kubernetes resource
45+
to be triggered by the task queue.
46+
type: object
47+
x-kubernetes-preserve-unknown-fields: true
48+
task:
49+
description: Task identifies the resource type that the taskQueue
50+
is responsible for triggering.
51+
properties:
52+
apiGroup:
53+
type: string
54+
kind:
55+
type: string
56+
type: object
4657
type: object
4758
status:
4859
description: PendingTaskStatus defines the observed state of PendingTask.
60+
properties:
61+
taskQueueName:
62+
description: TaskQueueName is the name of the taskQueue that is responsible
63+
for triggering this task.
64+
type: string
4965
type: object
5066
type: object
5167
served: true

0 commit comments

Comments
 (0)