Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<SerilogFormattingCompactVersion>1.1.0</SerilogFormattingCompactVersion>
<SerilogSinksConsoleVersion>3.1.1</SerilogSinksConsoleVersion>
<YamlDotNetVersion>16.3.0</YamlDotNetVersion>
<KubernetesClientVersion>17.0.14</KubernetesClientVersion>
<KubernetesClientVersion>18.0.13</KubernetesClientVersion>
<JsonSchemaNetVersion>7.0.2</JsonSchemaNetVersion>
<NewtonsoftJsonVersion>13.0.3</NewtonsoftJsonVersion>
<!-- Container app dependencies -->
Expand Down
27 changes: 15 additions & 12 deletions src/Kubernetes.Controller/Client/ResourceInformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ public override async Task RunAsync(CancellationToken cancellationToken)
}
}

protected abstract Task<HttpOperationResponse<TListResource>> RetrieveResourceListAsync(bool? watch = null, string resourceVersion = null, ResourceSelector<TResource> resourceSelector = null, CancellationToken cancellationToken = default);
protected abstract Task<HttpOperationResponse<TListResource>> RetrieveResourceListAsync(string resourceVersion = null, ResourceSelector<TResource> resourceSelector = null, CancellationToken cancellationToken = default);
protected abstract Watcher<TResource> WatchResourceListAsync(string resourceVersion = null, ResourceSelector<TResource> resourceSelector = null, Action<WatchEventType, TResource> onEvent = null, Action<Exception> onError = null, Action onClosed = null);

private static EventId EventId(EventType eventType) => new EventId((int)eventType, eventType.ToString());

Expand Down Expand Up @@ -254,14 +255,16 @@ private async Task ListAsync(CancellationToken cancellationToken)
{
// for anything which was previously known but not part of list
// send a deleted notification to clear any observer caches
var item = new TResource()
var item = new TResource
{
ApiVersion = _names.GroupApiVersion,
Kind = _names.Kind,
Metadata = new V1ObjectMeta(
name: key.Name,
namespaceProperty: key.Namespace,
ownerReferences: value),
Metadata = new V1ObjectMeta
{
Name = key.Name,
NamespaceProperty = key.Namespace,
OwnerReferences = value
}
};

InvokeRegistrationCallbacks(WatchEventType.Deleted, item);
Expand Down Expand Up @@ -291,15 +294,11 @@ private async Task WatchAsync(CancellationToken cancellationToken)
var watcherCompletionSource = new TaskCompletionSource<int>();

// begin watching where list left off
var watchWithHttpMessage = RetrieveResourceListAsync(watch: true, resourceVersion: _lastResourceVersion, resourceSelector: _selector, cancellationToken: cancellationToken);

var lastEventUtc = DateTime.UtcNow;
using var watcher = watchWithHttpMessage.Watch<TResource, TListResource>(
var watcher = WatchResourceListAsync(resourceVersion: _lastResourceVersion, resourceSelector: _selector,
(watchEventType, item) =>
{
if (!watcherCompletionSource.Task.IsCompleted)
{
lastEventUtc = DateTime.UtcNow;
OnEvent(watchEventType, item);
}
},
Expand All @@ -325,7 +324,10 @@ private async Task WatchAsync(CancellationToken cancellationToken)
() =>
{
watcherCompletionSource.TrySetResult(0);
});
}
);

var lastEventUtc = DateTime.UtcNow;

