mirror of https://github.com/k3s-io/k3s
commit
cacf888e49
|
@ -114,7 +114,7 @@ func main() {
|
|||
glog.Fatalf("-etcd_servers flag is required.")
|
||||
}
|
||||
|
||||
capabilities.InitializeCapabilities(capabilities.Capabilities{
|
||||
capabilities.Initialize(capabilities.Capabilities{
|
||||
AllowPrivileged: *allowPrivileged,
|
||||
})
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ func main() {
|
|||
|
||||
etcd.SetLogger(util.NewLogger("etcd "))
|
||||
|
||||
capabilities.InitializeCapabilities(capabilities.Capabilities{
|
||||
capabilities.Initialize(capabilities.Capabilities{
|
||||
AllowPrivileged: *allowPrivileged,
|
||||
})
|
||||
|
||||
|
|
|
@ -227,7 +227,7 @@ func validateContainers(containers []api.Container, volumes util.StringSet) errs
|
|||
for i := range containers {
|
||||
cErrs := errs.ErrorList{}
|
||||
ctr := &containers[i] // so we can set default values
|
||||
capabilities := capabilities.GetCapabilities()
|
||||
capabilities := capabilities.Get()
|
||||
if len(ctr.Name) == 0 {
|
||||
cErrs = append(cErrs, errs.NewFieldRequired("name", ctr.Name))
|
||||
} else if !util.IsDNSLabel(ctr.Name) {
|
||||
|
|
|
@ -180,7 +180,7 @@ func TestValidateVolumeMounts(t *testing.T) {
|
|||
|
||||
func TestValidateContainers(t *testing.T) {
|
||||
volumes := util.StringSet{}
|
||||
capabilities.SetCapabilitiesForTests(capabilities.Capabilities{
|
||||
capabilities.SetForTests(capabilities.Capabilities{
|
||||
AllowPrivileged: true,
|
||||
})
|
||||
|
||||
|
@ -203,7 +203,7 @@ func TestValidateContainers(t *testing.T) {
|
|||
t.Errorf("expected success: %v", errs)
|
||||
}
|
||||
|
||||
capabilities.SetCapabilitiesForTests(capabilities.Capabilities{
|
||||
capabilities.SetForTests(capabilities.Capabilities{
|
||||
AllowPrivileged: false,
|
||||
})
|
||||
errorCases := map[string][]api.Container{
|
||||
|
|
|
@ -30,7 +30,7 @@ var once sync.Once
|
|||
var capabilities *Capabilities
|
||||
|
||||
// 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
|
||||
once.Do(func() {
|
||||
capabilities = &c
|
||||
|
@ -38,14 +38,14 @@ func InitializeCapabilities(c Capabilities) {
|
|||
}
|
||||
|
||||
// SetCapabilitiesForTests. Convenience method for testing. This should only be called from tests.
|
||||
func SetCapabilitiesForTests(c Capabilities) {
|
||||
func SetForTests(c Capabilities) {
|
||||
capabilities = &c
|
||||
}
|
||||
|
||||
// Returns a read-only copy of the system capabilities.
|
||||
func GetCapabilities() Capabilities {
|
||||
func Get() Capabilities {
|
||||
if capabilities == nil {
|
||||
InitializeCapabilities(Capabilities{
|
||||
Initialize(Capabilities{
|
||||
AllowPrivileged: false,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -337,7 +337,7 @@ func (kl *Kubelet) runContainer(pod *Pod, container *api.Container, podVolumes v
|
|||
return "", err
|
||||
}
|
||||
privileged := false
|
||||
if capabilities.GetCapabilities().AllowPrivileged {
|
||||
if capabilities.Get().AllowPrivileged {
|
||||
privileged = container.Privileged
|
||||
} else if container.Privileged {
|
||||
return "", fmt.Errorf("Container requested privileged mode, but it is disallowed globally.")
|
||||
|
|
Loading…
Reference in New Issue