mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Merge pull request #1336 from brendandburns/privilege
Refactor to clean up names.
This commit is contained in:
commit
cacf888e49
@ -114,7 +114,7 @@ func main() {
|
|||||||
glog.Fatalf("-etcd_servers flag is required.")
|
glog.Fatalf("-etcd_servers flag is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
capabilities.InitializeCapabilities(capabilities.Capabilities{
|
capabilities.Initialize(capabilities.Capabilities{
|
||||||
AllowPrivileged: *allowPrivileged,
|
AllowPrivileged: *allowPrivileged,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ func main() {
|
|||||||
|
|
||||||
etcd.SetLogger(util.NewLogger("etcd "))
|
etcd.SetLogger(util.NewLogger("etcd "))
|
||||||
|
|
||||||
capabilities.InitializeCapabilities(capabilities.Capabilities{
|
capabilities.Initialize(capabilities.Capabilities{
|
||||||
AllowPrivileged: *allowPrivileged,
|
AllowPrivileged: *allowPrivileged,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -227,7 +227,7 @@ func validateContainers(containers []api.Container, volumes util.StringSet) errs
|
|||||||
for i := range containers {
|
for i := range containers {
|
||||||
cErrs := errs.ErrorList{}
|
cErrs := errs.ErrorList{}
|
||||||
ctr := &containers[i] // so we can set default values
|
ctr := &containers[i] // so we can set default values
|
||||||
capabilities := capabilities.GetCapabilities()
|
capabilities := capabilities.Get()
|
||||||
if len(ctr.Name) == 0 {
|
if len(ctr.Name) == 0 {
|
||||||
cErrs = append(cErrs, errs.NewFieldRequired("name", ctr.Name))
|
cErrs = append(cErrs, errs.NewFieldRequired("name", ctr.Name))
|
||||||
} else if !util.IsDNSLabel(ctr.Name) {
|
} else if !util.IsDNSLabel(ctr.Name) {
|
||||||
|
@ -180,7 +180,7 @@ func TestValidateVolumeMounts(t *testing.T) {
|
|||||||
|
|
||||||
func TestValidateContainers(t *testing.T) {
|
func TestValidateContainers(t *testing.T) {
|
||||||
volumes := util.StringSet{}
|
volumes := util.StringSet{}
|
||||||
capabilities.SetCapabilitiesForTests(capabilities.Capabilities{
|
capabilities.SetForTests(capabilities.Capabilities{
|
||||||
AllowPrivileged: true,
|
AllowPrivileged: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -203,7 +203,7 @@ func TestValidateContainers(t *testing.T) {
|
|||||||
t.Errorf("expected success: %v", errs)
|
t.Errorf("expected success: %v", errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
capabilities.SetCapabilitiesForTests(capabilities.Capabilities{
|
capabilities.SetForTests(capabilities.Capabilities{
|
||||||
AllowPrivileged: false,
|
AllowPrivileged: false,
|
||||||
})
|
})
|
||||||
errorCases := map[string][]api.Container{
|
errorCases := map[string][]api.Container{
|
||||||
|
@ -30,7 +30,7 @@ var once sync.Once
|
|||||||
var capabilities *Capabilities
|
var capabilities *Capabilities
|
||||||
|
|
||||||
// Initialize the capability set. This can only be done once per binary, subsequent calls are ignored.
|
// Initialize the capability set. This can only be done once per binary, subsequent calls are ignored.
|
||||||
func InitializeCapabilities(c Capabilities) {
|
func Initialize(c Capabilities) {
|
||||||
// Only do this once
|
// Only do this once
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
capabilities = &c
|
capabilities = &c
|
||||||
@ -38,14 +38,14 @@ func InitializeCapabilities(c Capabilities) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetCapabilitiesForTests. Convenience method for testing. This should only be called from tests.
|
// SetCapabilitiesForTests. Convenience method for testing. This should only be called from tests.
|
||||||
func SetCapabilitiesForTests(c Capabilities) {
|
func SetForTests(c Capabilities) {
|
||||||
capabilities = &c
|
capabilities = &c
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a read-only copy of the system capabilities.
|
// Returns a read-only copy of the system capabilities.
|
||||||
func GetCapabilities() Capabilities {
|
func Get() Capabilities {
|
||||||
if capabilities == nil {
|
if capabilities == nil {
|
||||||
InitializeCapabilities(Capabilities{
|
Initialize(Capabilities{
|
||||||
AllowPrivileged: false,
|
AllowPrivileged: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -337,7 +337,7 @@ func (kl *Kubelet) runContainer(pod *Pod, container *api.Container, podVolumes v
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
privileged := false
|
privileged := false
|
||||||
if capabilities.GetCapabilities().AllowPrivileged {
|
if capabilities.Get().AllowPrivileged {
|
||||||
privileged = container.Privileged
|
privileged = container.Privileged
|
||||||
} else if container.Privileged {
|
} else if container.Privileged {
|
||||||
return "", fmt.Errorf("Container requested privileged mode, but it is disallowed globally.")
|
return "", fmt.Errorf("Container requested privileged mode, but it is disallowed globally.")
|
||||||
|
Loading…
Reference in New Issue
Block a user