Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Rainbond2
Commits
e98f87ce
Unverified
Commit
e98f87ce
authored
5 years ago
by
barnettZQG
Committed by
GitHub
5 years ago
Browse files
Options
Download
Plain Diff
Merge pull request #359 from GLYASAI/issue#206
[FIX] wrong memory
parents
cfaeb330
d1564f1d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
builder/parser/parser.go
+30
-12
builder/parser/parser.go
builder/parser/parser_test.go
+5
-0
builder/parser/parser_test.go
with
35 additions
and
12 deletions
+35
-12
builder/parser/parser.go
+
30
-
12
View file @
e98f87ce
...
...
@@ -239,32 +239,50 @@ func DetermineDeployType(imageName Image) string {
//10k 128
//10b 128
func
readmemory
(
s
string
)
int
{
def
:=
512
s
=
strings
.
ToLower
(
s
)
// <binarySI> ::= Ki | Mi | Gi | Ti | Pi | Ei
unit
:=
map
[
string
]
string
{
"gi"
:
"Gi"
,
"g"
:
"Gi"
,
"mi"
:
"Mi"
,
"m"
:
"Mi"
,
"ki"
:
"Ki"
,
"k"
:
"Ki"
,
isValid
:=
false
validUnits
:=
map
[
string
]
string
{
"gi"
:
"Gi"
,
"mi"
:
"Mi"
,
"ki"
:
"Ki"
,
}
u
:=
""
for
k
,
v
:=
range
unit
{
for
k
,
v
:=
range
validUnits
{
if
strings
.
Contains
(
s
,
k
)
{
u
=
k
isValid
=
true
s
=
strings
.
Replace
(
s
,
k
,
v
,
1
)
break
}
}
if
u
==
""
{
return
512
if
!
isValid
{
validUnits
:=
map
[
string
]
string
{
"g"
:
"Gi"
,
"m"
:
"Mi"
,
"k"
:
"Ki"
,
}
for
k
,
v
:=
range
validUnits
{
if
strings
.
Contains
(
s
,
k
)
{
isValid
=
true
s
=
strings
.
Replace
(
s
,
k
,
v
,
1
)
break
}
}
}
if
!
isValid
{
logrus
.
Warningf
(
"s: %s; invalid unit"
,
s
)
return
def
}
q
,
err
:=
resource
.
ParseQuantity
(
s
)
if
err
!=
nil
{
return
512
logrus
.
Warningf
(
"s: %s; failed to parse quantity: %v"
,
s
,
err
)
return
def
}
re
,
ok
:=
q
.
AsInt64
()
if
!
ok
{
logrus
.
Warningf
(
"failed to int64: %d"
,
re
)
return
def
}
re
,
_
:=
q
.
AsInt64
()
if
re
!=
0
{
return
int
(
re
)
/
(
1024
*
1024
)
}
return
512
return
def
}
//ParseImageName parse image name
...
...
This diff is collapsed.
Click to expand it.
builder/parser/parser_test.go
+
5
-
0
View file @
e98f87ce
...
...
@@ -54,9 +54,14 @@ func TestReadmemory(t *testing.T) {
mem
string
exp
int
}{
{
mem
:
""
,
exp
:
512
},
{
mem
:
"2Gi"
,
exp
:
2
*
1024
},
{
mem
:
"2G"
,
exp
:
2
*
1024
},
{
mem
:
"300Mi"
,
exp
:
300
},
{
mem
:
"300m"
,
exp
:
300
},
{
mem
:
"1024Ki"
,
exp
:
1024
/
1024
},
{
mem
:
"1024k"
,
exp
:
1024
/
1024
},
{
mem
:
"1024K"
,
exp
:
1024
/
1024
},
{
mem
:
"1048576Bi"
,
exp
:
512
},
{
mem
:
"abc"
,
exp
:
512
},
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment