Skip to content

Commit e71436b

Browse files
feat(recipe): #78 - rename job to recipe (#97)
* chore(rename): rename job to recipe Signed-off-by: Harsh Shekhar <[email protected]>
1 parent 0e0de65 commit e71436b

39 files changed

+298
-298
lines changed

cmd/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
"mayadata.io/d-operators/controller/doperator"
2727
"mayadata.io/d-operators/controller/http"
28-
"mayadata.io/d-operators/controller/job"
28+
"mayadata.io/d-operators/controller/recipe"
2929
"mayadata.io/d-operators/controller/run"
3030
)
3131

@@ -62,7 +62,7 @@ func main() {
6262

6363
// controller name & corresponding controller reconcile function
6464
var controllers = map[string]generic.InlineInvokeFn{
65-
"sync/job": job.Sync,
65+
"sync/recipe": recipe.Sync,
6666
"sync/http": http.Sync,
6767
"sync/doperator": doperator.Sync,
6868
"sync/run": run.Sync,

controller/job/reconciler.go controller/recipe/reconciler.go

+37-37
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package job
17+
package recipe
1818

1919
import (
2020
"k8s.io/utils/pointer"
@@ -23,53 +23,53 @@ import (
2323

2424
commonctrl "mayadata.io/d-operators/common/controller"
2525
"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"
2828
)
2929

30-
// Reconciler manages reconciliation of Job custom resource
30+
// Reconciler manages reconciliation of Recipe custom resource
3131
type Reconciler struct {
3232
commonctrl.Reconciler
3333

34-
ObservedJob *types.Job
35-
JobStatus *types.JobStatus
34+
ObservedRecipe *types.Recipe
35+
RecipeStatus *types.RecipeStatus
3636
}
3737

3838
func (r *Reconciler) eval() {
39-
var j types.Job
39+
var j types.Recipe
4040
// convert from unstructured instance to typed instance
4141
err := unstruct.ToTyped(r.HookRequest.Watch, &j)
4242
if err != nil {
4343
r.Err = err
4444
return
4545
}
46-
r.ObservedJob = &j
46+
r.ObservedRecipe = &j
4747
}
4848

4949
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,
5353
},
5454
)
55-
r.JobStatus, r.Err = runner.Run()
55+
r.RecipeStatus, r.Err = runner.Run()
5656
}
5757

5858
func (r *Reconciler) setSyncResponse() {
5959
// we skip the reconcile always since there are no attachments
6060
// to reconcile
6161
r.HookResponse.SkipReconcile = true
6262
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
6666
}
67-
// set resync period for jobs with errors
67+
// set resync period for recipes with errors
6868
if r.Err != nil {
6969
// resync since this might be a temporary error
7070
//
7171
// TODO:
72-
// Might be better to expose this from job.spec
72+
// Might be better to expose this from recipe.spec
7373
r.HookResponse.ResyncAfterSeconds = 5.0
7474
}
7575
}
@@ -80,60 +80,60 @@ func (r *Reconciler) setWatchStatusAsError() {
8080
"reason": r.Err.Error(),
8181
}
8282
r.HookResponse.Labels = map[string]*string{
83-
"job.dope.metacontroller.io/phase": k8s.StringPtr("Error"),
83+
"recipe.dope.metacontroller.io/phase": k8s.StringPtr("Error"),
8484
}
8585
}
8686

87-
func (r *Reconciler) setWatchStatusFromJobStatus() {
87+
func (r *Reconciler) setWatchStatusFromRecipeStatus() {
8888
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,
9595
}
9696
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)),
9898
}
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
102102
}
103103
}
104104

105105
func (r *Reconciler) setWatchStatus() {
106106
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 {
109109
// resync based on configuration
110110
r.HookResponse.ResyncAfterSeconds =
111-
*r.ObservedJob.Spec.Refresh.OnErrorResyncAfterSeconds
111+
*r.ObservedRecipe.Spec.Refresh.OnErrorResyncAfterSeconds
112112
}
113113
r.setWatchStatusAsError()
114114
return
115115
}
116-
if r.JobStatus.Phase == types.JobStatusLocked {
116+
if r.RecipeStatus.Phase == types.RecipeStatusLocked {
117117
// nothing needs to be done
118118
// old status will persist
119119
return
120120
}
121-
r.setWatchStatusFromJobStatus()
121+
r.setWatchStatusFromRecipeStatus()
122122
}
123123

124-
// Sync implements the idempotent logic to sync Job resource
124+
// Sync implements the idempotent logic to sync Recipe resource
125125
//
126126
// NOTE:
127127
// SyncHookRequest is the payload received as part of reconcile
128128
// request. Similarly, SyncHookResponse is the payload sent as a
129129
// response as part of reconcile response.
130130
//
131131
// NOTE:
132-
// This controller watches Job custom resource
132+
// This controller watches Recipe custom resource
133133
func Sync(request *generic.SyncHookRequest, response *generic.SyncHookResponse) error {
134134
r := &Reconciler{
135135
Reconciler: commonctrl.Reconciler{
136-
Name: "job-sync-reconciler",
136+
Name: "recipe-sync-reconciler",
137137
HookRequest: request,
138138
HookResponse: response,
139139
},

manifests/crd.yaml

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ apiVersion: apiextensions.k8s.io/v1beta1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
name: jobs.metacontroller.app
6+
name: recipes.dope.metacontroller.io
77
spec:
8-
group: metacontroller.app
8+
group: dope.metacontroller.io
99
names:
10-
kind: Job
11-
listKind: JobList
12-
plural: jobs
10+
kind: Recipe
11+
listKind: RecipeList
12+
plural: recipes
1313
shortNames:
14-
- jb
15-
singular: job
14+
- rp
15+
singular: recipe
1616
scope: Namespaced
1717
subresources:
1818
status: {}

pkg/job/apply.go pkg/recipe/apply.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package job
17+
package recipe
1818

1919
import (
2020
"fmt"
@@ -24,7 +24,7 @@ import (
2424
apierrors "k8s.io/apimachinery/pkg/api/errors"
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
27-
types "mayadata.io/d-operators/types/job"
27+
types "mayadata.io/d-operators/types/recipe"
2828
dynamicapply "openebs.io/metac/dynamic/apply"
2929
)
3030

pkg/job/assert.go pkg/recipe/assert.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package job
17+
package recipe
1818

1919
import (
2020
"github.com/pkg/errors"
21-
types "mayadata.io/d-operators/types/job"
21+
types "mayadata.io/d-operators/types/recipe"
2222
)
2323

2424
// Assertable is used to perform matches of desired state(s)

pkg/job/base.go pkg/recipe/base.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package job
17+
package recipe
1818

19-
import types "mayadata.io/d-operators/types/job"
19+
import types "mayadata.io/d-operators/types/recipe"
2020

2121
// BaseRunner is the common runner used by all action runners
2222
type BaseRunner struct {

pkg/job/common.go pkg/recipe/common.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package job
17+
package recipe
1818

1919
import (
2020
"fmt"

pkg/job/create.go pkg/recipe/create.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package job
17+
package recipe
1818

1919
import (
2020
"fmt"
@@ -24,7 +24,7 @@ import (
2424
apierrors "k8s.io/apimachinery/pkg/api/errors"
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
27-
types "mayadata.io/d-operators/types/job"
27+
types "mayadata.io/d-operators/types/recipe"
2828
"openebs.io/metac/dynamic/clientset"
2929
)
3030

0 commit comments

Comments
 (0)