Skip to content

Commit 272a6ad

Browse files
committed
Refactor WorkloadResourceQuantity to use pointers for CPU and Memory fields
1 parent fa16da1 commit 272a6ad

File tree

5 files changed

+18
-30
lines changed

5 files changed

+18
-30
lines changed

internal/graph/gengql/generated.go

+6-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/graph/schema/workloads.graphqls

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ type WorkloadResourceQuantity {
181181
"""
182182
The number of CPU cores.
183183
"""
184-
cpu: Float!
184+
cpu: Float
185185

186186
"""
187187
The amount of memory in bytes.
188188
"""
189-
memory: Int!
189+
memory: Int
190190
}
191191

192192
"""

internal/workload/application/models.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -230,21 +230,21 @@ func (a *Application) Resources() *ApplicationResources {
230230
if resources := a.Spec.Resources; resources != nil {
231231
if resources.Limits != nil {
232232
if q, err := resource.ParseQuantity(resources.Limits.Cpu); err == nil {
233-
ret.Limits.CPU = q.AsApproximateFloat64()
233+
ret.Limits.CPU = ptr.To(q.AsApproximateFloat64())
234234
}
235235

236236
if m, err := resource.ParseQuantity(resources.Limits.Memory); err == nil {
237-
ret.Limits.Memory = m.Value()
237+
ret.Limits.Memory = ptr.To(m.Value())
238238
}
239239
}
240240

241241
if resources.Requests != nil {
242242
if q, err := resource.ParseQuantity(resources.Requests.Cpu); err == nil {
243-
ret.Requests.CPU = q.AsApproximateFloat64()
243+
ret.Requests.CPU = ptr.To(q.AsApproximateFloat64())
244244
}
245245

246246
if m, err := resource.ParseQuantity(resources.Requests.Memory); err == nil {
247-
ret.Requests.Memory = m.Value()
247+
ret.Requests.Memory = ptr.To(m.Value())
248248
}
249249
}
250250

internal/workload/job/models.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -268,21 +268,21 @@ func (j *Job) Resources() *JobResources {
268268

269269
if resources.Limits != nil {
270270
if q, err := resource.ParseQuantity(resources.Limits.Cpu); err == nil {
271-
ret.Limits.CPU = q.AsApproximateFloat64()
271+
ret.Limits.CPU = ptr.To(q.AsApproximateFloat64())
272272
}
273273

274274
if m, err := resource.ParseQuantity(resources.Limits.Memory); err == nil {
275-
ret.Limits.Memory = m.Value()
275+
ret.Limits.Memory = ptr.To(m.Value())
276276
}
277277
}
278278

279279
if resources.Requests != nil {
280280
if q, err := resource.ParseQuantity(resources.Requests.Cpu); err == nil {
281-
ret.Requests.CPU = q.AsApproximateFloat64()
281+
ret.Requests.CPU = ptr.To(q.AsApproximateFloat64())
282282
}
283283

284284
if m, err := resource.ParseQuantity(resources.Requests.Memory); err == nil {
285-
ret.Requests.Memory = m.Value()
285+
ret.Requests.Memory = ptr.To(m.Value())
286286
}
287287
}
288288

internal/workload/models.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ type WorkloadResources interface {
9191
}
9292

9393
type WorkloadResourceQuantity struct {
94-
CPU float64 `json:"cpu"`
95-
Memory int64 `json:"memory"`
94+
CPU *float64 `json:"cpu"`
95+
Memory *int64 `json:"memory"`
9696
}
9797

9898
type AuthIntegration interface {

0 commit comments

Comments
 (0)