@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- package job
17
+ package recipe
18
18
19
19
import (
20
20
"k8s.io/utils/pointer"
@@ -23,53 +23,53 @@ import (
23
23
24
24
commonctrl "mayadata.io/d-operators/common/controller"
25
25
"mayadata.io/d-operators/common/unstruct"
26
- "mayadata.io/d-operators/pkg/job "
27
- types "mayadata.io/d-operators/types/job "
26
+ "mayadata.io/d-operators/pkg/recipe "
27
+ types "mayadata.io/d-operators/types/recipe "
28
28
)
29
29
30
- // Reconciler manages reconciliation of Job custom resource
30
+ // Reconciler manages reconciliation of Recipe custom resource
31
31
type Reconciler struct {
32
32
commonctrl.Reconciler
33
33
34
- ObservedJob * types.Job
35
- JobStatus * types.JobStatus
34
+ ObservedRecipe * types.Recipe
35
+ RecipeStatus * types.RecipeStatus
36
36
}
37
37
38
38
func (r * Reconciler ) eval () {
39
- var j types.Job
39
+ var j types.Recipe
40
40
// convert from unstructured instance to typed instance
41
41
err := unstruct .ToTyped (r .HookRequest .Watch , & j )
42
42
if err != nil {
43
43
r .Err = err
44
44
return
45
45
}
46
- r .ObservedJob = & j
46
+ r .ObservedRecipe = & j
47
47
}
48
48
49
49
func (r * Reconciler ) invoke () {
50
- runner := job .NewRunner (
51
- job .RunnerConfig {
52
- Job : * r .ObservedJob ,
50
+ runner := recipe .NewRunner (
51
+ recipe .RunnerConfig {
52
+ Recipe : * r .ObservedRecipe ,
53
53
},
54
54
)
55
- r .JobStatus , r .Err = runner .Run ()
55
+ r .RecipeStatus , r .Err = runner .Run ()
56
56
}
57
57
58
58
func (r * Reconciler ) setSyncResponse () {
59
59
// we skip the reconcile always since there are no attachments
60
60
// to reconcile
61
61
r .HookResponse .SkipReconcile = true
62
62
r .SkipReason = "No attachments to reconcile"
63
- // update the skip reason for locked jobs
64
- if r .JobStatus .Phase == types .JobStatusLocked {
65
- r .SkipReason = r .JobStatus .Reason
63
+ // update the skip reason for locked recipes
64
+ if r .RecipeStatus .Phase == types .RecipeStatusLocked {
65
+ r .SkipReason = r .RecipeStatus .Reason
66
66
}
67
- // set resync period for jobs with errors
67
+ // set resync period for recipes with errors
68
68
if r .Err != nil {
69
69
// resync since this might be a temporary error
70
70
//
71
71
// TODO:
72
- // Might be better to expose this from job .spec
72
+ // Might be better to expose this from recipe .spec
73
73
r .HookResponse .ResyncAfterSeconds = 5.0
74
74
}
75
75
}
@@ -80,60 +80,60 @@ func (r *Reconciler) setWatchStatusAsError() {
80
80
"reason" : r .Err .Error (),
81
81
}
82
82
r .HookResponse .Labels = map [string ]* string {
83
- "job .dope.metacontroller.io/phase" : k8s .StringPtr ("Error" ),
83
+ "recipe .dope.metacontroller.io/phase" : k8s .StringPtr ("Error" ),
84
84
}
85
85
}
86
86
87
- func (r * Reconciler ) setWatchStatusFromJobStatus () {
87
+ func (r * Reconciler ) setWatchStatusFromRecipeStatus () {
88
88
r .HookResponse .Status = map [string ]interface {}{
89
- "phase" : string (r .JobStatus .Phase ),
90
- "reason" : r .JobStatus .Reason ,
91
- "message" : r .JobStatus .Message ,
92
- "failedTaskCount" : int64 (r .JobStatus .FailedTaskCount ),
93
- "taskCount" : int64 (r .JobStatus .TaskCount ),
94
- "taskListStatus" : r .JobStatus .TaskListStatus ,
89
+ "phase" : string (r .RecipeStatus .Phase ),
90
+ "reason" : r .RecipeStatus .Reason ,
91
+ "message" : r .RecipeStatus .Message ,
92
+ "failedTaskCount" : int64 (r .RecipeStatus .FailedTaskCount ),
93
+ "taskCount" : int64 (r .RecipeStatus .TaskCount ),
94
+ "taskListStatus" : r .RecipeStatus .TaskListStatus ,
95
95
}
96
96
r .HookResponse .Labels = map [string ]* string {
97
- "job .dope.metacontroller.io/phase" : pointer .StringPtr (string (r .JobStatus .Phase )),
97
+ "recipe .dope.metacontroller.io/phase" : pointer .StringPtr (string (r .RecipeStatus .Phase )),
98
98
}
99
- if r .ObservedJob != nil &&
100
- r .ObservedJob .Spec .Refresh .ResyncAfterSeconds != nil {
101
- r .HookResponse .ResyncAfterSeconds = * r .ObservedJob .Spec .Refresh .ResyncAfterSeconds
99
+ if r .ObservedRecipe != nil &&
100
+ r .ObservedRecipe .Spec .Refresh .ResyncAfterSeconds != nil {
101
+ r .HookResponse .ResyncAfterSeconds = * r .ObservedRecipe .Spec .Refresh .ResyncAfterSeconds
102
102
}
103
103
}
104
104
105
105
func (r * Reconciler ) setWatchStatus () {
106
106
if r .Err != nil {
107
- if r .ObservedJob != nil &&
108
- r .ObservedJob .Spec .Refresh .OnErrorResyncAfterSeconds != nil {
107
+ if r .ObservedRecipe != nil &&
108
+ r .ObservedRecipe .Spec .Refresh .OnErrorResyncAfterSeconds != nil {
109
109
// resync based on configuration
110
110
r .HookResponse .ResyncAfterSeconds =
111
- * r .ObservedJob .Spec .Refresh .OnErrorResyncAfterSeconds
111
+ * r .ObservedRecipe .Spec .Refresh .OnErrorResyncAfterSeconds
112
112
}
113
113
r .setWatchStatusAsError ()
114
114
return
115
115
}
116
- if r .JobStatus .Phase == types .JobStatusLocked {
116
+ if r .RecipeStatus .Phase == types .RecipeStatusLocked {
117
117
// nothing needs to be done
118
118
// old status will persist
119
119
return
120
120
}
121
- r .setWatchStatusFromJobStatus ()
121
+ r .setWatchStatusFromRecipeStatus ()
122
122
}
123
123
124
- // Sync implements the idempotent logic to sync Job resource
124
+ // Sync implements the idempotent logic to sync Recipe resource
125
125
//
126
126
// NOTE:
127
127
// SyncHookRequest is the payload received as part of reconcile
128
128
// request. Similarly, SyncHookResponse is the payload sent as a
129
129
// response as part of reconcile response.
130
130
//
131
131
// NOTE:
132
- // This controller watches Job custom resource
132
+ // This controller watches Recipe custom resource
133
133
func Sync (request * generic.SyncHookRequest , response * generic.SyncHookResponse ) error {
134
134
r := & Reconciler {
135
135
Reconciler : commonctrl.Reconciler {
136
- Name : "job -sync-reconciler" ,
136
+ Name : "recipe -sync-reconciler" ,
137
137
HookRequest : request ,
138
138
HookResponse : response ,
139
139
},
0 commit comments