mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #114834 from chendave/regression
kubeadm: unittest might run as non-root
This commit is contained in:
commit
bc61d70055
@ -72,18 +72,20 @@ func TestEnforceRequirements(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tcases := []struct {
|
tcases := []struct {
|
||||||
name string
|
name string
|
||||||
newK8sVersion string
|
newK8sVersion string
|
||||||
dryRun bool
|
dryRun bool
|
||||||
flags applyPlanFlags
|
flags applyPlanFlags
|
||||||
expectedErr string
|
expectedErr string
|
||||||
|
expectedErrNonRoot string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Fail pre-flight check",
|
name: "Fail pre-flight check",
|
||||||
flags: applyPlanFlags{
|
flags: applyPlanFlags{
|
||||||
kubeConfigPath: fullPath,
|
kubeConfigPath: fullPath,
|
||||||
},
|
},
|
||||||
expectedErr: "ERROR CoreDNSUnsupportedPlugins",
|
expectedErr: "ERROR CoreDNSUnsupportedPlugins",
|
||||||
|
expectedErrNonRoot: "user is not running as", // user is not running as (root || administrator)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Bogus preflight check specify all with individual check",
|
name: "Bogus preflight check specify all with individual check",
|
||||||
@ -109,8 +111,13 @@ func TestEnforceRequirements(t *testing.T) {
|
|||||||
t.Error("Expected error, but got success")
|
t.Error("Expected error, but got success")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil && !strings.Contains(err.Error(), tt.expectedErr) {
|
expErr := tt.expectedErr
|
||||||
t.Fatalf("enforceRequirements returned unexpected error, expected: %s, got %v", tt.expectedErr, err)
|
// pre-flight check expects the user to be root, so the root and non-root should hit different errors
|
||||||
|
if os.Getuid() != 0 && len(tt.expectedErrNonRoot) != 0 {
|
||||||
|
expErr = tt.expectedErrNonRoot
|
||||||
|
}
|
||||||
|
if err != nil && !strings.Contains(err.Error(), expErr) {
|
||||||
|
t.Fatalf("enforceRequirements returned unexpected error, expected: %s, got %v", expErr, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user