Skip to content
This repository has been archived by the owner on Sep 22, 2024. It is now read-only.

Commit

Permalink
feat: upgrade pki and translators (#2)
Browse files Browse the repository at this point in the history
This upgrades to the new PKI v2 (rust / grpc) and the new re-written translators.
  • Loading branch information
buehler authored May 2, 2022
1 parent 76e9642 commit 2e4d042
Show file tree
Hide file tree
Showing 48 changed files with 894 additions and 726 deletions.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-grpc": {
"version": "2.45.0",
"commands": [
"dotnet-grpc"
]
}
}
}
2 changes: 1 addition & 1 deletion .github/workflows/operator-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
if: ${{env.BUILD_VERSION != ''}}
with:
context: ./
file: ./WirePact.Operator/Dockerfile
file: ./Operator/Dockerfile
push: true
build-args: |
BUILD_VERSION=${{ env.BUILD_VERSION }}
Expand Down
40 changes: 40 additions & 0 deletions Envoy/Envoy.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.20.1" />
<PackageReference Include="Grpc" Version="2.45.0" />
<PackageReference Include="Grpc.Core" Version="2.45.0" />
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.45.0" />
<PackageReference Include="Grpc.Net.Common" Version="2.45.0" />
<PackageReference Include="Grpc.Tools" Version="2.45.0" PrivateAssets="All" />
</ItemGroup>

<!-- <Target Name="Protobuf_Override" BeforeTargets="_Protobuf_CoreCompile">-->
<!-- <PropertyGroup>-->
<!-- <Protobuf_StandardImportsPath>$(Protobuf_StandardImportsPath);@(ProtoRoot)</Protobuf_StandardImportsPath>-->
<!-- </PropertyGroup>-->
<!-- </Target>-->

<!-- <ItemGroup>-->
<!-- <ProtoRoot Include="../external/envoy/api" />-->
<!-- <ProtoRoot Include="../external/xds" />-->
<!-- <ProtoRoot Include="../external/googleapis" />-->
<!-- <ProtoRoot Include="../external/protoc-gen-validate" />-->
<!-- <ProtoRoot Include="../external/opencensus/src" />-->
<!-- <ProtoRoot Include="../external/opentelemetry" />-->

<!-- <Protobuf Include="../external/xds/**/*.proto" GrpcServices="None" />-->
<!-- <Protobuf Include="../external/envoy/api/envoy/config/**/*.proto" GrpcServices="None" />-->
<!--&lt;!&ndash; <Protobuf Include="../external/googleapis/google/**/*.proto" GrpcServices="None" />&ndash;&gt;-->
<!-- <Protobuf Include="../external/opencensus/**/*.proto" GrpcServices="None" />-->
<!-- <Protobuf Include="../external/opentelemetry/**/*.proto" GrpcServices="None" />-->
<!-- <Protobuf Include="../external/protoc-gen-validate/**/*.proto" GrpcServices="None" />-->
<!-- </ItemGroup>-->

</Project>
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DotnetKubernetesClient;
using DotnetKubernetesClient;
using k8s;
using k8s.Models;
using KubeOps.Operator.Controller;
using KubeOps.Operator.Controller.Results;
using KubeOps.Operator.Entities.Extensions;
using KubeOps.Operator.Rbac;
using Microsoft.Extensions.Logging;
using WirePact.Operator.Entities;
using Operator.Entities;

namespace WirePact.Operator.Controller;
namespace Operator.Controller;

