Skip to content

Commit

Permalink
Use maps for namespace labels and annotations
Browse files Browse the repository at this point in the history
Pointers to maps are superfluous, as iterating over an empty map will be
a no-op, and we do not need to otherwise differentiate an empty map from
an unset one.
This still leaves original namespace labels and annotations as pointers
to maps in bundle deployment options, for backward compatibility.
  • Loading branch information
weyfonk committed Jul 29, 2024
1 parent 87652a9 commit 04ba42c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
16 changes: 6 additions & 10 deletions internal/cmd/controller/target/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,14 @@ func (t *Target) BundleDeployment() *fleet.BundleDeployment {
bd.Spec.Paused = t.IsPaused()

for _, bundleTarget := range t.Bundle.Spec.Targets {
if bundleTarget.NamespaceLabels != nil {
for key, value := range *bundleTarget.NamespaceLabels {
(*bd.Spec.Options.NamespaceLabels)[key] = value
(*bd.Spec.StagedOptions.NamespaceLabels)[key] = value
}
for key, value := range bundleTarget.NamespaceLabels {
(*bd.Spec.Options.NamespaceLabels)[key] = value
(*bd.Spec.StagedOptions.NamespaceLabels)[key] = value
}

if bundleTarget.NamespaceAnnotations != nil {
for key, value := range *bundleTarget.NamespaceAnnotations {
(*bd.Spec.Options.NamespaceAnnotations)[key] = value
(*bd.Spec.StagedOptions.NamespaceAnnotations)[key] = value
}
for key, value := range bundleTarget.NamespaceAnnotations {
(*bd.Spec.Options.NamespaceAnnotations)[key] = value
(*bd.Spec.StagedOptions.NamespaceAnnotations)[key] = value
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/fleet.cattle.io/v1alpha1/bundle_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ type BundleTarget struct {
DoNotDeploy bool `json:"doNotDeploy,omitempty"`
// NamespaceLabels are labels that will be appended to the namespace created by Fleet.
// +nullable
NamespaceLabels *map[string]string `json:"namespaceLabels,omitempty"`
NamespaceLabels map[string]string `json:"namespaceLabels,omitempty"`
// NamespaceAnnotations are annotations that will be appended to the namespace created by Fleet.
// +nullable
NamespaceAnnotations *map[string]string `json:"namespaceAnnotations,omitempty"`
NamespaceAnnotations map[string]string `json:"namespaceAnnotations,omitempty"`
}

// BundleSummary contains the number of bundle deployments in each state and a
Expand Down
20 changes: 6 additions & 14 deletions pkg/apis/fleet.cattle.io/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 04ba42c

Please sign in to comment.