-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSetAnnotationCommandHandler.cs
44 lines (40 loc) · 1.5 KB
/
SetAnnotationCommandHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Threading.Tasks;
using Arcane.Operator.Services.Base;
using Arcane.Operator.Services.Commands;
using Microsoft.Extensions.Logging;
using Snd.Sdk.Kubernetes.Base;
using Snd.Sdk.Tasks;
namespace Arcane.Operator.Services.CommandHandlers;
public class SetAnnotationCommandHandler : ICommandHandler<SetAnnotationCommand>
{
private readonly IStreamClassRepository streamClassRepository;
private readonly IKubeCluster kubeCluster;
private readonly ILogger<SetAnnotationCommandHandler> logger;
public SetAnnotationCommandHandler(
IStreamClassRepository streamClassRepository,
IKubeCluster kubeCluster,
ILogger<SetAnnotationCommandHandler> logger)
{
this.streamClassRepository = streamClassRepository;
this.kubeCluster = kubeCluster;
this.logger = logger;
}
public Task Handle(SetAnnotationCommand command)
{
var ((nameSpace, kind, streamId), annotationKey, annotationValue) = command;
return this.streamClassRepository.Get(nameSpace, kind).Map(crdConf =>
{
if (crdConf is { HasValue: false })
{
this.logger.LogError("Failed to get configuration for kind {kind}", kind);
return Task.CompletedTask;
}
return this.kubeCluster
.AnnotateObject(crdConf.Value.ToNamespacedCrd(),
annotationKey,
annotationValue,
streamId,
nameSpace);
});
}
}