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
6 changes: 3 additions & 3 deletions .github/workflows/buildtest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
with:
fetch-depth: 0
- name: Setup dotnet
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v2
- name: Setup dotnet SDK
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v5
with:
dotnet-version: '9.0.x'
- name: Restore nugets (msbuild)
Expand All @@ -63,7 +63,7 @@ jobs:
with:
fetch-depth: 0
- name: Setup dotnet
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
fetch-depth: 0

- name: Setup dotnet
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docfx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
fetch-depth: 0

- name: Setup dotnet
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/draft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fetch-depth: 0

- name: Setup dotnet
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nuget.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fetch-depth: 0

- name: Setup dotnet
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
Expand Down
22 changes: 9 additions & 13 deletions src/KubernetesClient/KubernetesYaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeseria
return null;
}

return Encoding.UTF8.GetBytes(scalar.Value);
return Convert.FromBase64String(scalar.Value);
}
finally
{
Expand All @@ -91,19 +91,15 @@ public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeseria

public void WriteYaml(IEmitter emitter, object value, Type type, ObjectSerializer serializer)
{
if (value == null)
{
emitter.Emit(new Scalar(string.Empty));
return;
}

var obj = (byte[])value;
var strValue = Encoding.UTF8.GetString(obj);

// Check if the string is multi-line by looking for a newline character.
var scalarStyle = strValue.Contains('\n') ? ScalarStyle.Literal : ScalarStyle.Any;

emitter.Emit(new Scalar(
AnchorName.Empty,
TagName.Empty,
strValue,
scalarStyle,
true,
true));
var encoded = Convert.ToBase64String(obj);
emitter.Emit(new Scalar(encoded));
}
}

Expand Down
54 changes: 44 additions & 10 deletions tests/KubernetesClient.Tests/KubernetesYamlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -804,12 +804,12 @@ public void LoadSecret()
{
var kManifest = @"
apiVersion: v1
data:
username: YlhrdFlYQnc=
password: TXprMU1qZ2tkbVJuTjBwaQ==
kind: Secret
metadata:
name: test-secret
data:
username: bXktYXBw
password: Mzk1MjgkdmRnN0pi
";

var result = KubernetesYaml.Deserialize<V1Secret>(kManifest, true);
Expand All @@ -823,13 +823,8 @@ public void WriteSecret()
var kManifest = """
apiVersion: v1
data:
username: bXktYXBw
tls2.crt: |
-----BEGIN CERTIFICATE-----
FAKE CERT
FAKE CERT
FAKE CERT
-----END CERTIFICATE-----
username: YlhrdFlYQnc=
password: TXprMU1qZ2tkbVJuTjBwaQ==
kind: Secret
metadata:
name: test-secret
Expand All @@ -841,6 +836,45 @@ FAKE CERT
Assert.Equal(kManifest, yaml);
}

[Fact]
public void LoadConfigMap()
{
var kManifest = @"
apiVersion: v1
binaryData:
username: YlhrdFlYQnc=
data:
password: Mzk1MjgkdmRnN0pi
kind: ConfigMap
metadata:
name: test-configmap
";

var result = KubernetesYaml.Deserialize<V1ConfigMap>(kManifest, true);
Assert.Equal("bXktYXBw", Encoding.UTF8.GetString(result.BinaryData["username"]));
Assert.Equal("Mzk1MjgkdmRnN0pi", result.Data["password"]);
}

[Fact]
public void WriteConfigMap()
{
var kManifest = """
apiVersion: v1
binaryData:
username: YlhrdFlYQnc=
data:
password: Mzk1MjgkdmRnN0pi
kind: ConfigMap
metadata:
name: test-configmap
""";

var result = KubernetesYaml.Deserialize<V1ConfigMap>(kManifest, true);
var yaml = KubernetesYaml.Serialize(result);

Assert.Equal(kManifest, yaml);
}

[Fact]
public void DeserializeWithJsonPropertyName()
{
Expand Down
Loading