Skip to content

Commit 3cc7562

Browse files
authored
fix: Resource Status Comparison (#112)
This fix allows for complex status objects.
1 parent eb1ba60 commit 3cc7562

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

src/KubeOps/Operator/Caching/ResourceCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private CacheComparisonResult CompareCache(TEntity resource)
7777
return CacheComparisonResult.NotModified;
7878
}
7979

80-
if (comparison.Differences.All(d => d.ParentPropertyName == Status))
80+
if (comparison.Differences.All(d => d.PropertyName.Split('.')[0] == Status))
8181
{
8282
return CacheComparisonResult.StatusModified;
8383
}

tests/KubeOps.Test/Operator/Caching/ResourceCache.Test.cs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using FluentAssertions;
34
using k8s.Models;
45
using KubeOps.Operator;
@@ -135,6 +136,58 @@ public void Should_Remove_Object()
135136
CacheComparisonResult.StatusModified,
136137
},
137138
new object?[]
139+
{
140+
new TestStatusEntity
141+
{
142+
Metadata = new V1ObjectMeta { Uid = "test" },
143+
Status = new TestStatusEntityStatus { StatusString = "status" },
144+
},
145+
new TestStatusEntity
146+
{
147+
Metadata = new V1ObjectMeta { Uid = "test" },
148+
#pragma warning disable 8625
149+
Status = null,
150+
#pragma warning restore 8625
151+
},
152+
CacheComparisonResult.StatusModified,
153+
},
154+
new object?[]
155+
{
156+
new TestStatusEntity
157+
{
158+
Metadata = new V1ObjectMeta { Uid = "test" },
159+
Status = new TestStatusEntityStatus
160+
{
161+
StatusString = "status",
162+
StatusList = new List<ComplexStatusObject>()
163+
{
164+
new ComplexStatusObject()
165+
{
166+
ObjectName = "status",
167+
LastModified = DateTime.Parse("2020-01-01")
168+
}
169+
}
170+
},
171+
},
172+
new TestStatusEntity
173+
{
174+
Metadata = new V1ObjectMeta { Uid = "test" },
175+
Status = new TestStatusEntityStatus
176+
{
177+
StatusString = "status",
178+
StatusList = new List<ComplexStatusObject>()
179+
{
180+
new ComplexStatusObject()
181+
{
182+
ObjectName = "status",
183+
LastModified = DateTime.Parse("2020-01-02")
184+
}
185+
}
186+
},
187+
},
188+
CacheComparisonResult.StatusModified,
189+
},
190+
new object?[]
138191
{
139192
new TestStatusEntity
140193
{

tests/KubeOps.Test/TestEntities/TestStatusEntity.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using k8s.Models;
1+
using System;
2+
using System.Collections.Generic;
3+
using k8s.Models;
24
using KubeOps.Operator.Entities;
35

46
namespace KubeOps.Test.TestEntities
@@ -11,6 +13,13 @@ public class TestStatusEntitySpec
1113
public class TestStatusEntityStatus
1214
{
1315
public string StatusString { get; set; } = string.Empty;
16+
public List<ComplexStatusObject> StatusList { get; set; } = new List<ComplexStatusObject>();
17+
}
18+
19+
public class ComplexStatusObject
20+
{
21+
public string ObjectName { get; set; } = string.Empty;
22+
public DateTime LastModified { get; set; }
1423
}
1524

1625
[KubernetesEntity(Group = "kubeops.test.dev", ApiVersion = "V1")]

0 commit comments

Comments
 (0)