@@ -75,30 +75,6 @@ func (a *BundleMatch) MatchAllTargetCustomizations(clusterName string, clusterGr
7575 return result
7676}
7777
78- // HasDoNotDeployTarget returns true if any bundle target matching the given cluster
79- // has DoNotDeploy set to true. Unlike MatchTargetCustomizations, this scans all matching
80- // bundle targets instead of stopping at the first match, so a doNotDeploy entry does not have to
81- // appear before a broader-matching entry in the target list.
82- func (a * BundleMatch ) HasDoNotDeployTarget (clusterName string , clusterGroups map [string ]map [string ]string , clusterLabels map [string ]string ) bool {
83- for _ , tm := range a .matcher .matches {
84- if ! tm .bundleTarget .DoNotDeploy {
85- continue
86- }
87- if len (clusterGroups ) == 0 {
88- if criteriaWithoutRestrictions (tm , clusterName , "" , nil , clusterLabels ) {
89- return true
90- }
91- } else {
92- for cg , cgLabels := range clusterGroups {
93- if criteriaWithoutRestrictions (tm , clusterName , cg , cgLabels , clusterLabels ) {
94- return true
95- }
96- }
97- }
98- }
99- return false
100- }
101-
10278type targetMatch struct {
10379 bundleTarget * fleet.BundleTarget
10480 criteria * ClusterMatcher
@@ -126,7 +102,7 @@ func (a *BundleMatch) initMatcher() error {
126102 t := targetMatch {
127103 bundleTarget : & a .bundle .Spec .Targets [i ],
128104 criteria : clusterMatcher ,
129- isCustomization : determineIsCustomization (target , i , numCustomizations ),
105+ isCustomization : determineIsCustomization (target , i , numCustomizations , numRestrictions ),
130106 }
131107
132108 m .matches = append (m .matches , t )
@@ -146,7 +122,7 @@ func (a *BundleMatch) initMatcher() error {
146122
147123// determineIsCustomization uses explicit Source field if present,
148124// falls back to position-based detection for backward compatibility.
149- func determineIsCustomization (target fleet.BundleTarget , index int , numCustomizations int ) bool {
125+ func determineIsCustomization (target fleet.BundleTarget , index int , numCustomizations int , numRestrictions int ) bool {
150126 // NEW BUNDLES: Source field is populated by bundlereader
151127 // This is the preferred method for long-term maintainability
152128 if target .Source != "" {
@@ -160,7 +136,15 @@ func determineIsCustomization(target fleet.BundleTarget, index int, numCustomiza
160136 // - Therefore: first N targets are customizations
161137 // where N = len(Targets) - len(TargetRestrictions)
162138 //
139+ // SPECIAL CASE: If there are no targetRestrictions, this bundle wasn't
140+ // created by a GitRepo (e.g., CLI-loaded bundles, standalone bundles).
141+ // In this case, treat all targets as regular bundle targets (not customizations)
142+ // to maintain backward compatibility with bundles that predate the Source field.
143+ //
163144 // This fixes the collision bug for old Bundles without requiring recreation
145+ if numRestrictions == 0 {
146+ return false
147+ }
164148 return index < numCustomizations
165149}
166150
@@ -180,8 +164,12 @@ func (m *matcher) isRestricted(clusterName, clusterGroup string, clusterGroupLab
180164}
181165
182166// criteriaWithRestrictions checks that the cluster passes the restriction allowlist
183- // and matches the target's cluster selector. Used for GitRepo targets.
167+ // and matches the target's cluster selector. Used for GitRepo targets only;
168+ // customization targets (from fleet.yaml) are excluded.
184169func (m * matcher ) criteriaWithRestrictions (targetMatch targetMatch , clusterName , clusterGroup string , clusterGroupLabels , clusterLabels map [string ]string ) bool {
170+ if targetMatch .isCustomization {
171+ return false
172+ }
185173 if ! m .isRestricted (clusterName , clusterGroup , clusterGroupLabels , clusterLabels ) &&
186174 targetMatch .criteria .Match (clusterName , clusterGroup , clusterGroupLabels , clusterLabels ) {
187175 return true
@@ -190,13 +178,6 @@ func (m *matcher) criteriaWithRestrictions(targetMatch targetMatch, clusterName,
190178 return false
191179}
192180
193- // criteriaWithoutRestrictions checks targetMatch's criteria for a match on the specified cluster
194- // name, group and labels, without checking if target is inside the targetRestrictions.
195- // This is used for TargetCustomizations.
196- func criteriaWithoutRestrictions (targetMatch targetMatch , clusterName , clusterGroup string , clusterGroupLabels , clusterLabels map [string ]string ) bool {
197- return targetMatch .criteria .Match (clusterName , clusterGroup , clusterGroupLabels , clusterLabels )
198- }
199-
200181// match returns the first BundleTarget, from the matcher's target matches, which matches the specified cluster name, groups and labels, using matching logic implemented via findCriteriaMatch.
201182func (m * matcher ) match (clusterName string , clusterLabels map [string ]string , clusterGroups map [string ]map [string ]string , findCriteriaMatch findCriteriaMatch ) * fleet.BundleTarget {
202183 for _ , targetMatch := range m .matches {
0 commit comments