diff --git a/GZCTF/Models/Request/Game/ChallengeDetailModel.cs b/GZCTF/Models/Request/Game/ChallengeDetailModel.cs index b3ce5603a..93ff5a0dc 100644 --- a/GZCTF/Models/Request/Game/ChallengeDetailModel.cs +++ b/GZCTF/Models/Request/Game/ChallengeDetailModel.cs @@ -59,7 +59,7 @@ internal static ChallengeDetailModel FromInstance(Instance instance) { InstanceEntry = instance.Container?.Entry, CloseTime = instance.Container?.ExpectStopAt, - Url = instance.Challenge.Type.IsDynamic() ? + Url = instance.Challenge.Type == ChallengeType.DynamicAttachment ? instance.FlagContext?.Attachment?.UrlWithName(instance.Challenge.FileName) : instance.Challenge.Attachment?.UrlWithName() } diff --git a/GZCTF/Services/K8sService.cs b/GZCTF/Services/K8sService.cs index 2292bff5e..8deffcced 100644 --- a/GZCTF/Services/K8sService.cs +++ b/GZCTF/Services/K8sService.cs @@ -3,8 +3,10 @@ using CTFServer.Utils; using Docker.DotNet.Models; using k8s; +using k8s.Autorest; using k8s.Models; using Microsoft.Extensions.Options; +using System.Net; using System.Text; namespace CTFServer.Services; @@ -47,7 +49,8 @@ public K8sService(ILogger logger) public async Task CreateContainer(ContainerConfig config, CancellationToken token = default) { - var name = $"{config.Image.Split("/").LastOrDefault()?.Split(":").FirstOrDefault()}-{Codec.StrMD5(config.Flag ?? Guid.NewGuid().ToString())[..16]}"; + // use uuid avoid Conflict + var name = $"{config.Image.Split("/").LastOrDefault()?.Split(":").FirstOrDefault()}-{Guid.NewGuid().ToString("N")[..16]}"; name = name.Replace('_', '-'); // Ensure name is available var pod = new V1Pod("v1", "Pod") { @@ -99,6 +102,12 @@ public K8sService(ILogger logger) { pod = await kubernetesClient.CreateNamespacedPodAsync(pod, "gzctf", cancellationToken: token); } + catch(HttpOperationException e) + { + logger.SystemLog($"容器 {name} 创建失败, 状态:{e.Response.StatusCode.ToString()}", TaskStatus.Fail, LogLevel.Warning); + logger.SystemLog($"容器 {name} 创建失败, 响应:{e.Response.Content}", TaskStatus.Fail, LogLevel.Error); + return null; + } catch (Exception e) { logger.LogError(e, "创建容器失败"); @@ -146,7 +155,7 @@ public K8sService(ILogger logger) try { - service = await kubernetesClient.CreateNamespacedServiceAsync(service, "gzctf", cancellationToken: token); + service = await kubernetesClient.CoreV1.CreateNamespacedServiceAsync(service, "gzctf", cancellationToken: token); } catch (Exception e) {