Skip to content
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

Sanmeht/k8seslots #111

Merged
merged 3 commits into from
Mar 19, 2020
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
7 changes: 6 additions & 1 deletion Kudu.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ private static string GetSettingsPath(IEnvironment environment)
private static IEnvironment GetEnvironment(string siteRoot, string requestId)
{
string root = Path.GetFullPath(Path.Combine(siteRoot, ".."));
string appName = root.Replace("/home/apps/","");
System.Console.WriteLine("!!!!!!!!!!!! ROOT ::: "+root);
System.Console.WriteLine("!!!!!!!!!!!! AppNAME ::: " + appName);

// CORE TODO : test by setting SCM_REPOSITORY_PATH
// REVIEW: this looks wrong because it ignores SCM_REPOSITORY_PATH
Expand All @@ -293,7 +296,9 @@ private static IEnvironment GetEnvironment(string siteRoot, string requestId)
repositoryPath,
requestId,
Path.Combine(AppContext.BaseDirectory, "KuduConsole", "kudu.dll"),
null);
null,
appName);

return env;
}
}
Expand Down
7 changes: 1 addition & 6 deletions Kudu.Core/Deployment/Generator/OryxBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ public override Task Build(DeploymentContext context)
context.RepositoryPath = RepositoryPath;

// Initialize Oryx Args.
IOryxArguments args = OryxArgumentsFactory.CreateOryxArguments();

if(K8SEDeploymentHelper.IsK8SEEnvironment())
{
args.appName = environment.K8SEAppName;
}
IOryxArguments args = OryxArgumentsFactory.CreateOryxArguments(environment);

