From 939ce888a1586a1ad1c72130bfb1b0db3357918c Mon Sep 17 00:00:00 2001 From: d-g-town <66391417+d-g-town@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:51:08 -0500 Subject: [PATCH] patch yaml nil checks (#4038) --- .../handlers/porter_app/yaml_from_revision.go | 2 ++ internal/porter_app/v2/yaml.go | 31 ++++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/api/server/handlers/porter_app/yaml_from_revision.go b/api/server/handlers/porter_app/yaml_from_revision.go index 3ee8c39419..0589b2d494 100644 --- a/api/server/handlers/porter_app/yaml_from_revision.go +++ b/api/server/handlers/porter_app/yaml_from_revision.go @@ -66,6 +66,8 @@ func (c *PorterYAMLFromRevisionHandler) ServeHTTP(w http.ResponseWriter, r *http ctx, span := telemetry.NewSpan(r.Context(), "serve-porter-yaml-from-revision") defer span.End() + r = r.Clone(ctx) + project, _ := r.Context().Value(types.ProjectScope).(*models.Project) cluster, _ := r.Context().Value(types.ClusterScope).(*models.Cluster) diff --git a/internal/porter_app/v2/yaml.go b/internal/porter_app/v2/yaml.go index 4bbf05cf89..a9fc725316 100644 --- a/internal/porter_app/v2/yaml.go +++ b/internal/porter_app/v2/yaml.go @@ -481,7 +481,9 @@ func AppFromProto(appProto *porterv1.PorterApp) (PorterApp, error) { } for _, envGroup := range appProto.EnvGroups { - porterApp.EnvGroups = append(porterApp.EnvGroups, fmt.Sprintf("%s:v%d", envGroup.Name, envGroup.Version)) + if envGroup != nil { + porterApp.EnvGroups = append(porterApp.EnvGroups, fmt.Sprintf("%s:v%d", envGroup.Name, envGroup.Version)) + } } if appProto.EfsStorage != nil { @@ -494,19 +496,24 @@ func AppFromProto(appProto *porterv1.PorterApp) (PorterApp, error) { } func appServiceFromProto(service *porterv1.Service) (Service, error) { - appService := Service{ - Name: service.Name, - Run: service.RunOptional, - Instances: service.InstancesOptional, - CpuCores: service.CpuCores, - RamMegabytes: int(service.RamMegabytes), - GpuCoresNvidia: service.GpuCoresNvidia, // nolint:staticcheck // https://linear.app/porter/issue/POR-2137/support-new-gpu-field-in-porteryaml - Port: int(service.Port), - SmartOptimization: service.SmartOptimization, - GPU: &GPU{ + var gpu *GPU + if service.Gpu != nil { + gpu = &GPU{ Enabled: service.Gpu.Enabled, GpuCoresNvidia: int(service.Gpu.GpuCoresNvidia), - }, + } + } + + appService := Service{ + Name: service.Name, + Run: service.RunOptional, + Instances: service.InstancesOptional, + CpuCores: service.CpuCores, + RamMegabytes: int(service.RamMegabytes), + GpuCoresNvidia: service.GpuCoresNvidia, // nolint:staticcheck // https://linear.app/porter/issue/POR-2137/support-new-gpu-field-in-porteryaml + Port: int(service.Port), + SmartOptimization: service.SmartOptimization, + GPU: gpu, TerminationGracePeriodSeconds: service.TerminationGracePeriodSeconds, }