/
jobs.go
141 lines (126 loc) · 4.56 KB
/
jobs.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
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
131
132
133
134
135
136
137
138
139
140
141
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
package worker
import "k8s.io/apimachinery/pkg/types"
// Operations are the supported operations for on demand resource handler
type Operations string
const (
OperationProcessDeleteQueue Operations = "ProcessDeleteQueue"
// OperationReconcileNode represents a reconcile operation that reclaims dangling network interfaces using local cache
OperationReconcileNode Operations = "ReconcileNode"
// OperationCreate represents pods that are in created state
OperationCreate Operations = "Create"
// OperationDelete represents pods that have been deleted
OperationDeleted Operations = "Deleted"
// OperationDeleting represents pods that are being deleted
OperationDeleting Operations = "Deleting"
// OperationReconcileNotRequired represents job that don't need execution
OperationReconcileNotRequired Operations = "NoReconcile"
// OperationReSyncPool represents a job to re-sync a dirty pool
OperationReSyncPool Operations = "ReSyncPool"
// OperationDeleteNode represents the job to delete the node
OperationDeleteNode Operations = "NodeDelete"
)
// OnDemandJob represents the job that will be executed by the respective worker
type OnDemandJob struct {
// Operation is the type of operation to perform on the given pod
Operation Operations
// UID is the unique ID of the pod
UID string
// PodName is the name of the pod
PodName string
// PodNamespace is the pod's namespace
PodNamespace string
// RequestCount is the number of resources to create for operations of type Create. Optional for other operations
RequestCount int
// NodeName is the k8s node name
NodeName string
}
// NewOnDemandDeleteJob returns an on demand job for operation Create or Update
func NewOnDemandCreateJob(podNamespace string, podName string, requestCount int) OnDemandJob {
return OnDemandJob{
Operation: OperationCreate,
PodNamespace: podNamespace,
PodName: podName,
RequestCount: requestCount,
}
}
// NewOnDemandDeleteJob returns an on demand job for operation Deleted
func NewOnDemandDeletedJob(nodeName string, uid types.UID) OnDemandJob {
return OnDemandJob{
Operation: OperationDeleted,
NodeName: nodeName,
UID: string(uid),
}
}
// NewOnDemandReconcileJob returns a reconcile job
func NewOnDemandReconcileNodeJob(nodeName string) OnDemandJob {
return OnDemandJob{
Operation: OperationReconcileNode,
NodeName: nodeName,
}
}
// NewOnDemandProcessDeleteQueueJob returns a process delete queue job
func NewOnDemandProcessDeleteQueueJob(nodeName string) OnDemandJob {
return OnDemandJob{
Operation: OperationProcessDeleteQueue,
NodeName: nodeName,
}
}
// NewOnDemandDeleteNodeJob returns a delete node job
func NewOnDemandDeleteNodeJob(nodeName string) OnDemandJob {
return OnDemandJob{
Operation: OperationDeleteNode,
NodeName: nodeName,
}
}
// WarmPoolJob represents the job for a resource handler for warm pool resources
type WarmPoolJob struct {
// Operation is the type of operation on warm pool
Operations Operations
// Resources can hold the resource to delete or the created resources
Resources []string
// ResourceCount is the number of resource to be created
ResourceCount int
// NodeName is the name of the node
NodeName string
}
// NewWarmPoolCreateJob returns a job on warm pool of resource
func NewWarmPoolCreateJob(nodeName string, count int) *WarmPoolJob {
return &WarmPoolJob{
Operations: OperationCreate,
NodeName: nodeName,
ResourceCount: count,
}
}
// NewWarmPoolReSyncJob returns a job to re-sync the warm pool with upstream
func NewWarmPoolReSyncJob(nodeName string) *WarmPoolJob {
return &WarmPoolJob{
Operations: OperationReSyncPool,
NodeName: nodeName,
}
}
func NewWarmPoolDeleteJob(nodeName string, resourcesToDelete []string) *WarmPoolJob {
return &WarmPoolJob{
Operations: OperationDeleted,
NodeName: nodeName,
Resources: resourcesToDelete,
ResourceCount: len(resourcesToDelete),
}
}
func NewWarmProcessDeleteQueueJob(nodeName string) *WarmPoolJob {
return &WarmPoolJob{
Operations: OperationProcessDeleteQueue,
NodeName: nodeName,
}
}