Skip to content

Commit 931a49c

Browse files
author
Christoph Bühler
committed
fix(operator deployment): add port and probes.
This fixes #52. Adding the missing port definition and the paths for the liveness and readiness probes.
1 parent 3379763 commit 931a49c

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/KubeOps/Operator/Builder/OperatorBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ internal IOperatorBuilder AddOperatorBase(OperatorSettings settings)
114114
_ => new SerializerBuilder()
115115
.ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull)
116116
.WithNamingConvention(new NamingConvention())
117+
.WithTypeConverter(new YamlIntOrStrTypeConverter())
117118
.Build());
118119

119120
Services.AddTransient<EntitySerializer>();

src/KubeOps/Operator/Commands/Generators/OperatorGenerator.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ public async Task<int> OnExecuteAsync(CommandLineApplication app)
4141
{
4242
Image = "operator",
4343
Name = "operator",
44+
Ports = new List<V1ContainerPort>
45+
{
46+
new V1ContainerPort(80, name: "http"),
47+
},
48+
LivenessProbe = new V1Probe(
49+
timeoutSeconds: 1,
50+
initialDelaySeconds: 30,
51+
httpGet: new V1HTTPGetAction("http", path: "/health")),
52+
ReadinessProbe = new V1Probe(
53+
timeoutSeconds: 1,
54+
initialDelaySeconds: 15,
55+
httpGet: new V1HTTPGetAction("http", path: "/ready")),
4456
Resources = new V1ResourceRequirements
4557
{
4658
Requests = new Dictionary<string, ResourceQuantity>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using k8s.Models;
3+
using YamlDotNet.Core;
4+
using YamlDotNet.Core.Events;
5+
using YamlDotNet.Serialization;
6+
7+
namespace KubeOps.Operator.Serialization
8+
{
9+
internal class YamlIntOrStrTypeConverter : IYamlTypeConverter
10+
{
11+
private static readonly Type AcceptType = typeof(IntstrIntOrString);
12+
13+
public bool Accepts(Type type) => type == AcceptType;
14+
15+
public object? ReadYaml(IParser parser, Type type) => (IntstrIntOrString)parser.Consume<Scalar>().Value;
16+
17+
public void WriteYaml(IEmitter emitter, object? value, Type type)
18+
{
19+
var str = value is IntstrIntOrString intstrIntOrString ? intstrIntOrString.Value : string.Empty;
20+
emitter.Emit(new Scalar(str));
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)