Skip to content

Commit 994dc37

Browse files
authored
fix: Removing the nested Pair (#872)
This pull request refactors the handling of common labels in the `KustomizationCommonLabels` class and its associated `KustomizationCommonLabelsPair` class to simplify the data structure and improve usability. The most important changes include replacing the `KustomizationCommonLabelsPair` class with a direct inheritance from `Dictionary<string, string>` and updating the `KustomizationCommonLabels` class to reflect this change. ### Refactoring of common labels handling: * [`src/KubeOps.Abstractions/Kustomize/KustomizationCommonLabelsPair.cs`](diffhunk://#diff-500791e44853948e64cc50e1fbd37cb5ba56cef839636e30ab119a7ea54ba332L3-R3): Simplified the `KustomizationCommonLabelsPair` class by making it directly inherit from `Dictionary<string, string>`, removing its properties and methods. * [`src/KubeOps.Abstractions/Kustomize/KustomizationCommonLabels.cs`](diffhunk://#diff-9ff89020ff654e0389952b6f3075c61c281221e538f32dd9854c9586e5c1d469L10-R24): Updated the `Pairs` property in `KustomizationCommonLabels` to use the new `KustomizationCommonLabelsPair` structure. Replaced the initialization logic to add key-value pairs directly to the dictionary. Removed the `IncludeSelectors` property from `KustomizationCommonLabelsPair` and reintroduced it as a property in `KustomizationCommonLabels` with a default value of `true`. This is a fix for #868
1 parent 417df6b commit 994dc37

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/KubeOps.Abstractions/Kustomize/KustomizationCommonLabels.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ public class KustomizationCommonLabels
77
{
88
public KustomizationCommonLabels(IDictionary<string, string> pairs)
99
{
10-
Pairs.Add(new KustomizationCommonLabelsPair() { Pairs = pairs });
10+
foreach (var keyValuePair in pairs)
11+
{
12+
Pairs.Add(keyValuePair.Key, keyValuePair.Value);
13+
}
1114
}
1215

16+
/// <summary>
17+
/// Include selectors.
18+
/// </summary>
19+
public bool IncludeSelectors { get; init; } = true;
20+
1321
/// <summary>
1422
/// A list of common labels.
1523
/// </summary>
16-
public List<KustomizationCommonLabelsPair> Pairs { get; set; } = new List<KustomizationCommonLabelsPair>();
24+
public KustomizationCommonLabelsPair Pairs { get; set; } = new KustomizationCommonLabelsPair();
1725
}
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
11
namespace KubeOps.Abstractions.Kustomize;
22

3-
public class KustomizationCommonLabelsPair
4-
{
5-
/// <summary>
6-
/// A dictionary of common labels.
7-
/// </summary>
8-
public IDictionary<string, string>? Pairs { get; set; }
9-
10-
/// <summary>
11-
/// Include selectors.
12-
/// </summary>
13-
public bool IncludeSelectors { get; init; } = true;
14-
}
3+
public class KustomizationCommonLabelsPair : Dictionary<string, string>;

0 commit comments

Comments
 (0)