mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-05-07 01:49:27 +00:00
* ci(docker): build dist-tests images * Update to .net 10, kubernetes client 18.0.13 Kubernetes client 18.0.13 is compatible with Kubernetes 1.34.x. The Kubernetes version is selected automatically by kubeadm in docker desktop (v1.34.1). See https://github.com/kubernetes-client/csharp#version-compatibility for a compatibility table. * Updates to support Kubernetes upgrade * bump openapi.yaml to match openapi.yaml in the logos-storage-nim docker image * bump doc to .net 10 * bump docker to .net 10 * Build image with latest tag always Always build an image with a latest tag (as well as a sha commit hash) when there's a push to master * docker image tag as "latest" only when pushing to master * Update docker image to install doctl * Remove doctl install kubeconfig is now created and uses a plain bearer token instead of using doctl as a credential mgr * Rename and remove all instances of Codex * Further remove CodexNetDeployer as it is no longer needed --------- Co-authored-by: Adam Uhlíř <adam@uhlir.dev>
108 lines
4.0 KiB
C#
108 lines
4.0 KiB
C#
using Core;
|
|
using KubernetesWorkflow.Types;
|
|
using Logging;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using Utils;
|
|
|
|
namespace StoragePlugin
|
|
{
|
|
public class ApiChecker
|
|
{
|
|
// <INSERT-OPENAPI-YAML-HASH>
|
|
private const string OpenApiYamlHash = "47-B8-22-44-3B-51-EB-82-CC-C1-DD-56-F0-7E-EC-7F-CD-E0-8F-5E-F6-3B-40-E0-02-E6-71-DB-B8-03-65-18";
|
|
private const string OpenApiFilePath = "/logosstorage/openapi.yaml";
|
|
private const string DisableEnvironmentVariable = "StoragePlugin_DISABLE_APICHECK";
|
|
|
|
private const bool Disable = false;
|
|
|
|
private const string Warning =
|
|
"Warning: StoragePlugin was unable to find the openapi.yaml file in the Logos Storage container. Are you running an old version of Logos Storage? " +
|
|
"Plugin will continue as normal, but API compatibility is not guaranteed!";
|
|
|
|
private const string Failure =
|
|
"Logos Storage API compatibility check failed! " +
|
|
"openapi.yaml used by StoragePlugin does not match openapi.yaml in Logos Storage container. The openapi.yaml in " +
|
|
"'ProjectPlugins/StoragePlugin' has been overwritten with the container one. " +
|
|
"Please and rebuild this project. If you wish to disable API compatibility checking, please set " +
|
|
$"the environment variable '{DisableEnvironmentVariable}' or set the disable bool in 'ProjectPlugins/StoragePlugin/ApiChecker.cs'.";
|
|
|
|
private static bool checkPassed = false;
|
|
|
|
private readonly IPluginTools pluginTools;
|
|
private readonly ILog log;
|
|
|
|
public ApiChecker(IPluginTools pluginTools)
|
|
{
|
|
this.pluginTools = pluginTools;
|
|
log = pluginTools.GetLog();
|
|
|
|
if (string.IsNullOrEmpty(OpenApiYamlHash)) throw new Exception("OpenAPI yaml hash was not inserted by pre-build trigger.");
|
|
}
|
|
|
|
public void CheckCompatibility(RunningPod[] containers)
|
|
{
|
|
if (checkPassed) return;
|
|
|
|
Log("StoragePlugin is checking API compatibility...");
|
|
|
|
if (Disable || !string.IsNullOrEmpty(Environment.GetEnvironmentVariable(DisableEnvironmentVariable)))
|
|
{
|
|
Log("API compatibility checking has been disabled.");
|
|
checkPassed = true;
|
|
return;
|
|
}
|
|
|
|
var workflow = pluginTools.CreateWorkflow();
|
|
var container = containers.First().Containers.First();
|
|
var containerApi = workflow.ExecuteCommand(container, "cat", OpenApiFilePath);
|
|
|
|
if (string.IsNullOrEmpty(containerApi))
|
|
{
|
|
log.Error(Warning);
|
|
|
|
checkPassed = true;
|
|
return;
|
|
}
|
|
|
|
var containerHash = Hash(containerApi);
|
|
if (containerHash == OpenApiYamlHash)
|
|
{
|
|
Log("API compatibility check passed.");
|
|
checkPassed = true;
|
|
return;
|
|
}
|
|
|
|
OverwriteOpenApiYaml(containerApi);
|
|
|
|
log.Error(Failure);
|
|
throw new Exception(Failure);
|
|
}
|
|
|
|
private void OverwriteOpenApiYaml(string containerApi)
|
|
{
|
|
Log("API compatibility check failed. Updating StoragePlugin...");
|
|
var openApiFilePath = Path.Combine(PluginPathUtils.ProjectPluginsDir, "LogosStorageClient", "openapi.yaml");
|
|
if (!File.Exists(openApiFilePath)) throw new Exception("Unable to locate LogosStorageClient/openapi.yaml. Expected: " + openApiFilePath);
|
|
|
|
File.Delete(openApiFilePath);
|
|
File.WriteAllText(openApiFilePath, containerApi);
|
|
Log("LogosStorageClient/openapi.yaml has been updated.");
|
|
}
|
|
|
|
private string Hash(string file)
|
|
{
|
|
var fileBytes = Encoding.ASCII.GetBytes(file
|
|
.Replace(Environment.NewLine, ""));
|
|
var sha = SHA256.Create();
|
|
var hash = sha.ComputeHash(fileBytes);
|
|
return BitConverter.ToString(hash);
|
|
}
|
|
|
|
private void Log(string msg)
|
|
{
|
|
log.Log(msg);
|
|
}
|
|
}
|
|
}
|