@@ -193,7 +193,7 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
193
193
time .Since (reconcileStart ).String (),
194
194
obj .Spec .Interval .Duration .String ())
195
195
log .Info (msg , "revision" , obj .Status .LastAttemptedRevision )
196
- r .event (obj , obj .Status .LastAppliedRevision , eventv1 .EventSeverityInfo , msg ,
196
+ r .event (obj , obj .Status .LastAppliedRevision , obj . Status . LastAppliedOriginRevision , eventv1 .EventSeverityInfo , msg ,
197
197
map [string ]string {
198
198
kustomizev1 .GroupVersion .Group + "/" + eventv1 .MetaCommitStatusKey : eventv1 .MetaCommitStatusUpdateValue ,
199
199
})
@@ -234,7 +234,7 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
234
234
if acl .IsAccessDenied (err ) {
235
235
conditions .MarkFalse (obj , meta .ReadyCondition , apiacl .AccessDeniedReason , "%s" , err )
236
236
log .Error (err , "Access denied to cross-namespace source" )
237
- r .event (obj , "unknown " , eventv1 .EventSeverityError , err .Error (), nil )
237
+ r .event (obj , "" , " " , eventv1 .EventSeverityError , err .Error (), nil )
238
238
return ctrl.Result {RequeueAfter : obj .GetRetryInterval ()}, nil
239
239
}
240
240
@@ -249,14 +249,16 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
249
249
log .Info (msg )
250
250
return ctrl.Result {RequeueAfter : r .requeueDependency }, nil
251
251
}
252
+ revision := artifactSource .GetArtifact ().Revision
253
+ originRevision := getOriginRevision (artifactSource )
252
254
253
255
// Check dependencies and requeue the reconciliation if the check fails.
254
256
if len (obj .Spec .DependsOn ) > 0 {
255
257
if err := r .checkDependencies (ctx , obj , artifactSource ); err != nil {
256
258
conditions .MarkFalse (obj , meta .ReadyCondition , meta .DependencyNotReadyReason , "%s" , err )
257
259
msg := fmt .Sprintf ("Dependencies do not meet ready condition, retrying in %s" , r .requeueDependency .String ())
258
260
log .Info (msg )
259
- r .event (obj , artifactSource . GetArtifact (). Revision , eventv1 .EventSeverityInfo , msg , nil )
261
+ r .event (obj , revision , originRevision , eventv1 .EventSeverityInfo , msg , nil )
260
262
return ctrl.Result {RequeueAfter : r .requeueDependency }, nil
261
263
}
262
264
log .Info ("All dependencies are ready, proceeding with reconciliation" )
@@ -279,8 +281,8 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
279
281
time .Since (reconcileStart ).String (),
280
282
obj .GetRetryInterval ().String ()),
281
283
"revision" ,
282
- artifactSource . GetArtifact (). Revision )
283
- r .event (obj , artifactSource . GetArtifact (). Revision , eventv1 .EventSeverityError ,
284
+ revision )
285
+ r .event (obj , revision , originRevision , eventv1 .EventSeverityError ,
284
286
reconcileErr .Error (), nil )
285
287
return ctrl.Result {RequeueAfter : obj .GetRetryInterval ()}, nil
286
288
}
@@ -298,6 +300,7 @@ func (r *KustomizationReconciler) reconcile(
298
300
299
301
// Update status with the reconciliation progress.
300
302
revision := src .GetArtifact ().Revision
303
+ originRevision := getOriginRevision (src )
301
304
progressingMsg := fmt .Sprintf ("Fetching manifests for revision %s with a timeout of %s" , revision , obj .GetTimeout ().String ())
302
305
conditions .MarkUnknown (obj , meta .ReadyCondition , meta .ProgressingReason , "%s" , "Reconciliation in progress" )
303
306
conditions .MarkReconciling (obj , meta .ProgressingReason , "%s" , progressingMsg )
@@ -419,7 +422,7 @@ func (r *KustomizationReconciler) reconcile(
419
422
}
420
423
421
424
// Validate and apply resources in stages.
422
- drifted , changeSet , err := r .apply (ctx , resourceManager , obj , revision , objects )
425
+ drifted , changeSet , err := r .apply (ctx , resourceManager , obj , revision , originRevision , objects )
423
426
if err != nil {
424
427
conditions .MarkFalse (obj , meta .ReadyCondition , meta .ReconciliationFailedReason , "%s" , err )
425
428
return err
@@ -444,7 +447,7 @@ func (r *KustomizationReconciler) reconcile(
444
447
}
445
448
446
449
// Run garbage collection for stale resources that do not have pruning disabled.
447
- if _ , err := r .prune (ctx , resourceManager , obj , revision , staleObjects ); err != nil {
450
+ if _ , err := r .prune (ctx , resourceManager , obj , revision , originRevision , staleObjects ); err != nil {
448
451
conditions .MarkFalse (obj , meta .ReadyCondition , meta .PruneFailedReason , "%s" , err )
449
452
return err
450
453
}
@@ -456,15 +459,17 @@ func (r *KustomizationReconciler) reconcile(
456
459
patcher ,
457
460
obj ,
458
461
revision ,
462
+ originRevision ,
459
463
isNewRevision ,
460
464
drifted ,
461
465
changeSet .ToObjMetadataSet ()); err != nil {
462
466
conditions .MarkFalse (obj , meta .ReadyCondition , meta .HealthCheckFailedReason , "%s" , err )
463
467
return err
464
468
}
465
469
466
- // Set last applied revision .
470
+ // Set last applied revisions .
467
471
obj .Status .LastAppliedRevision = revision
472
+ obj .Status .LastAppliedOriginRevision = originRevision
468
473
469
474
// Mark the object as ready.
470
475
conditions .MarkTrue (obj ,
@@ -656,6 +661,7 @@ func (r *KustomizationReconciler) apply(ctx context.Context,
656
661
manager * ssa.ResourceManager ,
657
662
obj * kustomizev1.Kustomization ,
658
663
revision string ,
664
+ originRevision string ,
659
665
objects []* unstructured.Unstructured ) (bool , * ssa.ChangeSet , error ) {
660
666
log := ctrl .LoggerFrom (ctx )
661
667
@@ -841,7 +847,7 @@ func (r *KustomizationReconciler) apply(ctx context.Context,
841
847
// emit event only if the server-side apply resulted in changes
842
848
applyLog := strings .TrimSuffix (changeSetLog .String (), "\n " )
843
849
if applyLog != "" {
844
- r .event (obj , revision , eventv1 .EventSeverityInfo , applyLog , nil )
850
+ r .event (obj , revision , originRevision , eventv1 .EventSeverityInfo , applyLog , nil )
845
851
}
846
852
847
853
return applyLog != "" , resultSet , nil
@@ -852,6 +858,7 @@ func (r *KustomizationReconciler) checkHealth(ctx context.Context,
852
858
patcher * patch.SerialPatcher ,
853
859
obj * kustomizev1.Kustomization ,
854
860
revision string ,
861
+ originRevision string ,
855
862
isNewRevision bool ,
856
863
drifted bool ,
857
864
objects object.ObjMetadataSet ) error {
@@ -910,7 +917,7 @@ func (r *KustomizationReconciler) checkHealth(ctx context.Context,
910
917
// Emit recovery event if the previous health check failed.
911
918
msg := fmt .Sprintf ("Health check passed in %s" , time .Since (checkStart ).String ())
912
919
if ! wasHealthy || (isNewRevision && drifted ) {
913
- r .event (obj , revision , eventv1 .EventSeverityInfo , msg , nil )
920
+ r .event (obj , revision , originRevision , eventv1 .EventSeverityInfo , msg , nil )
914
921
}
915
922
916
923
conditions .MarkTrue (obj , meta .HealthyCondition , meta .SucceededReason , "%s" , msg )
@@ -925,6 +932,7 @@ func (r *KustomizationReconciler) prune(ctx context.Context,
925
932
manager * ssa.ResourceManager ,
926
933
obj * kustomizev1.Kustomization ,
927
934
revision string ,
935
+ originRevision string ,
928
936
objects []* unstructured.Unstructured ) (bool , error ) {
929
937
if ! obj .Spec .Prune {
930
938
return false , nil
@@ -949,7 +957,7 @@ func (r *KustomizationReconciler) prune(ctx context.Context,
949
957
// emit event only if the prune operation resulted in changes
950
958
if changeSet != nil && len (changeSet .Entries ) > 0 {
951
959
log .Info (fmt .Sprintf ("garbage collection completed: %s" , changeSet .String ()))
952
- r .event (obj , revision , eventv1 .EventSeverityInfo , changeSet .String (), nil )
960
+ r .event (obj , revision , originRevision , eventv1 .EventSeverityInfo , changeSet .String (), nil )
953
961
return true , nil
954
962
}
955
963
@@ -1004,19 +1012,19 @@ func (r *KustomizationReconciler) finalize(ctx context.Context,
1004
1012
1005
1013
changeSet , err := resourceManager .DeleteAll (ctx , objects , opts )
1006
1014
if err != nil {
1007
- r .event (obj , obj .Status .LastAppliedRevision , eventv1 .EventSeverityError , "pruning for deleted resource failed" , nil )
1015
+ r .event (obj , obj .Status .LastAppliedRevision , obj . Status . LastAppliedOriginRevision , eventv1 .EventSeverityError , "pruning for deleted resource failed" , nil )
1008
1016
// Return the error so we retry the failed garbage collection
1009
1017
return ctrl.Result {}, err
1010
1018
}
1011
1019
1012
1020
if changeSet != nil && len (changeSet .Entries ) > 0 {
1013
- r .event (obj , obj .Status .LastAppliedRevision , eventv1 .EventSeverityInfo , changeSet .String (), nil )
1021
+ r .event (obj , obj .Status .LastAppliedRevision , obj . Status . LastAppliedOriginRevision , eventv1 .EventSeverityInfo , changeSet .String (), nil )
1014
1022
}
1015
1023
} else {
1016
1024
// when the account to impersonate is gone, log the stale objects and continue with the finalization
1017
1025
msg := fmt .Sprintf ("unable to prune objects: \n %s" , ssautil .FmtUnstructuredList (objects ))
1018
1026
log .Error (fmt .Errorf ("skiping pruning, failed to find account to impersonate" ), msg )
1019
- r .event (obj , obj .Status .LastAppliedRevision , eventv1 .EventSeverityError , msg , nil )
1027
+ r .event (obj , obj .Status .LastAppliedRevision , obj . Status . LastAppliedOriginRevision , eventv1 .EventSeverityError , msg , nil )
1020
1028
}
1021
1029
}
1022
1030
@@ -1027,13 +1035,16 @@ func (r *KustomizationReconciler) finalize(ctx context.Context,
1027
1035
}
1028
1036
1029
1037
func (r * KustomizationReconciler ) event (obj * kustomizev1.Kustomization ,
1030
- revision , severity , msg string ,
1038
+ revision , originRevision , severity , msg string ,
1031
1039
metadata map [string ]string ) {
1032
1040
if metadata == nil {
1033
1041
metadata = map [string ]string {}
1034
1042
}
1035
1043
if revision != "" {
1036
- metadata [kustomizev1 .GroupVersion .Group + "/revision" ] = revision
1044
+ metadata [kustomizev1 .GroupVersion .Group + "/" + eventv1 .MetaRevisionKey ] = revision
1045
+ }
1046
+ if originRevision != "" {
1047
+ metadata [kustomizev1 .GroupVersion .Group + "/" + eventv1 .MetaOriginRevisionKey ] = originRevision
1037
1048
}
1038
1049
1039
1050
reason := severity
@@ -1108,3 +1119,14 @@ func (r *KustomizationReconciler) patch(ctx context.Context,
1108
1119
1109
1120
return nil
1110
1121
}
1122
+
1123
+ // getOriginRevision returns the origin revision of the source artifact,
1124
+ // or the empty string if it's not present, or if the artifact itself
1125
+ // is not present.
1126
+ func getOriginRevision (src sourcev1.Source ) string {
1127
+ a := src .GetArtifact ()
1128
+ if a == nil {
1129
+ return ""
1130
+ }
1131
+ return a .Metadata [OCIArtifactOriginRevisionAnnotation ]
1132
+ }
0 commit comments