Skip to content

Commit

Permalink
build: target .netstandard2.0 (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
bergmeister authored and felixfbecker committed Aug 2, 2019
1 parent 05a9a3c commit ea51307
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/Cmdlets/CompareKubeResourceCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ protected override async Task ProcessRecordAsync(CancellationToken cancellationT
string apiGroupVersion = (string)Original.ApiVersion;
string apiVersion = apiGroupVersion.Split('/').Last();
string kind = (string)Original.Kind;
Type type = ModelTypes.GetValueOrDefault((kind, apiVersion));
if (type == null) {
if (!ModelTypes.TryGetValue((kind, apiVersion), out Type type)) {
WriteError(new ErrorRecord(new Exception($"Unknown (kind: {kind}, apiVersion: {apiVersion}). {ModelTypes.Count} Known:\n{String.Join("\n", ModelTypes.Keys)}"), null, ErrorCategory.InvalidData, null));
return;
}
Expand Down
9 changes: 6 additions & 3 deletions src/Cmdlets/UpdateKubeResourceCmdlet.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Management.Automation;
using System.Reflection;
Expand Down Expand Up @@ -42,7 +43,10 @@ protected override async Task ProcessRecordAsync(CancellationToken cancellationT
var paths = GetResolvedProviderPathFromPSPath(Path, out provider);
foreach (var path in paths) {
WriteVerbose($"Reading object from YAML file {path}");
var yaml = await System.IO.File.ReadAllTextAsync(path, cancellationToken);
string yaml;
using (var streamReader = File.OpenText(path)) {
yaml = await streamReader.ReadToEndAsync();
}
var modified = deserializer.Deserialize(yaml);
await updateResource(modified, cancellationToken);
}
Expand All @@ -62,8 +66,7 @@ private async Task updateResource(dynamic modified, CancellationToken cancellati
}

// Figure out the model class - needed for diffing
Type type = ModelTypes.GetValueOrDefault((kind, apiVersion));
if (type == null) {
if (!ModelTypes.TryGetValue((kind, apiVersion), out Type type)) {
WriteError(new ErrorRecord(new Exception($"Unknown (kind: {kind}, apiVersion: {apiVersion}). {ModelTypes.Count} Known:\n{String.Join("\n", ModelTypes.Keys)}"), null, ErrorCategory.InvalidData, Resource));
return;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Cmdlets/UseKubeContextCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ protected override async Task ProcessRecordAsync(CancellationToken cancellationT
Serializer serializer = new SerializerBuilder().Build();
string yaml = serializer.Serialize(config);
if (ShouldProcess(configPath, "update")) {
await File.WriteAllTextAsync(configPath, yaml); // Do not pass cancellationToken to not corrupt config file
using (var streamWriter = new StreamWriter(configPath)) {
await streamWriter.WriteAsync(yaml); // Do not pass cancellationToken to not corrupt config file
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/KubeResourceComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ public void CreateTwoWayPatch(object original, object modified, Type type, JsonP
} else {
logger.LogTrace("List is unordered set");
// Lists are to be treated like unordered sets
HashSet<object> originalSet = originalEnumerable.ToHashSet();
HashSet<object> modifiedSet = modifiedEnumerable.ToHashSet();
var originalSet = new HashSet<object>(originalEnumerable);
var modifiedSet = new HashSet<object>(modifiedEnumerable);
// The index to adress the element on the server after applying every operation in the patch so far.
int index = 0;
foreach (var originalElement in originalEnumerable) {
Expand Down
3 changes: 1 addition & 2 deletions src/KubeYamlDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public object Deserialize(string yaml) {
string apiGroupVersion = (string)dict["apiVersion"];
string apiVersion = apiGroupVersion.Split('/').Last();
logger.LogDebug($"apiVersion {apiVersion}");
Type type = modelTypes.GetValueOrDefault((kind, apiVersion));
if (type == null) {
if (!modelTypes.TryGetValue((kind, apiVersion), out Type type)) {
throw new Exception($"Unknown (kind: {kind}, apiVersion: {apiVersion}). {modelTypes.Count} Known:\n{String.Join("\n", modelTypes.Keys)}");
}
return toPSObject(dict, type);
Expand Down
4 changes: 2 additions & 2 deletions src/PSKubectl.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<!-- <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> -->
</PropertyGroup>
<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/SetKubeConfigCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ protected override async Task ProcessRecordAsync(CancellationToken cancellationT
string yaml = serializer.Serialize(Config);
string configPath = K8sConfig.Locate();
if (ShouldProcess(configPath, "update")) {
await File.WriteAllTextAsync(configPath, yaml); // Do not pass cancellationToken to not corrupt config file
using (var streamWriter = new StreamWriter(configPath)) {
await streamWriter.WriteAsync(yaml); // Do not pass cancellationToken to not corrupt config file
}
}
}
}
Expand Down

0 comments on commit ea51307

Please sign in to comment.