if (!args.SkipKuduSync)
{
Expand Down
9 changes: 6 additions & 3 deletions Kudu.Core/Deployment/Oryx/AppServiceOryxArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class AppServiceOryxArguments : IOryxArguments

public string VirtualEnv { get; set; }

public string appName { get; set; }
public string AppName { get; set; }

public AppServiceOryxArguments()
public AppServiceOryxArguments(IEnvironment environment)
{
RunOryxBuild = false;
SkipKuduSync = false;
Expand All @@ -34,8 +34,11 @@ public AppServiceOryxArguments()

if (K8SEDeploymentHelper.IsK8SEEnvironment())
{
Console.WriteLine("Oryx App Name : " + environment.K8SEAppName);
this.AppName = environment.K8SEAppName;

// K8SE TODO: Inject Environment
var frameworkArr = K8SEDeploymentHelper.GetLinuxFxVersion(appName);
var frameworkArr = K8SEDeploymentHelper.GetLinuxFxVersion(AppName);
framework = frameworkArr.Split("|")[0];
version = frameworkArr.Split("|")[1];
}
Expand Down
2 changes: 1 addition & 1 deletion Kudu.Core/Deployment/Oryx/ExpressBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public string SetupK8Artifacts(DeploymentContext context, IEnvironment environme
context.Logger.Log($"Building for K8.");

// Create NetCore Zip at tm build folder where artifact were build and copy it to sitePackages, .GetBranch()
string zipAppName = $"{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.zip";
string zipAppName = $"artifact.zip";

context.Logger.Log($"From {context.BuildTempPath} to {(environment.RepositoryPath + "/../artifacts/" + environment.CurrId)} ");
FileSystemHelpers.EnsureDirectory(environment.RepositoryPath + "/../artifacts/");
Expand Down
4 changes: 2 additions & 2 deletions Kudu.Core/Deployment/Oryx/FunctionAppOryxArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class FunctionAppOryxArguments : IOryxArguments
public Framework Language { get; set; }
public string PublishFolder { get; set; }
public string VirtualEnv { get; set; }
public string appName { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
public string AppName { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }

public FunctionAppOryxArguments()
public FunctionAppOryxArguments(IEnvironment environment)
{
SkipKuduSync = false;
FunctionsWorkerRuntime = ResolveWorkerRuntime();
Expand Down
2 changes: 1 addition & 1 deletion Kudu.Core/Deployment/Oryx/IOryxArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public interface IOryxArguments

string PublishFolder { get; set; }
string VirtualEnv { get; set; }
string appName { get; set; }
string AppName { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Kudu.Core.Deployment.Oryx
{
public class LinuxConsumptionFunctionAppOryxArguments : FunctionAppOryxArguments
{
public LinuxConsumptionFunctionAppOryxArguments() : base()
public LinuxConsumptionFunctionAppOryxArguments(IEnvironment env) : base(env)
{
SkipKuduSync = true;
Flags = BuildOptimizationsFlags.Off;
Expand Down
8 changes: 4 additions & 4 deletions Kudu.Core/Deployment/Oryx/OryxArgumentsFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ namespace Kudu.Core.Deployment.Oryx
{
public class OryxArgumentsFactory
{
public static IOryxArguments CreateOryxArguments()
public static IOryxArguments CreateOryxArguments(IEnvironment environment)
{
if (FunctionAppHelper.LooksLikeFunctionApp())
{
if (FunctionAppHelper.HasScmRunFromPackage())
{
return new LinuxConsumptionFunctionAppOryxArguments();
return new LinuxConsumptionFunctionAppOryxArguments(environment);
} else {
return new FunctionAppOryxArguments();
return new FunctionAppOryxArguments(environment);
}
}
return new AppServiceOryxArguments();
return new AppServiceOryxArguments(environment);
}
}
}
2 changes: 1 addition & 1 deletion Kudu.Core/Functions/FunctionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ private string GetFunctionSecretsFilePath(string functionName)
/// <param name="zip">the <see cref="ZipArchive"/> to be populated with function app content.</param>
/// <param name="includeAppSettings">Optional: indicates whether to add local.settings.json or not to the archive. Default is false.</param>
/// <param name="includeCsproj">Optional: indicates whether to add a .csproj to the archive. Default is false.</param>
/// <param name="projectName">Optional: the name for *.csproj file if <paramref name="includeCsproj"/> is true. Default is appName.</param>
/// <param name="projectName">Optional: the name for *.csproj file if <paramref name="includeCsproj"/> is true. Default is AppName.</param>
public void CreateArchive(ZipArchive zip, bool includeAppSettings = false, bool includeCsproj = false, string projectName = null)
{
var tracer = _traceFactory.GetTracer();
Expand Down
28 changes: 5 additions & 23 deletions Kudu.Core/K8SE/K8SEDeploymentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static string GetLinuxFxVersion(string appName)
BuildCtlArgumentsHelper.AddBuildCtlCommand(cmd, "get");
BuildCtlArgumentsHelper.AddAppNameArgument(cmd, appName);
BuildCtlArgumentsHelper.AddAppPropertyArgument(cmd, "linuxFxVersion");
return RunBuildCtlCommand(cmd.ToString(), "Running buildctl to retrieve framework info...");
return RunBuildCtlCommand(cmd.ToString(), "Retrieving framework info...");
}

/// <summary>
Expand All @@ -47,7 +47,7 @@ public static void UpdateBuildNumber(string appName, string buildNumber)
BuildCtlArgumentsHelper.AddAppNameArgument(cmd, appName);
BuildCtlArgumentsHelper.AddAppPropertyArgument(cmd, "buildVersion");
BuildCtlArgumentsHelper.AddAppPropertyValueArgument(cmd, buildNumber);
RunBuildCtlCommand(cmd.ToString(), "Running buildctl to retrieve framework info...");
RunBuildCtlCommand(cmd.ToString(), "Updating build version...");
}

private static string RunBuildCtlCommand(string args, string msg)
Expand Down Expand Up @@ -83,34 +83,16 @@ private static string RunBuildCtlCommand(string args, string msg)

public static string GetAppName(HttpContext context)
{
var host = context.Request.Headers["Host"].ToString();
var appName = "";
var appName = context.Request.Headers["K8SE_APP_NAME"].ToString();

if (host.IndexOf(".") <= 0)
if (string.IsNullOrEmpty(appName))
{
context.Response.StatusCode = 401;
// K8SE TODO: move this to resource map
throw new InvalidOperationException("Couldn't recognize AppName");
}
else
{
appName = host.Substring(0, host.IndexOf("."));
}
Console.WriteLine("AppName :::::::: " + appName);

try
{
// block any internal service communication to build server
// K8SE TODO: Check source IP to be in the internal service range and block them
Int32.Parse(appName);
context.Response.StatusCode = 401;
// K8SE TODO: move this to resource map
throw new InvalidOperationException("Internal services prohibited to communicate with the build server.");
}
catch(Exception)
{
// pass
}
Console.WriteLine("AppName :::::::: " + appName);

return appName;
}
Expand Down
2 changes: 0 additions & 2 deletions Kudu.Services.Web/KubeMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using System;
Expand All @@ -10,7 +9,6 @@
using System.Text;
using Kudu.Core.Helpers;
using System.IO;
using System.Net.Http.Headers;
using Kudu.Core.K8SE;

namespace Kudu.Services.Web
Expand Down