/// <summary>
/// Controller that updates deployments/services for mesh participants.
/// </summary>
[EntityRbac(typeof(V1Alpha1CredentialTranslator), typeof(V1Alpha1Pki), Verbs = RbacVerb.Get)]
[EntityRbac(typeof(V1Alpha1CredentialTranslator), Verbs = RbacVerb.Get)]
[EntityRbac(typeof(V1Alpha1Pki), Verbs = RbacVerb.List)]
[EntityRbac(
typeof(V1Deployment),
typeof(V1Service),
Expand All @@ -33,23 +26,17 @@ public class ParticipantController : IResourceController<V1Alpha1MeshParticipant
private const string EnvoyContainerName = "wirepact-envoy";
private const string TranslatorContainerName = "wirepact-translator";
private const string ConfigVolumeName = "wirepact-envoy-config";
private const string EnvoyImage = "envoyproxy/envoy-alpine:v1.20-latest";
private const string EnvoyImage = "envoyproxy/envoy:v1.22-latest";

private readonly ILogger<ParticipantController> _logger;
private readonly IKubernetesClient _client;

/// <summary>
/// Ctor.
/// </summary>
/// <param name="logger"></param>
/// <param name="client"></param>
public ParticipantController(ILogger<ParticipantController> logger, IKubernetesClient client)
{
_logger = logger;
_client = client;
}

/// <inheritdoc />
public async Task<ResourceControllerResult?> ReconcileAsync(V1Alpha1MeshParticipant participant)
{
_logger.LogInformation(
Expand Down Expand Up @@ -123,7 +110,6 @@ public ParticipantController(ILogger<ParticipantController> logger, IKubernetesC
return null;
}

/// <inheritdoc />
public async Task DeletedAsync(V1Alpha1MeshParticipant participant)
{
// remove all additions from the deployment
Expand Down Expand Up @@ -275,13 +261,13 @@ private async Task<PortCollection> GetPorts(

private async Task<string> PkiAddress()
{
var pki = await _client.Get<V1Alpha1Pki>("wirepact-pki");
if (pki == null)
var pki = await _client.List<V1Alpha1Pki>();
if (pki == null || !pki.Any())
{
throw new Exception("PKI must not be null");
}

return $"http://{pki.Status.DnsAddress}";
return $"http://{pki.First().Status.DnsAddress}";
}

private async Task CheckDeployment(
Expand Down Expand Up @@ -316,15 +302,15 @@ private async Task CheckDeployment(
.Concat(
new[]
{
new V1EnvVar("COMMON_NAME", $"{participant.Spec.Translator}-{participant.Name()}"),
new V1EnvVar("NAME", $"{participant.Spec.Translator}-{participant.Name()}"),
new V1EnvVar("INGRESS_PORT", translatorIngressPort.ToString()),
new V1EnvVar("EGRESS_PORT", translatorEgressPort.ToString()),
new V1EnvVar("PKI_ADDRESS", pkiAddress),
})
.ToList(),
});
_logger.LogDebug(
@"Added translator container with common name ""{common_name}"", ingress port ""{ingressPort}"", egress port ""{egressPort}"" and pki address ""{pkiAddress}"".",
@"Added translator container with name ""{name}"", ingress port ""{ingressPort}"", egress port ""{egressPort}"" and pki address ""{pkiAddress}"".",
$"{participant.Spec.Translator}-{participant.Name()}",
translatorIngressPort.ToString(),
translatorEgressPort.ToString(),
Expand All @@ -339,7 +325,7 @@ private async Task CheckDeployment(
translatorContainer.Image = translator.Spec.Image;
deploymentUpdated |= translatorContainer.Image != translator.Spec.Image;
deploymentUpdated |= translatorContainer.EnsureEnvVar(
"COMMON_NAME",
"NAME",
$"{participant.Spec.Translator}-{participant.Name()}");
deploymentUpdated |= translatorContainer.EnsureEnvVar("INGRESS_PORT", translatorIngressPort.ToString());
deploymentUpdated |= translatorContainer.EnsureEnvVar("EGRESS_PORT", translatorEgressPort.ToString());
Expand Down Expand Up @@ -460,7 +446,7 @@ private async Task CheckDeployment(
}
}

// check if all other contains have the HTTP_PROXY env variable
// check if all other containers have the HTTP_PROXY env variable
foreach (var container in deployment.Spec.Template.Spec.Containers.Where(
c => c.Name != TranslatorContainerName &&
c.Name != EnvoyContainerName &&
Expand Down
Loading

0 comments on commit 2e4d042

Please sign in to comment.