-
Notifications
You must be signed in to change notification settings - Fork 8
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
Adding Managed Identity support for connecting to Cosmos DB, Update dependencies with latest. #71
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason for deletion of this file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was not in use, couldn't find any reference. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, didn't realize it was a template file. Will restore it back. |
This file was deleted.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What changes were made to the PowerPoint file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,23 @@ | ||
# https://hub.docker.com/_/microsoft-dotnet | ||
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this Dockerfile generated using Visual Studio? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, the original was not working. So, had to overwrite with VS generated Docker. |
||
|
||
FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base | ||
WORKDIR /app | ||
|
||
# Restore, build and publish project. | ||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build | ||
WORKDIR / | ||
COPY src/Scaler.Demo/OrderGenerator/ src/Scaler.Demo/OrderGenerator/ | ||
COPY src/Scaler.Demo/Shared/ src/Scaler.Demo/Shared/ | ||
ARG BUILD_CONFIGURATION=Release | ||
WORKDIR /src | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should WORKDIR be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second thought, the earlier Dockerfile was small and used to work. Can you minimize the changes to each Dockerfile, and keep it close to the original? |
||
COPY ["Scaler.Demo/OrderGenerator/Keda.CosmosDb.Scaler.Demo.OrderGenerator.csproj", "Scaler.Demo/OrderGenerator/"] | ||
COPY ["Scaler.Demo/Shared/Keda.CosmosDb.Scaler.Demo.Shared.csproj", "Scaler.Demo/Shared/"] | ||
RUN dotnet restore "./Scaler.Demo/OrderGenerator/Keda.CosmosDb.Scaler.Demo.OrderGenerator.csproj" | ||
COPY . . | ||
WORKDIR "/src/Scaler.Demo/OrderGenerator" | ||
RUN dotnet build "./Keda.CosmosDb.Scaler.Demo.OrderGenerator.csproj" -c $BUILD_CONFIGURATION -o /app/build | ||
|
||
WORKDIR /src/Scaler.Demo/OrderGenerator | ||
RUN dotnet publish --configuration Release --output /app | ||
FROM build AS publish | ||
ARG BUILD_CONFIGURATION=Release | ||
RUN dotnet publish "./Keda.CosmosDb.Scaler.Demo.OrderGenerator.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false | ||
|
||
# Stage application. | ||
FROM mcr.microsoft.com/dotnet/runtime:6.0 | ||
FROM base AS final | ||
WORKDIR /app | ||
COPY --from=build /app . | ||
ENTRYPOINT ["dotnet", "Keda.CosmosDb.Scaler.Demo.OrderGenerator.dll"] | ||
COPY --from=publish /app/publish . | ||
ENTRYPOINT ["dotnet", "Keda.CosmosDb.Scaler.Demo.OrderGenerator.dll"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Project Sdk="Microsoft.NET.Sdk;Microsoft.NET.Sdk.Publish"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | ||
<DockerfileContext>..\..</DockerfileContext> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Bogus" Version="34.0.2" /> | ||
<PackageReference Include="Bogus" Version="35.5.1" /> | ||
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.40.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Shared\Keda.CosmosDb.Scaler.Demo.Shared.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="appsettings.json" CopyToOutputDirectory="PreserveNewest" /> | ||
</ItemGroup> | ||
</Project> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"CosmosDbConfig": { | ||
"Connection": "<connection-string-of-monitored-container-account>", | ||
"Endpoint": "https://{Cosmos Account Name}.documents.azure.com:443/", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either keep just the 'Endpoint' config or make it clear that either one of the two properties are required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case of Order Generator, we are not deploying it on AKS. It just used locally to generate CosmosDB records and trigger the Change Feed, hence Order Generator is using connection string method to authenticate. |
||
"Connection": "<Delete this line if using managed identity to connect to Cosmos DB, else update with connection-string-of-monitored-container-account>", | ||
"DatabaseId": "StoreDatabase", | ||
"ContainerId": "OrderContainer", | ||
"ContainerThroughput": 11000 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,23 @@ | ||
# https://hub.docker.com/_/microsoft-dotnet | ||
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. | ||
|
||
FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base | ||
WORKDIR /app | ||
|
||
# Restore, build and publish project. | ||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build | ||
WORKDIR / | ||
COPY src/Scaler.Demo/OrderProcessor/ src/Scaler.Demo/OrderProcessor/ | ||
COPY src/Scaler.Demo/Shared/ src/Scaler.Demo/Shared/ | ||
ARG BUILD_CONFIGURATION=Release | ||
WORKDIR /src | ||
COPY ["Scaler.Demo/OrderProcessor/Keda.CosmosDb.Scaler.Demo.OrderProcessor.csproj", "Scaler.Demo/OrderProcessor/"] | ||
COPY ["Scaler.Demo/Shared/Keda.CosmosDb.Scaler.Demo.Shared.csproj", "Scaler.Demo/Shared/"] | ||
RUN dotnet restore "./Scaler.Demo/OrderProcessor/Keda.CosmosDb.Scaler.Demo.OrderProcessor.csproj" | ||
COPY . . | ||
WORKDIR "/src/Scaler.Demo/OrderProcessor" | ||
RUN dotnet build "./Keda.CosmosDb.Scaler.Demo.OrderProcessor.csproj" -c $BUILD_CONFIGURATION -o /app/build | ||
|
||
WORKDIR /src/Scaler.Demo/OrderProcessor | ||
RUN dotnet publish --configuration Release --output /app | ||
FROM build AS publish | ||
ARG BUILD_CONFIGURATION=Release | ||
RUN dotnet publish "./Keda.CosmosDb.Scaler.Demo.OrderProcessor.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false | ||
|
||
# Stage application. | ||
FROM mcr.microsoft.com/dotnet/runtime:6.0 | ||
FROM base AS final | ||
WORKDIR /app | ||
COPY --from=build /app . | ||
ENTRYPOINT ["dotnet", "Keda.CosmosDb.Scaler.Demo.OrderProcessor.dll"] | ||
COPY --from=publish /app/publish . | ||
ENTRYPOINT ["dotnet", "Keda.CosmosDb.Scaler.Demo.OrderProcessor.dll"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
using Microsoft.Azure.Cosmos; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Azure.Identity; | ||
using static Azure.Core.HttpHeader; | ||
|
||
namespace Keda.CosmosDb.Scaler.Demo.OrderProcessor | ||
{ | ||
|
@@ -25,8 +27,27 @@ public Worker(CosmosDbConfig cosmosDbConfig, ILogger<Worker> logger) | |
|
||
public override async Task StartAsync(CancellationToken cancellationToken) | ||
{ | ||
Database leaseDatabase = await new CosmosClient(_cosmosDbConfig.LeaseConnection) | ||
.CreateDatabaseIfNotExistsAsync(_cosmosDbConfig.LeaseDatabaseId, cancellationToken: cancellationToken); | ||
Database leaseDatabase; | ||
|
||
// Create a new instance of the CosmosClient with a custom name | ||
CosmosClientOptions clientOptions = new CosmosClientOptions | ||
{ | ||
ApplicationName = "keda-external-azure-cosmos-db" | ||
}; | ||
|
||
if (string.IsNullOrEmpty(_cosmosDbConfig.LeaseConnection)) | ||
{ | ||
var credential = new DefaultAzureCredential(); | ||
|
||
leaseDatabase = new Microsoft.Azure.Cosmos.CosmosClient(_cosmosDbConfig.LeaseEndpoint, credential, clientOptions) | ||
.GetDatabase(_cosmosDbConfig.LeaseDatabaseId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will check the demo project's Readme but creating the lease database here prevents user from that manual step. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No new database is getting created, the code has been modified to handle AAD based CS based authentications There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you create the lease database in that case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
} | ||
else | ||
{ | ||
leaseDatabase = new Microsoft.Azure.Cosmos.CosmosClient(_cosmosDbConfig.LeaseConnection, clientOptions) | ||
|
||
.GetDatabase(_cosmosDbConfig.LeaseDatabaseId); | ||
} | ||
|
||
Container leaseContainer = await leaseDatabase | ||
.CreateContainerIfNotExistsAsync( | ||
|
@@ -37,7 +58,21 @@ public override async Task StartAsync(CancellationToken cancellationToken) | |
// Change feed processor instance name should be unique for each container application. | ||
string instanceName = $"Instance-{Dns.GetHostName()}"; | ||
|
||
_processor = new CosmosClient(_cosmosDbConfig.Connection) | ||
|
||
CosmosClient cosmosClient; | ||
|
||
if (string.IsNullOrEmpty(_cosmosDbConfig.Connection)) | ||
{ | ||
var credential = new DefaultAzureCredential(); | ||
|
||
cosmosClient = new Microsoft.Azure.Cosmos.CosmosClient(_cosmosDbConfig.Endpoint, credential); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
} | ||
else | ||
{ | ||
cosmosClient = new Microsoft.Azure.Cosmos.CosmosClient(_cosmosDbConfig.Connection); | ||
} | ||
|
||
_processor = cosmosClient | ||
.GetContainer(_cosmosDbConfig.DatabaseId, _cosmosDbConfig.ContainerId) | ||
.GetChangeFeedProcessorBuilder<Order>(_cosmosDbConfig.ProcessorName, ProcessOrdersAsync) | ||
.WithInstanceName(instanceName) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,8 @@ | |
} | ||
}, | ||
"CosmosDbConfig": { | ||
"Connection": "<connection-string-of-monitored-container-account>", | ||
"DatabaseId": "StoreDatabase", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You only need it for local development. In AKS all config is passed via YAML. We use Endpoint in case of AAD and Connection in case of CS. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We ensured that local development is possible, that we will stop supporting with the change. Please ensure that all demo steps for connection string-based demo and connection string-based scaler continue to work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want these settings in the appsettings.json of the docker images, if add these here the user will have to explicitly delete it before publishing. I can add it in appsettings.development.json. Does that work? |
||
"ContainerId": "OrderContainer", | ||
"LeaseConnection": "<connection-string-of-lease-container-account>", | ||
"LeaseDatabaseId": "StoreDatabase", | ||
"LeaseContainerId": "OrderProcessorLeases", | ||
"ProcessorName": "OrderProcessor" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Deploy order processor application. | ||
|
||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: cosmosdb-order-processor | ||
namespace: default | ||
spec: | ||
replicas: 1 # A replica is required to be up momentarily to initialize the change-feed. | ||
selector: | ||
matchLabels: | ||
app: cosmosdb-order-processor | ||
template: | ||
metadata: | ||
labels: | ||
app: cosmosdb-order-processor | ||
spec: | ||
containers: | ||
- name: cosmosdb-order-processor | ||
image: <docker-id>/cosmosdb-order-processor:latest | ||
imagePullPolicy: Always | ||
env: | ||
- name: CosmosDbConfig__Connection | ||
value: <connection-string-of-monitored-container> | ||
- name: CosmosDbConfig__LeaseConnection | ||
value: <connection-string-of-lease-container> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Create KEDA scaled object to scale order processor application. | ||
|
||
apiVersion: keda.sh/v1alpha1 | ||
kind: ScaledObject | ||
metadata: | ||
name: cosmosdb-order-processor-scaledobject | ||
namespace: default | ||
spec: | ||
pollingInterval: 20 | ||
scaleTargetRef: | ||
name: cosmosdb-order-processor | ||
triggers: | ||
- type: external | ||
metadata: | ||
scalerAddress: cosmosdb-scaler.default:4050 | ||
connection: <connection-string-of-monitored-container-account> | ||
databaseId: StoreDatabase | ||
containerId: OrderContainer | ||
leaseConnection: <connection-string-of-lease-container-account> | ||
leaseDatabaseId: StoreDatabase | ||
leaseContainerId: OrderProcessorLeases | ||
processorName: OrderProcessor |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,10 @@ spec: | |
- type: external | ||
metadata: | ||
scalerAddress: cosmosdb-scaler.default:4050 | ||
connection: <connection-string-of-monitored-container-account> | ||
endpoint: <endpointURL-for-CosmosDB-account-monitored-container> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use kebab-case instead of a mix for all values inside angular brackets. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
databaseId: StoreDatabase | ||
containerId: OrderContainer | ||
leaseConnection: <connection-string-of-lease-container-account> | ||
leaseEndpoint: <endpointURL-for-CosmosDB-account-lease-container> | ||
leaseDatabaseId: StoreDatabase | ||
leaseContainerId: OrderProcessorLeases | ||
processorName: OrderProcessor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`connection` metadata
to`endpoint` metadata
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok