From 16845bae1d8dda30407b3bdb375a9b5800eca12c Mon Sep 17 00:00:00 2001 From: Boshi Lian Date: Sun, 1 Nov 2020 12:24:51 -0800 Subject: [PATCH] Style fix1 (#512) * fix SA1505 and SA1508 * fix SA1116 * fix SA1009 * fix SA1019 * fix SA1127 * fix SA1128 * fix SA1134 * fix indent * allow CA2227 * fix CA1810 * using clean up * fix naming * fix CA1806 * fix await * Revert "fix CA1806" This reverts commit a3b465087fdaf26ec461272373ee9810a90de2cc. * fix dotnet format * allow SA1009 --- examples/logs/Logs.cs | 4 +- kubernetes-client.ruleset | 8 ++-- .../Authentication/TokenFileAuth.cs | 4 +- src/KubernetesClient/ByteBuffer.cs | 3 +- src/KubernetesClient/CertUtils.cs | 2 - .../Exceptions/KubeConfigException.cs | 4 +- .../Exceptions/KubernetesClientException.cs | 4 +- src/KubernetesClient/Extensions.cs | 16 ++----- src/KubernetesClient/IntstrIntOrString.cs | 2 - .../KubeConfigModels/AuthProvider.cs | 7 ++- .../KubeConfigModels/Cluster.cs | 4 +- .../KubeConfigModels/ClusterEndpoint.cs | 6 +-- .../KubeConfigModels/Context.cs | 6 +-- .../KubeConfigModels/ContextDetails.cs | 6 +-- .../ExecCredentialResponse.cs | 9 ++-- .../KubeConfigModels/ExternalExecution.cs | 3 +- .../KubeConfigModels/K8SConfiguration.cs | 12 +++-- src/KubernetesClient/KubeConfigModels/User.cs | 4 +- .../KubeConfigModels/UserCredentials.cs | 7 ++- src/KubernetesClient/Kubernetes.ConfigInit.cs | 12 +++-- src/KubernetesClient/Kubernetes.Exec.cs | 3 +- src/KubernetesClient/Kubernetes.Watch.cs | 9 ++-- src/KubernetesClient/Kubernetes.WebSocket.cs | 3 +- ...ubernetesClientConfiguration.ConfigFile.cs | 47 ++++++++++++------- src/KubernetesClient/KubernetesList.cs | 7 +-- src/KubernetesClient/ModelExtensions.cs | 15 ++++-- src/KubernetesClient/StreamType.cs | 2 - src/KubernetesClient/StringQuotingEmitter.cs | 7 +-- src/KubernetesClient/V1Patch.cs | 3 +- .../Versioning/KubernetesVersionComparer.cs | 14 ++---- .../Versioning/VersionConverter.cs | 5 +- src/KubernetesClient/Watcher.cs | 15 ++++-- .../WatcherDelegatingHandler.cs | 4 +- src/KubernetesClient/WatcherExt.cs | 9 ++-- src/KubernetesClient/WebSocketBuilder.cs | 1 - src/KubernetesClient/Yaml.cs | 3 +- .../generated/VersionConverter.cs | 4 -- tests/KubernetesClient.Tests/AuthTests.cs | 6 +-- .../KubernetesClient.Tests/ByteBufferTests.cs | 5 +- .../KubernetesClient.Tests/CertUtilsTests.cs | 9 ++-- .../CertificateValidationTests.cs | 3 -- .../GcpTokenProviderTests.cs | 1 - .../KubernetesClientConfigurationTests.cs | 12 +++-- .../Logging/TestOutputLogger.cs | 3 +- .../Mock/MockWebSocket.cs | 6 ++- .../Server/Controllers/PodExecController.cs | 1 - .../Controllers/PodPortForwardController.cs | 1 - tests/KubernetesClient.Tests/PodExecTests.cs | 21 +++++---- .../StreamDemuxerTests.cs | 28 +++++++---- tests/KubernetesClient.Tests/TaskAssert.cs | 1 - .../TokenFileAuthTests.cs | 1 - .../VersionConverterTests.cs | 1 - tests/KubernetesClient.Tests/WatchTests.cs | 5 +- .../WebSocketTestBase.cs | 3 +- tests/KubernetesClient.Tests/YamlTests.cs | 10 ++-- 55 files changed, 212 insertions(+), 179 deletions(-) diff --git a/examples/logs/Logs.cs b/examples/logs/Logs.cs index ebd7716..cdc21c8 100755 --- a/examples/logs/Logs.cs +++ b/examples/logs/Logs.cs @@ -1,5 +1,4 @@ using System; -using System.IO; using System.Threading.Tasks; using k8s; @@ -22,7 +21,8 @@ namespace logs var pod = list.Items[0]; - var response = await client.ReadNamespacedPodLogWithHttpMessagesAsync(pod.Metadata.Name, + var response = await client.ReadNamespacedPodLogWithHttpMessagesAsync( + pod.Metadata.Name, pod.Metadata.NamespaceProperty, follow: true).ConfigureAwait(false); var stream = response.Body; stream.CopyTo(Console.OpenStandardOutput()); diff --git a/kubernetes-client.ruleset b/kubernetes-client.ruleset index a6bbe9d..0dc69f6 100644 --- a/kubernetes-client.ruleset +++ b/kubernetes-client.ruleset @@ -106,7 +106,7 @@ - + @@ -175,7 +175,7 @@ - + @@ -205,10 +205,10 @@ - + - + diff --git a/src/KubernetesClient/Authentication/TokenFileAuth.cs b/src/KubernetesClient/Authentication/TokenFileAuth.cs index ec9ea4d..6598e37 100644 --- a/src/KubernetesClient/Authentication/TokenFileAuth.cs +++ b/src/KubernetesClient/Authentication/TokenFileAuth.cs @@ -18,7 +18,7 @@ namespace k8s.Authentication TokenFile = tokenFile; } - public async Task GetAuthenticationHeaderAsync(CancellationToken cancellationToken) + public Task GetAuthenticationHeaderAsync(CancellationToken cancellationToken) { if (TokenExpiresAt < DateTime.UtcNow) { @@ -32,7 +32,7 @@ namespace k8s.Authentication TokenExpiresAt = DateTime.UtcNow.AddMinutes(1); } - return new AuthenticationHeaderValue("Bearer", token); + return Task.FromResult(new AuthenticationHeaderValue("Bearer", token)); } } } diff --git a/src/KubernetesClient/ByteBuffer.cs b/src/KubernetesClient/ByteBuffer.cs index 0dc638f..4bc2d28 100644 --- a/src/KubernetesClient/ByteBuffer.cs +++ b/src/KubernetesClient/ByteBuffer.cs @@ -282,7 +282,8 @@ namespace k8s Array.Copy(this.buffer, 0, newBuffer, 0, this.WriteWaterMark); int trailingDataLength = this.buffer.Length - this.ReadWaterMark; - Array.Copy(this.buffer, + Array.Copy( + this.buffer, sourceIndex: this.ReadWaterMark, destinationArray: newBuffer, destinationIndex: newBuffer.Length - trailingDataLength, diff --git a/src/KubernetesClient/CertUtils.cs b/src/KubernetesClient/CertUtils.cs index 9e3bbf8..84abf09 100644 --- a/src/KubernetesClient/CertUtils.cs +++ b/src/KubernetesClient/CertUtils.cs @@ -5,10 +5,8 @@ using Org.BouncyCastle.Pkcs; using Org.BouncyCastle.Security; using Org.BouncyCastle.X509; using System; -using System.Collections.Generic; using System.IO; using System.Security.Cryptography.X509Certificates; -using System.Text.RegularExpressions; namespace k8s { diff --git a/src/KubernetesClient/Exceptions/KubeConfigException.cs b/src/KubernetesClient/Exceptions/KubeConfigException.cs index f9d9b06..e0cfb0d 100644 --- a/src/KubernetesClient/Exceptions/KubeConfigException.cs +++ b/src/KubernetesClient/Exceptions/KubeConfigException.cs @@ -1,7 +1,7 @@ +using System; + namespace k8s.Exceptions { - using System; - /// /// The exception that is thrown when the kube config is invalid /// diff --git a/src/KubernetesClient/Exceptions/KubernetesClientException.cs b/src/KubernetesClient/Exceptions/KubernetesClientException.cs index 9f2344b..dde2913 100644 --- a/src/KubernetesClient/Exceptions/KubernetesClientException.cs +++ b/src/KubernetesClient/Exceptions/KubernetesClientException.cs @@ -1,7 +1,7 @@ +using System; + namespace k8s.Exceptions { - using System; - /// /// The exception that is thrown when there is a client exception /// diff --git a/src/KubernetesClient/Extensions.cs b/src/KubernetesClient/Extensions.cs index aa4829c..09696c9 100644 --- a/src/KubernetesClient/Extensions.cs +++ b/src/KubernetesClient/Extensions.cs @@ -1,22 +1,15 @@ using System; -using System.Collections.Concurrent; -using System.Linq; -using System.Net; -using System.Net.Http; using System.Reflection; using System.Text.RegularExpressions; -using System.Threading.Tasks; using k8s.Models; -using Microsoft.Rest; -using Microsoft.Rest.TransientFaultHandling; -using Newtonsoft.Json.Converters; -using VersionConverter = k8s.Versioning.VersionConverter; namespace k8s { public static class Extensions { - public static KubernetesEntityAttribute GetKubernetesTypeMetadata(this T obj) where T : IKubernetesObject => + public static KubernetesEntityAttribute GetKubernetesTypeMetadata(this T obj) + where T : IKubernetesObject + => obj.GetType().GetKubernetesTypeMetadata(); public static KubernetesEntityAttribute GetKubernetesTypeMetadata(this Type currentType) { @@ -29,7 +22,8 @@ namespace k8s return attr; } - public static T Initialize(this T obj) where T : IKubernetesObject + public static T Initialize(this T obj) + where T : IKubernetesObject { var metadata = obj.GetKubernetesTypeMetadata(); obj.ApiVersion = !string.IsNullOrEmpty(metadata.Group) ? $"{metadata.Group}/{metadata.ApiVersion}" : metadata.ApiVersion; diff --git a/src/KubernetesClient/IntstrIntOrString.cs b/src/KubernetesClient/IntstrIntOrString.cs index f02473e..68bbbd1 100644 --- a/src/KubernetesClient/IntstrIntOrString.cs +++ b/src/KubernetesClient/IntstrIntOrString.cs @@ -1,7 +1,5 @@ using System; using Newtonsoft.Json; -using YamlDotNet.Core.Events; -using YamlDotNet.Core.Tokens; namespace k8s.Models { diff --git a/src/KubernetesClient/KubeConfigModels/AuthProvider.cs b/src/KubernetesClient/KubeConfigModels/AuthProvider.cs index 8ab4f87..7c77c36 100644 --- a/src/KubernetesClient/KubeConfigModels/AuthProvider.cs +++ b/src/KubernetesClient/KubeConfigModels/AuthProvider.cs @@ -1,9 +1,8 @@ +using System.Collections.Generic; +using YamlDotNet.Serialization; + namespace k8s.KubeConfigModels { - using System.Collections.Generic; - using YamlDotNet.RepresentationModel; - using YamlDotNet.Serialization; - /// /// Contains information that describes identity information. This is use to tell the kubernetes cluster who you are. /// diff --git a/src/KubernetesClient/KubeConfigModels/Cluster.cs b/src/KubernetesClient/KubeConfigModels/Cluster.cs index 01a16c5..4d0a815 100644 --- a/src/KubernetesClient/KubeConfigModels/Cluster.cs +++ b/src/KubernetesClient/KubeConfigModels/Cluster.cs @@ -1,7 +1,7 @@ +using YamlDotNet.Serialization; + namespace k8s.KubeConfigModels { - using YamlDotNet.Serialization; - /// /// Relates nicknames to cluster information. /// diff --git a/src/KubernetesClient/KubeConfigModels/ClusterEndpoint.cs b/src/KubernetesClient/KubeConfigModels/ClusterEndpoint.cs index 478831e..c86034a 100644 --- a/src/KubernetesClient/KubeConfigModels/ClusterEndpoint.cs +++ b/src/KubernetesClient/KubeConfigModels/ClusterEndpoint.cs @@ -1,8 +1,8 @@ +using System.Collections.Generic; +using YamlDotNet.Serialization; + namespace k8s.KubeConfigModels { - using System.Collections.Generic; - using YamlDotNet.Serialization; - /// /// Contains information about how to communicate with a kubernetes cluster /// diff --git a/src/KubernetesClient/KubeConfigModels/Context.cs b/src/KubernetesClient/KubeConfigModels/Context.cs index d23fc2d..739b6dd 100644 --- a/src/KubernetesClient/KubeConfigModels/Context.cs +++ b/src/KubernetesClient/KubeConfigModels/Context.cs @@ -1,8 +1,8 @@ +using System; +using YamlDotNet.Serialization; + namespace k8s.KubeConfigModels { - using System; - using YamlDotNet.Serialization; - /// /// Relates nicknames to context information. /// diff --git a/src/KubernetesClient/KubeConfigModels/ContextDetails.cs b/src/KubernetesClient/KubeConfigModels/ContextDetails.cs index 43dc917..1fc5bfa 100644 --- a/src/KubernetesClient/KubeConfigModels/ContextDetails.cs +++ b/src/KubernetesClient/KubeConfigModels/ContextDetails.cs @@ -1,8 +1,8 @@ +using System.Collections.Generic; +using YamlDotNet.Serialization; + namespace k8s.KubeConfigModels { - using System.Collections.Generic; - using YamlDotNet.Serialization; - /// /// Represents a tuple of references to a cluster (how do I communicate with a kubernetes cluster), /// a user (how do I identify myself), and a namespace (what subset of resources do I want to work with) diff --git a/src/KubernetesClient/KubeConfigModels/ExecCredentialResponse.cs b/src/KubernetesClient/KubeConfigModels/ExecCredentialResponse.cs index 78c3bed..0c353fb 100644 --- a/src/KubernetesClient/KubeConfigModels/ExecCredentialResponse.cs +++ b/src/KubernetesClient/KubeConfigModels/ExecCredentialResponse.cs @@ -5,8 +5,11 @@ namespace k8s.KubeConfigModels { public class ExecCredentialResponse { - [JsonProperty("apiVersion")] public string ApiVersion { get; set; } - [JsonProperty("kind")] public string Kind { get; set; } - [JsonProperty("status")] public IDictionary Status { get; set; } + [JsonProperty("apiVersion")] + public string ApiVersion { get; set; } + [JsonProperty("kind")] + public string Kind { get; set; } + [JsonProperty("status")] + public IDictionary Status { get; set; } } } diff --git a/src/KubernetesClient/KubeConfigModels/ExternalExecution.cs b/src/KubernetesClient/KubeConfigModels/ExternalExecution.cs index 811192b..650d6d9 100644 --- a/src/KubernetesClient/KubeConfigModels/ExternalExecution.cs +++ b/src/KubernetesClient/KubeConfigModels/ExternalExecution.cs @@ -5,7 +5,8 @@ namespace k8s.KubeConfigModels { public class ExternalExecution { - [YamlMember(Alias = "apiVersion")] public string ApiVersion { get; set; } + [YamlMember(Alias = "apiVersion")] + public string ApiVersion { get; set; } /// /// The command to execute. Required. diff --git a/src/KubernetesClient/KubeConfigModels/K8SConfiguration.cs b/src/KubernetesClient/KubeConfigModels/K8SConfiguration.cs index 18eb9d6..2f66759 100644 --- a/src/KubernetesClient/KubeConfigModels/K8SConfiguration.cs +++ b/src/KubernetesClient/KubeConfigModels/K8SConfiguration.cs @@ -1,8 +1,8 @@ +using System.Collections.Generic; +using YamlDotNet.Serialization; + namespace k8s.KubeConfigModels { - using System.Collections.Generic; - using YamlDotNet.Serialization; - /// /// kubeconfig configuration model. Holds the information needed to build connect to remote /// Kubernetes clusters as a given user. @@ -19,9 +19,11 @@ namespace k8s.KubeConfigModels [YamlMember(Alias = "preferences")] public IDictionary Preferences { get; set; } - [YamlMember(Alias = "apiVersion")] public string ApiVersion { get; set; } + [YamlMember(Alias = "apiVersion")] + public string ApiVersion { get; set; } - [YamlMember(Alias = "kind")] public string Kind { get; set; } + [YamlMember(Alias = "kind")] + public string Kind { get; set; } /// /// Gets or sets the name of the context that you would like to use by default. diff --git a/src/KubernetesClient/KubeConfigModels/User.cs b/src/KubernetesClient/KubeConfigModels/User.cs index e0ef9b3..b92d7c5 100644 --- a/src/KubernetesClient/KubeConfigModels/User.cs +++ b/src/KubernetesClient/KubeConfigModels/User.cs @@ -1,7 +1,7 @@ +using YamlDotNet.Serialization; + namespace k8s.KubeConfigModels { - using YamlDotNet.Serialization; - /// /// Relates nicknames to auth information. /// diff --git a/src/KubernetesClient/KubeConfigModels/UserCredentials.cs b/src/KubernetesClient/KubeConfigModels/UserCredentials.cs index 7ab580e..ea91dff 100644 --- a/src/KubernetesClient/KubeConfigModels/UserCredentials.cs +++ b/src/KubernetesClient/KubeConfigModels/UserCredentials.cs @@ -1,9 +1,8 @@ +using System.Collections.Generic; +using YamlDotNet.Serialization; + namespace k8s.KubeConfigModels { - using System.Collections.Generic; - using YamlDotNet.RepresentationModel; - using YamlDotNet.Serialization; - /// /// Contains information that describes identity information. This is use to tell the kubernetes cluster who you are. /// diff --git a/src/KubernetesClient/Kubernetes.ConfigInit.cs b/src/KubernetesClient/Kubernetes.ConfigInit.cs index c43c1b8..208293c 100644 --- a/src/KubernetesClient/Kubernetes.ConfigInit.cs +++ b/src/KubernetesClient/Kubernetes.ConfigInit.cs @@ -22,7 +22,8 @@ namespace k8s /// /// The to use for all requests. /// - public Kubernetes(KubernetesClientConfiguration config, HttpClient httpClient) : this(config, httpClient, false) + public Kubernetes(KubernetesClientConfiguration config, HttpClient httpClient) + : this(config, httpClient, false) { } @@ -38,7 +39,8 @@ namespace k8s /// /// Whether or not the object should own the lifetime of . /// - public Kubernetes(KubernetesClientConfiguration config, HttpClient httpClient, bool disposeHttpClient) : this( + public Kubernetes(KubernetesClientConfiguration config, HttpClient httpClient, bool disposeHttpClient) + : this( httpClient, disposeHttpClient) { ValidateConfig(config); @@ -179,12 +181,14 @@ namespace k8s /// A that simply forwards a request with no further processing. private sealed class ForwardingHandler : DelegatingHandler { - public ForwardingHandler(HttpMessageHandler handler) : base(handler) + public ForwardingHandler(HttpMessageHandler handler) + : base(handler) { } } - private void AppendDelegatingHandler() where T : DelegatingHandler, new() + private void AppendDelegatingHandler() + where T : DelegatingHandler, new() { var cur = FirstMessageHandler as DelegatingHandler; diff --git a/src/KubernetesClient/Kubernetes.Exec.cs b/src/KubernetesClient/Kubernetes.Exec.cs index d8856c7..16d3135 100644 --- a/src/KubernetesClient/Kubernetes.Exec.cs +++ b/src/KubernetesClient/Kubernetes.Exec.cs @@ -23,7 +23,8 @@ namespace k8s try { - using (var muxedStream = await this.MuxedStreamNamespacedPodExecAsync(name: name, + using (var muxedStream = await this.MuxedStreamNamespacedPodExecAsync( + name: name, @namespace: @namespace, command: command, container: container, tty: tty, cancellationToken: cancellationToken).ConfigureAwait(false)) using (Stream stdIn = muxedStream.GetStream(null, ChannelIndex.StdIn)) diff --git a/src/KubernetesClient/Kubernetes.Watch.cs b/src/KubernetesClient/Kubernetes.Watch.cs index b849858..af38273 100644 --- a/src/KubernetesClient/Kubernetes.Watch.cs +++ b/src/KubernetesClient/Kubernetes.Watch.cs @@ -96,7 +96,8 @@ namespace k8s uriBuilder.Query = query.Length == 0 ? "" - : query.ToString(1, + : query.ToString( + 1, query.Length - 1); // UriBuilder.Query doesn't like leading '?' chars, so trim it // Create HTTP transport objects @@ -145,7 +146,8 @@ namespace k8s { string responseContent = string.Empty; - var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", + var ex = new HttpOperationException(string.Format( + "Operation returned an invalid status code '{0}'", httpResponse.StatusCode)); if (httpResponse.Content != null) { @@ -160,7 +162,8 @@ namespace k8s throw ex; } - return new Watcher(async () => + return new Watcher( + async () => { var stream = await httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false); StreamReader reader = new StreamReader(stream); diff --git a/src/KubernetesClient/Kubernetes.WebSocket.cs b/src/KubernetesClient/Kubernetes.WebSocket.cs index 84f68bd..1b8caa7 100644 --- a/src/KubernetesClient/Kubernetes.WebSocket.cs +++ b/src/KubernetesClient/Kubernetes.WebSocket.cs @@ -37,7 +37,8 @@ namespace k8s } /// - public virtual async Task MuxedStreamNamespacedPodExecAsync(string name, + public virtual async Task MuxedStreamNamespacedPodExecAsync( + string name, string @namespace = "default", IEnumerable command = null, string container = null, bool stderr = true, bool stdin = true, bool stdout = true, bool tty = true, string webSocketSubProtol = WebSocketProtocol.V4BinaryWebsocketProtocol, diff --git a/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs b/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs index 0cb058e..2d43577 100644 --- a/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs +++ b/src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs @@ -76,7 +76,8 @@ namespace k8s /// kube api server endpoint /// When , the paths in the kubeconfig file will be considered to be relative to the directory in which the kubeconfig /// file is located. When , the paths will be considered to be relative to the current working directory. - public static KubernetesClientConfiguration BuildConfigFromConfigFile(string kubeconfigPath = null, + public static KubernetesClientConfiguration BuildConfigFromConfigFile( + string kubeconfigPath = null, string currentContext = null, string masterUrl = null, bool useRelativePaths = true) { return BuildConfigFromConfigFile(new FileInfo(kubeconfigPath ?? KubeConfigDefaultLocation), currentContext, @@ -91,7 +92,8 @@ namespace k8s /// override the kube api server endpoint, set null if do not want to override /// When , the paths in the kubeconfig file will be considered to be relative to the directory in which the kubeconfig /// file is located. When , the paths will be considered to be relative to the current working directory. - public static KubernetesClientConfiguration BuildConfigFromConfigFile(FileInfo kubeconfig, + public static KubernetesClientConfiguration BuildConfigFromConfigFile( + FileInfo kubeconfig, string currentContext = null, string masterUrl = null, bool useRelativePaths = true) { return BuildConfigFromConfigFileAsync(kubeconfig, currentContext, masterUrl, useRelativePaths).GetAwaiter() @@ -106,7 +108,8 @@ namespace k8s /// override the kube api server endpoint, set null if do not want to override /// When , the paths in the kubeconfig file will be considered to be relative to the directory in which the kubeconfig /// file is located. When , the paths will be considered to be relative to the current working directory. - public static async Task BuildConfigFromConfigFileAsync(FileInfo kubeconfig, + public static async Task BuildConfigFromConfigFileAsync( + FileInfo kubeconfig, string currentContext = null, string masterUrl = null, bool useRelativePaths = true) { if (kubeconfig == null) @@ -126,7 +129,8 @@ namespace k8s /// Stream of the kubeconfig, cannot be null /// Override the current context in config, set null if do not want to override /// Override the Kubernetes API server endpoint, set null if do not want to override - public static KubernetesClientConfiguration BuildConfigFromConfigFile(Stream kubeconfig, + public static KubernetesClientConfiguration BuildConfigFromConfigFile( + Stream kubeconfig, string currentContext = null, string masterUrl = null) { return BuildConfigFromConfigFileAsync(kubeconfig, currentContext, masterUrl).GetAwaiter().GetResult(); @@ -138,7 +142,8 @@ namespace k8s /// Stream of the kubeconfig, cannot be null /// Override the current context in config, set null if do not want to override /// Override the Kubernetes API server endpoint, set null if do not want to override - public static async Task BuildConfigFromConfigFileAsync(Stream kubeconfig, + public static async Task BuildConfigFromConfigFileAsync( + Stream kubeconfig, string currentContext = null, string masterUrl = null) { if (kubeconfig == null) @@ -165,11 +170,13 @@ namespace k8s /// A , for example loaded from /// Override the current context in config, set null if do not want to override /// Override the Kubernetes API server endpoint, set null if do not want to override - public static KubernetesClientConfiguration BuildConfigFromConfigObject(K8SConfiguration k8SConfig, + public static KubernetesClientConfiguration BuildConfigFromConfigObject( + K8SConfiguration k8SConfig, string currentContext = null, string masterUrl = null) => GetKubernetesClientConfiguration(currentContext, masterUrl, k8SConfig); - private static KubernetesClientConfiguration GetKubernetesClientConfiguration(string currentContext, + private static KubernetesClientConfiguration GetKubernetesClientConfiguration( + string currentContext, string masterUrl, K8SConfiguration k8SConfig) { var k8SConfiguration = new KubernetesClientConfiguration(); @@ -232,7 +239,8 @@ namespace k8s private void SetClusterDetails(K8SConfiguration k8SConfig, Context activeContext) { var clusterDetails = - k8SConfig.Clusters.FirstOrDefault(c => c.Name.Equals(activeContext.ContextDetails.Cluster, + k8SConfig.Clusters.FirstOrDefault(c => c.Name.Equals( + activeContext.ContextDetails.Cluster, StringComparison.OrdinalIgnoreCase)); if (clusterDetails?.ClusterEndpoint == null) @@ -262,7 +270,8 @@ namespace k8s } else if (!string.IsNullOrEmpty(clusterDetails.ClusterEndpoint.CertificateAuthority)) { - SslCaCerts = new X509Certificate2Collection(new X509Certificate2(GetFullPath(k8SConfig, + SslCaCerts = new X509Certificate2Collection(new X509Certificate2(GetFullPath( + k8SConfig, clusterDetails.ClusterEndpoint.CertificateAuthority))); } } @@ -275,7 +284,8 @@ namespace k8s return; } - var userDetails = k8SConfig.Users.FirstOrDefault(c => c.Name.Equals(activeContext.ContextDetails.User, + var userDetails = k8SConfig.Users.FirstOrDefault(c => c.Name.Equals( + activeContext.ContextDetails.User, StringComparison.OrdinalIgnoreCase)); if (userDetails == null) @@ -343,15 +353,17 @@ namespace k8s expires = DateTimeOffset.FromUnixTimeSeconds(expiresOn); #endif - if (DateTimeOffset.Compare(expires, - DateTimeOffset.Now) + if (DateTimeOffset.Compare( + expires, + DateTimeOffset.Now) <= 0) { var tenantId = config["tenant-id"]; var clientId = config["client-id"]; var apiServerId = config["apiserver-id"]; var refresh = config["refresh-token"]; - var newToken = RenewAzureToken(tenantId, + var newToken = RenewAzureToken( + tenantId, clientId, apiServerId, refresh); @@ -533,7 +545,8 @@ namespace k8s /// When , the paths in the kubeconfig file will be considered to be relative to the directory in which the kubeconfig /// file is located. When , the paths will be considered to be relative to the current working directory. /// Instance of the class - public static async Task LoadKubeConfigAsync(string kubeconfigPath = null, + public static async Task LoadKubeConfigAsync( + string kubeconfigPath = null, bool useRelativePaths = true) { var fileInfo = new FileInfo(kubeconfigPath ?? KubeConfigDefaultLocation); @@ -560,7 +573,8 @@ namespace k8s /// When , the paths in the kubeconfig file will be considered to be relative to the directory in which the kubeconfig /// file is located. When , the paths will be considered to be relative to the current working directory. /// Instance of the class - public static async Task LoadKubeConfigAsync(FileInfo kubeconfig, + public static async Task LoadKubeConfigAsync( + FileInfo kubeconfig, bool useRelativePaths = true) { if (!kubeconfig.Exists) @@ -640,7 +654,8 @@ namespace k8s /// The kube config files will be merges into a single , where first occurence wins. /// See https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#merging-kubeconfig-files. /// - internal static async Task LoadKubeConfigAsync(FileInfo[] kubeConfigs, + internal static async Task LoadKubeConfigAsync( + FileInfo[] kubeConfigs, bool useRelativePaths = true) { var basek8SConfig = await LoadKubeConfigAsync(kubeConfigs[0], useRelativePaths).ConfigureAwait(false); diff --git a/src/KubernetesClient/KubernetesList.cs b/src/KubernetesClient/KubernetesList.cs index f1ef5a5..124e607 100644 --- a/src/KubernetesClient/KubernetesList.cs +++ b/src/KubernetesClient/KubernetesList.cs @@ -1,12 +1,12 @@ using System.Collections.Generic; using System.Linq; -using k8s.Models; using Microsoft.Rest; using Newtonsoft.Json; namespace k8s.Models { - public class KubernetesList : IMetadata, IItems where T : IKubernetesObject + public class KubernetesList : IMetadata, IItems + where T : IKubernetesObject { public KubernetesList(IList items, string apiVersion = default(string), string kind = default(string), V1ListMeta metadata = default(V1ListMeta)) @@ -27,7 +27,8 @@ namespace k8s.Models [JsonProperty(PropertyName = "apiVersion")] public string ApiVersion { get; set; } - [JsonProperty(PropertyName = "items")] public IList Items { get; set; } + [JsonProperty(PropertyName = "items")] + public IList Items { get; set; } /// /// Gets or sets kind is a string value representing the REST resource diff --git a/src/KubernetesClient/ModelExtensions.cs b/src/KubernetesClient/ModelExtensions.cs index cb3ac33..73af3f6 100644 --- a/src/KubernetesClient/ModelExtensions.cs +++ b/src/KubernetesClient/ModelExtensions.cs @@ -245,12 +245,14 @@ namespace k8s.Models } /// Gets that matches the given object, or null if no matching reference exists. - public static V1OwnerReference GetOwnerReference(this IMetadata obj, + public static V1OwnerReference GetOwnerReference( + this IMetadata obj, IKubernetesObject owner) => GetOwnerReference(obj, r => r.Matches(owner)); /// Gets the that matches the given predicate, or null if no matching reference exists. - public static V1OwnerReference GetOwnerReference(this IMetadata obj, + public static V1OwnerReference GetOwnerReference( + this IMetadata obj, Predicate predicate) { int index = FindOwnerReference(obj, predicate); @@ -310,7 +312,8 @@ namespace k8s.Models /// Removes the first that matches the given object and returns it, or returns null if no /// matching reference could be found. /// - public static V1OwnerReference RemoveOwnerReference(this IMetadata obj, + public static V1OwnerReference RemoveOwnerReference( + this IMetadata obj, IKubernetesObject owner) { int index = FindOwnerReference(obj, owner); @@ -326,7 +329,8 @@ namespace k8s.Models /// Removes all owner references that match the given predicate, and returns true if /// any were removed. /// - public static bool RemoveOwnerReferences(this IMetadata obj, + public static bool RemoveOwnerReferences( + this IMetadata obj, Predicate predicate) { if (obj == null) @@ -359,7 +363,8 @@ namespace k8s.Models /// Removes all owner references that match the given object, and returns true if /// any were removed. /// - public static bool RemoveOwnerReferences(this IMetadata obj, + public static bool RemoveOwnerReferences( + this IMetadata obj, IKubernetesObject owner) => RemoveOwnerReferences(obj, r => r.Matches(owner)); diff --git a/src/KubernetesClient/StreamType.cs b/src/KubernetesClient/StreamType.cs index c138ff7..983b171 100644 --- a/src/KubernetesClient/StreamType.cs +++ b/src/KubernetesClient/StreamType.cs @@ -1,5 +1,3 @@ -using System; - namespace k8s { /// diff --git a/src/KubernetesClient/StringQuotingEmitter.cs b/src/KubernetesClient/StringQuotingEmitter.cs index 3fdcd03..71b10c6 100644 --- a/src/KubernetesClient/StringQuotingEmitter.cs +++ b/src/KubernetesClient/StringQuotingEmitter.cs @@ -10,10 +10,11 @@ namespace k8s public class StringQuotingEmitter : ChainedEventEmitter { // Patterns from https://yaml.org/spec/1.2/spec.html#id2804356 - private static readonly Regex quotedRegex = + private static readonly Regex QuotedRegex = new Regex(@"^(\~|null|true|false|-?(0|[1-9][0-9]*)(\.[0-9]*)?([eE][-+]?[0-9]+)?)?$"); - public StringQuotingEmitter(IEventEmitter next) : base(next) + public StringQuotingEmitter(IEventEmitter next) + : base(next) { } @@ -34,7 +35,7 @@ namespace k8s break; case TypeCode.String: var val = eventInfo.Source.Value.ToString(); - if (quotedRegex.IsMatch(val)) + if (QuotedRegex.IsMatch(val)) { eventInfo.Style = ScalarStyle.DoubleQuoted; } diff --git a/src/KubernetesClient/V1Patch.cs b/src/KubernetesClient/V1Patch.cs index 8f32fe2..60f357a 100644 --- a/src/KubernetesClient/V1Patch.cs +++ b/src/KubernetesClient/V1Patch.cs @@ -16,7 +16,8 @@ namespace k8s.Models public PathType Type { get; private set; } - public V1Patch(IJsonPatchDocument jsonPatch) : this((object)jsonPatch) + public V1Patch(IJsonPatchDocument jsonPatch) + : this((object)jsonPatch) { } diff --git a/src/KubernetesClient/Versioning/KubernetesVersionComparer.cs b/src/KubernetesClient/Versioning/KubernetesVersionComparer.cs index 5dd87fa..853578b 100644 --- a/src/KubernetesClient/Versioning/KubernetesVersionComparer.cs +++ b/src/KubernetesClient/Versioning/KubernetesVersionComparer.cs @@ -6,14 +6,8 @@ namespace k8s.Versioning { public class KubernetesVersionComparer : IComparer { - public static KubernetesVersionComparer Instance { get; private set; } - private static readonly Regex _kubernetesVersionRegex; - - static KubernetesVersionComparer() - { - _kubernetesVersionRegex = new Regex(@"^v(?[0-9]+)((?alpha|beta)(?[0-9]+))?$", RegexOptions.Compiled); - Instance = new KubernetesVersionComparer(); - } + public static KubernetesVersionComparer Instance { get; } = new KubernetesVersionComparer(); + private static readonly Regex KubernetesVersionRegex = new Regex(@"^v(?[0-9]+)((?alpha|beta)(?[0-9]+))?$", RegexOptions.Compiled); internal KubernetesVersionComparer() { @@ -26,13 +20,13 @@ namespace k8s.Versioning return StringComparer.CurrentCulture.Compare(x, y); } - var matchX = _kubernetesVersionRegex.Match(x); + var matchX = KubernetesVersionRegex.Match(x); if (!matchX.Success) { return StringComparer.CurrentCulture.Compare(x, y); } - var matchY = _kubernetesVersionRegex.Match(y); + var matchY = KubernetesVersionRegex.Match(y); if (!matchY.Success) { return StringComparer.CurrentCulture.Compare(x, y); diff --git a/src/KubernetesClient/Versioning/VersionConverter.cs b/src/KubernetesClient/Versioning/VersionConverter.cs index 4b42494..4d8ed0d 100644 --- a/src/KubernetesClient/Versioning/VersionConverter.cs +++ b/src/KubernetesClient/Versioning/VersionConverter.cs @@ -59,7 +59,8 @@ namespace k8s.Versioning .GroupBy(x => x.Kind) .ToDictionary(x => x.Key, kindGroup => kindGroup .GroupBy(x => x.ApiVersion) - .ToDictionary(x => x.Key, + .ToDictionary( + x => x.Key, versionGroup => versionGroup.Select(x => x.Type).Distinct().Single())); // should only be one type for each Kind/Version combination } @@ -152,7 +153,7 @@ namespace k8s.Versioning .ForMember(dest => dest.AverageValue, opt => opt.MapFrom(src => src.TargetAverageValue)) .ForMember(dest => dest.Value, opt => opt.Ignore()) #if NET452 - .ForMember(dest => dest.Type, opt => opt.ResolveUsing(src => src.TargetAverageValue != null ? "AverageValue" : "Utilization" )) + .ForMember(dest => dest.Type, opt => opt.ResolveUsing(src => src.TargetAverageValue != null ? "AverageValue" : "Utilization")) #else .ForMember(dest => dest.Type, opt => opt.MapFrom((src, dest) => src.TargetAverageValue != null ? "AverageValue" : "Utilization")) #endif diff --git a/src/KubernetesClient/Watcher.cs b/src/KubernetesClient/Watcher.cs index 1a7db5e..06ec6be 100644 --- a/src/KubernetesClient/Watcher.cs +++ b/src/KubernetesClient/Watcher.cs @@ -12,23 +12,28 @@ namespace k8s public enum WatchEventType { /// Emitted when an object is created, modified to match a watch's filter, or when a watch is first opened. - [EnumMember(Value = "ADDED")] Added, + [EnumMember(Value = "ADDED")] + Added, /// Emitted when an object is modified. - [EnumMember(Value = "MODIFIED")] Modified, + [EnumMember(Value = "MODIFIED")] + Modified, /// Emitted when an object is deleted or modified to no longer match a watch's filter. - [EnumMember(Value = "DELETED")] Deleted, + [EnumMember(Value = "DELETED")] + Deleted, /// Emitted when an error occurs while watching resources. Most commonly, the error is 410 Gone which indicates that /// the watch resource version was outdated and events were probably lost. In that case, the watch should be restarted. /// - [EnumMember(Value = "ERROR")] Error, + [EnumMember(Value = "ERROR")] + Error, /// Bookmarks may be emitted periodically to update the resource version. The object will /// contain only the resource version. /// - [EnumMember(Value = "BOOKMARK")] Bookmark, + [EnumMember(Value = "BOOKMARK")] + Bookmark, } public class Watcher : IDisposable diff --git a/src/KubernetesClient/WatcherDelegatingHandler.cs b/src/KubernetesClient/WatcherDelegatingHandler.cs index 8ce0402..e2d43e9 100644 --- a/src/KubernetesClient/WatcherDelegatingHandler.cs +++ b/src/KubernetesClient/WatcherDelegatingHandler.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Net; using System.Net.Http; using System.Threading; @@ -15,7 +14,8 @@ namespace k8s /// internal class WatcherDelegatingHandler : DelegatingHandler { - protected override async Task SendAsync(HttpRequestMessage request, + protected override async Task SendAsync( + HttpRequestMessage request, CancellationToken cancellationToken) { var originResponse = await base.SendAsync(request, cancellationToken).ConfigureAwait(false); diff --git a/src/KubernetesClient/WatcherExt.cs b/src/KubernetesClient/WatcherExt.cs index 5f2fc68..af22139 100644 --- a/src/KubernetesClient/WatcherExt.cs +++ b/src/KubernetesClient/WatcherExt.cs @@ -19,12 +19,14 @@ namespace k8s /// The action to invoke when the server closes the connection. /// /// a watch object - public static Watcher Watch(this Task> responseTask, + public static Watcher Watch( + this Task> responseTask, Action onEvent, Action onError = null, Action onClosed = null) { - return new Watcher(async () => + return new Watcher( + async () => { var response = await responseTask.ConfigureAwait(false); @@ -49,7 +51,8 @@ namespace k8s /// The action to invoke when the server closes the connection. /// /// a watch object - public static Watcher Watch(this HttpOperationResponse response, + public static Watcher Watch( + this HttpOperationResponse response, Action onEvent, Action onError = null, Action onClosed = null) diff --git a/src/KubernetesClient/WebSocketBuilder.cs b/src/KubernetesClient/WebSocketBuilder.cs index 68b9844..b55dbe7 100644 --- a/src/KubernetesClient/WebSocketBuilder.cs +++ b/src/KubernetesClient/WebSocketBuilder.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Net.WebSockets; #if (NET452 || NETSTANDARD2_0) using System.Net.Security; diff --git a/src/KubernetesClient/Yaml.cs b/src/KubernetesClient/Yaml.cs index ad25265..1174a7f 100644 --- a/src/KubernetesClient/Yaml.cs +++ b/src/KubernetesClient/Yaml.cs @@ -265,7 +265,8 @@ namespace k8s set => _inner.ScalarStyle = value; } - public T GetCustomAttribute() where T : Attribute + public T GetCustomAttribute() + where T : Attribute { return _inner.GetCustomAttribute(); } diff --git a/src/KubernetesClient/generated/VersionConverter.cs b/src/KubernetesClient/generated/VersionConverter.cs index 261697b..2497bbe 100644 --- a/src/KubernetesClient/generated/VersionConverter.cs +++ b/src/KubernetesClient/generated/VersionConverter.cs @@ -3,8 +3,6 @@ using k8s.Models; namespace k8s.Versioning { - - public static partial class VersionConverter { private static void AutoConfigurations(IMapperConfigurationExpression cfg) @@ -160,6 +158,4 @@ namespace k8s.Versioning cfg.CreateMap().ReverseMap(); } } - - } diff --git a/tests/KubernetesClient.Tests/AuthTests.cs b/tests/KubernetesClient.Tests/AuthTests.cs index 6e6227c..38d6981 100644 --- a/tests/KubernetesClient.Tests/AuthTests.cs +++ b/tests/KubernetesClient.Tests/AuthTests.cs @@ -18,7 +18,6 @@ using Microsoft.Rest; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Pkcs; using Org.BouncyCastle.Security; -using Remotion.Linq.Clauses; using Xunit; using Xunit.Abstractions; @@ -89,8 +88,9 @@ namespace k8s.Tests { var header = cxt.Request.Headers["Authorization"].FirstOrDefault(); - var expect = new AuthenticationHeaderValue("Basic", - Convert.ToBase64String(Encoding.UTF8.GetBytes($"{testName}:{testPassword}"))) + var expect = new AuthenticationHeaderValue( + "Basic", + Convert.ToBase64String(Encoding.UTF8.GetBytes($"{testName}:{testPassword}"))) .ToString(); if (header != expect) diff --git a/tests/KubernetesClient.Tests/ByteBufferTests.cs b/tests/KubernetesClient.Tests/ByteBufferTests.cs index 6b7a796..5d47cb7 100644 --- a/tests/KubernetesClient.Tests/ByteBufferTests.cs +++ b/tests/KubernetesClient.Tests/ByteBufferTests.cs @@ -1,7 +1,5 @@ -using Nito.AsyncEx; using System; using System.Security.Cryptography; -using System.Threading; using System.Threading.Tasks; using Xunit; @@ -262,7 +260,8 @@ namespace k8s.Tests // Write data to the buffer buffer.Write(this.writeData, 0, 0x03); - await TaskAssert.Completed(readTask, + await TaskAssert.Completed( + readTask, timeout: TimeSpan.FromMilliseconds(1000), message: "Timed out waiting for read task to complete.").ConfigureAwait(false); diff --git a/tests/KubernetesClient.Tests/CertUtilsTests.cs b/tests/KubernetesClient.Tests/CertUtilsTests.cs index 2eb471b..c1c7487 100644 --- a/tests/KubernetesClient.Tests/CertUtilsTests.cs +++ b/tests/KubernetesClient.Tests/CertUtilsTests.cs @@ -1,9 +1,6 @@ using System; using Xunit; -using k8s; -using System.IO; using System.Security.Cryptography.X509Certificates; -using System.Net.Security; using System.Linq; namespace k8s.Tests @@ -42,7 +39,8 @@ namespace k8s.Tests [Fact] public void LoadFromFilesRelativePath() { - var cfg = KubernetesClientConfiguration.BuildConfigFromConfigFile(KubeConfigWithRelativePathsFileName, + var cfg = KubernetesClientConfiguration.BuildConfigFromConfigFile( + KubeConfigWithRelativePathsFileName, "federal-context"); // Just validate that this doesn't throw and private key is non-null @@ -70,7 +68,8 @@ namespace k8s.Tests [Fact] public void LoadFromInlineDataRelativePath() { - var cfg = KubernetesClientConfiguration.BuildConfigFromConfigFile(KubeConfigWithRelativePathsFileName, + var cfg = KubernetesClientConfiguration.BuildConfigFromConfigFile( + KubeConfigWithRelativePathsFileName, "victorian-context"); // Just validate that this doesn't throw and private key is non-null diff --git a/tests/KubernetesClient.Tests/CertificateValidationTests.cs b/tests/KubernetesClient.Tests/CertificateValidationTests.cs index d653c24..6776383 100644 --- a/tests/KubernetesClient.Tests/CertificateValidationTests.cs +++ b/tests/KubernetesClient.Tests/CertificateValidationTests.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; -using System.IO; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using Xunit; diff --git a/tests/KubernetesClient.Tests/GcpTokenProviderTests.cs b/tests/KubernetesClient.Tests/GcpTokenProviderTests.cs index b22cee9..555c7cc 100644 --- a/tests/KubernetesClient.Tests/GcpTokenProviderTests.cs +++ b/tests/KubernetesClient.Tests/GcpTokenProviderTests.cs @@ -4,7 +4,6 @@ using System.Threading; using System.Threading.Tasks; using FluentAssertions; using k8s.Authentication; -using Xunit; namespace k8s.Tests { diff --git a/tests/KubernetesClient.Tests/KubernetesClientConfigurationTests.cs b/tests/KubernetesClient.Tests/KubernetesClientConfigurationTests.cs index a62cc34..a2d86de 100755 --- a/tests/KubernetesClient.Tests/KubernetesClientConfigurationTests.cs +++ b/tests/KubernetesClient.Tests/KubernetesClientConfigurationTests.cs @@ -161,7 +161,8 @@ namespace k8s.Tests public void CreatedFromPreLoadedConfig() { var k8sConfig = - KubernetesClientConfiguration.LoadKubeConfig(new FileInfo("assets/kubeconfig.yml"), + KubernetesClientConfiguration.LoadKubeConfig( + new FileInfo("assets/kubeconfig.yml"), useRelativePaths: false); var cfg = KubernetesClientConfiguration.BuildConfigFromConfigObject(k8sConfig); Assert.NotNull(cfg.Host); @@ -173,7 +174,8 @@ namespace k8s.Tests [Fact] public void DefaultConfigurationLoaded() { - var cfg = KubernetesClientConfiguration.BuildConfigFromConfigFile(new FileInfo("assets/kubeconfig.yml"), + var cfg = KubernetesClientConfiguration.BuildConfigFromConfigFile( + new FileInfo("assets/kubeconfig.yml"), useRelativePaths: false); Assert.NotNull(cfg.Host); } @@ -442,7 +444,8 @@ namespace k8s.Tests var filePath = Path.GetFullPath("assets/kubeconfig.relative.yml"); var environmentVariable = "KUBECONFIG_LoadKubeConfigFromEnvironmentVariable_MultipleConfigs"; - Environment.SetEnvironmentVariable(environmentVariable, + Environment.SetEnvironmentVariable( + environmentVariable, string.Concat(filePath, RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ';' : ':', filePath)); KubernetesClientConfiguration.KubeConfigEnvironmentVariable = environmentVariable; @@ -576,7 +579,8 @@ namespace k8s.Tests { Assert.Equal(expected.Name, actual.Name); Assert.Equal(expected.ClusterEndpoint.CertificateAuthority, actual.ClusterEndpoint.CertificateAuthority); - Assert.Equal(expected.ClusterEndpoint.CertificateAuthorityData, + Assert.Equal( + expected.ClusterEndpoint.CertificateAuthorityData, actual.ClusterEndpoint.CertificateAuthorityData); Assert.Equal(expected.ClusterEndpoint.Server, actual.ClusterEndpoint.Server); Assert.Equal(expected.ClusterEndpoint.SkipTlsVerify, actual.ClusterEndpoint.SkipTlsVerify); diff --git a/tests/KubernetesClient.Tests/Logging/TestOutputLogger.cs b/tests/KubernetesClient.Tests/Logging/TestOutputLogger.cs index 5ef9e03..f9537b8 100644 --- a/tests/KubernetesClient.Tests/Logging/TestOutputLogger.cs +++ b/tests/KubernetesClient.Tests/Logging/TestOutputLogger.cs @@ -83,7 +83,8 @@ namespace k8s.Tests.Logging throw new ArgumentNullException(nameof(formatter)); } - TestOutput.WriteLine(string.Format("[{0}] {1}: {2}", + TestOutput.WriteLine(string.Format( + "[{0}] {1}: {2}", level, LoggerCategory, formatter(state, exception))); diff --git a/tests/KubernetesClient.Tests/Mock/MockWebSocket.cs b/tests/KubernetesClient.Tests/Mock/MockWebSocket.cs index 93cdb9e..66cfafa 100644 --- a/tests/KubernetesClient.Tests/Mock/MockWebSocket.cs +++ b/tests/KubernetesClient.Tests/Mock/MockWebSocket.cs @@ -75,7 +75,8 @@ namespace k8s.Tests.Mock throw new NotImplementedException(); } - public override async Task ReceiveAsync(ArraySegment buffer, + public override async Task ReceiveAsync( + ArraySegment buffer, CancellationToken cancellationToken) { if (this.receiveBuffers.Count == 0) @@ -113,7 +114,8 @@ namespace k8s.Tests.Mock public override Task SendAsync(ArraySegment buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken) { - this.MessageSent?.Invoke(this, + this.MessageSent?.Invoke( + this, new MessageDataEventArgs() { Data = new MessageData() diff --git a/tests/KubernetesClient.Tests/Mock/Server/Controllers/PodExecController.cs b/tests/KubernetesClient.Tests/Mock/Server/Controllers/PodExecController.cs index 2e555dd..e1dbf71 100644 --- a/tests/KubernetesClient.Tests/Mock/Server/Controllers/PodExecController.cs +++ b/tests/KubernetesClient.Tests/Mock/Server/Controllers/PodExecController.cs @@ -1,7 +1,6 @@ using Microsoft.AspNetCore.Mvc; using System; using System.Net.WebSockets; -using System.Threading; using System.Threading.Tasks; namespace k8s.Tests.Mock.Server.Controllers diff --git a/tests/KubernetesClient.Tests/Mock/Server/Controllers/PodPortForwardController.cs b/tests/KubernetesClient.Tests/Mock/Server/Controllers/PodPortForwardController.cs index 45d1c2d..1d8f679 100644 --- a/tests/KubernetesClient.Tests/Mock/Server/Controllers/PodPortForwardController.cs +++ b/tests/KubernetesClient.Tests/Mock/Server/Controllers/PodPortForwardController.cs @@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Net.WebSockets; -using System.Threading; using System.Threading.Tasks; namespace k8s.Tests.Mock.Server.Controllers diff --git a/tests/KubernetesClient.Tests/PodExecTests.cs b/tests/KubernetesClient.Tests/PodExecTests.cs index 3c02fe2..ac14b50 100644 --- a/tests/KubernetesClient.Tests/PodExecTests.cs +++ b/tests/KubernetesClient.Tests/PodExecTests.cs @@ -67,9 +67,9 @@ namespace k8s.Tests stdout: true, webSocketSubProtol: WebSocketProtocol.ChannelWebSocketProtocol, cancellationToken: TestCancellation).ConfigureAwait(false); - Assert.Equal(WebSocketProtocol.ChannelWebSocketProtocol, - clientSocket - .SubProtocol); // For WebSockets, the Kubernetes API defaults to the binary channel (v1) protocol. + Assert.Equal( + WebSocketProtocol.ChannelWebSocketProtocol, + clientSocket.SubProtocol); // For WebSockets, the Kubernetes API defaults to the binary channel (v1) protocol. testOutput.WriteLine( $"Client socket connected (socket state is {clientSocket.State}). Waiting for server-side socket to become available..."); @@ -200,8 +200,9 @@ namespace k8s.Tests using (Kubernetes client = kubernetesMock.Object) { - await Assert.ThrowsAsync(() => client.NamespacedPodExecAsync("pod-name", - "pod-namespace", "my-container", command, false, null, CancellationToken.None)) + await Assert.ThrowsAsync(() => client.NamespacedPodExecAsync( + "pod-name", + "pod-namespace", "my-container", command, false, null, CancellationToken.None)) .ConfigureAwait(false); } } @@ -223,8 +224,9 @@ namespace k8s.Tests using (Kubernetes client = kubernetesMock.Object) { - var ex = await Assert.ThrowsAsync(() => client.NamespacedPodExecAsync("pod-name", - "pod-namespace", "my-container", command, false, handler, CancellationToken.None)) + var ex = await Assert.ThrowsAsync(() => client.NamespacedPodExecAsync( + "pod-name", + "pod-namespace", "my-container", command, false, handler, CancellationToken.None)) .ConfigureAwait(false); Assert.Same(status, ex.Status); } @@ -269,8 +271,9 @@ namespace k8s.Tests using (Kubernetes client = kubernetesMock.Object) { - var ex = await Assert.ThrowsAsync(() => client.NamespacedPodExecAsync("pod-name", - "pod-namespace", "my-container", command, false, handler, CancellationToken.None)) + var ex = await Assert.ThrowsAsync(() => client.NamespacedPodExecAsync( + "pod-name", + "pod-namespace", "my-container", command, false, handler, CancellationToken.None)) .ConfigureAwait(false); Assert.Same(exception, ex); } diff --git a/tests/KubernetesClient.Tests/StreamDemuxerTests.cs b/tests/KubernetesClient.Tests/StreamDemuxerTests.cs index 4bead3b..c1d871c 100644 --- a/tests/KubernetesClient.Tests/StreamDemuxerTests.cs +++ b/tests/KubernetesClient.Tests/StreamDemuxerTests.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Net.WebSockets; -using System.Text; using System.Threading; using System.Threading.Tasks; using k8s.Tests.Mock; @@ -37,7 +36,8 @@ namespace k8s.Tests stream.Write(b, 0, b.Length); // Send 100 bytes, expect 1 (channel index) + 100 (payload) = 101 bytes - Assert.True(await WaitForAsync(() => sentBuffer.Count == 101).ConfigureAwait(false), + Assert.True( + await WaitForAsync(() => sentBuffer.Count == 101).ConfigureAwait(false), $"Demuxer error: expect to send 101 bytes, but actually send {sentBuffer.Count} bytes."); Assert.True(sentBuffer[0] == channelIndex, "The first sent byte is not channel index!"); Assert.True(sentBuffer[1] == 0xEF, "Incorrect payload!"); @@ -63,7 +63,8 @@ namespace k8s.Tests stream.Write(b, 0, b.Length); // Send 300 bytes in 2 messages, expect 1 (channel index) * 2 + 300 (payload) = 302 bytes - Assert.True(await WaitForAsync(() => sentBuffer.Count == 302).ConfigureAwait(false), + Assert.True( + await WaitForAsync(() => sentBuffer.Count == 302).ConfigureAwait(false), $"Demuxer error: expect to send 302 bytes, but actually send {sentBuffer.Count} bytes."); Assert.True(sentBuffer[0] == channelIndex, "The first sent byte is not channel index!"); Assert.True(sentBuffer[1] == 0xEF, "The first part of payload incorrect!"); @@ -119,7 +120,8 @@ namespace k8s.Tests await t.ConfigureAwait(false); - Assert.True(receivedBuffer.Count == expectedCount, + Assert.True( + receivedBuffer.Count == expectedCount, $"Demuxer error: expect to receive {expectedCount} bytes, but actually got {receivedBuffer.Count} bytes."); Assert.True(receivedBuffer[0] == 0xAA, "The first payload incorrect!"); Assert.True(receivedBuffer[98] == 0xAA, "The first payload incorrect!"); @@ -178,7 +180,8 @@ namespace k8s.Tests await t.ConfigureAwait(false); - Assert.True(receivedBuffer.Count == expectedCount, + Assert.True( + receivedBuffer.Count == expectedCount, $"Demuxer error: expect to receive {expectedCount} bytes, but actually got {receivedBuffer.Count} bytes."); Assert.True(receivedBuffer[0] == 0xB1, "The first payload incorrect!"); Assert.True(receivedBuffer[96] == 0xB1, "The first payload incorrect!"); @@ -237,7 +240,8 @@ namespace k8s.Tests await t.ConfigureAwait(false); - Assert.True(receivedBuffer.Count == expectedCount, + Assert.True( + receivedBuffer.Count == expectedCount, $"Demuxer error: expect to receive {expectedCount} bytes, but actually got {receivedBuffer.Count} bytes."); Assert.True(receivedBuffer[0] == 0xC2, "The first payload incorrect!"); Assert.True(receivedBuffer[98] == 0xC2, "The first payload incorrect!"); @@ -320,9 +324,11 @@ namespace k8s.Tests }); await Task.WhenAll(t1, t2, t3).ConfigureAwait(false); - Assert.True(receivedBuffer1.Count == expectedCount1, + Assert.True( + receivedBuffer1.Count == expectedCount1, $"Demuxer error: expect to receive {expectedCount1} bytes, but actually got {receivedBuffer1.Count} bytes."); - Assert.True(receivedBuffer2.Count == expectedCount2, + Assert.True( + receivedBuffer2.Count == expectedCount2, $"Demuxer error: expect to receive {expectedCount2} bytes, but actually got {receivedBuffer2.Count} bytes."); Assert.True(receivedBuffer1[0] == 0xD1, "The first payload incorrect!"); Assert.True(receivedBuffer1[98] == 0xD1, "The first payload incorrect!"); @@ -409,9 +415,11 @@ namespace k8s.Tests }); await Task.WhenAll(t1, t2, t3).ConfigureAwait(false); - Assert.True(receivedBuffer1.Count == expectedCount1, + Assert.True( + receivedBuffer1.Count == expectedCount1, $"Demuxer error: expect to receive {expectedCount1} bytes, but actually got {receivedBuffer1.Count} bytes."); - Assert.True(receivedBuffer2.Count == expectedCount2, + Assert.True( + receivedBuffer2.Count == expectedCount2, $"Demuxer error: expect to receive {expectedCount2} bytes, but actually got {receivedBuffer2.Count} bytes."); Assert.True(receivedBuffer1[0] == 0xE1, "The first payload incorrect!"); Assert.True(receivedBuffer1[96] == 0xE1, "The first payload incorrect!"); diff --git a/tests/KubernetesClient.Tests/TaskAssert.cs b/tests/KubernetesClient.Tests/TaskAssert.cs index a45c0dc..f3668d3 100644 --- a/tests/KubernetesClient.Tests/TaskAssert.cs +++ b/tests/KubernetesClient.Tests/TaskAssert.cs @@ -1,5 +1,4 @@ using System; -using System.Threading; using System.Threading.Tasks; using Xunit; diff --git a/tests/KubernetesClient.Tests/TokenFileAuthTests.cs b/tests/KubernetesClient.Tests/TokenFileAuthTests.cs index e4bc43f..9c355b6 100644 --- a/tests/KubernetesClient.Tests/TokenFileAuthTests.cs +++ b/tests/KubernetesClient.Tests/TokenFileAuthTests.cs @@ -3,7 +3,6 @@ using System.Threading; using System.Threading.Tasks; using FluentAssertions; using k8s.Authentication; -using Xunit; namespace k8s.Tests { diff --git a/tests/KubernetesClient.Tests/VersionConverterTests.cs b/tests/KubernetesClient.Tests/VersionConverterTests.cs index 05a9e02..b512ba9 100644 --- a/tests/KubernetesClient.Tests/VersionConverterTests.cs +++ b/tests/KubernetesClient.Tests/VersionConverterTests.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using k8s.Models; using Xunit; using FluentAssertions; diff --git a/tests/KubernetesClient.Tests/WatchTests.cs b/tests/KubernetesClient.Tests/WatchTests.cs index ef6da0f..05498cb 100644 --- a/tests/KubernetesClient.Tests/WatchTests.cs +++ b/tests/KubernetesClient.Tests/WatchTests.cs @@ -8,11 +8,9 @@ using System.Net; using System.Net.Http; using System.Threading; using System.Threading.Tasks; -using k8s.Exceptions; using k8s.Models; using k8s.Tests.Mock; using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Nito.AsyncEx; @@ -430,7 +428,8 @@ namespace k8s.Tests { internal bool Called { get; private set; } - protected override Task SendAsync(HttpRequestMessage request, + protected override Task SendAsync( + HttpRequestMessage request, CancellationToken cancellationToken) { Called = true; diff --git a/tests/KubernetesClient.Tests/WebSocketTestBase.cs b/tests/KubernetesClient.Tests/WebSocketTestBase.cs index ed0b193..261ea97 100644 --- a/tests/KubernetesClient.Tests/WebSocketTestBase.cs +++ b/tests/KubernetesClient.Tests/WebSocketTestBase.cs @@ -179,7 +179,8 @@ namespace k8s.Tests { if (received.IsFaulted) { - testOutput.WriteLine("Server socket operation to receive Close message failed: {0}", + testOutput.WriteLine( + "Server socket operation to receive Close message failed: {0}", received.Exception.Flatten().InnerExceptions[0]); } else if (received.IsCanceled) diff --git a/tests/KubernetesClient.Tests/YamlTests.cs b/tests/KubernetesClient.Tests/YamlTests.cs index b6f2f85..9cd6a93 100644 --- a/tests/KubernetesClient.Tests/YamlTests.cs +++ b/tests/KubernetesClient.Tests/YamlTests.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text; using k8s.Models; using Xunit; @@ -114,7 +113,8 @@ metadata: var pod = new V1Pod() { ApiVersion = "v1", Kind = "Pod", Metadata = new V1ObjectMeta() { Name = "foo" } }; var yaml = Yaml.SaveToString(pod); - Assert.Equal(ToLines(@"apiVersion: v1 + Assert.Equal( + ToLines(@"apiVersion: v1 kind: Pod metadata: name: foo"), ToLines(yaml)); @@ -131,7 +131,8 @@ metadata: }; var yaml = Yaml.SaveToString(pod); - Assert.Equal(ToLines(@"apiVersion: v1 + Assert.Equal( + ToLines(@"apiVersion: v1 kind: Pod metadata: name: foo @@ -170,7 +171,8 @@ metadata: }; var yaml = Yaml.SaveToString(pod); - Assert.Equal(ToLines(@"apiVersion: v1 + Assert.Equal( + ToLines(@"apiVersion: v1 kind: Pod metadata: name: foo