Skip to content

Commit

Permalink
Fixing issue with managed identity and added pod yaml for testing com…
Browse files Browse the repository at this point in the history
…mandline in hosted environment
  • Loading branch information
mmckechney committed Sep 19, 2023
1 parent 1342ada commit 52f348d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ Write-Host "Using keyvault name: '$keyVaultName'" -ForegroundColor DarkGreen
$scriptDir = Split-Path $script:MyInvocation.MyCommand.Path
.$scriptDir/create_aks_settingsfile.ps1 -sbmExe $sbmExe -path $path -resourceGroupName $resourceGroupName -storageAccountName $storageAccountName -eventHubNamespaceName $eventHubNamespaceName -serviceBusNamespaceName $serviceBusNamespaceName -sqlUserName $sqlUserName -sqlPassword $sqlPassword -acrName $containerRegistryName -keyVaultName $keyVaultName -serviceAccount $serviceAccountName -podCount $podCount

$yaml = Join-Path -Path $scriptDir -ChildPath "runnerpod.yaml"
$destYaml = Join-Path -Path $path -ChildPath "runnerpod.yaml"
(Get-Content $yaml) | foreach-object { $_ -replace "<<prefix>>", $prefix } | Set-Content $destYaml


28 changes: 28 additions & 0 deletions scripts/templates/kubernetes/runnerpod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: v1
kind: Pod
metadata:
name: sbm-runner
namespace: sqlbuildmanager
labels:
azure.workload.identity/use: 'true'
spec:
nodeSelector:
kubernetes.io/os: linux
serviceAccountName: <<prefix>>serviceaccount
containers:
- name: sbm-runner
image: <<prefix>>containerregistry.azurecr.io/sqlbuildmanager:latest-vNext
imagePullPolicy: Always
resources:
limits:
memory: 512M
cpu: 500m
command:
- sh
- -c
- tail -f /dev/null
restartPolicy: Always


#kubectl get pods -n sqlbuildmanager
#kubectl exec --stdin --tty sbm-runner -n sqlbuildmanager -- /bin/bash
1 change: 1 addition & 0 deletions src/SqlSync.Connection/ConnectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public static string GetConnectionString(string dbName, string serverName, strin
builder.Password = pw;
break;
}
log.LogDebug($"Database Connection string: {builder.ConnectionString}");
return builder.ConnectionString;
}

Expand Down
10 changes: 8 additions & 2 deletions src/SqlSync.SqlBuild/DacPacHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,24 @@ public static bool ExtractDacPac(string sourceDatabase, string sourceServer, Aut
connData.AuthenticationType = authType;
if (!string.IsNullOrWhiteSpace(userName)) connData.UserId = userName;
if (!string.IsNullOrWhiteSpace(password)) connData.Password = password;
if (!string.IsNullOrWhiteSpace(managedIdentityClientId)) connData.ManagedIdentityClientId = managedIdentityClientId;

//Pre-test the connection. the DacServices can hang for a long time if the connection is bad
log.LogInformation($"Testing connection to {sourceServer}/{sourceDatabase} using authentication type {authType}");
if (!ConnectionHelper.TestDatabaseConnection(sourceDatabase, sourceServer, userName, password,authType, timeouts, managedIdentityClientId))
{
log.LogError($"Unable to create Dacpac for {sourceServer}.{sourceDatabase}. Database connection test failed.");
log.LogError($"Unable to create Dacpac for {sourceServer}/{sourceDatabase}. Database connection test failed.");
return false;
}
else
{
log.LogInformation($"Connection to {sourceServer}/{sourceDatabase} with authentication type {authType} was successful");
}
var connString = ConnectionHelper.GetConnectionString(connData);
Version ver = Assembly.GetExecutingAssembly().GetName().Version;
DacServices service = new DacServices(connString);
service.Extract(dacPacFileName, sourceDatabase, "Sql Build Manager", ver, "Sql Build Manager",null, opts);
log.LogInformation($"dacpac from {sourceServer}.{sourceDatabase} saved to {dacPacFileName}");
log.LogInformation($"DACPAC from {sourceServer}.{sourceDatabase} saved to {dacPacFileName}");
return true;
}
catch (Exception exe)
Expand Down

0 comments on commit 52f348d

Please sign in to comment.