Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
88258431
Unverified
Commit
88258431
authored
Nov 09, 2018
by
k8s-ci-robot
Committed by
GitHub
Nov 09, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #70323 from qingsenLi/git181010
[kubeadm/app/..add other packages]Switch to github.com/pkg/errors
parents
e0ce8478
e94dd19e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
51 additions
and
35 deletions
+51
-35
BUILD
cmd/kubeadm/app/constants/BUILD
+5
-1
constants.go
cmd/kubeadm/app/constants/constants.go
+9
-7
constants_test.go
cmd/kubeadm/app/constants/constants_test.go
+3
-2
BUILD
cmd/kubeadm/app/features/BUILD
+1
-0
features.go
cmd/kubeadm/app/features/features.go
+8
-6
BUILD
cmd/kubeadm/app/preflight/BUILD
+2
-0
checks.go
cmd/kubeadm/app/preflight/checks.go
+0
-0
checks_test.go
cmd/kubeadm/app/preflight/checks_test.go
+4
-4
checks_unix.go
cmd/kubeadm/app/preflight/checks_unix.go
+6
-5
checks_windows.go
cmd/kubeadm/app/preflight/checks_windows.go
+7
-6
utils.go
cmd/kubeadm/app/preflight/utils.go
+3
-2
utils_test.go
cmd/kubeadm/app/preflight/utils_test.go
+3
-2
No files found.
cmd/kubeadm/app/constants/BUILD
View file @
88258431
...
...
@@ -15,6 +15,7 @@ go_library(
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/version:go_default_library",
"//staging/src/k8s.io/cluster-bootstrap/token/api:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
],
)
...
...
@@ -35,5 +36,8 @@ go_test(
name = "go_default_test",
srcs = ["constants_test.go"],
embed = [":go_default_library"],
deps = ["//staging/src/k8s.io/apimachinery/pkg/util/version:go_default_library"],
deps = [
"//staging/src/k8s.io/apimachinery/pkg/util/version:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
],
)
cmd/kubeadm/app/constants/constants.go
View file @
88258431
...
...
@@ -25,6 +25,8 @@ import (
"path/filepath"
"time"
"github.com/pkg/errors"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/version"
bootstrapapi
"k8s.io/cluster-bootstrap/token/api"
...
...
@@ -382,7 +384,7 @@ func EtcdSupportedVersion(versionString string) (*version.Version, error) {
}
return
etcdVersion
,
nil
}
return
nil
,
fmt
.
Errorf
(
"Unsupported or unknown Kubernetes version(%v)"
,
kubernetesVersion
)
return
nil
,
errors
.
Errorf
(
"Unsupported or unknown Kubernetes version(%v)"
,
kubernetesVersion
)
}
// GetStaticPodDirectory returns the location on the disk where the Static Pod should be present
...
...
@@ -420,12 +422,12 @@ func CreateTempDirForKubeadm(dirName string) (string, error) {
tempDir
:=
path
.
Join
(
KubernetesDir
,
TempDirForKubeadm
)
// creates target folder if not already exists
if
err
:=
os
.
MkdirAll
(
tempDir
,
0700
);
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"failed to create directory %q: %v"
,
tempDir
,
er
r
)
return
""
,
errors
.
Wrapf
(
err
,
"failed to create directory %q"
,
tempDi
r
)
}
tempDir
,
err
:=
ioutil
.
TempDir
(
tempDir
,
dirName
)
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"couldn't create a temporary directory: %v"
,
err
)
return
""
,
errors
.
Wrap
(
err
,
"couldn't create a temporary directory"
)
}
return
tempDir
,
nil
}
...
...
@@ -435,13 +437,13 @@ func CreateTimestampDirForKubeadm(dirName string) (string, error) {
tempDir
:=
path
.
Join
(
KubernetesDir
,
TempDirForKubeadm
)
// creates target folder if not already exists
if
err
:=
os
.
MkdirAll
(
tempDir
,
0700
);
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"failed to create directory %q: %v"
,
tempDir
,
er
r
)
return
""
,
errors
.
Wrapf
(
err
,
"failed to create directory %q"
,
tempDi
r
)
}
timestampDirName
:=
fmt
.
Sprintf
(
"%s-%s"
,
dirName
,
time
.
Now
()
.
Format
(
"2006-01-02-15-04-05"
))
timestampDir
:=
path
.
Join
(
tempDir
,
timestampDirName
)
if
err
:=
os
.
Mkdir
(
timestampDir
,
0700
);
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"could not create timestamp directory: %v"
,
err
)
return
""
,
errors
.
Wrap
(
err
,
"could not create timestamp directory"
)
}
return
timestampDir
,
nil
...
...
@@ -452,13 +454,13 @@ func GetDNSIP(svcSubnet string) (net.IP, error) {
// Get the service subnet CIDR
_
,
svcSubnetCIDR
,
err
:=
net
.
ParseCIDR
(
svcSubnet
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"couldn't parse service subnet CIDR %q: %v"
,
svcSubnet
,
err
)
return
nil
,
errors
.
Wrapf
(
err
,
"couldn't parse service subnet CIDR %q"
,
svcSubnet
)
}
// Selects the 10th IP in service subnet CIDR range as dnsIP
dnsIP
,
err
:=
ipallocator
.
GetIndexedIP
(
svcSubnetCIDR
,
10
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"unable to get tenth IP address from service subnet CIDR %s: %v"
,
svcSubnetCIDR
.
String
(),
err
)
return
nil
,
errors
.
Wrapf
(
err
,
"unable to get tenth IP address from service subnet CIDR %s"
,
svcSubnetCIDR
.
String
()
)
}
return
dnsIP
,
nil
...
...
cmd/kubeadm/app/constants/constants_test.go
View file @
88258431
...
...
@@ -17,11 +17,12 @@ limitations under the License.
package
constants
import
(
"fmt"
"path/filepath"
"strings"
"testing"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/version"
)
...
...
@@ -151,7 +152,7 @@ func TestEtcdSupportedVersion(t *testing.T) {
{
kubernetesVersion
:
"1.99.0"
,
expectedVersion
:
nil
,
expectedError
:
fmt
.
Errorf
(
"Unsupported or unknown Kubernetes version(1.99.0)"
),
expectedError
:
errors
.
New
(
"Unsupported or unknown Kubernetes version(1.99.0)"
),
},
{
kubernetesVersion
:
"1.10.0"
,
...
...
cmd/kubeadm/app/features/BUILD
View file @
88258431
...
...
@@ -13,6 +13,7 @@ go_library(
deps = [
"//staging/src/k8s.io/apimachinery/pkg/util/version:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
],
)
...
...
cmd/kubeadm/app/features/features.go
View file @
88258431
...
...
@@ -22,6 +22,8 @@ import (
"strconv"
"strings"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/version"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
)
...
...
@@ -63,12 +65,12 @@ func ValidateVersion(allFeatures FeatureList, requestedFeatures map[string]bool,
}
parsedExpVersion
,
err
:=
version
.
ParseSemantic
(
requestedVersion
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Error parsing version %s: %v"
,
requestedVersion
,
err
)
return
errors
.
Wrapf
(
err
,
"error parsing version %s"
,
requestedVersion
)
}
for
k
:=
range
requestedFeatures
{
if
minVersion
:=
allFeatures
[
k
]
.
MinimumVersion
;
minVersion
!=
nil
{
if
!
parsedExpVersion
.
AtLeast
(
minVersion
)
{
return
fmt
.
Errorf
(
return
errors
.
Errorf
(
"the requested Kubernetes version (%s) is incompatible with the %s feature gate, which needs %s as a minimum"
,
requestedVersion
,
k
,
minVersion
)
}
...
...
@@ -134,7 +136,7 @@ func NewFeatureGate(f *FeatureList, value string) (map[string]bool, error) {
arr
:=
strings
.
SplitN
(
s
,
"="
,
2
)
if
len
(
arr
)
!=
2
{
return
nil
,
fmt
.
Errorf
(
"missing bool value for feature-gate key:%s"
,
s
)
return
nil
,
errors
.
Errorf
(
"missing bool value for feature-gate key:%s"
,
s
)
}
k
:=
strings
.
TrimSpace
(
arr
[
0
])
...
...
@@ -142,16 +144,16 @@ func NewFeatureGate(f *FeatureList, value string) (map[string]bool, error) {
featureSpec
,
ok
:=
(
*
f
)[
k
]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"unrecognized feature-gate key: %s"
,
k
)
return
nil
,
errors
.
Errorf
(
"unrecognized feature-gate key: %s"
,
k
)
}
if
featureSpec
.
PreRelease
==
utilfeature
.
Deprecated
{
return
nil
,
fmt
.
Errorf
(
"feature-gate key is deprecated: %s"
,
k
)
return
nil
,
errors
.
Errorf
(
"feature-gate key is deprecated: %s"
,
k
)
}
boolValue
,
err
:=
strconv
.
ParseBool
(
v
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid value %v for feature-gate key: %s, use true|false instead"
,
v
,
k
)
return
nil
,
errors
.
Errorf
(
"invalid value %v for feature-gate key: %s, use true|false instead"
,
v
,
k
)
}
featureGate
[
k
]
=
boolValue
}
...
...
cmd/kubeadm/app/preflight/BUILD
View file @
88258431
...
...
@@ -31,6 +31,7 @@ go_library(
"//vendor/github.com/PuerkitoBio/purell:go_default_library",
"//vendor/github.com/blang/semver:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/k8s.io/utils/exec:go_default_library",
],
)
...
...
@@ -47,6 +48,7 @@ go_test(
"//cmd/kubeadm/app/apis/kubeadm/v1beta1:go_default_library",
"//cmd/kubeadm/app/util/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/github.com/renstrom/dedent:go_default_library",
"//vendor/k8s.io/utils/exec:go_default_library",
"//vendor/k8s.io/utils/exec/testing:go_default_library",
...
...
cmd/kubeadm/app/preflight/checks.go
View file @
88258431
This diff is collapsed.
Click to expand it.
cmd/kubeadm/app/preflight/checks_test.go
View file @
88258431
...
...
@@ -18,11 +18,11 @@ package preflight
import
(
"bytes"
"fmt"
"io/ioutil"
"strings"
"testing"
"github.com/pkg/errors"
"github.com/renstrom/dedent"
"net/http"
...
...
@@ -173,12 +173,12 @@ func (pfct preflightCheckTest) Name() string {
return
"preflightCheckTest"
}
func
(
pfct
preflightCheckTest
)
Check
()
(
warning
,
error
s
[]
error
)
{
func
(
pfct
preflightCheckTest
)
Check
()
(
warning
,
error
List
[]
error
)
{
if
pfct
.
msg
==
"warning"
{
return
[]
error
{
fmt
.
Errorf
(
"warning"
)},
nil
return
[]
error
{
errors
.
New
(
"warning"
)},
nil
}
if
pfct
.
msg
!=
""
{
return
nil
,
[]
error
{
fmt
.
Errorf
(
"fake error"
)}
return
nil
,
[]
error
{
errors
.
New
(
"fake error"
)}
}
return
}
...
...
cmd/kubeadm/app/preflight/checks_unix.go
View file @
88258431
...
...
@@ -19,16 +19,17 @@ limitations under the License.
package
preflight
import
(
"fmt"
"os"
"github.com/pkg/errors"
)
// Check validates if an user has elevated (root) privileges.
func
(
ipuc
IsPrivilegedUserCheck
)
Check
()
(
warnings
,
error
s
[]
error
)
{
error
s
=
[]
error
{}
func
(
ipuc
IsPrivilegedUserCheck
)
Check
()
(
warnings
,
error
List
[]
error
)
{
error
List
=
[]
error
{}
if
os
.
Getuid
()
!=
0
{
error
s
=
append
(
errors
,
fmt
.
Errorf
(
"user is not running as root"
))
error
List
=
append
(
errorList
,
errors
.
New
(
"user is not running as root"
))
}
return
nil
,
error
s
return
nil
,
error
List
}
cmd/kubeadm/app/preflight/checks_windows.go
View file @
88258431
...
...
@@ -19,14 +19,15 @@ limitations under the License.
package
preflight
import
(
"fmt"
"os/exec"
"strings"
"github.com/pkg/errors"
)
// Check validates if an user has elevated (administrator) privileges.
func
(
ipuc
IsPrivilegedUserCheck
)
Check
()
(
warnings
,
error
s
[]
error
)
{
error
s
=
[]
error
{}
func
(
ipuc
IsPrivilegedUserCheck
)
Check
()
(
warnings
,
error
List
[]
error
)
{
error
List
=
[]
error
{}
// The "Well-known SID" of Administrator group is S-1-5-32-544
// The following powershell will return "True" if run as an administrator, "False" otherwise
...
...
@@ -35,10 +36,10 @@ func (ipuc IsPrivilegedUserCheck) Check() (warnings, errors []error) {
isAdmin
,
err
:=
exec
.
Command
(
"powershell"
,
args
...
)
.
Output
()
if
err
!=
nil
{
error
s
=
append
(
errors
,
fmt
.
Errorf
(
"unable to determine if user is running as administrator: %s"
,
err
))
error
List
=
append
(
errorList
,
errors
.
Wrap
(
err
,
"unable to determine if user is running as administrator"
))
}
else
if
strings
.
EqualFold
(
strings
.
TrimSpace
(
string
(
isAdmin
)),
"false"
)
{
error
s
=
append
(
errors
,
fmt
.
Errorf
(
"user is not running as administrator"
))
error
List
=
append
(
errorList
,
errors
.
New
(
"user is not running as administrator"
))
}
return
nil
,
error
s
return
nil
,
error
List
}
cmd/kubeadm/app/preflight/utils.go
View file @
88258431
...
...
@@ -17,10 +17,11 @@ limitations under the License.
package
preflight
import
(
"fmt"
"regexp"
"strings"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/version"
utilsexec
"k8s.io/utils/exec"
)
...
...
@@ -38,7 +39,7 @@ func GetKubeletVersion(execer utilsexec.Interface) (*version.Version, error) {
cleanOutput
:=
strings
.
TrimSpace
(
string
(
out
))
subs
:=
kubeletVersionRegex
.
FindAllStringSubmatch
(
cleanOutput
,
-
1
)
if
len
(
subs
)
!=
1
||
len
(
subs
[
0
])
<
2
{
return
nil
,
fmt
.
Errorf
(
"Unable to parse output from Kubelet: %q"
,
cleanOutput
)
return
nil
,
errors
.
Errorf
(
"Unable to parse output from Kubelet: %q"
,
cleanOutput
)
}
return
version
.
ParseSemantic
(
subs
[
0
][
1
])
}
cmd/kubeadm/app/preflight/utils_test.go
View file @
88258431
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
preflight
import
(
"fmt"
"testing"
"github.com/pkg/errors"
utilsexec
"k8s.io/utils/exec"
fakeexec
"k8s.io/utils/exec/testing"
)
...
...
@@ -34,7 +35,7 @@ func TestGetKubeletVersion(t *testing.T) {
{
"Kubernetes v1.7.0"
,
"1.7.0"
,
nil
,
true
},
{
"Kubernetes v1.8.0-alpha.2.1231+afabd012389d53a"
,
"1.8.0-alpha.2.1231+afabd012389d53a"
,
nil
,
true
},
{
"something-invalid"
,
""
,
nil
,
false
},
{
"command not found"
,
""
,
fmt
.
Errorf
(
"kubelet not found"
),
false
},
{
"command not found"
,
""
,
errors
.
New
(
"kubelet not found"
),
false
},
{
""
,
""
,
nil
,
false
},
}
...
...
Write
Preview
Markdown
is supported
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