Skip to content

Commit 3ff3d89

Browse files
committed
refactor: remove field-shadowing of TargetCustomizationMode in FleetYAML
FleetYAML was declaring its own TargetCustomizationMode field with the same JSON tag as the embedded BundleSpec.TargetCustomizationMode, causing field shadowing and requiring manual propagation. Since FleetYAML embeds BundleSpec, the field is already accessible and YAML unmarshalling works correctly without duplication. Fixes Copilot review comments in PR rancher#4940. Changes: - Remove duplicate TargetCustomizationMode field from FleetYAML - Remove manual copy in bundleFromDir() - Update test comment to reflect unmarshalling via embedded struct
1 parent a094580 commit 3ff3d89

3 files changed

Lines changed: 2 additions & 9 deletions

File tree

internal/bundlereader/read.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ func bundleFromDir(ctx context.Context, name, baseDir string, bundleData []byte,
189189
tc.Source = "customization"
190190
fy.Targets = append(fy.Targets, tc)
191191
}
192-
fy.BundleSpec.TargetCustomizationMode = fy.TargetCustomizationMode
193192

194193
meta, err := readMetadata(bundleData)
195194
if err != nil {

internal/bundlereader/read_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
)
1212

1313
// TestBundleFromDir_TargetCustomizationModePropagate verifies that the
14-
// targetCustomizationMode field from fleet.yaml is copied into
15-
// bundle.Spec.TargetCustomizationMode by bundleFromDir.
14+
// targetCustomizationMode field from fleet.yaml is correctly unmarshalled into
15+
// bundle.Spec.TargetCustomizationMode via the embedded BundleSpec.
1616
func TestBundleFromDir_TargetCustomizationModePropagate(t *testing.T) {
1717
dir := t.TempDir()
1818

pkg/apis/fleet.cattle.io/v1alpha1/fleetyaml.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ type FleetYAML struct {
1010
// dependsOn.selector.
1111
Labels map[string]string `json:"labels,omitempty"`
1212
BundleSpec
13-
// TargetCustomizationMode controls how targetCustomizations are evaluated.
14-
// "FirstMatch" (default) stops at the first matching entry.
15-
// "AllMatches" applies all matching entries in order, merging them.
16-
// +kubebuilder:default=FirstMatch
17-
// +kubebuilder:validation:Enum=FirstMatch;AllMatches
18-
TargetCustomizationMode TargetCustomizationMode `json:"targetCustomizationMode,omitempty"`
1913
// TargetCustomizations are used to determine how resources should be
2014
// modified per target. Targets are evaluated in order. By default
2115
// (FirstMatch) the first one to match a cluster is used for that cluster.

0 commit comments

Comments
 (0)