Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YAML and Helm support in .NET SDK #980

Merged
merged 3 commits into from
Feb 26, 2020
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
- Fix .NET resources with empty arguments. (https://github.com/pulumi/pulumi-kubernetes/pull/983).
- Fix panic condition in Pod await logic. (https://github.com/pulumi/pulumi-kubernetes/pull/998).

### Improvements

- .NET SDK supports resources to work with YAML Kubernetes files and Helm charts.
(https://github.com/pulumi/pulumi-kubernetes/pull/980).

## 1.5.3 (February 11, 2020)

### Bug fixes
Expand Down
7 changes: 6 additions & 1 deletion cmd/pulumi-gen-kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func writePythonClient(data map[string]interface{}, outdir, templateDir string)

func writeDotnetClient(data map[string]interface{}, outdir, templateDir string) {

inputAPIcs, ouputAPIcs, kindsCs, err := gen.DotnetClient(data, templateDir)
inputAPIcs, ouputAPIcs, yamlcs, kindsCs, err := gen.DotnetClient(data, templateDir)
if err != nil {
panic(err)
}
Expand All @@ -247,6 +247,11 @@ func writeDotnetClient(data map[string]interface{}, outdir, templateDir string)
panic(err)
}

err = ioutil.WriteFile(fmt.Sprintf("%s/Yaml/Yaml.cs", outdir), []byte(yamlcs), 0777)
if err != nil {
panic(err)
}

for path, contents := range kindsCs {
filename := filepath.Join(outdir, path)
err := os.MkdirAll(filepath.Dir(filename), 0700)
Expand Down
1 change: 1 addition & 0 deletions pkg/gen/dotnet-templates/Pulumi.Kubernetes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<ItemGroup>
<PackageReference Include="Pulumi" Version="1.11.0-preview" />
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
<PackageReference Include="Glob" Version="1.1.5" />
</ItemGroup>

<ItemGroup>
Expand Down
135 changes: 127 additions & 8 deletions pkg/gen/dotnet-templates/Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,145 @@
// *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. ***
// Copyright 2016-2020, Pulumi Corporation
// *** WARNING: this file was generated by the Pulumi Kubernetes codegen tool. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***

using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using Pulumi;
using System.Text;

namespace Pulumi.Kubernetes
{
static class Utilities
internal static class Utilities
{
private readonly static string version;
public static string Version => version;
public static string Version { get; }

static Utilities()
{
var assembly = typeof(Utilities).GetTypeInfo().Assembly;
using (var stream = assembly.GetManifestResourceStream("Pulumi.Kubernetes.version.txt"))
using (var reader = new StreamReader(stream))
using var stream = assembly.GetManifestResourceStream("Pulumi.Kubernetes.version.txt");
if (stream == null)
throw new Exception("Manifest file 'version.txt' not found");
using var reader = new StreamReader(stream);
Version = reader.ReadToEnd().Trim();
}

public static InvokeOptions WithVersion(this InvokeOptions? options)
{
if (options?.Version != null)
{
return options;
}
return new InvokeOptions
{
Parent = options?.Parent,
lblackstone marked this conversation as resolved.
Show resolved Hide resolved
Provider = options?.Provider,
Version = Version,
};
}

public static string ExecuteCommand(string command, string[] flags)
{
using var process = new Process
{
StartInfo =
{
FileName = command,
Arguments = EscapeArguments(flags),
RedirectStandardOutput = true,
RedirectStandardError = true
}
};
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
if (process.ExitCode > 0)
{
string error = process.StandardError.ReadToEnd();
throw new Exception(error);
}
return output;
}

/// <summary>
/// Convert an argument array to an argument string for using with Process.StartInfo.Arguments.
/// </summary>
private static string EscapeArguments(params string[] args)
=> string.Join(" ", args.Select(EscapeArguments));

/// <summary>
/// Convert an argument array to an argument string for using with Process.StartInfo.Arguments.
/// </summary>
private static string EscapeArguments(string argument)
{
var escapedArgument = new StringBuilder();
var backslashCount = 0;
var needsQuotes = false;

foreach (var character in argument)
{
switch (character)
{
case '\\':
// Backslashes are simply passed through, except when they need
// to be escaped when followed by a \", e.g. the argument string
// \", which would be encoded to \\\"
backslashCount++;
escapedArgument.Append('\\');
break;

case '\"':
// Escape any preceding backslashes
escapedArgument.Append(new string('\\', backslashCount));

// Append an escaped double quote.
escapedArgument.Append("\\\"");

// Reset the backslash counter.
backslashCount = 0;
break;

case ' ':
case '\t':
// White spaces are escaped by surrounding the entire string with
// double quotes, which should be done at the end to prevent
// multiple wrappings.
needsQuotes = true;

// Append the whitespace
escapedArgument.Append(character);

// Reset the backslash counter.
backslashCount = 0;
break;

default:
// Reset the backslash counter.
backslashCount = 0;

// Append the current character
escapedArgument.Append(character);
break;
}
}

// No need to wrap in quotes
if (!needsQuotes)
{
version = reader.ReadToEnd().Trim();
return escapedArgument.ToString();
}

// Prepend the "
escapedArgument.Insert(0, '"');

// Escape any preceding backslashes before appending the "
escapedArgument.Append(new string('\\', backslashCount));

// Append the final "
escapedArgument.Append('\"');

return escapedArgument.ToString();
}
}
}
Loading