Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
kube-bench
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
aquasecurity
kube-bench
Commits
42a10689
Commit
42a10689
authored
7 years ago
by
Abubakr-Sadik Nii Nai Davis
Browse files
Options
Downloads
Patches
Plain Diff
Add default version if version check fails.
parent
f90dd925
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/root.go
+11
-10
11 additions, 10 deletions
cmd/root.go
cmd/util.go
+16
-6
16 additions, 6 deletions
cmd/util.go
with
27 additions
and
16 deletions
cmd/root.go
+
11
−
10
View file @
42a10689
...
@@ -27,6 +27,7 @@ import (
...
@@ -27,6 +27,7 @@ import (
var
(
var
(
envVarsPrefix
=
"KUBE_BENCH"
envVarsPrefix
=
"KUBE_BENCH"
cfgDir
=
"./cfg"
cfgDir
=
"./cfg"
defaultKubeVersion
=
"1.6"
cfgFile
string
cfgFile
string
jsonFmt
bool
jsonFmt
bool
pgSql
bool
pgSql
bool
...
...
This diff is collapsed.
Click to expand it.
cmd/util.go
+
16
−
6
View file @
42a10689
...
@@ -214,25 +214,35 @@ func multiWordReplace(s string, subname string, sub string) string {
...
@@ -214,25 +214,35 @@ func multiWordReplace(s string, subname string, sub string) string {
}
}
func
getKubeVersion
()
string
{
func
getKubeVersion
()
string
{
var
ver
string
var
matched
bool
failmsg
:=
"kubernetes version check failed"
failmsg
:=
"kubernetes version check failed"
// These executables might not be on the user's path.
// These executables might not be on the user's path.
_
,
err
:=
exec
.
LookPath
(
"kubectl"
)
_
,
err
:=
exec
.
LookPath
(
"kubectl"
)
if
err
!=
nil
{
if
err
!=
nil
{
exit
WithError
(
fmt
.
Errorf
(
"%s: %s"
,
failmsg
,
err
)
)
continue
WithError
(
err
,
failmsg
)
}
}
cmd
:=
exec
.
Command
(
"kubectl"
,
"version"
,
"--short"
)
cmd
:=
exec
.
Command
(
"kubectl"
,
"version"
,
"--short"
)
out
,
err
:=
cmd
.
CombinedOutput
()
out
,
err
:=
cmd
.
CombinedOutput
()
if
err
!=
nil
{
if
err
!=
nil
{
exit
WithError
(
fmt
.
Errorf
(
"%s
, %s"
,
failmsg
,
out
)
)
continue
WithError
(
fmt
.
Errorf
(
"%s
"
,
out
),
""
)
}
}
validVersionPttn
:=
`\d.\d`
serverVersionRe
:=
regexp
.
MustCompile
(
`Server Version: v(\d+.\d+)`
)
serverVersionRe
:=
regexp
.
MustCompile
(
`Server Version: v(\d+.\d+)`
)
ver
:=
serverVersionRe
.
FindStringSubmatch
(
string
(
out
))[
1
]
subs
:=
serverVersionRe
.
FindStringSubmatch
(
string
(
out
))
if
len
(
subs
)
>
2
{
ver
=
string
(
subs
[
1
])
validVersionPttn
:=
`\d.\d`
if
matched
,
_
=
regexp
.
MatchString
(
validVersionPttn
,
ver
);
!
matched
{
continueWithError
(
fmt
.
Errorf
(
"%s: invalid server version "
,
ver
),
failmsg
)
}
}
if
matched
,
_
:=
regexp
.
MatchString
(
validVersionPttn
,
ver
);
!
matched
{
if
ver
==
""
||
!
matched
{
exitWithError
(
fmt
.
Errorf
(
"%s: invalid server version "
,
failmsg
,
ver
))
printlnWarn
(
fmt
.
Sprintf
(
"Unable to get kubectl version, using default version: %s"
,
defaultKubeVersion
))
ver
=
defaultKubeVersion
}
}
return
ver
return
ver
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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