// reconnect if no events have arrived after a certain time
using var checkLastEventUtcTimer = new Timer(
Expand All @@ -342,6 +344,7 @@ private async Task WatchAsync(CancellationToken cancellationToken)

watcherCompletionSource.TrySetCanceled();
watcher.Dispose();

}
},
state: null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using k8s;
using k8s.Autorest;
using k8s.Models;
Expand All @@ -22,8 +23,13 @@ public V1EndpointsResourceInformer(
{
}

protected override Task<HttpOperationResponse<V1EndpointsList>> RetrieveResourceListAsync(bool? watch = null, string resourceVersion = null, ResourceSelector<V1Endpoints> resourceSelector = null, CancellationToken cancellationToken = default)
protected override Task<HttpOperationResponse<V1EndpointsList>> RetrieveResourceListAsync(string resourceVersion = null, ResourceSelector<V1Endpoints> resourceSelector = null, CancellationToken cancellationToken = default)
{
return Client.CoreV1.ListEndpointsForAllNamespacesWithHttpMessagesAsync(watch: watch, resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, cancellationToken: cancellationToken);
return Client.CoreV1.ListEndpointsForAllNamespacesWithHttpMessagesAsync(resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, cancellationToken: cancellationToken);
}

protected override Watcher<V1Endpoints> WatchResourceListAsync(string resourceVersion = null, ResourceSelector<V1Endpoints> resourceSelector = null, Action<WatchEventType, V1Endpoints> onEvent = null, Action<Exception> onError = null, Action onClosed = null)
{
return Client.CoreV1.WatchListEndpointsForAllNamespaces(resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, onEvent: onEvent, onError: onError, onClosed: onClosed);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using k8s;
using k8s.Autorest;
using k8s.Models;
Expand All @@ -22,8 +23,13 @@ public V1IngressClassResourceInformer(
{
}

protected override Task<HttpOperationResponse<V1IngressClassList>> RetrieveResourceListAsync(bool? watch = null, string resourceVersion = null, ResourceSelector<V1IngressClass> resourceSelector = null, CancellationToken cancellationToken = default)
protected override Task<HttpOperationResponse<V1IngressClassList>> RetrieveResourceListAsync(string resourceVersion = null, ResourceSelector<V1IngressClass> resourceSelector = null, CancellationToken cancellationToken = default)
{
return Client.NetworkingV1.ListIngressClassWithHttpMessagesAsync(watch: watch, resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, cancellationToken: cancellationToken);
return Client.NetworkingV1.ListIngressClassWithHttpMessagesAsync(resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, cancellationToken: cancellationToken);
}

protected override Watcher<V1IngressClass> WatchResourceListAsync(string resourceVersion = null, ResourceSelector<V1IngressClass> resourceSelector = null, Action<WatchEventType, V1IngressClass> onEvent = null, Action<Exception> onError = null, Action onClosed = null)
{
return Client.NetworkingV1.WatchListIngressClass(resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, onEvent: onEvent, onError: onError, onClosed: onClosed);
}
}
11 changes: 9 additions & 2 deletions src/Kubernetes.Controller/Client/V1IngressResourceInformer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using k8s;
using k8s.Autorest;
using k8s.Models;
Expand All @@ -22,8 +23,14 @@ public V1IngressResourceInformer(
{
}

protected override Task<HttpOperationResponse<V1IngressList>> RetrieveResourceListAsync(bool? watch = null, string resourceVersion = null, ResourceSelector<V1Ingress> resourceSelector = null, CancellationToken cancellationToken = default)
protected override Task<HttpOperationResponse<V1IngressList>> RetrieveResourceListAsync(string resourceVersion = null, ResourceSelector<V1Ingress> resourceSelector = null, CancellationToken cancellationToken = default)
{
return Client.NetworkingV1.ListIngressForAllNamespacesWithHttpMessagesAsync(watch: watch, resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, cancellationToken: cancellationToken);
return Client.NetworkingV1.ListIngressForAllNamespacesWithHttpMessagesAsync(resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, cancellationToken: cancellationToken);
}

protected override Watcher<V1Ingress> WatchResourceListAsync(string resourceVersion = null, ResourceSelector<V1Ingress> resourceSelector = null, Action<WatchEventType, V1Ingress> onEvent = null, Action<Exception> onError = null, Action onClosed = null)
{
return Client.NetworkingV1.WatchListIngressForAllNamespaces(resourceVersion: resourceVersion,
fieldSelector: resourceSelector?.FieldSelector, onEvent: onEvent, onError: onError, onClosed: onClosed);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,21 @@ public async Task UpdateStatusAsync(CancellationToken cancellationToken)
var service = await _client.CoreV1.ReadNamespacedServiceStatusAsync(_options.ControllerServiceName, _options.ControllerServiceNamespace, cancellationToken: cancellationToken);
if (service.Status?.LoadBalancer?.Ingress is { } loadBalancerIngresses)
{
var status = new V1IngressStatus(new V1IngressLoadBalancerStatus(loadBalancerIngresses?.Select(ingress => new V1IngressLoadBalancerIngress
var status = new V1IngressStatus
{
Hostname = ingress.Hostname,
Ip = ingress.Ip,
Ports = ingress.Ports?.Select(port => new V1IngressPortStatus(port.Port, port.Protocol, port.Error)).ToArray()
}).ToArray()));
LoadBalancer = new V1IngressLoadBalancerStatus
{
Ingress = loadBalancerIngresses?.Select(ingress => new V1IngressLoadBalancerIngress
{
Hostname = ingress.Hostname,
Ip = ingress.Ip,
Ports = ingress.Ports?.Select(port => new V1IngressPortStatus
{
Port = port.Port, Protocol = port.Protocol, Error = port.Error
}).ToArray()
}).ToArray()
}
};

var ingresses = _cache.GetIngresses().ToArray();
foreach (var ingress in ingresses)
Expand Down
10 changes: 8 additions & 2 deletions src/Kubernetes.Controller/Client/V1SecretResourceInformer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using k8s;
using k8s.Autorest;
using k8s.Models;
Expand All @@ -22,8 +23,13 @@ public V1SecretResourceInformer(
{
}

protected override Task<HttpOperationResponse<V1SecretList>> RetrieveResourceListAsync(bool? watch = null, string resourceVersion = null, ResourceSelector<V1Secret> resourceSelector = null, CancellationToken cancellationToken = default)
protected override Task<HttpOperationResponse<V1SecretList>> RetrieveResourceListAsync(string resourceVersion = null, ResourceSelector<V1Secret> resourceSelector = null, CancellationToken cancellationToken = default)
{
return Client.CoreV1.ListSecretForAllNamespacesWithHttpMessagesAsync(watch: watch, resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, cancellationToken: cancellationToken);
return Client.CoreV1.ListSecretForAllNamespacesWithHttpMessagesAsync(resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, cancellationToken: cancellationToken);
}

protected override Watcher<V1Secret> WatchResourceListAsync(string resourceVersion = null, ResourceSelector<V1Secret> resourceSelector = null, Action<WatchEventType, V1Secret> onEvent = null, Action<Exception> onError = null, Action onClosed = null)
{
return Client.CoreV1.WatchListSecretForAllNamespaces(resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, onEvent: onEvent, onError: onError, onClosed: onClosed);
}
}
10 changes: 8 additions & 2 deletions src/Kubernetes.Controller/Client/V1ServiceResourceInformer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using k8s;
using k8s.Autorest;
using k8s.Models;
Expand All @@ -22,8 +23,13 @@ public V1ServiceResourceInformer(
{
}

protected override Task<HttpOperationResponse<V1ServiceList>> RetrieveResourceListAsync(bool? watch = null, string resourceVersion = null, ResourceSelector<V1Service> resourceSelector = null, CancellationToken cancellationToken = default)
protected override Task<HttpOperationResponse<V1ServiceList>> RetrieveResourceListAsync(string resourceVersion = null, ResourceSelector<V1Service> resourceSelector = null, CancellationToken cancellationToken = default)
{
return Client.CoreV1.ListServiceForAllNamespacesWithHttpMessagesAsync(watch: watch, resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, cancellationToken: cancellationToken);
return Client.CoreV1.ListServiceForAllNamespacesWithHttpMessagesAsync(resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, cancellationToken: cancellationToken);
}

protected override Watcher<V1Service> WatchResourceListAsync(string resourceVersion = null, ResourceSelector<V1Service> resourceSelector = null, Action<WatchEventType, V1Service> onEvent = null, Action<Exception> onError = null, Action onClosed = null)
{
return Client.CoreV1.WatchListServiceForAllNamespaces(resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, onEvent: onEvent, onError: onError, onClosed: onClosed);
}
}
10 changes: 8 additions & 2 deletions test/Kubernetes.Tests/Client/V1DeploymentResourceInformer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using k8s;
using k8s.Autorest;
using k8s.Models;
Expand All @@ -22,8 +23,13 @@ public V1DeploymentResourceInformer(
{
}

protected override Task<HttpOperationResponse<V1DeploymentList>> RetrieveResourceListAsync(bool? watch = null, string resourceVersion = null, ResourceSelector<V1Deployment> resourceSelector = null, CancellationToken cancellationToken = default)
protected override Task<HttpOperationResponse<V1DeploymentList>> RetrieveResourceListAsync(string resourceVersion = null, ResourceSelector<V1Deployment> resourceSelector = null, CancellationToken cancellationToken = default)
{
return Client.AppsV1.ListDeploymentForAllNamespacesWithHttpMessagesAsync(watch: watch, resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, cancellationToken: cancellationToken);
return Client.AppsV1.ListDeploymentForAllNamespacesWithHttpMessagesAsync(resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, cancellationToken: cancellationToken);
}

protected override Watcher<V1Deployment> WatchResourceListAsync(string resourceVersion = null, ResourceSelector<V1Deployment> resourceSelector = null, Action<WatchEventType, V1Deployment> onEvent = null, Action<Exception> onError = null, Action onClosed = null)
{
return Client.AppsV1.WatchListDeploymentForAllNamespaces(resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, onEvent: onEvent, onError: onError, onClosed: onClosed);
}
}
10 changes: 8 additions & 2 deletions test/Kubernetes.Tests/Client/V1PodResourceInformer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using k8s;
using k8s.Autorest;
using k8s.Models;
Expand All @@ -22,8 +23,13 @@ public V1PodResourceInformer(
{
}

protected override Task<HttpOperationResponse<V1PodList>> RetrieveResourceListAsync(bool? watch = null, string resourceVersion = null, ResourceSelector<V1Pod> resourceSelector = null, CancellationToken cancellationToken = default)
protected override Task<HttpOperationResponse<V1PodList>> RetrieveResourceListAsync(string resourceVersion = null, ResourceSelector<V1Pod> resourceSelector = null, CancellationToken cancellationToken = default)
{
return Client.CoreV1.ListPodForAllNamespacesWithHttpMessagesAsync(watch: watch, resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, cancellationToken: cancellationToken);
return Client.CoreV1.ListPodForAllNamespacesWithHttpMessagesAsync(resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, cancellationToken: cancellationToken);
}

protected override Watcher<V1Pod> WatchResourceListAsync(string resourceVersion = null, ResourceSelector<V1Pod> resourceSelector = null, Action<WatchEventType, V1Pod> onEvent = null, Action<Exception> onError = null, Action onClosed = null)
{
return Client.CoreV1.WatchListPodForAllNamespaces(resourceVersion: resourceVersion, fieldSelector: resourceSelector?.FieldSelector, onEvent: onEvent, onError: onError, onClosed: onClosed);
}
}
23 changes: 12 additions & 11 deletions test/Kubernetes.Tests/NamespacedNameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public void EqualityAndInequality(
[Fact]
public void NamespaceAndNameFromResource()
{
var resource = new V1ConfigMap(
apiVersion: V1ConfigMap.KubeApiVersion,
kind: V1ConfigMap.KubeKind,
metadata: new V1ObjectMeta(
name: "the-name",
namespaceProperty: "the-namespace"));
var resource = new V1ConfigMap
{
ApiVersion = V1ConfigMap.KubeApiVersion,
Kind = V1ConfigMap.KubeKind,
Metadata = new V1ObjectMeta {Name = "the-name", NamespaceProperty = "the-namespace"}
};

var nn = NamespacedName.From(resource);

Expand All @@ -78,11 +78,12 @@ public void NamespaceAndNameFromResource()
[Fact]
public void JustNameFromClusterResource()
{
var resource = new V1ClusterRole(
apiVersion: V1ClusterRole.KubeApiVersion,
kind: V1ClusterRole.KubeKind,
metadata: new V1ObjectMeta(
name: "the-name"));
var resource = new V1ClusterRole
{
ApiVersion = V1ClusterRole.KubeApiVersion,
Kind = V1ClusterRole.KubeKind,
Metadata = new V1ObjectMeta { Name = "the-name" }
};

var nn = NamespacedName.From(resource);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public async Task<IActionResult> ListAsync(ListParameters parameters)
var result = new KubernetesList<ResourceObject>(
apiVersion: Version,
kind: "PodList",
metadata: new V1ListMeta(
continueProperty: list.Continue,
remainingItemCount: null,
resourceVersion: list.ResourceVersion),
metadata: new V1ListMeta
{
ContinueProperty = list.Continue, RemainingItemCount = null, ResourceVersion = list.ResourceVersion
},
items: list.Items);

return new ObjectResult(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public async Task<IActionResult> ListAsync(ListParameters parameters)
var result = new KubernetesList<ResourceObject>(
apiVersion: $"{Group}/{Version}",
kind: "DeploymentList",
metadata: new V1ListMeta(
continueProperty: list.Continue,
remainingItemCount: null,
resourceVersion: list.ResourceVersion),
metadata: new V1ListMeta
{
ContinueProperty = list.Continue, RemainingItemCount = null, ResourceVersion = list.ResourceVersion
},
items: list.Items);

return new ObjectResult(result);
Expand Down
Loading