@@ -43,6 +43,7 @@ import (
43
43
"k8s.io/apimachinery/pkg/types"
44
44
"k8s.io/apimachinery/pkg/util/sets"
45
45
kuberecorder "k8s.io/client-go/tools/record"
46
+ "k8s.io/utils/pointer"
46
47
47
48
ctrl "sigs.k8s.io/controller-runtime"
48
49
"sigs.k8s.io/controller-runtime/pkg/builder"
@@ -418,8 +419,9 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, obj *sour
418
419
conditions .MarkTrue (obj , sourcev1 .SourceVerifiedCondition , meta .SucceededReason , "verified signature of revision %s" , revision )
419
420
}
420
421
421
- // Skip pulling if the artifact revision hasn't changes
422
- if obj .GetArtifact ().HasRevision (revision ) {
422
+ // Skip pulling if the artifact revision and the source configuration has
423
+ // not changed.
424
+ if obj .GetArtifact ().HasRevision (revision ) && ! ociSourceConfigChanged (obj ) {
423
425
conditions .Delete (obj , sourcev1 .FetchFailedCondition )
424
426
return sreconcile .ResultSuccess , nil
425
427
}
@@ -924,15 +926,15 @@ func (r *OCIRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *so
924
926
925
927
// Set the ArtifactInStorageCondition if there's no drift.
926
928
defer func () {
927
- if obj .GetArtifact ().HasRevision (artifact .Revision ) {
929
+ if obj .GetArtifact ().HasRevision (artifact .Revision ) && ! ociSourceConfigChanged ( obj ) {
928
930
conditions .Delete (obj , sourcev1 .ArtifactOutdatedCondition )
929
931
conditions .MarkTrue (obj , sourcev1 .ArtifactInStorageCondition , meta .SucceededReason ,
930
932
"stored artifact for digest '%s'" , artifact .Revision )
931
933
}
932
934
}()
933
935
934
936
// The artifact is up-to-date
935
- if obj .GetArtifact ().HasRevision (artifact .Revision ) {
937
+ if obj .GetArtifact ().HasRevision (artifact .Revision ) && ! ociSourceConfigChanged ( obj ) {
936
938
r .eventLogf (ctx , obj , events .EventTypeTrace , sourcev1 .ArtifactUpToDateReason ,
937
939
"artifact up-to-date with remote revision: '%s'" , artifact .Revision )
938
940
return sreconcile .ResultSuccess , nil
@@ -994,9 +996,11 @@ func (r *OCIRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *so
994
996
}
995
997
}
996
998
997
- // Record it on the object
999
+ // Record the observations on the object.
998
1000
obj .Status .Artifact = artifact .DeepCopy ()
999
1001
obj .Status .Artifact .Metadata = metadata .Metadata
1002
+ obj .Status .ObservedIgnore = obj .Spec .Ignore
1003
+ obj .Status .ObservedLayerSelector = obj .Spec .LayerSelector
1000
1004
1001
1005
// Update symlink on a "best effort" basis
1002
1006
url , err := r .Storage .Symlink (artifact , "latest.tar.gz" )
@@ -1125,3 +1129,29 @@ func (r *OCIRepositoryReconciler) notify(ctx context.Context, oldObj, newObj *so
1125
1129
}
1126
1130
}
1127
1131
}
1132
+
1133
+ // ociSourceConfigChanged evaluates the current spec with the observations
1134
+ // of the artifact in the status to determine if source configuration has
1135
+ // changed and requires rebuilding the artifact.
1136
+ func ociSourceConfigChanged (obj * sourcev1.OCIRepository ) bool {
1137
+ if ! pointer .StringEqual (obj .Spec .Ignore , obj .Status .ObservedIgnore ) {
1138
+ return true
1139
+ }
1140
+
1141
+ if ! layerSelectorEqual (obj .Spec .LayerSelector , obj .Status .ObservedLayerSelector ) {
1142
+ return true
1143
+ }
1144
+
1145
+ return false
1146
+ }
1147
+
1148
+ // Based on k8s.io/utils/pointer/pointer.go pointer value equality.
1149
+ func layerSelectorEqual (a , b * sourcev1.OCILayerSelector ) bool {
1150
+ if (a == nil ) != (b == nil ) {
1151
+ return false
1152
+ }
1153
+ if a == nil {
1154
+ return true
1155
+ }
1156
+ return * a == * b
1157
+ }
0 commit comments