Skip to content

Commit

Permalink
revert back to previous commit and add acr workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubramanianaks committed Oct 18, 2023
1 parent 0e43a11 commit 0c09970
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 187 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/acr-build-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: build and push to acr
on: [workflow_dispatch]

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: "mindarodev.azurecr.io"
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}

- name: Build and push for devhostagent
uses: docker/build-push-action@v5
with:
file: src/devhostagent/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: mindarodev.azurecr.io/lpkremoteagent:latest

- name: Build and push for devhostagent.restorationjob
uses: docker/build-push-action@v5
with:
file: src/devhostagent.restorationjob/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: mindarodev.azurecr.io/lpkrestorationjob:latest

- name: Build and push for routingmanager
uses: docker/build-push-action@v5
with:
file: src/routingmanager/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: mindarodev.azurecr.io/routingmanager:latest
4 changes: 2 additions & 2 deletions build/setup-kubectl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function install_kubectl {
arch="arm64"
fi

echo "Setting up kubectl $kubectl_version in $install_location with arch $arch"
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$kubectl_version/bin/linux/$arch/kubectl"
echo "Setting up kubectl $kubectl_version in $install_location with arch $arch"
curl -LO "https://dl.k8s.io/release/$kubectl_version/bin/linux/$arch/kubectl"
chmod +x kubectl
mkdir -p "$install_location"
mv kubectl "$install_location"
Expand Down
12 changes: 0 additions & 12 deletions src/common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,6 @@ internal static class ManagedIdentity
internal static class ImageName
{
public const string RemoteAgentImageName = "lpkremoteagent";
public const string RestorationJobImageName = "lpkrestorationjob";
}

internal static class ImageTag
{
public const string RoutingManagerImageTag = "stable";
}

internal static class Architecture
{
public const string Arm64 = "arm64";
public const string Amd64 = "amd64";
}

internal static class Https
Expand Down
7 changes: 0 additions & 7 deletions src/common/Kubernetes/IKubernetesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,6 @@ internal interface IKubernetesClient
/// <returns></returns>
Task<V1NamespaceList> ListNamespacesAsync(IEnumerable<KeyValuePair<string, string>> labels = null, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Retrieve the list of k8s nodes.
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<V1NodeList> ListNodes(CancellationToken cancellationToken = default);

#region Pods

/// <summary>
Expand Down
19 changes: 0 additions & 19 deletions src/common/Kubernetes/KubernetesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,6 @@ public KubernetesClient(

#endregion List namespaces

#region List nodes

/// <summary>
/// <see cref="IKubernetesClient.ListNodes(CancellationToken)"/>
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<V1NodeList> ListNodes(CancellationToken cancellationToken = default)
{
var result = await ClientInvokeWrapperAsync(async () =>
{
return await RestClient.CoreV1.ListNodeAsync(cancellationToken: cancellationToken);
}, nameof(ListNodes), cancellationToken);

return result?.Items == null ? new V1NodeList(new List<V1Node>()) : result;
}

#endregion List nodes

#region Deployments

/// <summary>
Expand Down
5 changes: 2 additions & 3 deletions src/devhostagent.restorationjob/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Build container
ARG ARCH=amd64
FROM mcr.microsoft.com/dotnet/sdk:7.0-cbl-mariner2.0-${ARCH} AS build
FROM mcr.microsoft.com/dotnet/sdk:7.0-cbl-mariner2.0 AS build

ARG Configuration=Release
ARG TelemetryType=TELEMETRY_DEVELOPMENT
Expand All @@ -19,7 +18,7 @@ ENV MINDARO_BUILD_NUMBER=${MindaroBuildNumber}
RUN dotnet publish -c ${Configuration} -o /output devhostAgent.restorationjob.csproj

# Final container
FROM mcr.microsoft.com/dotnet/aspnet:7.0-cbl-mariner2.0-${ARCH} as final
FROM mcr.microsoft.com/dotnet/aspnet:7.0-cbl-mariner2.0 as final

# Setup common tools
RUN tdnf clean all && \
Expand Down
5 changes: 2 additions & 3 deletions src/devhostagent/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Build container
ARG ARCH=amd64
FROM mcr.microsoft.com/dotnet/sdk:7.0-cbl-mariner2.0-${ARCH} AS build
FROM mcr.microsoft.com/dotnet/sdk:7.0-cbl-mariner2.0 AS build

RUN tdnf clean all && \
tdnf check-update && \
Expand All @@ -23,7 +22,7 @@ ENV MINDARO_BUILD_NUMBER=${MindaroBuildNumber}
RUN dotnet publish -c ${Configuration} -o /src/publish devhostAgent.csproj

# Final container
FROM mcr.microsoft.com/dotnet/aspnet:7.0-cbl-mariner2.0-${ARCH} as final
FROM mcr.microsoft.com/dotnet/aspnet:7.0-cbl-mariner2.0 as final

RUN tdnf clean all && \
tdnf check-update && \
Expand Down
58 changes: 4 additions & 54 deletions src/library.tests/EmbeddedFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,8 @@
// --------------------------------------------------------------------------------------------

using System;
using System.Threading;
using System.Threading.Tasks;
using FakeItEasy;
using k8s.Models;
using Microsoft.BridgeToKubernetes.Library.Client.ManagementClients;
using Microsoft.BridgeToKubernetes.Library.ClientFactory;
using Microsoft.BridgeToKubernetes.Library.ManagementClients;
using Microsoft.BridgeToKubernetes.Library.Models;
using Microsoft.BridgeToKubernetes.TestHelpers;
using Xunit;
using static Microsoft.BridgeToKubernetes.Common.Constants;

namespace Microsoft.BridgeToKubernetes.Library.Tests
{
Expand All @@ -23,70 +14,29 @@ namespace Microsoft.BridgeToKubernetes.Library.Tests
/// </summary>
public class EmbeddedFileTests : TestsBase
{
private ImageProvider _imageProvider;
private readonly IManagementClientFactory _managementClientFactory = A.Fake<IManagementClientFactory>();
private readonly IKubeConfigManagementClient _kubeConfigManagementClient = A.Fake<IKubeConfigManagementClient>();
private readonly IKubernetesManagementClient _kubernetesManagementClient = A.Fake<IKubernetesManagementClient>();
private readonly ImageProvider _imageProvider;

public EmbeddedFileTests()
{
_managementClientFactory = _autoFake.Resolve<IManagementClientFactory>();
_autoFake.Provide(_managementClientFactory);
_autoFake.Provide(_kubeConfigManagementClient);
_autoFake.Provide(_kubernetesManagementClient);
A.CallTo(() => _managementClientFactory.CreateKubeConfigClient(A<string>.Ignored)).Returns(_kubeConfigManagementClient);
A.CallTo(() => _kubeConfigManagementClient.GetKubeConfigDetails()).Returns(new KubeConfigDetails("", null, null, null, null));
A.CallTo(() => _managementClientFactory.CreateKubernetesManagementClient(A<KubeConfigDetails>.Ignored)).Returns(_kubernetesManagementClient);
A.CallTo(() => _kubernetesManagementClient.ListNodes(A<CancellationToken>._)).Returns(CreateV1NodeList());
_imageProvider = _autoFake.Resolve<ImageProvider>();
}

[Fact]
public void DevHostAgentImageTag() {
ImageTagTest(() => _imageProvider.DevHostImage);
}
public void DevHostAgentImageTag()
=> ImageTagTest(() => _imageProvider.DevHostImage);

[Fact]
public void RestorationJobImageTag()
=> ImageTagTest(() => _imageProvider.DevHostRestorationJobImage);

[Fact]
public void RoutingManagerImageTag()
=> ImageTagTest(() => _imageProvider.RoutingManagerImage);

[Fact]
public void DevHostAgentImageTagForArmArch() {
ImageTagTest(() => _imageProvider.DevHostImage, true);
}

private static Task<OperationResponse<V1NodeList>> CreateV1NodeList()
{
var v1NodeList = new V1NodeList();
var v1Node = new V1Node();
var v1NodeStatus = new V1NodeStatus
{
NodeInfo = new V1NodeSystemInfo()
};
v1NodeStatus.NodeInfo.Architecture = Architecture.Arm64.ToString();
v1Node.Status = v1NodeStatus;
v1NodeList.Items = new System.Collections.Generic.List<V1Node>
{
v1Node
};
return Task.FromResult(new OperationResponse<V1NodeList>(v1NodeList, null));
}

private static void ImageTagTest(Func<string> tagProperty, bool isArmArch = false)
private static void ImageTagTest(Func<string> tagProperty)
{
string image = tagProperty.Invoke();
Assert.False(string.IsNullOrWhiteSpace(image));
int i = image.IndexOf(':');
Assert.NotEqual(-1, i);
string tag = image.Substring(i + 1);
Assert.False(string.IsNullOrWhiteSpace(tag));
if (isArmArch) {
Assert.Contains("-"+Architecture.Arm64.ToString(), image);
}
}
}
}
9 changes: 0 additions & 9 deletions src/library/AppContainerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,6 @@ static AppContainerConfig()
MacAddressHash = (c) => c.Resolve<MacInformationProvider>().MacAddressHash
});

builder.Register(c =>
{
ManagementClientFactory.IsTelemetryEnabledCallback = c.Resolve<IApplicationInsightsLoggerConfig>().IsTelemetryEnabledCallback; // Set the IsTelemetryEnabled callback, in order to instantiate the SDK with the same telemetry collection settings as the CLI
ManagementClientFactory.IsLogFileEnabled = c.Resolve<IFileLoggerConfig>().LogFileEnabled;
return new ManagementClientFactory(c.Resolve<SourceUserAgentProvider>().UserAgent, c.Resolve<IOperationContext>().CorrelationId);
})
.As<IManagementClientFactory>()
.SingleInstance();

// Common Module
builder.RegisterModule<CommonModule>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ public interface IKubernetesManagementClient : IDisposable
/// <returns></returns>
Task<OperationResponse<IEnumerable<string>>> ListServicesInNamespacesAsync(string namespaceName, CancellationToken cancellationToken, bool excludeSystemServices = true);

/// <summary>
/// List all nodes in the cluster
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<OperationResponse<V1NodeList>> ListNodes(CancellationToken cancellationToken);

/// <summary>
/// Lists all the public Urls in the specified namespace
/// </summary>
Expand Down
23 changes: 0 additions & 23 deletions src/library/Client/ManagementClients/KubernetesManagementClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,29 +207,6 @@ public async Task<OperationResponse<IEnumerable<string>>> ListServicesInNamespac
new PII(namespaceName)));
}

public async Task<OperationResponse<V1NodeList>> ListNodes(CancellationToken cancellationToken)
{
return await this._managementClientExceptionStrategy.RunWithHandlingAsync(
async () =>
{
using (var perfLogger = _log.StartPerformanceLogger(
Events.KubernetesManagementClient.AreaName,
Events.KubernetesManagementClient.Operations.ListNodes))
{
V1NodeList result = await _kubernetesRestClientExceptionStrategy.RunWithHandlingAsync(
async () =>
{
return await _kubernetesClient.ListNodes(cancellationToken: cancellationToken);
},
new KubernetesRestClientExceptionStrategy.FailureConfig("Failed to list nodes."));

perfLogger.SetSucceeded();
return new OperationResponse<V1NodeList>(result, _operationContext);
}
},
new ManagementClientExceptionStrategy.FailureConfig("Failed to list nodes."));
}

public async Task<OperationResponse<IEnumerable<Uri>>> ListPublicUrlsInNamespaceAsync(string namespaceName, CancellationToken cancellationToken, string routingHeaderValue = null)
{
return await this._managementClientExceptionStrategy.RunWithHandlingAsync(
Expand Down
Loading

0 comments on commit 0c09970

Please sign in to comment.