@@ -72,6 +72,7 @@ func (m *Manager) Targets(ctx context.Context, bundle *fleet.Bundle, manifestID
7272 if err != nil {
7373 return nil , false , err
7474 }
75+ clusterLoop:
7576 for _ , cluster := range clusters .Items {
7677 logger .V (4 ).Info ("Cluster has namespace?" , "cluster" , cluster .Name , "namespace" , cluster .Status .Namespace )
7778 clusterGroups , err := m .clusterGroupsForCluster (ctx , & cluster )
@@ -85,28 +86,50 @@ func (m *Manager) Targets(ctx context.Context, bundle *fleet.Bundle, manifestID
8586 if target == nil {
8687 continue
8788 }
88- // Check all matching targetCustomizations for doNotDeploy, not just the first match.
89- // This ensures that a doNotDeploy entry is honoured even when a broader-matching
90- // target appears before it in the target list (fixes first-match bypass).
91- doNotDeploy := target .DoNotDeploy || bm .HasDoNotDeployTarget (cluster .Name , clusterGroupsAsLabelMap , cluster .Labels )
92- if doNotDeploy {
89+ // Check if the GitRepo target has doNotDeploy set
90+ if target .DoNotDeploy {
9391 logger .V (1 ).Info ("Skipping BundleDeployment creation because doNotDeploy is set to true." ,
9492 "bundle" , bundle .Name ,
9593 "bundleNamespace" , bundle .Namespace ,
9694 "cluster" , cluster .Name ,
9795 "clusterNamespace" , cluster .Namespace ,
98- "reason" , "doNotDeploy" ,
96+ "reason" , "doNotDeploy on GitRepo target " ,
9997 )
10098 continue
10199 }
102100 // check if there is any matching targetCustomization that should be applied
103101 targetOpts := target .BundleDeploymentOptions
104102 if bundle .Spec .TargetCustomizationMode == fleet .TargetCustomizationModeAllMatches {
105- for _ , tc := range bm .MatchAllTargetCustomizations (cluster .Name , clusterGroupsAsLabelMap , cluster .Labels ) {
103+ // AllMatches mode: merge all matching customizations
104+ // Check if any matching customization has doNotDeploy=true (OR logic)
105+ matchedCustomizations := bm .MatchAllTargetCustomizations (cluster .Name , clusterGroupsAsLabelMap , cluster .Labels )
106+ for _ , tc := range matchedCustomizations {
107+ if tc .DoNotDeploy {
108+ logger .V (1 ).Info ("Skipping BundleDeployment creation because doNotDeploy is set to true." ,
109+ "bundle" , bundle .Name ,
110+ "bundleNamespace" , bundle .Namespace ,
111+ "cluster" , cluster .Name ,
112+ "clusterNamespace" , cluster .Namespace ,
113+ "reason" , "doNotDeploy on targetCustomization (AllMatches mode)" ,
114+ )
115+ continue clusterLoop
116+ }
106117 targetOpts = options .Merge (targetOpts , tc .BundleDeploymentOptions )
107118 }
108119 } else {
120+ // FirstMatch mode: apply only the first matching customization
109121 if targetCustomized := bm .MatchTargetCustomizations (cluster .Name , clusterGroupsAsLabelMap , cluster .Labels ); targetCustomized != nil {
122+ // Check if the first matching targetCustomization has doNotDeploy set
123+ if targetCustomized .DoNotDeploy {
124+ logger .V (1 ).Info ("Skipping BundleDeployment creation because doNotDeploy is set to true." ,
125+ "bundle" , bundle .Name ,
126+ "bundleNamespace" , bundle .Namespace ,
127+ "cluster" , cluster .Name ,
128+ "clusterNamespace" , cluster .Namespace ,
129+ "reason" , "doNotDeploy on targetCustomization (FirstMatch mode)" ,
130+ )
131+ continue
132+ }
110133 targetOpts = targetCustomized .BundleDeploymentOptions
111134 }
112135 }
0 commit comments