Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ede289b

Browse files
committed
initial check for complete algorithm, will work until merge algorithm is implemented
1 parent e9ef54c commit ede289b

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed

list/src/K8sControllers/BlockK8sController.cs

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using list.K8sHelpers;
55
using list.crd.block;
66
using list.CustomResourceDefinitions;
7+
using System.Net;
8+
using k8s.Models;
79

810
namespace gge.K8sControllers
911
{
@@ -92,30 +94,64 @@ public async Task Process(CrdBlock b)
9294
Console.WriteLine("Addition/Modify detected: " + b.Metadata.Name);
9395
Console.WriteLine("b.Spec.block.state: " + b.Spec.block.state);
9496

97+
// get list associated with block
98+
CrdList l = null;
99+
try
100+
{
101+
// otherwise, if listId is provided, return all properties of list
102+
l = await zK8sList.generic.ReadNamespacedAsync<CrdList>(
103+
Globals.service.kubeconfig.Namespace, b.Spec.block.list);
104+
}
105+
catch (k8s.Autorest.HttpOperationException ex)
106+
{
107+
/*
108+
Console.WriteLine("** one **");
109+
*/
110+
Console.WriteLine("StatusCode: " + ex.Response.StatusCode);
111+
/*
112+
Console.WriteLine(" Message: " + ex.Message);
113+
Console.WriteLine(" Data: " + ex.InnerException.Data);
114+
*/
115+
116+
// abort, list not found
117+
return;
118+
}
119+
95120

96121
// merge blocks if possible
97122

98123
// if all blocks are complete, set list to complete
99124

100-
/*
125+
126+
// temporary check for complete before merge is implemented
127+
long total = 0;
128+
101129
// loop through all blocks associated with deleted list & delete
102130
CustomResourceList<CrdBlock> blocks = await zK8sBlock.generic.ListNamespacedAsync<CustomResourceList<CrdBlock>>(
103131
Globals.service.kubeconfig.Namespace);
104-
Console.WriteLine("items.count: " + blocks.Items.Count());
105132
foreach (CrdBlock block in blocks.Items)
106133
{
107134
// is this block associated with the list?
108-
Console.WriteLine(block.Spec.block.list + " vs " + l.Metadata.Name);
109-
if (block.Spec.block.list.Equals(l.Metadata.Name))
135+
Console.WriteLine(block.Spec.block.list + " vs " + b.Spec.block.list);
136+
if (block.Spec.block.list.Equals(b.Spec.block.list) && block.Spec.block.state.Equals("complete"))
110137
{
111-
// if yes, then delete block
112-
Console.WriteLine("delete block: " + block.Metadata.Name);
113-
zK8sBlock.generic.DeleteNamespacedAsync<CrdBlock>(
114-
Globals.service.kubeconfig.Namespace,
115-
block.Metadata.Name);
138+
// if yes, add to total
139+
total += long.Parse(block.Spec.block.size);
116140
}
117141
}
118-
*/
142+
143+
// check if total is expected total
144+
if (total == long.Parse(l.Spec.list.total))
145+
{
146+
// set list as complete
147+
l.Spec.list.state = "complete";
148+
149+
// patch list with updated state
150+
await zK8sList.generic.PatchNamespacedAsync<CrdList>(
151+
new V1Patch(l, V1Patch.PatchType.MergePatch),
152+
Globals.service.kubeconfig.Namespace,
153+
l.Metadata.Name);
154+
}
119155

120156

121157
return;

0 commit comments

Comments
 (0)