Skip to content

Commit

Permalink
patch yaml nil checks (#4038)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-g-town authored Dec 1, 2023
1 parent 6f24455 commit 939ce88
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
2 changes: 2 additions & 0 deletions api/server/handlers/porter_app/yaml_from_revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
31 changes: 19 additions & 12 deletions internal/porter_app/v2/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}

Expand Down

0 comments on commit 939ce88

Please sign in to comment.