Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
zombienet-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
zombienet-sdk
Commits
d2bed823
Verified
Commit
d2bed823
authored
1 year ago
by
Loris Moulin
Browse files
Options
Downloads
Patches
Plain Diff
feat: added custom serialization logic for Resources
parent
1afdb4ab
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
crates/configuration/src/shared/node.rs
+0
-2
0 additions, 2 deletions
crates/configuration/src/shared/node.rs
crates/configuration/src/shared/resources.rs
+43
-2
43 additions, 2 deletions
crates/configuration/src/shared/resources.rs
with
43 additions
and
4 deletions
crates/configuration/src/shared/node.rs
+
0
−
2
View file @
d2bed823
...
...
@@ -118,8 +118,6 @@ impl Serialize for NodeConfig {
state
.serialize_field
(
"bootnodes_addresses"
,
&
self
.bootnodes_addresses
)
?
;
}
state
.serialize_field
(
"resources"
,
&
self
.resources
)
?
;
if
self
.resources
==
self
.chain_context.default_resources
{
state
.skip_field
(
"resources"
)
?
;
}
else
{
...
...
This diff is collapsed.
Click to expand it.
crates/configuration/src/shared/resources.rs
+
43
−
2
View file @
d2bed823
...
...
@@ -2,7 +2,7 @@ use std::error::Error;
use
lazy_static
::
lazy_static
;
use
regex
::
Regex
;
use
serde
::
Serialize
;
use
serde
::
{
ser
::
Serialize
Struct
,
Serialize
}
;
use
super
::{
errors
::{
ConversionError
,
FieldError
},
...
...
@@ -64,7 +64,7 @@ impl From<u64> for ResourceQuantity {
}
/// Resources limits used in the context of podman/k8s.
#[derive(Debug,
Default,
Clone,
PartialEq
,
Serialize
)]
#[derive(Debug,
Default,
Clone,
PartialEq)]
pub
struct
Resources
{
request_memory
:
Option
<
ResourceQuantity
>
,
request_cpu
:
Option
<
ResourceQuantity
>
,
...
...
@@ -72,6 +72,47 @@ pub struct Resources {
limit_cpu
:
Option
<
ResourceQuantity
>
,
}
impl
Serialize
for
Resources
{
fn
serialize
<
S
>
(
&
self
,
serializer
:
S
)
->
Result
<
S
::
Ok
,
S
::
Error
>
where
S
:
serde
::
Serializer
,
{
let
mut
state
=
serializer
.serialize_struct
(
"Resources"
,
2
)
?
;
#[derive(Serialize)]
struct
ResourcesField
{
memory
:
Option
<
ResourceQuantity
>
,
cpu
:
Option
<
ResourceQuantity
>
,
}
if
self
.request_memory
.is_some
()
||
self
.request_memory
.is_some
()
{
state
.serialize_field
(
"requests"
,
&
ResourcesField
{
memory
:
self
.request_memory
.clone
(),
cpu
:
self
.request_cpu
.clone
(),
},
)
?
;
}
else
{
state
.skip_field
(
"requests"
)
?
;
}
if
self
.limit_memory
.is_some
()
||
self
.limit_memory
.is_some
()
{
state
.serialize_field
(
"limits"
,
&
ResourcesField
{
memory
:
self
.limit_memory
.clone
(),
cpu
:
self
.limit_cpu
.clone
(),
},
)
?
;
}
else
{
state
.skip_field
(
"limits"
)
?
;
}
state
.end
()
}
}
impl
Resources
{
/// Memory limit applied to requests.
pub
fn
request_memory
(
&
self
)
->
Option
<&
ResourceQuantity
>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment