Skip to content

Commit 9253eeb

Browse files
qmfrederikbrendandburns
authored andcommitted
Fix issue where the watcher URLs would be prefixed with a '/'. This would lead to URLs such as https://localhost:8443//api/..., and the double // after the port number would case a 404 NOT FOUND response. (#164)
1 parent e6c1177 commit 9253eeb

File tree

3 files changed

+83
-77
lines changed

3 files changed

+83
-77
lines changed

gen/KubernetesWatchGenerator/Program.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@ static void GetPathExpression(RenderContext context, IList<object> arguments, ID
314314
private static string GetPathExpression(SwaggerOperationDescription operation)
315315
{
316316
string pathExpression = operation.Path;
317+
318+
if(pathExpression.StartsWith("/"))
319+
{
320+
pathExpression = pathExpression.Substring(1);
321+
}
322+
317323
pathExpression = pathExpression.Replace("{namespace}", "{@namespace}");
318324
return pathExpression;
319325
}

src/KubernetesClient/Watcher.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66
using k8s.Exceptions;
7-
using k8s.Models;
7+
using k8s.Models;
88
using Microsoft.Rest;
99
using Microsoft.Rest.Serialization;
1010

@@ -57,19 +57,19 @@ public Watcher(StreamReader streamReader, Action<WatchEventType, T> onEvent, Act
5757
var line = await streamReader.ReadLineAsync();
5858

5959
try
60-
{
61-
var genericEvent = SafeJsonConvert.DeserializeObject<k8s.Watcher<KubernetesObject>.WatchEvent>(line);
62-
63-
if (genericEvent.Object.Kind == "Status")
64-
{
65-
var statusEvent = SafeJsonConvert.DeserializeObject<k8s.Watcher<V1Status>.WatchEvent>(line);
66-
var exception = new KubernetesException(statusEvent.Object);
67-
this.OnError?.Invoke(exception);
68-
}
69-
else
70-
{
71-
var @event = SafeJsonConvert.DeserializeObject<k8s.Watcher<T>.WatchEvent>(line);
72-
this.OnEvent?.Invoke(@event.Type, @event.Object);
60+
{
61+
var genericEvent = SafeJsonConvert.DeserializeObject<k8s.Watcher<KubernetesObject>.WatchEvent>(line);
62+
63+
if (genericEvent.Object.Kind == "Status")
64+
{
65+
var statusEvent = SafeJsonConvert.DeserializeObject<k8s.Watcher<V1Status>.WatchEvent>(line);
66+
var exception = new KubernetesException(statusEvent.Object);
67+
this.OnError?.Invoke(exception);
68+
}
69+
else
70+
{
71+
var @event = SafeJsonConvert.DeserializeObject<k8s.Watcher<T>.WatchEvent>(line);
72+
this.OnEvent?.Invoke(@event.Type, @event.Object);
7373
}
7474
}
7575
catch (Exception e)
@@ -152,4 +152,4 @@ public static Watcher<T> Watch<T>(this HttpOperationResponse<T> response,
152152
return Watch((HttpOperationResponse) response, onEvent, onError);
153153
}
154154
}
155-
}
155+
}

0 commit comments

Comments
 (0)