@@ -100,7 +100,7 @@ func (r *RatingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
100
100
return reconcile.Result {}, err
101
101
}
102
102
if requeue {
103
- return reconcile.Result {Requeue : true }, nil
103
+ return reconcile.Result {Requeue : requeue }, nil
104
104
}
105
105
106
106
// update status to false when rating is disabled
@@ -148,28 +148,55 @@ func (r RatingReconciler) updateLabels(ctx context.Context, instance *corev1alph
148
148
instance .Labels [corev1alpha1 .RatingRepositoryLabel ] = component .Labels [corev1alpha1 .ComponentRepositoryLabel ]
149
149
updateLabel = true
150
150
}
151
+ for _ , p := range instance .Spec .PipelineParams {
152
+ shouldBreak := false
153
+ for _ , pr := range p .Params {
154
+ if pr .Name == "VERSION" {
155
+ shouldBreak = true
156
+ if v , ok := instance .Labels [corev1alpha1 .RatingComponentVersion ]; ! ok || v != pr .Value .StringVal {
157
+ instance .Labels [corev1alpha1 .RatingComponentVersion ] = pr .Value .StringVal
158
+ updateLabel = true
159
+ }
160
+ break
161
+ }
162
+ }
163
+ if shouldBreak {
164
+ break
165
+ }
166
+ }
151
167
152
- if ! updateLabel {
153
- return false , nil
168
+ setOwner := true
169
+ for _ , owner := range instance .OwnerReferences {
170
+ if owner .UID == component .UID {
171
+ setOwner = false
172
+ break
173
+ }
174
+ }
175
+ if setOwner {
176
+ _ = controllerutil .SetOwnerReference (component , instance , r .Scheme )
154
177
}
155
178
156
- if err := r . Client . Update ( ctx , instance ); err != nil {
157
- return false , err
179
+ if updateLabel || setOwner {
180
+ return true , r . Client . Update ( ctx , instance )
158
181
}
159
- // when update labels, we should patch a initial status
160
- instanceDeepCopy := instance .DeepCopy ()
161
- instanceDeepCopy .Status .ConditionedStatus = corev1alpha1.ConditionedStatus {
162
- Conditions : []corev1alpha1.Condition {
163
- {
164
- Status : v1 .ConditionFalse ,
165
- LastTransitionTime : metav1 .Now (),
166
- Reason : corev1alpha1 .ReasonCreated ,
167
- Message : "Rating is created." ,
168
- Type : corev1alpha1 .TypeReady ,
182
+
183
+ if len (instance .Status .Conditions ) == 0 {
184
+ // when update labels, we should patch a initial status
185
+ instanceDeepCopy := instance .DeepCopy ()
186
+ instanceDeepCopy .Status .ConditionedStatus = corev1alpha1.ConditionedStatus {
187
+ Conditions : []corev1alpha1.Condition {
188
+ {
189
+ Status : v1 .ConditionFalse ,
190
+ LastTransitionTime : metav1 .Now (),
191
+ Reason : corev1alpha1 .ReasonCreated ,
192
+ Message : "Rating is created." ,
193
+ Type : corev1alpha1 .TypeReady ,
194
+ },
169
195
},
170
- },
196
+ }
197
+ return true , r .Client .Status ().Patch (ctx , instanceDeepCopy , client .MergeFrom (instance ))
171
198
}
172
- return true , r . Client . Status (). Patch ( ctx , instanceDeepCopy , client . MergeFrom ( instance ))
199
+ return false , nil
173
200
}
174
201
175
202
func (r * RatingReconciler ) CreatePipelineRun (logger logr.Logger , ctx context.Context , instance * corev1alpha1.Rating ) error {
0 commit comments