Skip to content

Commit

Permalink
[Fix] mapping ownerreferences of pipeline to ij (#403)
Browse files Browse the repository at this point in the history
* [fix] pipeline ownerreferences

* fix ij not completed

* [fix] lint : reduce Cyclomatic Complexity

* [chore] bump up version to v0.6.2
  • Loading branch information
chanwook-lee authored Mar 15, 2023
1 parent a789582 commit 149976e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Current Operator version
VERSION ?= v0.6.1
VERSION ?= v0.6.2
REGISTRY ?= tmaxcloudck

# Image URL to use all building/pushing image targets
Expand Down
8 changes: 4 additions & 4 deletions config/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ spec:
containers:
- command:
- /controller
image: docker.io/tmaxcloudck/cicd-operator:v0.6.1
image: docker.io/tmaxcloudck/cicd-operator:v0.6.2
imagePullPolicy: Always
name: manager
env:
Expand Down Expand Up @@ -171,7 +171,7 @@ spec:
containers:
- command:
- /blocker
image: docker.io/tmaxcloudck/cicd-blocker:v0.6.1
image: docker.io/tmaxcloudck/cicd-blocker:v0.6.2
imagePullPolicy: Always
name: manager
resources:
Expand Down Expand Up @@ -231,7 +231,7 @@ spec:
containers:
- command:
- /webhook
image: docker.io/tmaxcloudck/cicd-webhook:v0.6.1
image: docker.io/tmaxcloudck/cicd-webhook:v0.6.2
imagePullPolicy: Always
name: manager
resources:
Expand Down Expand Up @@ -291,7 +291,7 @@ spec:
containers:
- command:
- /apiserver
image: docker.io/tmaxcloudck/cicd-api-server:v0.6.1
image: docker.io/tmaxcloudck/cicd-api-server:v0.6.2
imagePullPolicy: Always
name: manager
resources:
Expand Down
1 change: 1 addition & 0 deletions controllers/integrationjob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,6 @@ func (r *integrationJobReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&cicdv1.IntegrationJob{}).
Owns(&tektonv1beta1.PipelineRun{}).
Owns(&tektonv1beta1.Pipeline{}).
Complete(r)
}
49 changes: 33 additions & 16 deletions pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,24 @@ func (s *scheduler) schedulePending(availableCnt *int) func(structs.Item) {

// Generate PipeLine and PipeLineRun
pl, pr, err := s.pm.Generate(jobNode.IntegrationJob)
if err != nil {
if err := s.patchJobScheduleFailed(jobNode.IntegrationJob, err.Error()); err != nil {
log.Error(err, "")
}
log.Error(err, "")
return
}

if err := s.SetControllerReferences(jobNode.IntegrationJob, pr, pl, s.scheme); err != nil {
return
}

log.Info(fmt.Sprintf("Scheduled %s / %s / %s", jobNode.Name, jobNode.Namespace, jobNode.CreationTimestamp))

// Check whether PipeLine exists
testPl := &tektonv1beta1.Pipeline{}
if err := s.k8sClient.Get(context.Background(), types.NamespacedName{Name: pipelinemanager.Name(jobNode.IntegrationJob), Namespace: jobNode.Namespace}, testPl); err != nil {
//
// If not, create PipeLine
if err := s.k8sClient.Create(context.Background(), pl); err != nil {
if err := s.patchJobScheduleFailed(jobNode.IntegrationJob, err.Error()); err != nil {
log.Error(err, "")
Expand All @@ -183,33 +196,37 @@ func (s *scheduler) schedulePending(availableCnt *int) func(structs.Item) {
}
}

if err != nil {
// Create PipelineRun only when there is no Pipeline exists
if err := s.k8sClient.Create(context.Background(), pr); err != nil {
if err := s.patchJobScheduleFailed(jobNode.IntegrationJob, err.Error()); err != nil {
log.Error(err, "")
}
log.Error(err, "")
return
}
if err := controllerutil.SetControllerReference(jobNode.IntegrationJob, pr, s.scheme); err != nil {
if err := s.patchJobScheduleFailed(jobNode.IntegrationJob, err.Error()); err != nil {
log.Error(err, "")
}

*availableCnt = *availableCnt - 1
}
}

func (s *scheduler) SetControllerReferences(job *cicdv1.IntegrationJob, pr metav1.Object, pl metav1.Object, scheme *runtime.Scheme) error {
if err := controllerutil.SetControllerReference(job, pr, s.scheme); err != nil {
if err := s.patchJobScheduleFailed(job, err.Error()); err != nil {
log.Error(err, "")
return
}
log.Error(err, "")
return err
}

log.Info(fmt.Sprintf("Scheduled %s / %s / %s", jobNode.Name, jobNode.Namespace, jobNode.CreationTimestamp))
// Create PipelineRun only when there is no Pipeline exists
if err := s.k8sClient.Create(context.Background(), pr); err != nil {
if err := s.patchJobScheduleFailed(jobNode.IntegrationJob, err.Error()); err != nil {
log.Error(err, "")
}
if err := controllerutil.SetControllerReference(job, pl, s.scheme); err != nil {
if err := s.patchJobScheduleFailed(job, err.Error()); err != nil {
log.Error(err, "")
return
}

*availableCnt = *availableCnt - 1
log.Error(err, "")
return err
}

return nil
}

func (s *scheduler) patchJobScheduleFailed(job *cicdv1.IntegrationJob, msg string) error {
Expand Down

0 comments on commit 149976e

Please sign in to comment.