Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
songlinfeng
container-toolkit
Commits
d7e13eb9
Commit
d7e13eb9
authored
Oct 22, 2025
by
songlinfeng
Browse files
add dtk-container-toolkit
parent
fcdba4f3
Changes
345
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
3769 additions
and
0 deletions
+3769
-0
vendor/github.com/fsnotify/fsnotify/internal/debug_linux.go
vendor/github.com/fsnotify/fsnotify/internal/debug_linux.go
+56
-0
vendor/github.com/fsnotify/fsnotify/internal/debug_netbsd.go
vendor/github.com/fsnotify/fsnotify/internal/debug_netbsd.go
+25
-0
vendor/github.com/fsnotify/fsnotify/internal/debug_openbsd.go
...or/github.com/fsnotify/fsnotify/internal/debug_openbsd.go
+28
-0
vendor/github.com/fsnotify/fsnotify/internal/debug_solaris.go
...or/github.com/fsnotify/fsnotify/internal/debug_solaris.go
+45
-0
vendor/github.com/fsnotify/fsnotify/internal/debug_windows.go
...or/github.com/fsnotify/fsnotify/internal/debug_windows.go
+40
-0
vendor/github.com/fsnotify/fsnotify/internal/freebsd.go
vendor/github.com/fsnotify/fsnotify/internal/freebsd.go
+31
-0
vendor/github.com/fsnotify/fsnotify/internal/internal.go
vendor/github.com/fsnotify/fsnotify/internal/internal.go
+2
-0
vendor/github.com/fsnotify/fsnotify/internal/unix.go
vendor/github.com/fsnotify/fsnotify/internal/unix.go
+31
-0
vendor/github.com/fsnotify/fsnotify/internal/unix2.go
vendor/github.com/fsnotify/fsnotify/internal/unix2.go
+7
-0
vendor/github.com/fsnotify/fsnotify/internal/windows.go
vendor/github.com/fsnotify/fsnotify/internal/windows.go
+41
-0
vendor/github.com/fsnotify/fsnotify/system_bsd.go
vendor/github.com/fsnotify/fsnotify/system_bsd.go
+7
-0
vendor/github.com/fsnotify/fsnotify/system_darwin.go
vendor/github.com/fsnotify/fsnotify/system_darwin.go
+8
-0
vendor/github.com/opencontainers/runtime-spec/LICENSE
vendor/github.com/opencontainers/runtime-spec/LICENSE
+191
-0
vendor/github.com/opencontainers/runtime-spec/specs-go/config.go
...github.com/opencontainers/runtime-spec/specs-go/config.go
+917
-0
vendor/github.com/opencontainers/runtime-spec/specs-go/state.go
.../github.com/opencontainers/runtime-spec/specs-go/state.go
+56
-0
vendor/github.com/opencontainers/runtime-spec/specs-go/version.go
...ithub.com/opencontainers/runtime-spec/specs-go/version.go
+18
-0
vendor/github.com/opencontainers/runtime-tools/LICENSE
vendor/github.com/opencontainers/runtime-tools/LICENSE
+191
-0
vendor/github.com/opencontainers/runtime-tools/generate/config.go
...ithub.com/opencontainers/runtime-tools/generate/config.go
+194
-0
vendor/github.com/opencontainers/runtime-tools/generate/generate.go
...hub.com/opencontainers/runtime-tools/generate/generate.go
+1874
-0
vendor/github.com/opencontainers/runtime-tools/generate/seccomp/consts.go
...m/opencontainers/runtime-tools/generate/seccomp/consts.go
+7
-0
No files found.
Too many changes to show.
To preserve performance only
345 of 345+
files are displayed.
Plain diff
Email patch
vendor/github.com/fsnotify/fsnotify/internal/debug_linux.go
0 → 100644
View file @
d7e13eb9
package
internal
import
(
"fmt"
"os"
"strings"
"time"
"golang.org/x/sys/unix"
)
func
Debug
(
name
string
,
mask
,
cookie
uint32
)
{
names
:=
[]
struct
{
n
string
m
uint32
}{
{
"IN_ACCESS"
,
unix
.
IN_ACCESS
},
{
"IN_ATTRIB"
,
unix
.
IN_ATTRIB
},
{
"IN_CLOSE"
,
unix
.
IN_CLOSE
},
{
"IN_CLOSE_NOWRITE"
,
unix
.
IN_CLOSE_NOWRITE
},
{
"IN_CLOSE_WRITE"
,
unix
.
IN_CLOSE_WRITE
},
{
"IN_CREATE"
,
unix
.
IN_CREATE
},
{
"IN_DELETE"
,
unix
.
IN_DELETE
},
{
"IN_DELETE_SELF"
,
unix
.
IN_DELETE_SELF
},
{
"IN_IGNORED"
,
unix
.
IN_IGNORED
},
{
"IN_ISDIR"
,
unix
.
IN_ISDIR
},
{
"IN_MODIFY"
,
unix
.
IN_MODIFY
},
{
"IN_MOVE"
,
unix
.
IN_MOVE
},
{
"IN_MOVED_FROM"
,
unix
.
IN_MOVED_FROM
},
{
"IN_MOVED_TO"
,
unix
.
IN_MOVED_TO
},
{
"IN_MOVE_SELF"
,
unix
.
IN_MOVE_SELF
},
{
"IN_OPEN"
,
unix
.
IN_OPEN
},
{
"IN_Q_OVERFLOW"
,
unix
.
IN_Q_OVERFLOW
},
{
"IN_UNMOUNT"
,
unix
.
IN_UNMOUNT
},
}
var
(
l
[]
string
unknown
=
mask
)
for
_
,
n
:=
range
names
{
if
mask
&
n
.
m
==
n
.
m
{
l
=
append
(
l
,
n
.
n
)
unknown
^=
n
.
m
}
}
if
unknown
>
0
{
l
=
append
(
l
,
fmt
.
Sprintf
(
"0x%x"
,
unknown
))
}
var
c
string
if
cookie
>
0
{
c
=
fmt
.
Sprintf
(
"(cookie: %d) "
,
cookie
)
}
fmt
.
Fprintf
(
os
.
Stderr
,
"FSNOTIFY_DEBUG: %s %-30s → %s%q
\n
"
,
time
.
Now
()
.
Format
(
"15:04:05.000000000"
),
strings
.
Join
(
l
,
"|"
),
c
,
name
)
}
vendor/github.com/fsnotify/fsnotify/internal/debug_netbsd.go
0 → 100644
View file @
d7e13eb9
package
internal
import
"golang.org/x/sys/unix"
var
names
=
[]
struct
{
n
string
m
uint32
}{
{
"NOTE_ATTRIB"
,
unix
.
NOTE_ATTRIB
},
{
"NOTE_CHILD"
,
unix
.
NOTE_CHILD
},
{
"NOTE_DELETE"
,
unix
.
NOTE_DELETE
},
{
"NOTE_EXEC"
,
unix
.
NOTE_EXEC
},
{
"NOTE_EXIT"
,
unix
.
NOTE_EXIT
},
{
"NOTE_EXTEND"
,
unix
.
NOTE_EXTEND
},
{
"NOTE_FORK"
,
unix
.
NOTE_FORK
},
{
"NOTE_LINK"
,
unix
.
NOTE_LINK
},
{
"NOTE_LOWAT"
,
unix
.
NOTE_LOWAT
},
{
"NOTE_PCTRLMASK"
,
unix
.
NOTE_PCTRLMASK
},
{
"NOTE_PDATAMASK"
,
unix
.
NOTE_PDATAMASK
},
{
"NOTE_RENAME"
,
unix
.
NOTE_RENAME
},
{
"NOTE_REVOKE"
,
unix
.
NOTE_REVOKE
},
{
"NOTE_TRACK"
,
unix
.
NOTE_TRACK
},
{
"NOTE_TRACKERR"
,
unix
.
NOTE_TRACKERR
},
{
"NOTE_WRITE"
,
unix
.
NOTE_WRITE
},
}
vendor/github.com/fsnotify/fsnotify/internal/debug_openbsd.go
0 → 100644
View file @
d7e13eb9
package
internal
import
"golang.org/x/sys/unix"
var
names
=
[]
struct
{
n
string
m
uint32
}{
{
"NOTE_ATTRIB"
,
unix
.
NOTE_ATTRIB
},
// {"NOTE_CHANGE", unix.NOTE_CHANGE}, // Not on 386?
{
"NOTE_CHILD"
,
unix
.
NOTE_CHILD
},
{
"NOTE_DELETE"
,
unix
.
NOTE_DELETE
},
{
"NOTE_EOF"
,
unix
.
NOTE_EOF
},
{
"NOTE_EXEC"
,
unix
.
NOTE_EXEC
},
{
"NOTE_EXIT"
,
unix
.
NOTE_EXIT
},
{
"NOTE_EXTEND"
,
unix
.
NOTE_EXTEND
},
{
"NOTE_FORK"
,
unix
.
NOTE_FORK
},
{
"NOTE_LINK"
,
unix
.
NOTE_LINK
},
{
"NOTE_LOWAT"
,
unix
.
NOTE_LOWAT
},
{
"NOTE_PCTRLMASK"
,
unix
.
NOTE_PCTRLMASK
},
{
"NOTE_PDATAMASK"
,
unix
.
NOTE_PDATAMASK
},
{
"NOTE_RENAME"
,
unix
.
NOTE_RENAME
},
{
"NOTE_REVOKE"
,
unix
.
NOTE_REVOKE
},
{
"NOTE_TRACK"
,
unix
.
NOTE_TRACK
},
{
"NOTE_TRACKERR"
,
unix
.
NOTE_TRACKERR
},
{
"NOTE_TRUNCATE"
,
unix
.
NOTE_TRUNCATE
},
{
"NOTE_WRITE"
,
unix
.
NOTE_WRITE
},
}
vendor/github.com/fsnotify/fsnotify/internal/debug_solaris.go
0 → 100644
View file @
d7e13eb9
package
internal
import
(
"fmt"
"os"
"strings"
"time"
"golang.org/x/sys/unix"
)
func
Debug
(
name
string
,
mask
int32
)
{
names
:=
[]
struct
{
n
string
m
int32
}{
{
"FILE_ACCESS"
,
unix
.
FILE_ACCESS
},
{
"FILE_MODIFIED"
,
unix
.
FILE_MODIFIED
},
{
"FILE_ATTRIB"
,
unix
.
FILE_ATTRIB
},
{
"FILE_TRUNC"
,
unix
.
FILE_TRUNC
},
{
"FILE_NOFOLLOW"
,
unix
.
FILE_NOFOLLOW
},
{
"FILE_DELETE"
,
unix
.
FILE_DELETE
},
{
"FILE_RENAME_TO"
,
unix
.
FILE_RENAME_TO
},
{
"FILE_RENAME_FROM"
,
unix
.
FILE_RENAME_FROM
},
{
"UNMOUNTED"
,
unix
.
UNMOUNTED
},
{
"MOUNTEDOVER"
,
unix
.
MOUNTEDOVER
},
{
"FILE_EXCEPTION"
,
unix
.
FILE_EXCEPTION
},
}
var
(
l
[]
string
unknown
=
mask
)
for
_
,
n
:=
range
names
{
if
mask
&
n
.
m
==
n
.
m
{
l
=
append
(
l
,
n
.
n
)
unknown
^=
n
.
m
}
}
if
unknown
>
0
{
l
=
append
(
l
,
fmt
.
Sprintf
(
"0x%x"
,
unknown
))
}
fmt
.
Fprintf
(
os
.
Stderr
,
"FSNOTIFY_DEBUG: %s %10d:%-30s → %q
\n
"
,
time
.
Now
()
.
Format
(
"15:04:05.000000000"
),
mask
,
strings
.
Join
(
l
,
" | "
),
name
)
}
vendor/github.com/fsnotify/fsnotify/internal/debug_windows.go
0 → 100644
View file @
d7e13eb9
package
internal
import
(
"fmt"
"os"
"path/filepath"
"strings"
"time"
"golang.org/x/sys/windows"
)
func
Debug
(
name
string
,
mask
uint32
)
{
names
:=
[]
struct
{
n
string
m
uint32
}{
{
"FILE_ACTION_ADDED"
,
windows
.
FILE_ACTION_ADDED
},
{
"FILE_ACTION_REMOVED"
,
windows
.
FILE_ACTION_REMOVED
},
{
"FILE_ACTION_MODIFIED"
,
windows
.
FILE_ACTION_MODIFIED
},
{
"FILE_ACTION_RENAMED_OLD_NAME"
,
windows
.
FILE_ACTION_RENAMED_OLD_NAME
},
{
"FILE_ACTION_RENAMED_NEW_NAME"
,
windows
.
FILE_ACTION_RENAMED_NEW_NAME
},
}
var
(
l
[]
string
unknown
=
mask
)
for
_
,
n
:=
range
names
{
if
mask
&
n
.
m
==
n
.
m
{
l
=
append
(
l
,
n
.
n
)
unknown
^=
n
.
m
}
}
if
unknown
>
0
{
l
=
append
(
l
,
fmt
.
Sprintf
(
"0x%x"
,
unknown
))
}
fmt
.
Fprintf
(
os
.
Stderr
,
"FSNOTIFY_DEBUG: %s %-65s → %q
\n
"
,
time
.
Now
()
.
Format
(
"15:04:05.000000000"
),
strings
.
Join
(
l
,
" | "
),
filepath
.
ToSlash
(
name
))
}
vendor/github.com/fsnotify/fsnotify/internal/freebsd.go
0 → 100644
View file @
d7e13eb9
//go:build freebsd
package
internal
import
(
"syscall"
"golang.org/x/sys/unix"
)
var
(
SyscallEACCES
=
syscall
.
EACCES
UnixEACCES
=
unix
.
EACCES
)
var
maxfiles
uint64
func
SetRlimit
()
{
// Go 1.19 will do this automatically: https://go-review.googlesource.com/c/go/+/393354/
var
l
syscall
.
Rlimit
err
:=
syscall
.
Getrlimit
(
syscall
.
RLIMIT_NOFILE
,
&
l
)
if
err
==
nil
&&
l
.
Cur
!=
l
.
Max
{
l
.
Cur
=
l
.
Max
syscall
.
Setrlimit
(
syscall
.
RLIMIT_NOFILE
,
&
l
)
}
maxfiles
=
uint64
(
l
.
Cur
)
}
func
Maxfiles
()
uint64
{
return
maxfiles
}
func
Mkfifo
(
path
string
,
mode
uint32
)
error
{
return
unix
.
Mkfifo
(
path
,
mode
)
}
func
Mknod
(
path
string
,
mode
uint32
,
dev
int
)
error
{
return
unix
.
Mknod
(
path
,
mode
,
uint64
(
dev
))
}
vendor/github.com/fsnotify/fsnotify/internal/internal.go
0 → 100644
View file @
d7e13eb9
// Package internal contains some helpers.
package
internal
vendor/github.com/fsnotify/fsnotify/internal/unix.go
0 → 100644
View file @
d7e13eb9
//go:build !windows && !darwin && !freebsd
package
internal
import
(
"syscall"
"golang.org/x/sys/unix"
)
var
(
SyscallEACCES
=
syscall
.
EACCES
UnixEACCES
=
unix
.
EACCES
)
var
maxfiles
uint64
func
SetRlimit
()
{
// Go 1.19 will do this automatically: https://go-review.googlesource.com/c/go/+/393354/
var
l
syscall
.
Rlimit
err
:=
syscall
.
Getrlimit
(
syscall
.
RLIMIT_NOFILE
,
&
l
)
if
err
==
nil
&&
l
.
Cur
!=
l
.
Max
{
l
.
Cur
=
l
.
Max
syscall
.
Setrlimit
(
syscall
.
RLIMIT_NOFILE
,
&
l
)
}
maxfiles
=
uint64
(
l
.
Cur
)
}
func
Maxfiles
()
uint64
{
return
maxfiles
}
func
Mkfifo
(
path
string
,
mode
uint32
)
error
{
return
unix
.
Mkfifo
(
path
,
mode
)
}
func
Mknod
(
path
string
,
mode
uint32
,
dev
int
)
error
{
return
unix
.
Mknod
(
path
,
mode
,
dev
)
}
vendor/github.com/fsnotify/fsnotify/internal/unix2.go
0 → 100644
View file @
d7e13eb9
//go:build !windows
package
internal
func
HasPrivilegesForSymlink
()
bool
{
return
true
}
vendor/github.com/fsnotify/fsnotify/internal/windows.go
0 → 100644
View file @
d7e13eb9
//go:build windows
package
internal
import
(
"errors"
"golang.org/x/sys/windows"
)
// Just a dummy.
var
(
SyscallEACCES
=
errors
.
New
(
"dummy"
)
UnixEACCES
=
errors
.
New
(
"dummy"
)
)
func
SetRlimit
()
{}
func
Maxfiles
()
uint64
{
return
1
<<
64
-
1
}
func
Mkfifo
(
path
string
,
mode
uint32
)
error
{
return
errors
.
New
(
"no FIFOs on Windows"
)
}
func
Mknod
(
path
string
,
mode
uint32
,
dev
int
)
error
{
return
errors
.
New
(
"no device nodes on Windows"
)
}
func
HasPrivilegesForSymlink
()
bool
{
var
sid
*
windows
.
SID
err
:=
windows
.
AllocateAndInitializeSid
(
&
windows
.
SECURITY_NT_AUTHORITY
,
2
,
windows
.
SECURITY_BUILTIN_DOMAIN_RID
,
windows
.
DOMAIN_ALIAS_RID_ADMINS
,
0
,
0
,
0
,
0
,
0
,
0
,
&
sid
)
if
err
!=
nil
{
return
false
}
defer
windows
.
FreeSid
(
sid
)
token
:=
windows
.
Token
(
0
)
member
,
err
:=
token
.
IsMember
(
sid
)
if
err
!=
nil
{
return
false
}
return
member
||
token
.
IsElevated
()
}
vendor/github.com/fsnotify/fsnotify/system_bsd.go
0 → 100644
View file @
d7e13eb9
//go:build freebsd || openbsd || netbsd || dragonfly
package
fsnotify
import
"golang.org/x/sys/unix"
const
openMode
=
unix
.
O_NONBLOCK
|
unix
.
O_RDONLY
|
unix
.
O_CLOEXEC
vendor/github.com/fsnotify/fsnotify/system_darwin.go
0 → 100644
View file @
d7e13eb9
//go:build darwin
package
fsnotify
import
"golang.org/x/sys/unix"
// note: this constant is not defined on BSD
const
openMode
=
unix
.
O_EVTONLY
|
unix
.
O_CLOEXEC
vendor/github.com/opencontainers/runtime-spec/LICENSE
0 → 100644
View file @
d7e13eb9
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
Copyright 2015 The Linux Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
vendor/github.com/opencontainers/runtime-spec/specs-go/config.go
0 → 100644
View file @
d7e13eb9
package
specs
import
"os"
// Spec is the base configuration for the container.
type
Spec
struct
{
// Version of the Open Container Initiative Runtime Specification with which the bundle complies.
Version
string
`json:"ociVersion"`
// Process configures the container process.
Process
*
Process
`json:"process,omitempty"`
// Root configures the container's root filesystem.
Root
*
Root
`json:"root,omitempty"`
// Hostname configures the container's hostname.
Hostname
string
`json:"hostname,omitempty"`
// Domainname configures the container's domainname.
Domainname
string
`json:"domainname,omitempty"`
// Mounts configures additional mounts (on top of Root).
Mounts
[]
Mount
`json:"mounts,omitempty"`
// Hooks configures callbacks for container lifecycle events.
Hooks
*
Hooks
`json:"hooks,omitempty" platform:"linux,solaris,zos"`
// Annotations contains arbitrary metadata for the container.
Annotations
map
[
string
]
string
`json:"annotations,omitempty"`
// Linux is platform-specific configuration for Linux based containers.
Linux
*
Linux
`json:"linux,omitempty" platform:"linux"`
// Solaris is platform-specific configuration for Solaris based containers.
Solaris
*
Solaris
`json:"solaris,omitempty" platform:"solaris"`
// Windows is platform-specific configuration for Windows based containers.
Windows
*
Windows
`json:"windows,omitempty" platform:"windows"`
// VM specifies configuration for virtual-machine-based containers.
VM
*
VM
`json:"vm,omitempty" platform:"vm"`
// ZOS is platform-specific configuration for z/OS based containers.
ZOS
*
ZOS
`json:"zos,omitempty" platform:"zos"`
}
// Scheduler represents the scheduling attributes for a process. It is based on
// the Linux sched_setattr(2) syscall.
type
Scheduler
struct
{
// Policy represents the scheduling policy (e.g., SCHED_FIFO, SCHED_RR, SCHED_OTHER).
Policy
LinuxSchedulerPolicy
`json:"policy"`
// Nice is the nice value for the process, which affects its priority.
Nice
int32
`json:"nice,omitempty"`
// Priority represents the static priority of the process.
Priority
int32
`json:"priority,omitempty"`
// Flags is an array of scheduling flags.
Flags
[]
LinuxSchedulerFlag
`json:"flags,omitempty"`
// The following ones are used by the DEADLINE scheduler.
// Runtime is the amount of time in nanoseconds during which the process
// is allowed to run in a given period.
Runtime
uint64
`json:"runtime,omitempty"`
// Deadline is the absolute deadline for the process to complete its execution.
Deadline
uint64
`json:"deadline,omitempty"`
// Period is the length of the period in nanoseconds used for determining the process runtime.
Period
uint64
`json:"period,omitempty"`
}
// Process contains information to start a specific application inside the container.
type
Process
struct
{
// Terminal creates an interactive terminal for the container.
Terminal
bool
`json:"terminal,omitempty"`
// ConsoleSize specifies the size of the console.
ConsoleSize
*
Box
`json:"consoleSize,omitempty"`
// User specifies user information for the process.
User
User
`json:"user"`
// Args specifies the binary and arguments for the application to execute.
Args
[]
string
`json:"args,omitempty"`
// CommandLine specifies the full command line for the application to execute on Windows.
CommandLine
string
`json:"commandLine,omitempty" platform:"windows"`
// Env populates the process environment for the process.
Env
[]
string
`json:"env,omitempty"`
// Cwd is the current working directory for the process and must be
// relative to the container's root.
Cwd
string
`json:"cwd"`
// Capabilities are Linux capabilities that are kept for the process.
Capabilities
*
LinuxCapabilities
`json:"capabilities,omitempty" platform:"linux"`
// Rlimits specifies rlimit options to apply to the process.
Rlimits
[]
POSIXRlimit
`json:"rlimits,omitempty" platform:"linux,solaris,zos"`
// NoNewPrivileges controls whether additional privileges could be gained by processes in the container.
NoNewPrivileges
bool
`json:"noNewPrivileges,omitempty" platform:"linux,zos"`
// ApparmorProfile specifies the apparmor profile for the container.
ApparmorProfile
string
`json:"apparmorProfile,omitempty" platform:"linux"`
// Specify an oom_score_adj for the container.
OOMScoreAdj
*
int
`json:"oomScoreAdj,omitempty" platform:"linux"`
// Scheduler specifies the scheduling attributes for a process
Scheduler
*
Scheduler
`json:"scheduler,omitempty" platform:"linux"`
// SelinuxLabel specifies the selinux context that the container process is run as.
SelinuxLabel
string
`json:"selinuxLabel,omitempty" platform:"linux"`
// IOPriority contains the I/O priority settings for the cgroup.
IOPriority
*
LinuxIOPriority
`json:"ioPriority,omitempty" platform:"linux"`
// ExecCPUAffinity specifies CPU affinity for exec processes.
ExecCPUAffinity
*
CPUAffinity
`json:"execCPUAffinity,omitempty" platform:"linux"`
}
// LinuxCapabilities specifies the list of allowed capabilities that are kept for a process.
// https://man7.org/linux/man-pages/man7/capabilities.7.html
type
LinuxCapabilities
struct
{
// Bounding is the set of capabilities checked by the kernel.
Bounding
[]
string
`json:"bounding,omitempty" platform:"linux"`
// Effective is the set of capabilities checked by the kernel.
Effective
[]
string
`json:"effective,omitempty" platform:"linux"`
// Inheritable is the capabilities preserved across execve.
Inheritable
[]
string
`json:"inheritable,omitempty" platform:"linux"`
// Permitted is the limiting superset for effective capabilities.
Permitted
[]
string
`json:"permitted,omitempty" platform:"linux"`
// Ambient is the ambient set of capabilities that are kept.
Ambient
[]
string
`json:"ambient,omitempty" platform:"linux"`
}
// IOPriority represents I/O priority settings for the container's processes within the process group.
type
LinuxIOPriority
struct
{
Class
IOPriorityClass
`json:"class"`
Priority
int
`json:"priority"`
}
// IOPriorityClass represents an I/O scheduling class.
type
IOPriorityClass
string
// Possible values for IOPriorityClass.
const
(
IOPRIO_CLASS_RT
IOPriorityClass
=
"IOPRIO_CLASS_RT"
IOPRIO_CLASS_BE
IOPriorityClass
=
"IOPRIO_CLASS_BE"
IOPRIO_CLASS_IDLE
IOPriorityClass
=
"IOPRIO_CLASS_IDLE"
)
// CPUAffinity specifies process' CPU affinity.
type
CPUAffinity
struct
{
Initial
string
`json:"initial,omitempty"`
Final
string
`json:"final,omitempty"`
}
// Box specifies dimensions of a rectangle. Used for specifying the size of a console.
type
Box
struct
{
// Height is the vertical dimension of a box.
Height
uint
`json:"height"`
// Width is the horizontal dimension of a box.
Width
uint
`json:"width"`
}
// User specifies specific user (and group) information for the container process.
type
User
struct
{
// UID is the user id.
UID
uint32
`json:"uid" platform:"linux,solaris,zos"`
// GID is the group id.
GID
uint32
`json:"gid" platform:"linux,solaris,zos"`
// Umask is the umask for the init process.
Umask
*
uint32
`json:"umask,omitempty" platform:"linux,solaris,zos"`
// AdditionalGids are additional group ids set for the container's process.
AdditionalGids
[]
uint32
`json:"additionalGids,omitempty" platform:"linux,solaris"`
// Username is the user name.
Username
string
`json:"username,omitempty" platform:"windows"`
}
// Root contains information about the container's root filesystem on the host.
type
Root
struct
{
// Path is the absolute path to the container's root filesystem.
Path
string
`json:"path"`
// Readonly makes the root filesystem for the container readonly before the process is executed.
Readonly
bool
`json:"readonly,omitempty"`
}
// Mount specifies a mount for a container.
type
Mount
struct
{
// Destination is the absolute path where the mount will be placed in the container.
Destination
string
`json:"destination"`
// Type specifies the mount kind.
Type
string
`json:"type,omitempty" platform:"linux,solaris,zos"`
// Source specifies the source path of the mount.
Source
string
`json:"source,omitempty"`
// Options are fstab style mount options.
Options
[]
string
`json:"options,omitempty"`
// UID/GID mappings used for changing file owners w/o calling chown, fs should support it.
// Every mount point could have its own mapping.
UIDMappings
[]
LinuxIDMapping
`json:"uidMappings,omitempty" platform:"linux"`
GIDMappings
[]
LinuxIDMapping
`json:"gidMappings,omitempty" platform:"linux"`
}
// Hook specifies a command that is run at a particular event in the lifecycle of a container
type
Hook
struct
{
Path
string
`json:"path"`
Args
[]
string
`json:"args,omitempty"`
Env
[]
string
`json:"env,omitempty"`
Timeout
*
int
`json:"timeout,omitempty"`
}
// Hooks specifies a command that is run in the container at a particular event in the lifecycle of a container
// Hooks for container setup and teardown
type
Hooks
struct
{
// Prestart is Deprecated. Prestart is a list of hooks to be run before the container process is executed.
// It is called in the Runtime Namespace
//
// Deprecated: use [Hooks.CreateRuntime], [Hooks.CreateContainer], and
// [Hooks.StartContainer] instead, which allow more granular hook control
// during the create and start phase.
Prestart
[]
Hook
`json:"prestart,omitempty"`
// CreateRuntime is a list of hooks to be run after the container has been created but before pivot_root or any equivalent operation has been called
// It is called in the Runtime Namespace
CreateRuntime
[]
Hook
`json:"createRuntime,omitempty"`
// CreateContainer is a list of hooks to be run after the container has been created but before pivot_root or any equivalent operation has been called
// It is called in the Container Namespace
CreateContainer
[]
Hook
`json:"createContainer,omitempty"`
// StartContainer is a list of hooks to be run after the start operation is called but before the container process is started
// It is called in the Container Namespace
StartContainer
[]
Hook
`json:"startContainer,omitempty"`
// Poststart is a list of hooks to be run after the container process is started.
// It is called in the Runtime Namespace
Poststart
[]
Hook
`json:"poststart,omitempty"`
// Poststop is a list of hooks to be run after the container process exits.
// It is called in the Runtime Namespace
Poststop
[]
Hook
`json:"poststop,omitempty"`
}
// Linux contains platform-specific configuration for Linux based containers.
type
Linux
struct
{
// UIDMapping specifies user mappings for supporting user namespaces.
UIDMappings
[]
LinuxIDMapping
`json:"uidMappings,omitempty"`
// GIDMapping specifies group mappings for supporting user namespaces.
GIDMappings
[]
LinuxIDMapping
`json:"gidMappings,omitempty"`
// Sysctl are a set of key value pairs that are set for the container on start
Sysctl
map
[
string
]
string
`json:"sysctl,omitempty"`
// Resources contain cgroup information for handling resource constraints
// for the container
Resources
*
LinuxResources
`json:"resources,omitempty"`
// CgroupsPath specifies the path to cgroups that are created and/or joined by the container.
// The path is expected to be relative to the cgroups mountpoint.
// If resources are specified, the cgroups at CgroupsPath will be updated based on resources.
CgroupsPath
string
`json:"cgroupsPath,omitempty"`
// Namespaces contains the namespaces that are created and/or joined by the container
Namespaces
[]
LinuxNamespace
`json:"namespaces,omitempty"`
// Devices are a list of device nodes that are created for the container
Devices
[]
LinuxDevice
`json:"devices,omitempty"`
// Seccomp specifies the seccomp security settings for the container.
Seccomp
*
LinuxSeccomp
`json:"seccomp,omitempty"`
// RootfsPropagation is the rootfs mount propagation mode for the container.
RootfsPropagation
string
`json:"rootfsPropagation,omitempty"`
// MaskedPaths masks over the provided paths inside the container.
MaskedPaths
[]
string
`json:"maskedPaths,omitempty"`
// ReadonlyPaths sets the provided paths as RO inside the container.
ReadonlyPaths
[]
string
`json:"readonlyPaths,omitempty"`
// MountLabel specifies the selinux context for the mounts in the container.
MountLabel
string
`json:"mountLabel,omitempty"`
// IntelRdt contains Intel Resource Director Technology (RDT) information for
// handling resource constraints and monitoring metrics (e.g., L3 cache, memory bandwidth) for the container
IntelRdt
*
LinuxIntelRdt
`json:"intelRdt,omitempty"`
// Personality contains configuration for the Linux personality syscall
Personality
*
LinuxPersonality
`json:"personality,omitempty"`
// TimeOffsets specifies the offset for supporting time namespaces.
TimeOffsets
map
[
string
]
LinuxTimeOffset
`json:"timeOffsets,omitempty"`
}
// LinuxNamespace is the configuration for a Linux namespace
type
LinuxNamespace
struct
{
// Type is the type of namespace
Type
LinuxNamespaceType
`json:"type"`
// Path is a path to an existing namespace persisted on disk that can be joined
// and is of the same type
Path
string
`json:"path,omitempty"`
}
// LinuxNamespaceType is one of the Linux namespaces
type
LinuxNamespaceType
string
const
(
// PIDNamespace for isolating process IDs
PIDNamespace
LinuxNamespaceType
=
"pid"
// NetworkNamespace for isolating network devices, stacks, ports, etc
NetworkNamespace
LinuxNamespaceType
=
"network"
// MountNamespace for isolating mount points
MountNamespace
LinuxNamespaceType
=
"mount"
// IPCNamespace for isolating System V IPC, POSIX message queues
IPCNamespace
LinuxNamespaceType
=
"ipc"
// UTSNamespace for isolating hostname and NIS domain name
UTSNamespace
LinuxNamespaceType
=
"uts"
// UserNamespace for isolating user and group IDs
UserNamespace
LinuxNamespaceType
=
"user"
// CgroupNamespace for isolating cgroup hierarchies
CgroupNamespace
LinuxNamespaceType
=
"cgroup"
// TimeNamespace for isolating the clocks
TimeNamespace
LinuxNamespaceType
=
"time"
)
// LinuxIDMapping specifies UID/GID mappings
type
LinuxIDMapping
struct
{
// ContainerID is the starting UID/GID in the container
ContainerID
uint32
`json:"containerID"`
// HostID is the starting UID/GID on the host to be mapped to 'ContainerID'
HostID
uint32
`json:"hostID"`
// Size is the number of IDs to be mapped
Size
uint32
`json:"size"`
}
// LinuxTimeOffset specifies the offset for Time Namespace
type
LinuxTimeOffset
struct
{
// Secs is the offset of clock (in secs) in the container
Secs
int64
`json:"secs,omitempty"`
// Nanosecs is the additional offset for Secs (in nanosecs)
Nanosecs
uint32
`json:"nanosecs,omitempty"`
}
// POSIXRlimit type and restrictions
type
POSIXRlimit
struct
{
// Type of the rlimit to set
Type
string
`json:"type"`
// Hard is the hard limit for the specified type
Hard
uint64
`json:"hard"`
// Soft is the soft limit for the specified type
Soft
uint64
`json:"soft"`
}
// LinuxHugepageLimit structure corresponds to limiting kernel hugepages.
// Default to reservation limits if supported. Otherwise fallback to page fault limits.
type
LinuxHugepageLimit
struct
{
// Pagesize is the hugepage size.
// Format: "<size><unit-prefix>B' (e.g. 64KB, 2MB, 1GB, etc.).
Pagesize
string
`json:"pageSize"`
// Limit is the limit of "hugepagesize" hugetlb reservations (if supported) or usage.
Limit
uint64
`json:"limit"`
}
// LinuxInterfacePriority for network interfaces
type
LinuxInterfacePriority
struct
{
// Name is the name of the network interface
Name
string
`json:"name"`
// Priority for the interface
Priority
uint32
`json:"priority"`
}
// LinuxBlockIODevice holds major:minor format supported in blkio cgroup
type
LinuxBlockIODevice
struct
{
// Major is the device's major number.
Major
int64
`json:"major"`
// Minor is the device's minor number.
Minor
int64
`json:"minor"`
}
// LinuxWeightDevice struct holds a `major:minor weight` pair for weightDevice
type
LinuxWeightDevice
struct
{
LinuxBlockIODevice
// Weight is the bandwidth rate for the device.
Weight
*
uint16
`json:"weight,omitempty"`
// LeafWeight is the bandwidth rate for the device while competing with the cgroup's child cgroups, CFQ scheduler only
LeafWeight
*
uint16
`json:"leafWeight,omitempty"`
}
// LinuxThrottleDevice struct holds a `major:minor rate_per_second` pair
type
LinuxThrottleDevice
struct
{
LinuxBlockIODevice
// Rate is the IO rate limit per cgroup per device
Rate
uint64
`json:"rate"`
}
// LinuxBlockIO for Linux cgroup 'blkio' resource management
type
LinuxBlockIO
struct
{
// Specifies per cgroup weight
Weight
*
uint16
`json:"weight,omitempty"`
// Specifies tasks' weight in the given cgroup while competing with the cgroup's child cgroups, CFQ scheduler only
LeafWeight
*
uint16
`json:"leafWeight,omitempty"`
// Weight per cgroup per device, can override BlkioWeight
WeightDevice
[]
LinuxWeightDevice
`json:"weightDevice,omitempty"`
// IO read rate limit per cgroup per device, bytes per second
ThrottleReadBpsDevice
[]
LinuxThrottleDevice
`json:"throttleReadBpsDevice,omitempty"`
// IO write rate limit per cgroup per device, bytes per second
ThrottleWriteBpsDevice
[]
LinuxThrottleDevice
`json:"throttleWriteBpsDevice,omitempty"`
// IO read rate limit per cgroup per device, IO per second
ThrottleReadIOPSDevice
[]
LinuxThrottleDevice
`json:"throttleReadIOPSDevice,omitempty"`
// IO write rate limit per cgroup per device, IO per second
ThrottleWriteIOPSDevice
[]
LinuxThrottleDevice
`json:"throttleWriteIOPSDevice,omitempty"`
}
// LinuxMemory for Linux cgroup 'memory' resource management
type
LinuxMemory
struct
{
// Memory limit (in bytes).
Limit
*
int64
`json:"limit,omitempty"`
// Memory reservation or soft_limit (in bytes).
Reservation
*
int64
`json:"reservation,omitempty"`
// Total memory limit (memory + swap).
Swap
*
int64
`json:"swap,omitempty"`
// Kernel memory limit (in bytes).
//
// Deprecated: kernel-memory limits are not supported in cgroups v2, and
// were obsoleted in [kernel v5.4]. This field should no longer be used,
// as it may be ignored by runtimes.
//
// [kernel v5.4]: https://github.com/torvalds/linux/commit/0158115f702b0ba208ab0
Kernel
*
int64
`json:"kernel,omitempty"`
// Kernel memory limit for tcp (in bytes)
KernelTCP
*
int64
`json:"kernelTCP,omitempty"`
// How aggressive the kernel will swap memory pages.
Swappiness
*
uint64
`json:"swappiness,omitempty"`
// DisableOOMKiller disables the OOM killer for out of memory conditions
DisableOOMKiller
*
bool
`json:"disableOOMKiller,omitempty"`
// Enables hierarchical memory accounting
UseHierarchy
*
bool
`json:"useHierarchy,omitempty"`
// CheckBeforeUpdate enables checking if a new memory limit is lower
// than the current usage during update, and if so, rejecting the new
// limit.
CheckBeforeUpdate
*
bool
`json:"checkBeforeUpdate,omitempty"`
}
// LinuxCPU for Linux cgroup 'cpu' resource management
type
LinuxCPU
struct
{
// CPU shares (relative weight (ratio) vs. other cgroups with cpu shares).
Shares
*
uint64
`json:"shares,omitempty"`
// CPU hardcap limit (in usecs). Allowed cpu time in a given period.
Quota
*
int64
`json:"quota,omitempty"`
// CPU hardcap burst limit (in usecs). Allowed accumulated cpu time additionally for burst in a
// given period.
Burst
*
uint64
`json:"burst,omitempty"`
// CPU period to be used for hardcapping (in usecs).
Period
*
uint64
`json:"period,omitempty"`
// How much time realtime scheduling may use (in usecs).
RealtimeRuntime
*
int64
`json:"realtimeRuntime,omitempty"`
// CPU period to be used for realtime scheduling (in usecs).
RealtimePeriod
*
uint64
`json:"realtimePeriod,omitempty"`
// CPUs to use within the cpuset. Default is to use any CPU available.
Cpus
string
`json:"cpus,omitempty"`
// List of memory nodes in the cpuset. Default is to use any available memory node.
Mems
string
`json:"mems,omitempty"`
// cgroups are configured with minimum weight, 0: default behavior, 1: SCHED_IDLE.
Idle
*
int64
`json:"idle,omitempty"`
}
// LinuxPids for Linux cgroup 'pids' resource management (Linux 4.3)
type
LinuxPids
struct
{
// Maximum number of PIDs. Default is "no limit".
Limit
int64
`json:"limit"`
}
// LinuxNetwork identification and priority configuration
type
LinuxNetwork
struct
{
// Set class identifier for container's network packets
ClassID
*
uint32
`json:"classID,omitempty"`
// Set priority of network traffic for container
Priorities
[]
LinuxInterfacePriority
`json:"priorities,omitempty"`
}
// LinuxRdma for Linux cgroup 'rdma' resource management (Linux 4.11)
type
LinuxRdma
struct
{
// Maximum number of HCA handles that can be opened. Default is "no limit".
HcaHandles
*
uint32
`json:"hcaHandles,omitempty"`
// Maximum number of HCA objects that can be created. Default is "no limit".
HcaObjects
*
uint32
`json:"hcaObjects,omitempty"`
}
// LinuxResources has container runtime resource constraints
type
LinuxResources
struct
{
// Devices configures the device allowlist.
Devices
[]
LinuxDeviceCgroup
`json:"devices,omitempty"`
// Memory restriction configuration
Memory
*
LinuxMemory
`json:"memory,omitempty"`
// CPU resource restriction configuration
CPU
*
LinuxCPU
`json:"cpu,omitempty"`
// Task resource restriction configuration.
Pids
*
LinuxPids
`json:"pids,omitempty"`
// BlockIO restriction configuration
BlockIO
*
LinuxBlockIO
`json:"blockIO,omitempty"`
// Hugetlb limits (in bytes). Default to reservation limits if supported.
HugepageLimits
[]
LinuxHugepageLimit
`json:"hugepageLimits,omitempty"`
// Network restriction configuration
Network
*
LinuxNetwork
`json:"network,omitempty"`
// Rdma resource restriction configuration.
// Limits are a set of key value pairs that define RDMA resource limits,
// where the key is device name and value is resource limits.
Rdma
map
[
string
]
LinuxRdma
`json:"rdma,omitempty"`
// Unified resources.
Unified
map
[
string
]
string
`json:"unified,omitempty"`
}
// LinuxDevice represents the mknod information for a Linux special device file
type
LinuxDevice
struct
{
// Path to the device.
Path
string
`json:"path"`
// Device type, block, char, etc.
Type
string
`json:"type"`
// Major is the device's major number.
Major
int64
`json:"major"`
// Minor is the device's minor number.
Minor
int64
`json:"minor"`
// FileMode permission bits for the device.
FileMode
*
os
.
FileMode
`json:"fileMode,omitempty"`
// UID of the device.
UID
*
uint32
`json:"uid,omitempty"`
// Gid of the device.
GID
*
uint32
`json:"gid,omitempty"`
}
// LinuxDeviceCgroup represents a device rule for the devices specified to
// the device controller
type
LinuxDeviceCgroup
struct
{
// Allow or deny
Allow
bool
`json:"allow"`
// Device type, block, char, etc.
Type
string
`json:"type,omitempty"`
// Major is the device's major number.
Major
*
int64
`json:"major,omitempty"`
// Minor is the device's minor number.
Minor
*
int64
`json:"minor,omitempty"`
// Cgroup access permissions format, rwm.
Access
string
`json:"access,omitempty"`
}
// LinuxPersonalityDomain refers to a personality domain.
type
LinuxPersonalityDomain
string
// LinuxPersonalityFlag refers to an additional personality flag. None are currently defined.
type
LinuxPersonalityFlag
string
// Define domain and flags for Personality
const
(
// PerLinux is the standard Linux personality
PerLinux
LinuxPersonalityDomain
=
"LINUX"
// PerLinux32 sets personality to 32 bit
PerLinux32
LinuxPersonalityDomain
=
"LINUX32"
)
// LinuxPersonality represents the Linux personality syscall input
type
LinuxPersonality
struct
{
// Domain for the personality
Domain
LinuxPersonalityDomain
`json:"domain"`
// Additional flags
Flags
[]
LinuxPersonalityFlag
`json:"flags,omitempty"`
}
// Solaris contains platform-specific configuration for Solaris application containers.
type
Solaris
struct
{
// SMF FMRI which should go "online" before we start the container process.
Milestone
string
`json:"milestone,omitempty"`
// Maximum set of privileges any process in this container can obtain.
LimitPriv
string
`json:"limitpriv,omitempty"`
// The maximum amount of shared memory allowed for this container.
MaxShmMemory
string
`json:"maxShmMemory,omitempty"`
// Specification for automatic creation of network resources for this container.
Anet
[]
SolarisAnet
`json:"anet,omitempty"`
// Set limit on the amount of CPU time that can be used by container.
CappedCPU
*
SolarisCappedCPU
`json:"cappedCPU,omitempty"`
// The physical and swap caps on the memory that can be used by this container.
CappedMemory
*
SolarisCappedMemory
`json:"cappedMemory,omitempty"`
}
// SolarisCappedCPU allows users to set limit on the amount of CPU time that can be used by container.
type
SolarisCappedCPU
struct
{
Ncpus
string
`json:"ncpus,omitempty"`
}
// SolarisCappedMemory allows users to set the physical and swap caps on the memory that can be used by this container.
type
SolarisCappedMemory
struct
{
Physical
string
`json:"physical,omitempty"`
Swap
string
`json:"swap,omitempty"`
}
// SolarisAnet provides the specification for automatic creation of network resources for this container.
type
SolarisAnet
struct
{
// Specify a name for the automatically created VNIC datalink.
Linkname
string
`json:"linkname,omitempty"`
// Specify the link over which the VNIC will be created.
Lowerlink
string
`json:"lowerLink,omitempty"`
// The set of IP addresses that the container can use.
Allowedaddr
string
`json:"allowedAddress,omitempty"`
// Specifies whether allowedAddress limitation is to be applied to the VNIC.
Configallowedaddr
string
`json:"configureAllowedAddress,omitempty"`
// The value of the optional default router.
Defrouter
string
`json:"defrouter,omitempty"`
// Enable one or more types of link protection.
Linkprotection
string
`json:"linkProtection,omitempty"`
// Set the VNIC's macAddress
Macaddress
string
`json:"macAddress,omitempty"`
}
// Windows defines the runtime configuration for Windows based containers, including Hyper-V containers.
type
Windows
struct
{
// LayerFolders contains a list of absolute paths to directories containing image layers.
LayerFolders
[]
string
`json:"layerFolders"`
// Devices are the list of devices to be mapped into the container.
Devices
[]
WindowsDevice
`json:"devices,omitempty"`
// Resources contains information for handling resource constraints for the container.
Resources
*
WindowsResources
`json:"resources,omitempty"`
// CredentialSpec contains a JSON object describing a group Managed Service Account (gMSA) specification.
CredentialSpec
interface
{}
`json:"credentialSpec,omitempty"`
// Servicing indicates if the container is being started in a mode to apply a Windows Update servicing operation.
Servicing
bool
`json:"servicing,omitempty"`
// IgnoreFlushesDuringBoot indicates if the container is being started in a mode where disk writes are not flushed during its boot process.
IgnoreFlushesDuringBoot
bool
`json:"ignoreFlushesDuringBoot,omitempty"`
// HyperV contains information for running a container with Hyper-V isolation.
HyperV
*
WindowsHyperV
`json:"hyperv,omitempty"`
// Network restriction configuration.
Network
*
WindowsNetwork
`json:"network,omitempty"`
}
// WindowsDevice represents information about a host device to be mapped into the container.
type
WindowsDevice
struct
{
// Device identifier: interface class GUID, etc.
ID
string
`json:"id"`
// Device identifier type: "class", etc.
IDType
string
`json:"idType"`
}
// WindowsResources has container runtime resource constraints for containers running on Windows.
type
WindowsResources
struct
{
// Memory restriction configuration.
Memory
*
WindowsMemoryResources
`json:"memory,omitempty"`
// CPU resource restriction configuration.
CPU
*
WindowsCPUResources
`json:"cpu,omitempty"`
// Storage restriction configuration.
Storage
*
WindowsStorageResources
`json:"storage,omitempty"`
}
// WindowsMemoryResources contains memory resource management settings.
type
WindowsMemoryResources
struct
{
// Memory limit in bytes.
Limit
*
uint64
`json:"limit,omitempty"`
}
// WindowsCPUResources contains CPU resource management settings.
type
WindowsCPUResources
struct
{
// Count is the number of CPUs available to the container. It represents the
// fraction of the configured processor `count` in a container in relation
// to the processors available in the host. The fraction ultimately
// determines the portion of processor cycles that the threads in a
// container can use during each scheduling interval, as the number of
// cycles per 10,000 cycles.
Count
*
uint64
`json:"count,omitempty"`
// Shares limits the share of processor time given to the container relative
// to other workloads on the processor. The processor `shares` (`weight` at
// the platform level) is a value between 0 and 10000.
Shares
*
uint16
`json:"shares,omitempty"`
// Maximum determines the portion of processor cycles that the threads in a
// container can use during each scheduling interval, as the number of
// cycles per 10,000 cycles. Set processor `maximum` to a percentage times
// 100.
Maximum
*
uint16
`json:"maximum,omitempty"`
// Set of CPUs to affinitize for this container.
Affinity
[]
WindowsCPUGroupAffinity
`json:"affinity,omitempty"`
}
// Similar to _GROUP_AFFINITY struct defined in
// https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/miniport/ns-miniport-_group_affinity
type
WindowsCPUGroupAffinity
struct
{
// CPU mask relative to this CPU group.
Mask
uint64
`json:"mask,omitempty"`
// Processor group the mask refers to, as returned by GetLogicalProcessorInformationEx.
Group
uint32
`json:"group,omitempty"`
}
// WindowsStorageResources contains storage resource management settings.
type
WindowsStorageResources
struct
{
// Specifies maximum Iops for the system drive.
Iops
*
uint64
`json:"iops,omitempty"`
// Specifies maximum bytes per second for the system drive.
Bps
*
uint64
`json:"bps,omitempty"`
// Sandbox size specifies the minimum size of the system drive in bytes.
SandboxSize
*
uint64
`json:"sandboxSize,omitempty"`
}
// WindowsNetwork contains network settings for Windows containers.
type
WindowsNetwork
struct
{
// List of HNS endpoints that the container should connect to.
EndpointList
[]
string
`json:"endpointList,omitempty"`
// Specifies if unqualified DNS name resolution is allowed.
AllowUnqualifiedDNSQuery
bool
`json:"allowUnqualifiedDNSQuery,omitempty"`
// Comma separated list of DNS suffixes to use for name resolution.
DNSSearchList
[]
string
`json:"DNSSearchList,omitempty"`
// Name (ID) of the container that we will share with the network stack.
NetworkSharedContainerName
string
`json:"networkSharedContainerName,omitempty"`
// name (ID) of the network namespace that will be used for the container.
NetworkNamespace
string
`json:"networkNamespace,omitempty"`
}
// WindowsHyperV contains information for configuring a container to run with Hyper-V isolation.
type
WindowsHyperV
struct
{
// UtilityVMPath is an optional path to the image used for the Utility VM.
UtilityVMPath
string
`json:"utilityVMPath,omitempty"`
}
// VM contains information for virtual-machine-based containers.
type
VM
struct
{
// Hypervisor specifies hypervisor-related configuration for virtual-machine-based containers.
Hypervisor
VMHypervisor
`json:"hypervisor,omitempty"`
// Kernel specifies kernel-related configuration for virtual-machine-based containers.
Kernel
VMKernel
`json:"kernel"`
// Image specifies guest image related configuration for virtual-machine-based containers.
Image
VMImage
`json:"image,omitempty"`
}
// VMHypervisor contains information about the hypervisor to use for a virtual machine.
type
VMHypervisor
struct
{
// Path is the host path to the hypervisor used to manage the virtual machine.
Path
string
`json:"path"`
// Parameters specifies parameters to pass to the hypervisor.
Parameters
[]
string
`json:"parameters,omitempty"`
}
// VMKernel contains information about the kernel to use for a virtual machine.
type
VMKernel
struct
{
// Path is the host path to the kernel used to boot the virtual machine.
Path
string
`json:"path"`
// Parameters specifies parameters to pass to the kernel.
Parameters
[]
string
`json:"parameters,omitempty"`
// InitRD is the host path to an initial ramdisk to be used by the kernel.
InitRD
string
`json:"initrd,omitempty"`
}
// VMImage contains information about the virtual machine root image.
type
VMImage
struct
{
// Path is the host path to the root image that the VM kernel would boot into.
Path
string
`json:"path"`
// Format is the root image format type (e.g. "qcow2", "raw", "vhd", etc).
Format
string
`json:"format"`
}
// LinuxSeccomp represents syscall restrictions
type
LinuxSeccomp
struct
{
DefaultAction
LinuxSeccompAction
`json:"defaultAction"`
DefaultErrnoRet
*
uint
`json:"defaultErrnoRet,omitempty"`
Architectures
[]
Arch
`json:"architectures,omitempty"`
Flags
[]
LinuxSeccompFlag
`json:"flags,omitempty"`
ListenerPath
string
`json:"listenerPath,omitempty"`
ListenerMetadata
string
`json:"listenerMetadata,omitempty"`
Syscalls
[]
LinuxSyscall
`json:"syscalls,omitempty"`
}
// Arch used for additional architectures
type
Arch
string
// LinuxSeccompFlag is a flag to pass to seccomp(2).
type
LinuxSeccompFlag
string
const
(
// LinuxSeccompFlagLog is a seccomp flag to request all returned
// actions except SECCOMP_RET_ALLOW to be logged. An administrator may
// override this filter flag by preventing specific actions from being
// logged via the /proc/sys/kernel/seccomp/actions_logged file. (since
// Linux 4.14)
LinuxSeccompFlagLog
LinuxSeccompFlag
=
"SECCOMP_FILTER_FLAG_LOG"
// LinuxSeccompFlagSpecAllow can be used to disable Speculative Store
// Bypass mitigation. (since Linux 4.17)
LinuxSeccompFlagSpecAllow
LinuxSeccompFlag
=
"SECCOMP_FILTER_FLAG_SPEC_ALLOW"
// LinuxSeccompFlagWaitKillableRecv can be used to switch to the wait
// killable semantics. (since Linux 5.19)
LinuxSeccompFlagWaitKillableRecv
LinuxSeccompFlag
=
"SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV"
)
// Additional architectures permitted to be used for system calls
// By default only the native architecture of the kernel is permitted
const
(
ArchX86
Arch
=
"SCMP_ARCH_X86"
ArchX86_64
Arch
=
"SCMP_ARCH_X86_64"
ArchX32
Arch
=
"SCMP_ARCH_X32"
ArchARM
Arch
=
"SCMP_ARCH_ARM"
ArchAARCH64
Arch
=
"SCMP_ARCH_AARCH64"
ArchMIPS
Arch
=
"SCMP_ARCH_MIPS"
ArchMIPS64
Arch
=
"SCMP_ARCH_MIPS64"
ArchMIPS64N32
Arch
=
"SCMP_ARCH_MIPS64N32"
ArchMIPSEL
Arch
=
"SCMP_ARCH_MIPSEL"
ArchMIPSEL64
Arch
=
"SCMP_ARCH_MIPSEL64"
ArchMIPSEL64N32
Arch
=
"SCMP_ARCH_MIPSEL64N32"
ArchPPC
Arch
=
"SCMP_ARCH_PPC"
ArchPPC64
Arch
=
"SCMP_ARCH_PPC64"
ArchPPC64LE
Arch
=
"SCMP_ARCH_PPC64LE"
ArchS390
Arch
=
"SCMP_ARCH_S390"
ArchS390X
Arch
=
"SCMP_ARCH_S390X"
ArchPARISC
Arch
=
"SCMP_ARCH_PARISC"
ArchPARISC64
Arch
=
"SCMP_ARCH_PARISC64"
ArchRISCV64
Arch
=
"SCMP_ARCH_RISCV64"
ArchLOONGARCH64
Arch
=
"SCMP_ARCH_LOONGARCH64"
ArchM68K
Arch
=
"SCMP_ARCH_M68K"
ArchSH
Arch
=
"SCMP_ARCH_SH"
ArchSHEB
Arch
=
"SCMP_ARCH_SHEB"
)
// LinuxSeccompAction taken upon Seccomp rule match
type
LinuxSeccompAction
string
// Define actions for Seccomp rules
const
(
ActKill
LinuxSeccompAction
=
"SCMP_ACT_KILL"
ActKillProcess
LinuxSeccompAction
=
"SCMP_ACT_KILL_PROCESS"
ActKillThread
LinuxSeccompAction
=
"SCMP_ACT_KILL_THREAD"
ActTrap
LinuxSeccompAction
=
"SCMP_ACT_TRAP"
ActErrno
LinuxSeccompAction
=
"SCMP_ACT_ERRNO"
ActTrace
LinuxSeccompAction
=
"SCMP_ACT_TRACE"
ActAllow
LinuxSeccompAction
=
"SCMP_ACT_ALLOW"
ActLog
LinuxSeccompAction
=
"SCMP_ACT_LOG"
ActNotify
LinuxSeccompAction
=
"SCMP_ACT_NOTIFY"
)
// LinuxSeccompOperator used to match syscall arguments in Seccomp
type
LinuxSeccompOperator
string
// Define operators for syscall arguments in Seccomp
const
(
OpNotEqual
LinuxSeccompOperator
=
"SCMP_CMP_NE"
OpLessThan
LinuxSeccompOperator
=
"SCMP_CMP_LT"
OpLessEqual
LinuxSeccompOperator
=
"SCMP_CMP_LE"
OpEqualTo
LinuxSeccompOperator
=
"SCMP_CMP_EQ"
OpGreaterEqual
LinuxSeccompOperator
=
"SCMP_CMP_GE"
OpGreaterThan
LinuxSeccompOperator
=
"SCMP_CMP_GT"
OpMaskedEqual
LinuxSeccompOperator
=
"SCMP_CMP_MASKED_EQ"
)
// LinuxSeccompArg used for matching specific syscall arguments in Seccomp
type
LinuxSeccompArg
struct
{
Index
uint
`json:"index"`
Value
uint64
`json:"value"`
ValueTwo
uint64
`json:"valueTwo,omitempty"`
Op
LinuxSeccompOperator
`json:"op"`
}
// LinuxSyscall is used to match a syscall in Seccomp
type
LinuxSyscall
struct
{
Names
[]
string
`json:"names"`
Action
LinuxSeccompAction
`json:"action"`
ErrnoRet
*
uint
`json:"errnoRet,omitempty"`
Args
[]
LinuxSeccompArg
`json:"args,omitempty"`
}
// LinuxIntelRdt has container runtime resource constraints for Intel RDT CAT and MBA
// features and flags enabling Intel RDT CMT and MBM features.
// Intel RDT features are available in Linux 4.14 and newer kernel versions.
type
LinuxIntelRdt
struct
{
// The identity for RDT Class of Service
ClosID
string
`json:"closID,omitempty"`
// The schema for L3 cache id and capacity bitmask (CBM)
// Format: "L3:<cache_id0>=<cbm0>;<cache_id1>=<cbm1>;..."
L3CacheSchema
string
`json:"l3CacheSchema,omitempty"`
// The schema of memory bandwidth per L3 cache id
// Format: "MB:<cache_id0>=bandwidth0;<cache_id1>=bandwidth1;..."
// The unit of memory bandwidth is specified in "percentages" by
// default, and in "MBps" if MBA Software Controller is enabled.
MemBwSchema
string
`json:"memBwSchema,omitempty"`
// EnableCMT is the flag to indicate if the Intel RDT CMT is enabled. CMT (Cache Monitoring Technology) supports monitoring of
// the last-level cache (LLC) occupancy for the container.
EnableCMT
bool
`json:"enableCMT,omitempty"`
// EnableMBM is the flag to indicate if the Intel RDT MBM is enabled. MBM (Memory Bandwidth Monitoring) supports monitoring of
// total and local memory bandwidth for the container.
EnableMBM
bool
`json:"enableMBM,omitempty"`
}
// ZOS contains platform-specific configuration for z/OS based containers.
type
ZOS
struct
{
// Namespaces contains the namespaces that are created and/or joined by the container
Namespaces
[]
ZOSNamespace
`json:"namespaces,omitempty"`
}
// ZOSNamespace is the configuration for a z/OS namespace
type
ZOSNamespace
struct
{
// Type is the type of namespace
Type
ZOSNamespaceType
`json:"type"`
// Path is a path to an existing namespace persisted on disk that can be joined
// and is of the same type
Path
string
`json:"path,omitempty"`
}
// ZOSNamespaceType is one of the z/OS namespaces
type
ZOSNamespaceType
string
const
(
// PIDNamespace for isolating process IDs
ZOSPIDNamespace
ZOSNamespaceType
=
"pid"
// MountNamespace for isolating mount points
ZOSMountNamespace
ZOSNamespaceType
=
"mount"
// IPCNamespace for isolating System V IPC, POSIX message queues
ZOSIPCNamespace
ZOSNamespaceType
=
"ipc"
// UTSNamespace for isolating hostname and NIS domain name
ZOSUTSNamespace
ZOSNamespaceType
=
"uts"
)
// LinuxSchedulerPolicy represents different scheduling policies used with the Linux Scheduler
type
LinuxSchedulerPolicy
string
const
(
// SchedOther is the default scheduling policy
SchedOther
LinuxSchedulerPolicy
=
"SCHED_OTHER"
// SchedFIFO is the First-In-First-Out scheduling policy
SchedFIFO
LinuxSchedulerPolicy
=
"SCHED_FIFO"
// SchedRR is the Round-Robin scheduling policy
SchedRR
LinuxSchedulerPolicy
=
"SCHED_RR"
// SchedBatch is the Batch scheduling policy
SchedBatch
LinuxSchedulerPolicy
=
"SCHED_BATCH"
// SchedISO is the Isolation scheduling policy
SchedISO
LinuxSchedulerPolicy
=
"SCHED_ISO"
// SchedIdle is the Idle scheduling policy
SchedIdle
LinuxSchedulerPolicy
=
"SCHED_IDLE"
// SchedDeadline is the Deadline scheduling policy
SchedDeadline
LinuxSchedulerPolicy
=
"SCHED_DEADLINE"
)
// LinuxSchedulerFlag represents the flags used by the Linux Scheduler.
type
LinuxSchedulerFlag
string
const
(
// SchedFlagResetOnFork represents the reset on fork scheduling flag
SchedFlagResetOnFork
LinuxSchedulerFlag
=
"SCHED_FLAG_RESET_ON_FORK"
// SchedFlagReclaim represents the reclaim scheduling flag
SchedFlagReclaim
LinuxSchedulerFlag
=
"SCHED_FLAG_RECLAIM"
// SchedFlagDLOverrun represents the deadline overrun scheduling flag
SchedFlagDLOverrun
LinuxSchedulerFlag
=
"SCHED_FLAG_DL_OVERRUN"
// SchedFlagKeepPolicy represents the keep policy scheduling flag
SchedFlagKeepPolicy
LinuxSchedulerFlag
=
"SCHED_FLAG_KEEP_POLICY"
// SchedFlagKeepParams represents the keep parameters scheduling flag
SchedFlagKeepParams
LinuxSchedulerFlag
=
"SCHED_FLAG_KEEP_PARAMS"
// SchedFlagUtilClampMin represents the utilization clamp minimum scheduling flag
SchedFlagUtilClampMin
LinuxSchedulerFlag
=
"SCHED_FLAG_UTIL_CLAMP_MIN"
// SchedFlagUtilClampMin represents the utilization clamp maximum scheduling flag
SchedFlagUtilClampMax
LinuxSchedulerFlag
=
"SCHED_FLAG_UTIL_CLAMP_MAX"
)
vendor/github.com/opencontainers/runtime-spec/specs-go/state.go
0 → 100644
View file @
d7e13eb9
package
specs
// ContainerState represents the state of a container.
type
ContainerState
string
const
(
// StateCreating indicates that the container is being created
StateCreating
ContainerState
=
"creating"
// StateCreated indicates that the runtime has finished the create operation
StateCreated
ContainerState
=
"created"
// StateRunning indicates that the container process has executed the
// user-specified program but has not exited
StateRunning
ContainerState
=
"running"
// StateStopped indicates that the container process has exited
StateStopped
ContainerState
=
"stopped"
)
// State holds information about the runtime state of the container.
type
State
struct
{
// Version is the version of the specification that is supported.
Version
string
`json:"ociVersion"`
// ID is the container ID
ID
string
`json:"id"`
// Status is the runtime status of the container.
Status
ContainerState
`json:"status"`
// Pid is the process ID for the container process.
Pid
int
`json:"pid,omitempty"`
// Bundle is the path to the container's bundle directory.
Bundle
string
`json:"bundle"`
// Annotations are key values associated with the container.
Annotations
map
[
string
]
string
`json:"annotations,omitempty"`
}
const
(
// SeccompFdName is the name of the seccomp notify file descriptor.
SeccompFdName
string
=
"seccompFd"
)
// ContainerProcessState holds information about the state of a container process.
type
ContainerProcessState
struct
{
// Version is the version of the specification that is supported.
Version
string
`json:"ociVersion"`
// Fds is a string array containing the names of the file descriptors passed.
// The index of the name in this array corresponds to index of the file
// descriptor in the `SCM_RIGHTS` array.
Fds
[]
string
`json:"fds"`
// Pid is the process ID as seen by the runtime.
Pid
int
`json:"pid"`
// Opaque metadata.
Metadata
string
`json:"metadata,omitempty"`
// State of the container.
State
State
`json:"state"`
}
vendor/github.com/opencontainers/runtime-spec/specs-go/version.go
0 → 100644
View file @
d7e13eb9
package
specs
import
"fmt"
const
(
// VersionMajor is for an API incompatible changes
VersionMajor
=
1
// VersionMinor is for functionality in a backwards-compatible manner
VersionMinor
=
2
// VersionPatch is for backwards-compatible bug fixes
VersionPatch
=
1
// VersionDev indicates development branch. Releases will be empty string.
VersionDev
=
""
)
// Version is the specification version that the package types support.
var
Version
=
fmt
.
Sprintf
(
"%d.%d.%d%s"
,
VersionMajor
,
VersionMinor
,
VersionPatch
,
VersionDev
)
vendor/github.com/opencontainers/runtime-tools/LICENSE
0 → 100644
View file @
d7e13eb9
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
Copyright 2015 The Linux Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
vendor/github.com/opencontainers/runtime-tools/generate/config.go
0 → 100644
View file @
d7e13eb9
package
generate
import
(
rspec
"github.com/opencontainers/runtime-spec/specs-go"
)
func
(
g
*
Generator
)
initConfig
()
{
if
g
.
Config
==
nil
{
g
.
Config
=
&
rspec
.
Spec
{}
}
}
func
(
g
*
Generator
)
initConfigProcess
()
{
g
.
initConfig
()
if
g
.
Config
.
Process
==
nil
{
g
.
Config
.
Process
=
&
rspec
.
Process
{}
}
}
func
(
g
*
Generator
)
initConfigProcessConsoleSize
()
{
g
.
initConfigProcess
()
if
g
.
Config
.
Process
.
ConsoleSize
==
nil
{
g
.
Config
.
Process
.
ConsoleSize
=
&
rspec
.
Box
{}
}
}
func
(
g
*
Generator
)
initConfigProcessCapabilities
()
{
g
.
initConfigProcess
()
if
g
.
Config
.
Process
.
Capabilities
==
nil
{
g
.
Config
.
Process
.
Capabilities
=
&
rspec
.
LinuxCapabilities
{}
}
}
func
(
g
*
Generator
)
initConfigRoot
()
{
g
.
initConfig
()
if
g
.
Config
.
Root
==
nil
{
g
.
Config
.
Root
=
&
rspec
.
Root
{}
}
}
func
(
g
*
Generator
)
initConfigAnnotations
()
{
g
.
initConfig
()
if
g
.
Config
.
Annotations
==
nil
{
g
.
Config
.
Annotations
=
make
(
map
[
string
]
string
)
}
}
func
(
g
*
Generator
)
initConfigHooks
()
{
g
.
initConfig
()
if
g
.
Config
.
Hooks
==
nil
{
g
.
Config
.
Hooks
=
&
rspec
.
Hooks
{}
}
}
func
(
g
*
Generator
)
initConfigLinux
()
{
g
.
initConfig
()
if
g
.
Config
.
Linux
==
nil
{
g
.
Config
.
Linux
=
&
rspec
.
Linux
{}
}
}
func
(
g
*
Generator
)
initConfigLinuxIntelRdt
()
{
g
.
initConfigLinux
()
if
g
.
Config
.
Linux
.
IntelRdt
==
nil
{
g
.
Config
.
Linux
.
IntelRdt
=
&
rspec
.
LinuxIntelRdt
{}
}
}
func
(
g
*
Generator
)
initConfigLinuxSysctl
()
{
g
.
initConfigLinux
()
if
g
.
Config
.
Linux
.
Sysctl
==
nil
{
g
.
Config
.
Linux
.
Sysctl
=
make
(
map
[
string
]
string
)
}
}
func
(
g
*
Generator
)
initConfigLinuxSeccomp
()
{
g
.
initConfigLinux
()
if
g
.
Config
.
Linux
.
Seccomp
==
nil
{
g
.
Config
.
Linux
.
Seccomp
=
&
rspec
.
LinuxSeccomp
{}
}
}
func
(
g
*
Generator
)
initConfigLinuxResources
()
{
g
.
initConfigLinux
()
if
g
.
Config
.
Linux
.
Resources
==
nil
{
g
.
Config
.
Linux
.
Resources
=
&
rspec
.
LinuxResources
{}
}
}
func
(
g
*
Generator
)
initConfigLinuxResourcesBlockIO
()
{
g
.
initConfigLinuxResources
()
if
g
.
Config
.
Linux
.
Resources
.
BlockIO
==
nil
{
g
.
Config
.
Linux
.
Resources
.
BlockIO
=
&
rspec
.
LinuxBlockIO
{}
}
}
// InitConfigLinuxResourcesCPU initializes CPU of Linux resources
func
(
g
*
Generator
)
InitConfigLinuxResourcesCPU
()
{
g
.
initConfigLinuxResources
()
if
g
.
Config
.
Linux
.
Resources
.
CPU
==
nil
{
g
.
Config
.
Linux
.
Resources
.
CPU
=
&
rspec
.
LinuxCPU
{}
}
}
func
(
g
*
Generator
)
initConfigLinuxResourcesMemory
()
{
g
.
initConfigLinuxResources
()
if
g
.
Config
.
Linux
.
Resources
.
Memory
==
nil
{
g
.
Config
.
Linux
.
Resources
.
Memory
=
&
rspec
.
LinuxMemory
{}
}
}
func
(
g
*
Generator
)
initConfigLinuxResourcesNetwork
()
{
g
.
initConfigLinuxResources
()
if
g
.
Config
.
Linux
.
Resources
.
Network
==
nil
{
g
.
Config
.
Linux
.
Resources
.
Network
=
&
rspec
.
LinuxNetwork
{}
}
}
func
(
g
*
Generator
)
initConfigLinuxResourcesPids
()
{
g
.
initConfigLinuxResources
()
if
g
.
Config
.
Linux
.
Resources
.
Pids
==
nil
{
g
.
Config
.
Linux
.
Resources
.
Pids
=
&
rspec
.
LinuxPids
{}
}
}
func
(
g
*
Generator
)
initConfigLinuxResourcesUnified
()
{
g
.
initConfigLinuxResources
()
if
g
.
Config
.
Linux
.
Resources
.
Unified
==
nil
{
g
.
Config
.
Linux
.
Resources
.
Unified
=
map
[
string
]
string
{}
}
}
func
(
g
*
Generator
)
initConfigSolaris
()
{
g
.
initConfig
()
if
g
.
Config
.
Solaris
==
nil
{
g
.
Config
.
Solaris
=
&
rspec
.
Solaris
{}
}
}
func
(
g
*
Generator
)
initConfigSolarisCappedCPU
()
{
g
.
initConfigSolaris
()
if
g
.
Config
.
Solaris
.
CappedCPU
==
nil
{
g
.
Config
.
Solaris
.
CappedCPU
=
&
rspec
.
SolarisCappedCPU
{}
}
}
func
(
g
*
Generator
)
initConfigSolarisCappedMemory
()
{
g
.
initConfigSolaris
()
if
g
.
Config
.
Solaris
.
CappedMemory
==
nil
{
g
.
Config
.
Solaris
.
CappedMemory
=
&
rspec
.
SolarisCappedMemory
{}
}
}
func
(
g
*
Generator
)
initConfigWindows
()
{
g
.
initConfig
()
if
g
.
Config
.
Windows
==
nil
{
g
.
Config
.
Windows
=
&
rspec
.
Windows
{}
}
}
func
(
g
*
Generator
)
initConfigWindowsNetwork
()
{
g
.
initConfigWindows
()
if
g
.
Config
.
Windows
.
Network
==
nil
{
g
.
Config
.
Windows
.
Network
=
&
rspec
.
WindowsNetwork
{}
}
}
func
(
g
*
Generator
)
initConfigWindowsHyperV
()
{
g
.
initConfigWindows
()
if
g
.
Config
.
Windows
.
HyperV
==
nil
{
g
.
Config
.
Windows
.
HyperV
=
&
rspec
.
WindowsHyperV
{}
}
}
func
(
g
*
Generator
)
initConfigWindowsResources
()
{
g
.
initConfigWindows
()
if
g
.
Config
.
Windows
.
Resources
==
nil
{
g
.
Config
.
Windows
.
Resources
=
&
rspec
.
WindowsResources
{}
}
}
func
(
g
*
Generator
)
initConfigWindowsResourcesMemory
()
{
g
.
initConfigWindowsResources
()
if
g
.
Config
.
Windows
.
Resources
.
Memory
==
nil
{
g
.
Config
.
Windows
.
Resources
.
Memory
=
&
rspec
.
WindowsMemoryResources
{}
}
}
func
(
g
*
Generator
)
initConfigVM
()
{
g
.
initConfig
()
if
g
.
Config
.
VM
==
nil
{
g
.
Config
.
VM
=
&
rspec
.
VM
{}
}
}
vendor/github.com/opencontainers/runtime-tools/generate/generate.go
0 → 100644
View file @
d7e13eb9
// Package generate implements functions generating container config files.
package
generate
import
(
"encoding/json"
"fmt"
"io"
"os"
"strings"
rspec
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/generate/seccomp"
capsCheck
"github.com/opencontainers/runtime-tools/validate/capabilities"
"github.com/syndtr/gocapability/capability"
)
var
(
// Namespaces include the names of supported namespaces.
Namespaces
=
[]
string
{
"network"
,
"pid"
,
"mount"
,
"ipc"
,
"uts"
,
"user"
,
"cgroup"
}
// we don't care about order...and this is way faster...
removeFunc
=
func
(
s
[]
string
,
i
int
)
[]
string
{
s
[
i
]
=
s
[
len
(
s
)
-
1
]
return
s
[
:
len
(
s
)
-
1
]
}
)
// Generator represents a generator for a container config.
type
Generator
struct
{
Config
*
rspec
.
Spec
HostSpecific
bool
// This is used to keep a cache of the ENVs added to improve
// performance when adding a huge number of ENV variables
envMap
map
[
string
]
int
}
// ExportOptions have toggles for exporting only certain parts of the specification
type
ExportOptions
struct
{
Seccomp
bool
// seccomp toggles if only seccomp should be exported
}
// New creates a configuration Generator with the default
// configuration for the target operating system.
func
New
(
os
string
)
(
generator
Generator
,
err
error
)
{
if
os
!=
"linux"
&&
os
!=
"solaris"
&&
os
!=
"windows"
&&
os
!=
"freebsd"
{
return
generator
,
fmt
.
Errorf
(
"no defaults configured for %s"
,
os
)
}
config
:=
rspec
.
Spec
{
Version
:
rspec
.
Version
,
Hostname
:
"mrsdalloway"
,
}
if
os
==
"windows"
{
config
.
Process
=
&
rspec
.
Process
{
Args
:
[]
string
{
"cmd"
,
},
Cwd
:
`C:\`
,
}
config
.
Windows
=
&
rspec
.
Windows
{}
}
else
{
config
.
Root
=
&
rspec
.
Root
{
Path
:
"rootfs"
,
Readonly
:
false
,
}
config
.
Process
=
&
rspec
.
Process
{
Terminal
:
false
,
Args
:
[]
string
{
"sh"
,
},
}
}
if
os
==
"linux"
||
os
==
"solaris"
||
os
==
"freebsd"
{
config
.
Process
.
User
=
rspec
.
User
{}
config
.
Process
.
Env
=
[]
string
{
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
,
"TERM=xterm"
,
}
config
.
Process
.
Cwd
=
"/"
config
.
Process
.
Rlimits
=
[]
rspec
.
POSIXRlimit
{
{
Type
:
"RLIMIT_NOFILE"
,
Hard
:
uint64
(
1024
),
Soft
:
uint64
(
1024
),
},
}
}
if
os
==
"linux"
{
config
.
Process
.
Capabilities
=
&
rspec
.
LinuxCapabilities
{
Bounding
:
[]
string
{
"CAP_CHOWN"
,
"CAP_DAC_OVERRIDE"
,
"CAP_FSETID"
,
"CAP_FOWNER"
,
"CAP_MKNOD"
,
"CAP_NET_RAW"
,
"CAP_SETGID"
,
"CAP_SETUID"
,
"CAP_SETFCAP"
,
"CAP_SETPCAP"
,
"CAP_NET_BIND_SERVICE"
,
"CAP_SYS_CHROOT"
,
"CAP_KILL"
,
"CAP_AUDIT_WRITE"
,
},
Permitted
:
[]
string
{
"CAP_CHOWN"
,
"CAP_DAC_OVERRIDE"
,
"CAP_FSETID"
,
"CAP_FOWNER"
,
"CAP_MKNOD"
,
"CAP_NET_RAW"
,
"CAP_SETGID"
,
"CAP_SETUID"
,
"CAP_SETFCAP"
,
"CAP_SETPCAP"
,
"CAP_NET_BIND_SERVICE"
,
"CAP_SYS_CHROOT"
,
"CAP_KILL"
,
"CAP_AUDIT_WRITE"
,
},
Inheritable
:
[]
string
{
"CAP_CHOWN"
,
"CAP_DAC_OVERRIDE"
,
"CAP_FSETID"
,
"CAP_FOWNER"
,
"CAP_MKNOD"
,
"CAP_NET_RAW"
,
"CAP_SETGID"
,
"CAP_SETUID"
,
"CAP_SETFCAP"
,
"CAP_SETPCAP"
,
"CAP_NET_BIND_SERVICE"
,
"CAP_SYS_CHROOT"
,
"CAP_KILL"
,
"CAP_AUDIT_WRITE"
,
},
Effective
:
[]
string
{
"CAP_CHOWN"
,
"CAP_DAC_OVERRIDE"
,
"CAP_FSETID"
,
"CAP_FOWNER"
,
"CAP_MKNOD"
,
"CAP_NET_RAW"
,
"CAP_SETGID"
,
"CAP_SETUID"
,
"CAP_SETFCAP"
,
"CAP_SETPCAP"
,
"CAP_NET_BIND_SERVICE"
,
"CAP_SYS_CHROOT"
,
"CAP_KILL"
,
"CAP_AUDIT_WRITE"
,
},
Ambient
:
[]
string
{
"CAP_CHOWN"
,
"CAP_DAC_OVERRIDE"
,
"CAP_FSETID"
,
"CAP_FOWNER"
,
"CAP_MKNOD"
,
"CAP_NET_RAW"
,
"CAP_SETGID"
,
"CAP_SETUID"
,
"CAP_SETFCAP"
,
"CAP_SETPCAP"
,
"CAP_NET_BIND_SERVICE"
,
"CAP_SYS_CHROOT"
,
"CAP_KILL"
,
"CAP_AUDIT_WRITE"
,
},
}
config
.
Mounts
=
[]
rspec
.
Mount
{
{
Destination
:
"/proc"
,
Type
:
"proc"
,
Source
:
"proc"
,
Options
:
[]
string
{
"nosuid"
,
"noexec"
,
"nodev"
},
},
{
Destination
:
"/dev"
,
Type
:
"tmpfs"
,
Source
:
"tmpfs"
,
Options
:
[]
string
{
"nosuid"
,
"noexec"
,
"strictatime"
,
"mode=755"
,
"size=65536k"
},
},
{
Destination
:
"/dev/pts"
,
Type
:
"devpts"
,
Source
:
"devpts"
,
Options
:
[]
string
{
"nosuid"
,
"noexec"
,
"newinstance"
,
"ptmxmode=0666"
,
"mode=0620"
,
"gid=5"
},
},
{
Destination
:
"/dev/shm"
,
Type
:
"tmpfs"
,
Source
:
"shm"
,
Options
:
[]
string
{
"nosuid"
,
"noexec"
,
"nodev"
,
"mode=1777"
,
"size=65536k"
},
},
{
Destination
:
"/dev/mqueue"
,
Type
:
"mqueue"
,
Source
:
"mqueue"
,
Options
:
[]
string
{
"nosuid"
,
"noexec"
,
"nodev"
},
},
{
Destination
:
"/sys"
,
Type
:
"sysfs"
,
Source
:
"sysfs"
,
Options
:
[]
string
{
"nosuid"
,
"noexec"
,
"nodev"
,
"ro"
},
},
}
config
.
Linux
=
&
rspec
.
Linux
{
Resources
:
&
rspec
.
LinuxResources
{
Devices
:
[]
rspec
.
LinuxDeviceCgroup
{
{
Allow
:
false
,
Access
:
"rwm"
,
},
},
},
Namespaces
:
[]
rspec
.
LinuxNamespace
{
{
Type
:
"pid"
,
},
{
Type
:
"network"
,
},
{
Type
:
"ipc"
,
},
{
Type
:
"uts"
,
},
{
Type
:
"mount"
,
},
},
Seccomp
:
seccomp
.
DefaultProfile
(
&
config
),
}
}
else
if
os
==
"freebsd"
{
config
.
Mounts
=
[]
rspec
.
Mount
{
{
Destination
:
"/dev"
,
Type
:
"devfs"
,
Source
:
"devfs"
,
Options
:
[]
string
{
"ruleset=4"
},
},
{
Destination
:
"/dev/fd"
,
Type
:
"fdescfs"
,
Source
:
"fdesc"
,
Options
:
[]
string
{},
},
}
}
envCache
:=
map
[
string
]
int
{}
if
config
.
Process
!=
nil
{
envCache
=
createEnvCacheMap
(
config
.
Process
.
Env
)
}
return
Generator
{
Config
:
&
config
,
envMap
:
envCache
},
nil
}
// NewFromSpec creates a configuration Generator from a given
// configuration.
func
NewFromSpec
(
config
*
rspec
.
Spec
)
Generator
{
envCache
:=
map
[
string
]
int
{}
if
config
!=
nil
&&
config
.
Process
!=
nil
{
envCache
=
createEnvCacheMap
(
config
.
Process
.
Env
)
}
return
Generator
{
Config
:
config
,
envMap
:
envCache
,
}
}
// NewFromFile loads the template specified in a file into a
// configuration Generator.
func
NewFromFile
(
path
string
)
(
Generator
,
error
)
{
cf
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
return
Generator
{},
fmt
.
Errorf
(
"template configuration at %s not found"
,
path
)
}
return
Generator
{},
err
}
defer
cf
.
Close
()
return
NewFromTemplate
(
cf
)
}
// NewFromTemplate loads the template from io.Reader into a
// configuration Generator.
func
NewFromTemplate
(
r
io
.
Reader
)
(
Generator
,
error
)
{
var
config
rspec
.
Spec
if
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
&
config
);
err
!=
nil
{
return
Generator
{},
err
}
envCache
:=
map
[
string
]
int
{}
if
config
.
Process
!=
nil
{
envCache
=
createEnvCacheMap
(
config
.
Process
.
Env
)
}
return
Generator
{
Config
:
&
config
,
envMap
:
envCache
,
},
nil
}
// createEnvCacheMap creates a hash map with the ENV variables given by the config
func
createEnvCacheMap
(
env
[]
string
)
map
[
string
]
int
{
envMap
:=
make
(
map
[
string
]
int
,
len
(
env
))
for
i
,
val
:=
range
env
{
envMap
[
val
]
=
i
}
return
envMap
}
// SetSpec sets the configuration in the Generator g.
//
// Deprecated: Replace with:
//
// Use generator.Config = config
func
(
g
*
Generator
)
SetSpec
(
config
*
rspec
.
Spec
)
{
g
.
Config
=
config
}
// Spec gets the configuration from the Generator g.
//
// Deprecated: Replace with generator.Config.
func
(
g
*
Generator
)
Spec
()
*
rspec
.
Spec
{
return
g
.
Config
}
// Save writes the configuration into w.
func
(
g
*
Generator
)
Save
(
w
io
.
Writer
,
exportOpts
ExportOptions
)
(
err
error
)
{
var
data
[]
byte
if
g
.
Config
.
Linux
!=
nil
{
buf
,
err
:=
json
.
Marshal
(
g
.
Config
.
Linux
)
if
err
!=
nil
{
return
err
}
if
string
(
buf
)
==
"{}"
{
g
.
Config
.
Linux
=
nil
}
}
if
exportOpts
.
Seccomp
{
data
,
err
=
json
.
MarshalIndent
(
g
.
Config
.
Linux
.
Seccomp
,
""
,
"
\t
"
)
}
else
{
data
,
err
=
json
.
MarshalIndent
(
g
.
Config
,
""
,
"
\t
"
)
}
if
err
!=
nil
{
return
err
}
_
,
err
=
w
.
Write
(
data
)
if
err
!=
nil
{
return
err
}
return
nil
}
// SaveToFile writes the configuration into a file.
func
(
g
*
Generator
)
SaveToFile
(
path
string
,
exportOpts
ExportOptions
)
error
{
f
,
err
:=
os
.
Create
(
path
)
if
err
!=
nil
{
return
err
}
defer
f
.
Close
()
return
g
.
Save
(
f
,
exportOpts
)
}
// SetVersion sets g.Config.Version.
func
(
g
*
Generator
)
SetVersion
(
version
string
)
{
g
.
initConfig
()
g
.
Config
.
Version
=
version
}
// SetRootPath sets g.Config.Root.Path.
func
(
g
*
Generator
)
SetRootPath
(
path
string
)
{
g
.
initConfigRoot
()
g
.
Config
.
Root
.
Path
=
path
}
// SetRootReadonly sets g.Config.Root.Readonly.
func
(
g
*
Generator
)
SetRootReadonly
(
b
bool
)
{
g
.
initConfigRoot
()
g
.
Config
.
Root
.
Readonly
=
b
}
// SetHostname sets g.Config.Hostname.
func
(
g
*
Generator
)
SetHostname
(
s
string
)
{
g
.
initConfig
()
g
.
Config
.
Hostname
=
s
}
// SetOCIVersion sets g.Config.Version.
func
(
g
*
Generator
)
SetOCIVersion
(
s
string
)
{
g
.
initConfig
()
g
.
Config
.
Version
=
s
}
// ClearAnnotations clears g.Config.Annotations.
func
(
g
*
Generator
)
ClearAnnotations
()
{
if
g
.
Config
==
nil
{
return
}
g
.
Config
.
Annotations
=
make
(
map
[
string
]
string
)
}
// AddAnnotation adds an annotation into g.Config.Annotations.
func
(
g
*
Generator
)
AddAnnotation
(
key
,
value
string
)
{
g
.
initConfigAnnotations
()
g
.
Config
.
Annotations
[
key
]
=
value
}
// RemoveAnnotation remove an annotation from g.Config.Annotations.
func
(
g
*
Generator
)
RemoveAnnotation
(
key
string
)
{
if
g
.
Config
==
nil
||
g
.
Config
.
Annotations
==
nil
{
return
}
delete
(
g
.
Config
.
Annotations
,
key
)
}
// RemoveHostname removes g.Config.Hostname, setting it to an empty string.
func
(
g
*
Generator
)
RemoveHostname
()
{
if
g
.
Config
==
nil
{
return
}
g
.
Config
.
Hostname
=
""
}
// SetProcessConsoleSize sets g.Config.Process.ConsoleSize.
func
(
g
*
Generator
)
SetProcessConsoleSize
(
width
,
height
uint
)
{
g
.
initConfigProcessConsoleSize
()
g
.
Config
.
Process
.
ConsoleSize
.
Width
=
width
g
.
Config
.
Process
.
ConsoleSize
.
Height
=
height
}
// SetProcessUID sets g.Config.Process.User.UID.
func
(
g
*
Generator
)
SetProcessUID
(
uid
uint32
)
{
g
.
initConfigProcess
()
g
.
Config
.
Process
.
User
.
UID
=
uid
}
// SetProcessUsername sets g.Config.Process.User.Username.
func
(
g
*
Generator
)
SetProcessUsername
(
username
string
)
{
g
.
initConfigProcess
()
g
.
Config
.
Process
.
User
.
Username
=
username
}
// SetProcessUmask sets g.Config.Process.User.Umask.
func
(
g
*
Generator
)
SetProcessUmask
(
umask
uint32
)
{
g
.
initConfigProcess
()
u
:=
umask
g
.
Config
.
Process
.
User
.
Umask
=
&
u
}
// SetProcessGID sets g.Config.Process.User.GID.
func
(
g
*
Generator
)
SetProcessGID
(
gid
uint32
)
{
g
.
initConfigProcess
()
g
.
Config
.
Process
.
User
.
GID
=
gid
}
// SetProcessCwd sets g.Config.Process.Cwd.
func
(
g
*
Generator
)
SetProcessCwd
(
cwd
string
)
{
g
.
initConfigProcess
()
g
.
Config
.
Process
.
Cwd
=
cwd
}
// SetProcessNoNewPrivileges sets g.Config.Process.NoNewPrivileges.
func
(
g
*
Generator
)
SetProcessNoNewPrivileges
(
b
bool
)
{
g
.
initConfigProcess
()
g
.
Config
.
Process
.
NoNewPrivileges
=
b
}
// SetProcessTerminal sets g.Config.Process.Terminal.
func
(
g
*
Generator
)
SetProcessTerminal
(
b
bool
)
{
g
.
initConfigProcess
()
g
.
Config
.
Process
.
Terminal
=
b
}
// SetProcessApparmorProfile sets g.Config.Process.ApparmorProfile.
func
(
g
*
Generator
)
SetProcessApparmorProfile
(
prof
string
)
{
g
.
initConfigProcess
()
g
.
Config
.
Process
.
ApparmorProfile
=
prof
}
// SetProcessArgs sets g.Config.Process.Args.
func
(
g
*
Generator
)
SetProcessArgs
(
args
[]
string
)
{
g
.
initConfigProcess
()
g
.
Config
.
Process
.
Args
=
args
}
// ClearProcessEnv clears g.Config.Process.Env.
func
(
g
*
Generator
)
ClearProcessEnv
()
{
if
g
.
Config
==
nil
||
g
.
Config
.
Process
==
nil
{
return
}
g
.
Config
.
Process
.
Env
=
[]
string
{}
// Clear out the env cache map as well
g
.
envMap
=
map
[
string
]
int
{}
}
// AddProcessEnv adds name=value into g.Config.Process.Env, or replaces an
// existing entry with the given name.
func
(
g
*
Generator
)
AddProcessEnv
(
name
,
value
string
)
{
if
name
==
""
{
return
}
g
.
initConfigProcess
()
g
.
addEnv
(
fmt
.
Sprintf
(
"%s=%s"
,
name
,
value
),
name
)
}
// AddMultipleProcessEnv adds multiple name=value into g.Config.Process.Env, or replaces
// existing entries with the given name.
func
(
g
*
Generator
)
AddMultipleProcessEnv
(
envs
[]
string
)
{
g
.
initConfigProcess
()
for
_
,
val
:=
range
envs
{
split
:=
strings
.
SplitN
(
val
,
"="
,
2
)
g
.
addEnv
(
val
,
split
[
0
])
}
}
// addEnv looks through adds ENV to the Process and checks envMap for
// any duplicates
// This is called by both AddMultipleProcessEnv and AddProcessEnv
func
(
g
*
Generator
)
addEnv
(
env
,
key
string
)
{
if
idx
,
ok
:=
g
.
envMap
[
key
];
ok
{
// The ENV exists in the cache, so change its value in g.Config.Process.Env
g
.
Config
.
Process
.
Env
[
idx
]
=
env
}
else
{
// else the env doesn't exist, so add it and add it's index to g.envMap
g
.
Config
.
Process
.
Env
=
append
(
g
.
Config
.
Process
.
Env
,
env
)
g
.
envMap
[
key
]
=
len
(
g
.
Config
.
Process
.
Env
)
-
1
}
}
// AddProcessRlimits adds rlimit into g.Config.Process.Rlimits.
func
(
g
*
Generator
)
AddProcessRlimits
(
rType
string
,
rHard
uint64
,
rSoft
uint64
)
{
g
.
initConfigProcess
()
for
i
,
rlimit
:=
range
g
.
Config
.
Process
.
Rlimits
{
if
rlimit
.
Type
==
rType
{
g
.
Config
.
Process
.
Rlimits
[
i
]
.
Hard
=
rHard
g
.
Config
.
Process
.
Rlimits
[
i
]
.
Soft
=
rSoft
return
}
}
newRlimit
:=
rspec
.
POSIXRlimit
{
Type
:
rType
,
Hard
:
rHard
,
Soft
:
rSoft
,
}
g
.
Config
.
Process
.
Rlimits
=
append
(
g
.
Config
.
Process
.
Rlimits
,
newRlimit
)
}
// RemoveProcessRlimits removes a rlimit from g.Config.Process.Rlimits.
func
(
g
*
Generator
)
RemoveProcessRlimits
(
rType
string
)
{
if
g
.
Config
==
nil
||
g
.
Config
.
Process
==
nil
{
return
}
for
i
,
rlimit
:=
range
g
.
Config
.
Process
.
Rlimits
{
if
rlimit
.
Type
==
rType
{
g
.
Config
.
Process
.
Rlimits
=
append
(
g
.
Config
.
Process
.
Rlimits
[
:
i
],
g
.
Config
.
Process
.
Rlimits
[
i
+
1
:
]
...
)
return
}
}
}
// ClearProcessRlimits clear g.Config.Process.Rlimits.
func
(
g
*
Generator
)
ClearProcessRlimits
()
{
if
g
.
Config
==
nil
||
g
.
Config
.
Process
==
nil
{
return
}
g
.
Config
.
Process
.
Rlimits
=
[]
rspec
.
POSIXRlimit
{}
}
// ClearProcessAdditionalGids clear g.Config.Process.AdditionalGids.
func
(
g
*
Generator
)
ClearProcessAdditionalGids
()
{
if
g
.
Config
==
nil
||
g
.
Config
.
Process
==
nil
{
return
}
g
.
Config
.
Process
.
User
.
AdditionalGids
=
[]
uint32
{}
}
// AddProcessAdditionalGid adds an additional gid into g.Config.Process.AdditionalGids.
func
(
g
*
Generator
)
AddProcessAdditionalGid
(
gid
uint32
)
{
g
.
initConfigProcess
()
for
_
,
group
:=
range
g
.
Config
.
Process
.
User
.
AdditionalGids
{
if
group
==
gid
{
return
}
}
g
.
Config
.
Process
.
User
.
AdditionalGids
=
append
(
g
.
Config
.
Process
.
User
.
AdditionalGids
,
gid
)
}
// SetProcessSelinuxLabel sets g.Config.Process.SelinuxLabel.
func
(
g
*
Generator
)
SetProcessSelinuxLabel
(
label
string
)
{
g
.
initConfigProcess
()
g
.
Config
.
Process
.
SelinuxLabel
=
label
}
// SetLinuxCgroupsPath sets g.Config.Linux.CgroupsPath.
func
(
g
*
Generator
)
SetLinuxCgroupsPath
(
path
string
)
{
g
.
initConfigLinux
()
g
.
Config
.
Linux
.
CgroupsPath
=
path
}
// SetLinuxIntelRdtClosID sets g.Config.Linux.IntelRdt.ClosID
func
(
g
*
Generator
)
SetLinuxIntelRdtClosID
(
clos
string
)
{
g
.
initConfigLinuxIntelRdt
()
g
.
Config
.
Linux
.
IntelRdt
.
ClosID
=
clos
}
// SetLinuxIntelRdtL3CacheSchema sets g.Config.Linux.IntelRdt.L3CacheSchema
func
(
g
*
Generator
)
SetLinuxIntelRdtL3CacheSchema
(
schema
string
)
{
g
.
initConfigLinuxIntelRdt
()
g
.
Config
.
Linux
.
IntelRdt
.
L3CacheSchema
=
schema
}
// SetLinuxMountLabel sets g.Config.Linux.MountLabel.
func
(
g
*
Generator
)
SetLinuxMountLabel
(
label
string
)
{
g
.
initConfigLinux
()
g
.
Config
.
Linux
.
MountLabel
=
label
}
// SetProcessOOMScoreAdj sets g.Config.Process.OOMScoreAdj.
func
(
g
*
Generator
)
SetProcessOOMScoreAdj
(
adj
int
)
{
g
.
initConfigProcess
()
g
.
Config
.
Process
.
OOMScoreAdj
=
&
adj
}
// SetLinuxResourcesBlockIOLeafWeight sets g.Config.Linux.Resources.BlockIO.LeafWeight.
func
(
g
*
Generator
)
SetLinuxResourcesBlockIOLeafWeight
(
weight
uint16
)
{
g
.
initConfigLinuxResourcesBlockIO
()
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
LeafWeight
=
&
weight
}
// AddLinuxResourcesBlockIOLeafWeightDevice adds or sets g.Config.Linux.Resources.BlockIO.WeightDevice.LeafWeight.
func
(
g
*
Generator
)
AddLinuxResourcesBlockIOLeafWeightDevice
(
major
int64
,
minor
int64
,
weight
uint16
)
{
g
.
initConfigLinuxResourcesBlockIO
()
for
i
,
weightDevice
:=
range
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
WeightDevice
{
if
weightDevice
.
Major
==
major
&&
weightDevice
.
Minor
==
minor
{
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
WeightDevice
[
i
]
.
LeafWeight
=
&
weight
return
}
}
weightDevice
:=
new
(
rspec
.
LinuxWeightDevice
)
weightDevice
.
Major
=
major
weightDevice
.
Minor
=
minor
weightDevice
.
LeafWeight
=
&
weight
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
WeightDevice
=
append
(
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
WeightDevice
,
*
weightDevice
)
}
// DropLinuxResourcesBlockIOLeafWeightDevice drops a item form g.Config.Linux.Resources.BlockIO.WeightDevice.LeafWeight
func
(
g
*
Generator
)
DropLinuxResourcesBlockIOLeafWeightDevice
(
major
int64
,
minor
int64
)
{
if
g
.
Config
==
nil
||
g
.
Config
.
Linux
==
nil
||
g
.
Config
.
Linux
.
Resources
==
nil
||
g
.
Config
.
Linux
.
Resources
.
BlockIO
==
nil
{
return
}
for
i
,
weightDevice
:=
range
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
WeightDevice
{
if
weightDevice
.
Major
==
major
&&
weightDevice
.
Minor
==
minor
{
if
weightDevice
.
Weight
!=
nil
{
newWeightDevice
:=
new
(
rspec
.
LinuxWeightDevice
)
newWeightDevice
.
Major
=
major
newWeightDevice
.
Minor
=
minor
newWeightDevice
.
Weight
=
weightDevice
.
Weight
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
WeightDevice
[
i
]
=
*
newWeightDevice
}
else
{
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
WeightDevice
=
append
(
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
WeightDevice
[
:
i
],
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
WeightDevice
[
i
+
1
:
]
...
)
}
return
}
}
}
// SetLinuxResourcesBlockIOWeight sets g.Config.Linux.Resources.BlockIO.Weight.
func
(
g
*
Generator
)
SetLinuxResourcesBlockIOWeight
(
weight
uint16
)
{
g
.
initConfigLinuxResourcesBlockIO
()
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
Weight
=
&
weight
}
// AddLinuxResourcesBlockIOWeightDevice adds or sets g.Config.Linux.Resources.BlockIO.WeightDevice.Weight.
func
(
g
*
Generator
)
AddLinuxResourcesBlockIOWeightDevice
(
major
int64
,
minor
int64
,
weight
uint16
)
{
g
.
initConfigLinuxResourcesBlockIO
()
for
i
,
weightDevice
:=
range
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
WeightDevice
{
if
weightDevice
.
Major
==
major
&&
weightDevice
.
Minor
==
minor
{
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
WeightDevice
[
i
]
.
Weight
=
&
weight
return
}
}
weightDevice
:=
new
(
rspec
.
LinuxWeightDevice
)
weightDevice
.
Major
=
major
weightDevice
.
Minor
=
minor
weightDevice
.
Weight
=
&
weight
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
WeightDevice
=
append
(
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
WeightDevice
,
*
weightDevice
)
}
// DropLinuxResourcesBlockIOWeightDevice drops a item form g.Config.Linux.Resources.BlockIO.WeightDevice.Weight
func
(
g
*
Generator
)
DropLinuxResourcesBlockIOWeightDevice
(
major
int64
,
minor
int64
)
{
if
g
.
Config
==
nil
||
g
.
Config
.
Linux
==
nil
||
g
.
Config
.
Linux
.
Resources
==
nil
||
g
.
Config
.
Linux
.
Resources
.
BlockIO
==
nil
{
return
}
for
i
,
weightDevice
:=
range
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
WeightDevice
{
if
weightDevice
.
Major
==
major
&&
weightDevice
.
Minor
==
minor
{
if
weightDevice
.
LeafWeight
!=
nil
{
newWeightDevice
:=
new
(
rspec
.
LinuxWeightDevice
)
newWeightDevice
.
Major
=
major
newWeightDevice
.
Minor
=
minor
newWeightDevice
.
LeafWeight
=
weightDevice
.
LeafWeight
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
WeightDevice
[
i
]
=
*
newWeightDevice
}
else
{
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
WeightDevice
=
append
(
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
WeightDevice
[
:
i
],
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
WeightDevice
[
i
+
1
:
]
...
)
}
return
}
}
}
// AddLinuxResourcesBlockIOThrottleReadBpsDevice adds or sets g.Config.Linux.Resources.BlockIO.ThrottleReadBpsDevice.
func
(
g
*
Generator
)
AddLinuxResourcesBlockIOThrottleReadBpsDevice
(
major
int64
,
minor
int64
,
rate
uint64
)
{
g
.
initConfigLinuxResourcesBlockIO
()
throttleDevices
:=
addOrReplaceBlockIOThrottleDevice
(
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
ThrottleReadBpsDevice
,
major
,
minor
,
rate
)
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
ThrottleReadBpsDevice
=
throttleDevices
}
// DropLinuxResourcesBlockIOThrottleReadBpsDevice drops a item from g.Config.Linux.Resources.BlockIO.ThrottleReadBpsDevice.
func
(
g
*
Generator
)
DropLinuxResourcesBlockIOThrottleReadBpsDevice
(
major
int64
,
minor
int64
)
{
if
g
.
Config
==
nil
||
g
.
Config
.
Linux
==
nil
||
g
.
Config
.
Linux
.
Resources
==
nil
||
g
.
Config
.
Linux
.
Resources
.
BlockIO
==
nil
{
return
}
throttleDevices
:=
dropBlockIOThrottleDevice
(
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
ThrottleReadBpsDevice
,
major
,
minor
)
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
ThrottleReadBpsDevice
=
throttleDevices
}
// AddLinuxResourcesBlockIOThrottleReadIOPSDevice adds or sets g.Config.Linux.Resources.BlockIO.ThrottleReadIOPSDevice.
func
(
g
*
Generator
)
AddLinuxResourcesBlockIOThrottleReadIOPSDevice
(
major
int64
,
minor
int64
,
rate
uint64
)
{
g
.
initConfigLinuxResourcesBlockIO
()
throttleDevices
:=
addOrReplaceBlockIOThrottleDevice
(
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
ThrottleReadIOPSDevice
,
major
,
minor
,
rate
)
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
ThrottleReadIOPSDevice
=
throttleDevices
}
// DropLinuxResourcesBlockIOThrottleReadIOPSDevice drops a item from g.Config.Linux.Resources.BlockIO.ThrottleReadIOPSDevice.
func
(
g
*
Generator
)
DropLinuxResourcesBlockIOThrottleReadIOPSDevice
(
major
int64
,
minor
int64
)
{
if
g
.
Config
==
nil
||
g
.
Config
.
Linux
==
nil
||
g
.
Config
.
Linux
.
Resources
==
nil
||
g
.
Config
.
Linux
.
Resources
.
BlockIO
==
nil
{
return
}
throttleDevices
:=
dropBlockIOThrottleDevice
(
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
ThrottleReadIOPSDevice
,
major
,
minor
)
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
ThrottleReadIOPSDevice
=
throttleDevices
}
// AddLinuxResourcesBlockIOThrottleWriteBpsDevice adds or sets g.Config.Linux.Resources.BlockIO.ThrottleWriteBpsDevice.
func
(
g
*
Generator
)
AddLinuxResourcesBlockIOThrottleWriteBpsDevice
(
major
int64
,
minor
int64
,
rate
uint64
)
{
g
.
initConfigLinuxResourcesBlockIO
()
throttleDevices
:=
addOrReplaceBlockIOThrottleDevice
(
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
ThrottleWriteBpsDevice
,
major
,
minor
,
rate
)
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
ThrottleWriteBpsDevice
=
throttleDevices
}
// DropLinuxResourcesBlockIOThrottleWriteBpsDevice drops a item from g.Config.Linux.Resources.BlockIO.ThrottleWriteBpsDevice.
func
(
g
*
Generator
)
DropLinuxResourcesBlockIOThrottleWriteBpsDevice
(
major
int64
,
minor
int64
)
{
if
g
.
Config
==
nil
||
g
.
Config
.
Linux
==
nil
||
g
.
Config
.
Linux
.
Resources
==
nil
||
g
.
Config
.
Linux
.
Resources
.
BlockIO
==
nil
{
return
}
throttleDevices
:=
dropBlockIOThrottleDevice
(
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
ThrottleWriteBpsDevice
,
major
,
minor
)
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
ThrottleWriteBpsDevice
=
throttleDevices
}
// AddLinuxResourcesBlockIOThrottleWriteIOPSDevice adds or sets g.Config.Linux.Resources.BlockIO.ThrottleWriteIOPSDevice.
func
(
g
*
Generator
)
AddLinuxResourcesBlockIOThrottleWriteIOPSDevice
(
major
int64
,
minor
int64
,
rate
uint64
)
{
g
.
initConfigLinuxResourcesBlockIO
()
throttleDevices
:=
addOrReplaceBlockIOThrottleDevice
(
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
ThrottleWriteIOPSDevice
,
major
,
minor
,
rate
)
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
ThrottleWriteIOPSDevice
=
throttleDevices
}
// DropLinuxResourcesBlockIOThrottleWriteIOPSDevice drops a item from g.Config.Linux.Resources.BlockIO.ThrottleWriteIOPSDevice.
func
(
g
*
Generator
)
DropLinuxResourcesBlockIOThrottleWriteIOPSDevice
(
major
int64
,
minor
int64
)
{
if
g
.
Config
==
nil
||
g
.
Config
.
Linux
==
nil
||
g
.
Config
.
Linux
.
Resources
==
nil
||
g
.
Config
.
Linux
.
Resources
.
BlockIO
==
nil
{
return
}
throttleDevices
:=
dropBlockIOThrottleDevice
(
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
ThrottleWriteIOPSDevice
,
major
,
minor
)
g
.
Config
.
Linux
.
Resources
.
BlockIO
.
ThrottleWriteIOPSDevice
=
throttleDevices
}
// SetLinuxResourcesCPUShares sets g.Config.Linux.Resources.CPU.Shares.
func
(
g
*
Generator
)
SetLinuxResourcesCPUShares
(
shares
uint64
)
{
g
.
InitConfigLinuxResourcesCPU
()
g
.
Config
.
Linux
.
Resources
.
CPU
.
Shares
=
&
shares
}
// SetLinuxResourcesCPUQuota sets g.Config.Linux.Resources.CPU.Quota.
func
(
g
*
Generator
)
SetLinuxResourcesCPUQuota
(
quota
int64
)
{
g
.
InitConfigLinuxResourcesCPU
()
g
.
Config
.
Linux
.
Resources
.
CPU
.
Quota
=
&
quota
}
// SetLinuxResourcesCPUPeriod sets g.Config.Linux.Resources.CPU.Period.
func
(
g
*
Generator
)
SetLinuxResourcesCPUPeriod
(
period
uint64
)
{
g
.
InitConfigLinuxResourcesCPU
()
g
.
Config
.
Linux
.
Resources
.
CPU
.
Period
=
&
period
}
// SetLinuxResourcesCPURealtimeRuntime sets g.Config.Linux.Resources.CPU.RealtimeRuntime.
func
(
g
*
Generator
)
SetLinuxResourcesCPURealtimeRuntime
(
time
int64
)
{
g
.
InitConfigLinuxResourcesCPU
()
g
.
Config
.
Linux
.
Resources
.
CPU
.
RealtimeRuntime
=
&
time
}
// SetLinuxResourcesCPURealtimePeriod sets g.Config.Linux.Resources.CPU.RealtimePeriod.
func
(
g
*
Generator
)
SetLinuxResourcesCPURealtimePeriod
(
period
uint64
)
{
g
.
InitConfigLinuxResourcesCPU
()
g
.
Config
.
Linux
.
Resources
.
CPU
.
RealtimePeriod
=
&
period
}
// SetLinuxResourcesCPUCpus sets g.Config.Linux.Resources.CPU.Cpus.
func
(
g
*
Generator
)
SetLinuxResourcesCPUCpus
(
cpus
string
)
{
g
.
InitConfigLinuxResourcesCPU
()
g
.
Config
.
Linux
.
Resources
.
CPU
.
Cpus
=
cpus
}
// SetLinuxResourcesCPUMems sets g.Config.Linux.Resources.CPU.Mems.
func
(
g
*
Generator
)
SetLinuxResourcesCPUMems
(
mems
string
)
{
g
.
InitConfigLinuxResourcesCPU
()
g
.
Config
.
Linux
.
Resources
.
CPU
.
Mems
=
mems
}
// AddLinuxResourcesHugepageLimit adds or sets g.Config.Linux.Resources.HugepageLimits.
func
(
g
*
Generator
)
AddLinuxResourcesHugepageLimit
(
pageSize
string
,
limit
uint64
)
{
hugepageLimit
:=
rspec
.
LinuxHugepageLimit
{
Pagesize
:
pageSize
,
Limit
:
limit
,
}
g
.
initConfigLinuxResources
()
for
i
,
pageLimit
:=
range
g
.
Config
.
Linux
.
Resources
.
HugepageLimits
{
if
pageLimit
.
Pagesize
==
pageSize
{
g
.
Config
.
Linux
.
Resources
.
HugepageLimits
[
i
]
.
Limit
=
limit
return
}
}
g
.
Config
.
Linux
.
Resources
.
HugepageLimits
=
append
(
g
.
Config
.
Linux
.
Resources
.
HugepageLimits
,
hugepageLimit
)
}
// DropLinuxResourcesHugepageLimit drops a hugepage limit from g.Config.Linux.Resources.HugepageLimits.
func
(
g
*
Generator
)
DropLinuxResourcesHugepageLimit
(
pageSize
string
)
{
if
g
.
Config
==
nil
||
g
.
Config
.
Linux
==
nil
||
g
.
Config
.
Linux
.
Resources
==
nil
{
return
}
for
i
,
pageLimit
:=
range
g
.
Config
.
Linux
.
Resources
.
HugepageLimits
{
if
pageLimit
.
Pagesize
==
pageSize
{
g
.
Config
.
Linux
.
Resources
.
HugepageLimits
=
append
(
g
.
Config
.
Linux
.
Resources
.
HugepageLimits
[
:
i
],
g
.
Config
.
Linux
.
Resources
.
HugepageLimits
[
i
+
1
:
]
...
)
return
}
}
}
// AddLinuxResourcesUnified sets the g.Config.Linux.Resources.Unified
func
(
g
*
Generator
)
SetLinuxResourcesUnified
(
unified
map
[
string
]
string
)
{
g
.
initConfigLinuxResourcesUnified
()
for
k
,
v
:=
range
unified
{
g
.
Config
.
Linux
.
Resources
.
Unified
[
k
]
=
v
}
}
// AddLinuxResourcesUnified adds or updates the key-value pair from g.Config.Linux.Resources.Unified
func
(
g
*
Generator
)
AddLinuxResourcesUnified
(
key
,
val
string
)
{
g
.
initConfigLinuxResourcesUnified
()
g
.
Config
.
Linux
.
Resources
.
Unified
[
key
]
=
val
}
// DropLinuxResourcesUnified drops a key-value pair from g.Config.Linux.Resources.Unified
func
(
g
*
Generator
)
DropLinuxResourcesUnified
(
key
string
)
{
if
g
.
Config
==
nil
||
g
.
Config
.
Linux
==
nil
||
g
.
Config
.
Linux
.
Resources
==
nil
||
g
.
Config
.
Linux
.
Resources
.
Unified
==
nil
{
return
}
delete
(
g
.
Config
.
Linux
.
Resources
.
Unified
,
key
)
}
// SetLinuxResourcesMemoryLimit sets g.Config.Linux.Resources.Memory.Limit.
func
(
g
*
Generator
)
SetLinuxResourcesMemoryLimit
(
limit
int64
)
{
g
.
initConfigLinuxResourcesMemory
()
g
.
Config
.
Linux
.
Resources
.
Memory
.
Limit
=
&
limit
}
// SetLinuxResourcesMemoryReservation sets g.Config.Linux.Resources.Memory.Reservation.
func
(
g
*
Generator
)
SetLinuxResourcesMemoryReservation
(
reservation
int64
)
{
g
.
initConfigLinuxResourcesMemory
()
g
.
Config
.
Linux
.
Resources
.
Memory
.
Reservation
=
&
reservation
}
// SetLinuxResourcesMemorySwap sets g.Config.Linux.Resources.Memory.Swap.
func
(
g
*
Generator
)
SetLinuxResourcesMemorySwap
(
swap
int64
)
{
g
.
initConfigLinuxResourcesMemory
()
g
.
Config
.
Linux
.
Resources
.
Memory
.
Swap
=
&
swap
}
// SetLinuxResourcesMemoryKernel sets g.Config.Linux.Resources.Memory.Kernel.
func
(
g
*
Generator
)
SetLinuxResourcesMemoryKernel
(
kernel
int64
)
{
g
.
initConfigLinuxResourcesMemory
()
g
.
Config
.
Linux
.
Resources
.
Memory
.
Kernel
=
&
kernel
}
// SetLinuxResourcesMemoryKernelTCP sets g.Config.Linux.Resources.Memory.KernelTCP.
func
(
g
*
Generator
)
SetLinuxResourcesMemoryKernelTCP
(
kernelTCP
int64
)
{
g
.
initConfigLinuxResourcesMemory
()
g
.
Config
.
Linux
.
Resources
.
Memory
.
KernelTCP
=
&
kernelTCP
}
// SetLinuxResourcesMemorySwappiness sets g.Config.Linux.Resources.Memory.Swappiness.
func
(
g
*
Generator
)
SetLinuxResourcesMemorySwappiness
(
swappiness
uint64
)
{
g
.
initConfigLinuxResourcesMemory
()
g
.
Config
.
Linux
.
Resources
.
Memory
.
Swappiness
=
&
swappiness
}
// SetLinuxResourcesMemoryDisableOOMKiller sets g.Config.Linux.Resources.Memory.DisableOOMKiller.
func
(
g
*
Generator
)
SetLinuxResourcesMemoryDisableOOMKiller
(
disable
bool
)
{
g
.
initConfigLinuxResourcesMemory
()
g
.
Config
.
Linux
.
Resources
.
Memory
.
DisableOOMKiller
=
&
disable
}
// SetLinuxResourcesNetworkClassID sets g.Config.Linux.Resources.Network.ClassID.
func
(
g
*
Generator
)
SetLinuxResourcesNetworkClassID
(
classid
uint32
)
{
g
.
initConfigLinuxResourcesNetwork
()
g
.
Config
.
Linux
.
Resources
.
Network
.
ClassID
=
&
classid
}
// AddLinuxResourcesNetworkPriorities adds or sets g.Config.Linux.Resources.Network.Priorities.
func
(
g
*
Generator
)
AddLinuxResourcesNetworkPriorities
(
name
string
,
prio
uint32
)
{
g
.
initConfigLinuxResourcesNetwork
()
for
i
,
netPriority
:=
range
g
.
Config
.
Linux
.
Resources
.
Network
.
Priorities
{
if
netPriority
.
Name
==
name
{
g
.
Config
.
Linux
.
Resources
.
Network
.
Priorities
[
i
]
.
Priority
=
prio
return
}
}
interfacePrio
:=
new
(
rspec
.
LinuxInterfacePriority
)
interfacePrio
.
Name
=
name
interfacePrio
.
Priority
=
prio
g
.
Config
.
Linux
.
Resources
.
Network
.
Priorities
=
append
(
g
.
Config
.
Linux
.
Resources
.
Network
.
Priorities
,
*
interfacePrio
)
}
// DropLinuxResourcesNetworkPriorities drops one item from g.Config.Linux.Resources.Network.Priorities.
func
(
g
*
Generator
)
DropLinuxResourcesNetworkPriorities
(
name
string
)
{
if
g
.
Config
==
nil
||
g
.
Config
.
Linux
==
nil
||
g
.
Config
.
Linux
.
Resources
==
nil
||
g
.
Config
.
Linux
.
Resources
.
Network
==
nil
{
return
}
for
i
,
netPriority
:=
range
g
.
Config
.
Linux
.
Resources
.
Network
.
Priorities
{
if
netPriority
.
Name
==
name
{
g
.
Config
.
Linux
.
Resources
.
Network
.
Priorities
=
append
(
g
.
Config
.
Linux
.
Resources
.
Network
.
Priorities
[
:
i
],
g
.
Config
.
Linux
.
Resources
.
Network
.
Priorities
[
i
+
1
:
]
...
)
return
}
}
}
// SetLinuxResourcesPidsLimit sets g.Config.Linux.Resources.Pids.Limit.
func
(
g
*
Generator
)
SetLinuxResourcesPidsLimit
(
limit
int64
)
{
g
.
initConfigLinuxResourcesPids
()
g
.
Config
.
Linux
.
Resources
.
Pids
.
Limit
=
limit
}
// ClearLinuxSysctl clears g.Config.Linux.Sysctl.
func
(
g
*
Generator
)
ClearLinuxSysctl
()
{
if
g
.
Config
==
nil
||
g
.
Config
.
Linux
==
nil
{
return
}
g
.
Config
.
Linux
.
Sysctl
=
make
(
map
[
string
]
string
)
}
// AddLinuxSysctl adds a new sysctl config into g.Config.Linux.Sysctl.
func
(
g
*
Generator
)
AddLinuxSysctl
(
key
,
value
string
)
{
g
.
initConfigLinuxSysctl
()
g
.
Config
.
Linux
.
Sysctl
[
key
]
=
value
}
// RemoveLinuxSysctl removes a sysctl config from g.Config.Linux.Sysctl.
func
(
g
*
Generator
)
RemoveLinuxSysctl
(
key
string
)
{
if
g
.
Config
==
nil
||
g
.
Config
.
Linux
==
nil
||
g
.
Config
.
Linux
.
Sysctl
==
nil
{
return
}
delete
(
g
.
Config
.
Linux
.
Sysctl
,
key
)
}
// ClearLinuxUIDMappings clear g.Config.Linux.UIDMappings.
func
(
g
*
Generator
)
ClearLinuxUIDMappings
()
{
if
g
.
Config
==
nil
||
g
.
Config
.
Linux
==
nil
{
return
}
g
.
Config
.
Linux
.
UIDMappings
=
[]
rspec
.
LinuxIDMapping
{}
}
// AddLinuxUIDMapping adds uidMap into g.Config.Linux.UIDMappings.
func
(
g
*
Generator
)
AddLinuxUIDMapping
(
hid
,
cid
,
size
uint32
)
{
idMapping
:=
rspec
.
LinuxIDMapping
{
HostID
:
hid
,
ContainerID
:
cid
,
Size
:
size
,
}
g
.
initConfigLinux
()
g
.
Config
.
Linux
.
UIDMappings
=
append
(
g
.
Config
.
Linux
.
UIDMappings
,
idMapping
)
}
// ClearLinuxGIDMappings clear g.Config.Linux.GIDMappings.
func
(
g
*
Generator
)
ClearLinuxGIDMappings
()
{
if
g
.
Config
==
nil
||
g
.
Config
.
Linux
==
nil
{
return
}
g
.
Config
.
Linux
.
GIDMappings
=
[]
rspec
.
LinuxIDMapping
{}
}
// AddLinuxGIDMapping adds gidMap into g.Config.Linux.GIDMappings.
func
(
g
*
Generator
)
AddLinuxGIDMapping
(
hid
,
cid
,
size
uint32
)
{
idMapping
:=
rspec
.
LinuxIDMapping
{
HostID
:
hid
,
ContainerID
:
cid
,
Size
:
size
,
}
g
.
initConfigLinux
()
g
.
Config
.
Linux
.
GIDMappings
=
append
(
g
.
Config
.
Linux
.
GIDMappings
,
idMapping
)
}
// SetLinuxRootPropagation sets g.Config.Linux.RootfsPropagation.
func
(
g
*
Generator
)
SetLinuxRootPropagation
(
rp
string
)
error
{
switch
rp
{
case
""
:
case
"private"
:
case
"rprivate"
:
case
"slave"
:
case
"rslave"
:
case
"shared"
:
case
"rshared"
:
case
"unbindable"
:
case
"runbindable"
:
default
:
return
fmt
.
Errorf
(
"rootfs-propagation %q must be empty or one of (r)private|(r)slave|(r)shared|(r)unbindable"
,
rp
)
}
g
.
initConfigLinux
()
g
.
Config
.
Linux
.
RootfsPropagation
=
rp
return
nil
}
// ClearPreStartHooks clear g.Config.Hooks.Prestart.
func
(
g
*
Generator
)
ClearPreStartHooks
()
{
if
g
.
Config
==
nil
||
g
.
Config
.
Hooks
==
nil
{
return
}
g
.
Config
.
Hooks
.
Prestart
=
[]
rspec
.
Hook
{}
}
// AddPreStartHook add a prestart hook into g.Config.Hooks.Prestart.
func
(
g
*
Generator
)
AddPreStartHook
(
preStartHook
rspec
.
Hook
)
{
g
.
initConfigHooks
()
g
.
Config
.
Hooks
.
Prestart
=
append
(
g
.
Config
.
Hooks
.
Prestart
,
preStartHook
)
}
// ClearPostStopHooks clear g.Config.Hooks.Poststop.
func
(
g
*
Generator
)
ClearPostStopHooks
()
{
if
g
.
Config
==
nil
||
g
.
Config
.
Hooks
==
nil
{
return
}
g
.
Config
.
Hooks
.
Poststop
=
[]
rspec
.
Hook
{}
}
// AddPostStopHook adds a poststop hook into g.Config.Hooks.Poststop.
func
(
g
*
Generator
)
AddPostStopHook
(
postStopHook
rspec
.
Hook
)
{
g
.
initConfigHooks
()
g
.
Config
.
Hooks
.
Poststop
=
append
(
g
.
Config
.
Hooks
.
Poststop
,
postStopHook
)
}
// ClearPostStartHooks clear g.Config.Hooks.Poststart.
func
(
g
*
Generator
)
ClearPostStartHooks
()
{
if
g
.
Config
==
nil
||
g
.
Config
.
Hooks
==
nil
{
return
}
g
.
Config
.
Hooks
.
Poststart
=
[]
rspec
.
Hook
{}
}
// AddPostStartHook adds a poststart hook into g.Config.Hooks.Poststart.
func
(
g
*
Generator
)
AddPostStartHook
(
postStartHook
rspec
.
Hook
)
{
g
.
initConfigHooks
()
g
.
Config
.
Hooks
.
Poststart
=
append
(
g
.
Config
.
Hooks
.
Poststart
,
postStartHook
)
}
// AddMount adds a mount into g.Config.Mounts.
func
(
g
*
Generator
)
AddMount
(
mnt
rspec
.
Mount
)
{
g
.
initConfig
()
g
.
Config
.
Mounts
=
append
(
g
.
Config
.
Mounts
,
mnt
)
}
// RemoveMount removes a mount point on the dest directory
func
(
g
*
Generator
)
RemoveMount
(
dest
string
)
{
g
.
initConfig
()
for
index
,
mount
:=
range
g
.
Config
.
Mounts
{
if
mount
.
Destination
==
dest
{
g
.
Config
.
Mounts
=
append
(
g
.
Config
.
Mounts
[
:
index
],
g
.
Config
.
Mounts
[
index
+
1
:
]
...
)
return
}
}
}
// Mounts returns the list of mounts
func
(
g
*
Generator
)
Mounts
()
[]
rspec
.
Mount
{
g
.
initConfig
()
return
g
.
Config
.
Mounts
}
// ClearMounts clear g.Config.Mounts
func
(
g
*
Generator
)
ClearMounts
()
{
if
g
.
Config
==
nil
{
return
}
g
.
Config
.
Mounts
=
[]
rspec
.
Mount
{}
}
// SetupPrivileged sets up the privilege-related fields inside g.Config.
func
(
g
*
Generator
)
SetupPrivileged
(
privileged
bool
)
{
if
privileged
{
// Add all capabilities in privileged mode.
var
finalCapList
[]
string
for
_
,
cap
:=
range
capability
.
List
()
{
if
g
.
HostSpecific
&&
cap
>
capsCheck
.
LastCap
()
{
continue
}
finalCapList
=
append
(
finalCapList
,
fmt
.
Sprintf
(
"CAP_%s"
,
strings
.
ToUpper
(
cap
.
String
())))
}
g
.
initConfigLinux
()
g
.
initConfigProcessCapabilities
()
g
.
ClearProcessCapabilities
()
g
.
Config
.
Process
.
Capabilities
.
Bounding
=
append
(
g
.
Config
.
Process
.
Capabilities
.
Bounding
,
finalCapList
...
)
g
.
Config
.
Process
.
Capabilities
.
Effective
=
append
(
g
.
Config
.
Process
.
Capabilities
.
Effective
,
finalCapList
...
)
g
.
Config
.
Process
.
Capabilities
.
Inheritable
=
append
(
g
.
Config
.
Process
.
Capabilities
.
Inheritable
,
finalCapList
...
)
g
.
Config
.
Process
.
Capabilities
.
Permitted
=
append
(
g
.
Config
.
Process
.
Capabilities
.
Permitted
,
finalCapList
...
)
g
.
Config
.
Process
.
Capabilities
.
Ambient
=
append
(
g
.
Config
.
Process
.
Capabilities
.
Ambient
,
finalCapList
...
)
g
.
Config
.
Process
.
SelinuxLabel
=
""
g
.
Config
.
Process
.
ApparmorProfile
=
""
g
.
Config
.
Linux
.
Seccomp
=
nil
}
}
// ClearProcessCapabilities clear g.Config.Process.Capabilities.
func
(
g
*
Generator
)
ClearProcessCapabilities
()
{
if
g
.
Config
==
nil
||
g
.
Config
.
Process
==
nil
||
g
.
Config
.
Process
.
Capabilities
==
nil
{
return
}
g
.
Config
.
Process
.
Capabilities
.
Bounding
=
[]
string
{}
g
.
Config
.
Process
.
Capabilities
.
Effective
=
[]
string
{}
g
.
Config
.
Process
.
Capabilities
.
Inheritable
=
[]
string
{}
g
.
Config
.
Process
.
Capabilities
.
Permitted
=
[]
string
{}
g
.
Config
.
Process
.
Capabilities
.
Ambient
=
[]
string
{}
}
// AddProcessCapability adds a process capability into all 5 capability sets.
func
(
g
*
Generator
)
AddProcessCapability
(
c
string
)
error
{
cp
:=
strings
.
ToUpper
(
c
)
if
err
:=
capsCheck
.
CapValid
(
cp
,
g
.
HostSpecific
);
err
!=
nil
{
return
err
}
g
.
initConfigProcessCapabilities
()
var
foundAmbient
,
foundBounding
,
foundEffective
,
foundInheritable
,
foundPermitted
bool
for
_
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Ambient
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
foundAmbient
=
true
break
}
}
if
!
foundAmbient
{
g
.
Config
.
Process
.
Capabilities
.
Ambient
=
append
(
g
.
Config
.
Process
.
Capabilities
.
Ambient
,
cp
)
}
for
_
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Bounding
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
foundBounding
=
true
break
}
}
if
!
foundBounding
{
g
.
Config
.
Process
.
Capabilities
.
Bounding
=
append
(
g
.
Config
.
Process
.
Capabilities
.
Bounding
,
cp
)
}
for
_
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Effective
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
foundEffective
=
true
break
}
}
if
!
foundEffective
{
g
.
Config
.
Process
.
Capabilities
.
Effective
=
append
(
g
.
Config
.
Process
.
Capabilities
.
Effective
,
cp
)
}
for
_
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Inheritable
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
foundInheritable
=
true
break
}
}
if
!
foundInheritable
{
g
.
Config
.
Process
.
Capabilities
.
Inheritable
=
append
(
g
.
Config
.
Process
.
Capabilities
.
Inheritable
,
cp
)
}
for
_
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Permitted
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
foundPermitted
=
true
break
}
}
if
!
foundPermitted
{
g
.
Config
.
Process
.
Capabilities
.
Permitted
=
append
(
g
.
Config
.
Process
.
Capabilities
.
Permitted
,
cp
)
}
return
nil
}
// AddProcessCapabilityAmbient adds a process capability into g.Config.Process.Capabilities.Ambient.
func
(
g
*
Generator
)
AddProcessCapabilityAmbient
(
c
string
)
error
{
cp
:=
strings
.
ToUpper
(
c
)
if
err
:=
capsCheck
.
CapValid
(
cp
,
g
.
HostSpecific
);
err
!=
nil
{
return
err
}
g
.
initConfigProcessCapabilities
()
var
foundAmbient
bool
for
_
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Ambient
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
foundAmbient
=
true
break
}
}
if
!
foundAmbient
{
g
.
Config
.
Process
.
Capabilities
.
Ambient
=
append
(
g
.
Config
.
Process
.
Capabilities
.
Ambient
,
cp
)
}
return
nil
}
// AddProcessCapabilityBounding adds a process capability into g.Config.Process.Capabilities.Bounding.
func
(
g
*
Generator
)
AddProcessCapabilityBounding
(
c
string
)
error
{
cp
:=
strings
.
ToUpper
(
c
)
if
err
:=
capsCheck
.
CapValid
(
cp
,
g
.
HostSpecific
);
err
!=
nil
{
return
err
}
g
.
initConfigProcessCapabilities
()
var
foundBounding
bool
for
_
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Bounding
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
foundBounding
=
true
break
}
}
if
!
foundBounding
{
g
.
Config
.
Process
.
Capabilities
.
Bounding
=
append
(
g
.
Config
.
Process
.
Capabilities
.
Bounding
,
cp
)
}
return
nil
}
// AddProcessCapabilityEffective adds a process capability into g.Config.Process.Capabilities.Effective.
func
(
g
*
Generator
)
AddProcessCapabilityEffective
(
c
string
)
error
{
cp
:=
strings
.
ToUpper
(
c
)
if
err
:=
capsCheck
.
CapValid
(
cp
,
g
.
HostSpecific
);
err
!=
nil
{
return
err
}
g
.
initConfigProcessCapabilities
()
var
foundEffective
bool
for
_
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Effective
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
foundEffective
=
true
break
}
}
if
!
foundEffective
{
g
.
Config
.
Process
.
Capabilities
.
Effective
=
append
(
g
.
Config
.
Process
.
Capabilities
.
Effective
,
cp
)
}
return
nil
}
// AddProcessCapabilityInheritable adds a process capability into g.Config.Process.Capabilities.Inheritable.
func
(
g
*
Generator
)
AddProcessCapabilityInheritable
(
c
string
)
error
{
cp
:=
strings
.
ToUpper
(
c
)
if
err
:=
capsCheck
.
CapValid
(
cp
,
g
.
HostSpecific
);
err
!=
nil
{
return
err
}
g
.
initConfigProcessCapabilities
()
var
foundInheritable
bool
for
_
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Inheritable
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
foundInheritable
=
true
break
}
}
if
!
foundInheritable
{
g
.
Config
.
Process
.
Capabilities
.
Inheritable
=
append
(
g
.
Config
.
Process
.
Capabilities
.
Inheritable
,
cp
)
}
return
nil
}
// AddProcessCapabilityPermitted adds a process capability into g.Config.Process.Capabilities.Permitted.
func
(
g
*
Generator
)
AddProcessCapabilityPermitted
(
c
string
)
error
{
cp
:=
strings
.
ToUpper
(
c
)
if
err
:=
capsCheck
.
CapValid
(
cp
,
g
.
HostSpecific
);
err
!=
nil
{
return
err
}
g
.
initConfigProcessCapabilities
()
var
foundPermitted
bool
for
_
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Permitted
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
foundPermitted
=
true
break
}
}
if
!
foundPermitted
{
g
.
Config
.
Process
.
Capabilities
.
Permitted
=
append
(
g
.
Config
.
Process
.
Capabilities
.
Permitted
,
cp
)
}
return
nil
}
// DropProcessCapability drops a process capability from all 5 capability sets.
func
(
g
*
Generator
)
DropProcessCapability
(
c
string
)
error
{
if
g
.
Config
==
nil
||
g
.
Config
.
Process
==
nil
||
g
.
Config
.
Process
.
Capabilities
==
nil
{
return
nil
}
cp
:=
strings
.
ToUpper
(
c
)
for
i
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Ambient
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
g
.
Config
.
Process
.
Capabilities
.
Ambient
=
removeFunc
(
g
.
Config
.
Process
.
Capabilities
.
Ambient
,
i
)
}
}
for
i
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Bounding
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
g
.
Config
.
Process
.
Capabilities
.
Bounding
=
removeFunc
(
g
.
Config
.
Process
.
Capabilities
.
Bounding
,
i
)
}
}
for
i
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Effective
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
g
.
Config
.
Process
.
Capabilities
.
Effective
=
removeFunc
(
g
.
Config
.
Process
.
Capabilities
.
Effective
,
i
)
}
}
for
i
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Inheritable
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
g
.
Config
.
Process
.
Capabilities
.
Inheritable
=
removeFunc
(
g
.
Config
.
Process
.
Capabilities
.
Inheritable
,
i
)
}
}
for
i
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Permitted
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
g
.
Config
.
Process
.
Capabilities
.
Permitted
=
removeFunc
(
g
.
Config
.
Process
.
Capabilities
.
Permitted
,
i
)
}
}
return
capsCheck
.
CapValid
(
cp
,
false
)
}
// DropProcessCapabilityAmbient drops a process capability from g.Config.Process.Capabilities.Ambient.
func
(
g
*
Generator
)
DropProcessCapabilityAmbient
(
c
string
)
error
{
if
g
.
Config
==
nil
||
g
.
Config
.
Process
==
nil
||
g
.
Config
.
Process
.
Capabilities
==
nil
{
return
nil
}
cp
:=
strings
.
ToUpper
(
c
)
for
i
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Ambient
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
g
.
Config
.
Process
.
Capabilities
.
Ambient
=
removeFunc
(
g
.
Config
.
Process
.
Capabilities
.
Ambient
,
i
)
}
}
return
capsCheck
.
CapValid
(
cp
,
false
)
}
// DropProcessCapabilityBounding drops a process capability from g.Config.Process.Capabilities.Bounding.
func
(
g
*
Generator
)
DropProcessCapabilityBounding
(
c
string
)
error
{
if
g
.
Config
==
nil
||
g
.
Config
.
Process
==
nil
||
g
.
Config
.
Process
.
Capabilities
==
nil
{
return
nil
}
cp
:=
strings
.
ToUpper
(
c
)
for
i
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Bounding
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
g
.
Config
.
Process
.
Capabilities
.
Bounding
=
removeFunc
(
g
.
Config
.
Process
.
Capabilities
.
Bounding
,
i
)
}
}
return
capsCheck
.
CapValid
(
cp
,
false
)
}
// DropProcessCapabilityEffective drops a process capability from g.Config.Process.Capabilities.Effective.
func
(
g
*
Generator
)
DropProcessCapabilityEffective
(
c
string
)
error
{
if
g
.
Config
==
nil
||
g
.
Config
.
Process
==
nil
||
g
.
Config
.
Process
.
Capabilities
==
nil
{
return
nil
}
cp
:=
strings
.
ToUpper
(
c
)
for
i
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Effective
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
g
.
Config
.
Process
.
Capabilities
.
Effective
=
removeFunc
(
g
.
Config
.
Process
.
Capabilities
.
Effective
,
i
)
}
}
return
capsCheck
.
CapValid
(
cp
,
false
)
}
// DropProcessCapabilityInheritable drops a process capability from g.Config.Process.Capabilities.Inheritable.
func
(
g
*
Generator
)
DropProcessCapabilityInheritable
(
c
string
)
error
{
if
g
.
Config
==
nil
||
g
.
Config
.
Process
==
nil
||
g
.
Config
.
Process
.
Capabilities
==
nil
{
return
nil
}
cp
:=
strings
.
ToUpper
(
c
)
for
i
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Inheritable
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
g
.
Config
.
Process
.
Capabilities
.
Inheritable
=
removeFunc
(
g
.
Config
.
Process
.
Capabilities
.
Inheritable
,
i
)
}
}
return
capsCheck
.
CapValid
(
cp
,
false
)
}
// DropProcessCapabilityPermitted drops a process capability from g.Config.Process.Capabilities.Permitted.
func
(
g
*
Generator
)
DropProcessCapabilityPermitted
(
c
string
)
error
{
if
g
.
Config
==
nil
||
g
.
Config
.
Process
==
nil
||
g
.
Config
.
Process
.
Capabilities
==
nil
{
return
nil
}
cp
:=
strings
.
ToUpper
(
c
)
for
i
,
cap
:=
range
g
.
Config
.
Process
.
Capabilities
.
Permitted
{
if
strings
.
ToUpper
(
cap
)
==
cp
{
g
.
Config
.
Process
.
Capabilities
.
Permitted
=
removeFunc
(
g
.
Config
.
Process
.
Capabilities
.
Permitted
,
i
)
}
}
return
capsCheck
.
CapValid
(
cp
,
false
)
}
func
mapStrToNamespace
(
ns
string
,
path
string
)
(
rspec
.
LinuxNamespace
,
error
)
{
switch
ns
{
case
"network"
:
return
rspec
.
LinuxNamespace
{
Type
:
rspec
.
NetworkNamespace
,
Path
:
path
},
nil
case
"pid"
:
return
rspec
.
LinuxNamespace
{
Type
:
rspec
.
PIDNamespace
,
Path
:
path
},
nil
case
"mount"
:
return
rspec
.
LinuxNamespace
{
Type
:
rspec
.
MountNamespace
,
Path
:
path
},
nil
case
"ipc"
:
return
rspec
.
LinuxNamespace
{
Type
:
rspec
.
IPCNamespace
,
Path
:
path
},
nil
case
"uts"
:
return
rspec
.
LinuxNamespace
{
Type
:
rspec
.
UTSNamespace
,
Path
:
path
},
nil
case
"user"
:
return
rspec
.
LinuxNamespace
{
Type
:
rspec
.
UserNamespace
,
Path
:
path
},
nil
case
"cgroup"
:
return
rspec
.
LinuxNamespace
{
Type
:
rspec
.
CgroupNamespace
,
Path
:
path
},
nil
default
:
return
rspec
.
LinuxNamespace
{},
fmt
.
Errorf
(
"unrecognized namespace %q"
,
ns
)
}
}
// ClearLinuxNamespaces clear g.Config.Linux.Namespaces.
func
(
g
*
Generator
)
ClearLinuxNamespaces
()
{
if
g
.
Config
==
nil
||
g
.
Config
.
Linux
==
nil
{
return
}
g
.
Config
.
Linux
.
Namespaces
=
[]
rspec
.
LinuxNamespace
{}
}
// AddOrReplaceLinuxNamespace adds or replaces a namespace inside
// g.Config.Linux.Namespaces.
func
(
g
*
Generator
)
AddOrReplaceLinuxNamespace
(
ns
string
,
path
string
)
error
{
namespace
,
err
:=
mapStrToNamespace
(
ns
,
path
)
if
err
!=
nil
{
return
err
}
g
.
initConfigLinux
()
for
i
,
ns
:=
range
g
.
Config
.
Linux
.
Namespaces
{
if
ns
.
Type
==
namespace
.
Type
{
g
.
Config
.
Linux
.
Namespaces
[
i
]
=
namespace
return
nil
}
}
g
.
Config
.
Linux
.
Namespaces
=
append
(
g
.
Config
.
Linux
.
Namespaces
,
namespace
)
return
nil
}
// RemoveLinuxNamespace removes a namespace from g.Config.Linux.Namespaces.
func
(
g
*
Generator
)
RemoveLinuxNamespace
(
ns
string
)
error
{
namespace
,
err
:=
mapStrToNamespace
(
ns
,
""
)
if
err
!=
nil
{
return
err
}
if
g
.
Config
==
nil
||
g
.
Config
.
Linux
==
nil
{
return
nil
}
for
i
,
ns
:=
range
g
.
Config
.
Linux
.
Namespaces
{
if
ns
.
Type
==
namespace
.
Type
{
g
.
Config
.
Linux
.
Namespaces
=
append
(
g
.
Config
.
Linux
.
Namespaces
[
:
i
],
g
.
Config
.
Linux
.
Namespaces
[
i
+
1
:
]
...
)
return
nil
}
}
return
nil
}
// AddDevice - add a device into g.Config.Linux.Devices
func
(
g
*
Generator
)
AddDevice
(
device
rspec
.
LinuxDevice
)
{
g
.
initConfigLinux
()
for
i
,
dev
:=
range
g
.
Config
.
Linux
.
Devices
{
if
dev
.
Path
==
device
.
Path
{
g
.
Config
.
Linux
.
Devices
[
i
]
=
device
return
}
}
g
.
Config
.
Linux
.
Devices
=
append
(
g
.
Config
.
Linux
.
Devices
,
device
)
}
// RemoveDevice remove a device from g.Config.Linux.Devices
func
(
g
*
Generator
)
RemoveDevice
(
path
string
)
{
if
g
.
Config
==
nil
||
g
.
Config
.
Linux
==
nil
||
g
.
Config
.
Linux
.
Devices
==
nil
{
return
}
for
i
,
device
:=
range
g
.
Config
.
Linux
.
Devices
{
if
device
.
Path
==
path
{
g
.
Config
.
Linux
.
Devices
=
append
(
g
.
Config
.
Linux
.
Devices
[
:
i
],
g
.
Config
.
Linux
.
Devices
[
i
+
1
:
]
...
)
return
}
}
}
// ClearLinuxDevices clears g.Config.Linux.Devices
func
(
g
*
Generator
)
ClearLinuxDevices
()
{
if
g
.
Config
==
nil
||
g
.
Config
.
Linux
==
nil
||
g
.
Config
.
Linux
.
Devices
==
nil
{
return
}
g
.
Config
.
Linux
.
Devices
=
[]
rspec
.
LinuxDevice
{}
}
// AddLinuxResourcesDevice - add a device into g.Config.Linux.Resources.Devices
func
(
g
*
Generator
)
AddLinuxResourcesDevice
(
allow
bool
,
devType
string
,
major
,
minor
*
int64
,
access
string
)
{
g
.
initConfigLinuxResources
()
device
:=
rspec
.
LinuxDeviceCgroup
{
Allow
:
allow
,
Type
:
devType
,
Access
:
access
,
Major
:
major
,
Minor
:
minor
,
}
g
.
Config
.
Linux
.
Resources
.
Devices
=
append
(
g
.
Config
.
Linux
.
Resources
.
Devices
,
device
)
}
// RemoveLinuxResourcesDevice - remove a device from g.Config.Linux.Resources.Devices
func
(
g
*
Generator
)
RemoveLinuxResourcesDevice
(
allow
bool
,
devType
string
,
major
,
minor
*
int64
,
access
string
)
{
if
g
.
Config
==
nil
||
g
.
Config
.
Linux
==
nil
||
g
.
Config
.
Linux
.
Resources
==
nil
{
return
}
for
i
,
device
:=
range
g
.
Config
.
Linux
.
Resources
.
Devices
{
if
device
.
Allow
==
allow
&&
(
devType
==
device
.
Type
||
(
devType
!=
""
&&
device
.
Type
!=
""
&&
devType
==
device
.
Type
))
&&
(
access
==
device
.
Access
||
(
access
!=
""
&&
device
.
Access
!=
""
&&
access
==
device
.
Access
))
&&
(
major
==
device
.
Major
||
(
major
!=
nil
&&
device
.
Major
!=
nil
&&
*
major
==
*
device
.
Major
))
&&
(
minor
==
device
.
Minor
||
(
minor
!=
nil
&&
device
.
Minor
!=
nil
&&
*
minor
==
*
device
.
Minor
))
{
g
.
Config
.
Linux
.
Resources
.
Devices
=
append
(
g
.
Config
.
Linux
.
Resources
.
Devices
[
:
i
],
g
.
Config
.
Linux
.
Resources
.
Devices
[
i
+
1
:
]
...
)
return
}
}
}
// SetSyscallAction adds rules for syscalls with the specified action
func
(
g
*
Generator
)
SetSyscallAction
(
arguments
seccomp
.
SyscallOpts
)
error
{
g
.
initConfigLinuxSeccomp
()
return
seccomp
.
ParseSyscallFlag
(
arguments
,
g
.
Config
.
Linux
.
Seccomp
)
}
// SetDefaultSeccompAction sets the default action for all syscalls not defined
// and then removes any syscall rules with this action already specified.
func
(
g
*
Generator
)
SetDefaultSeccompAction
(
action
string
)
error
{
g
.
initConfigLinuxSeccomp
()
return
seccomp
.
ParseDefaultAction
(
action
,
g
.
Config
.
Linux
.
Seccomp
)
}
// SetDefaultSeccompActionForce only sets the default action for all syscalls not defined
func
(
g
*
Generator
)
SetDefaultSeccompActionForce
(
action
string
)
error
{
g
.
initConfigLinuxSeccomp
()
return
seccomp
.
ParseDefaultActionForce
(
action
,
g
.
Config
.
Linux
.
Seccomp
)
}
// SetDomainName sets g.Config.Domainname
func
(
g
*
Generator
)
SetDomainName
(
domain
string
)
{
g
.
initConfig
()
g
.
Config
.
Domainname
=
domain
}
// SetSeccompArchitecture sets the supported seccomp architectures
func
(
g
*
Generator
)
SetSeccompArchitecture
(
architecture
string
)
error
{
g
.
initConfigLinuxSeccomp
()
return
seccomp
.
ParseArchitectureFlag
(
architecture
,
g
.
Config
.
Linux
.
Seccomp
)
}
// RemoveSeccompRule removes rules for any specified syscalls
func
(
g
*
Generator
)
RemoveSeccompRule
(
arguments
string
)
error
{
g
.
initConfigLinuxSeccomp
()
return
seccomp
.
RemoveAction
(
arguments
,
g
.
Config
.
Linux
.
Seccomp
)
}
// RemoveAllSeccompRules removes all syscall rules
func
(
g
*
Generator
)
RemoveAllSeccompRules
()
error
{
g
.
initConfigLinuxSeccomp
()
return
seccomp
.
RemoveAllSeccompRules
(
g
.
Config
.
Linux
.
Seccomp
)
}
// AddLinuxMaskedPaths adds masked paths into g.Config.Linux.MaskedPaths.
func
(
g
*
Generator
)
AddLinuxMaskedPaths
(
path
string
)
{
g
.
initConfigLinux
()
g
.
Config
.
Linux
.
MaskedPaths
=
append
(
g
.
Config
.
Linux
.
MaskedPaths
,
path
)
}
// AddLinuxReadonlyPaths adds readonly paths into g.Config.Linux.MaskedPaths.
func
(
g
*
Generator
)
AddLinuxReadonlyPaths
(
path
string
)
{
g
.
initConfigLinux
()
g
.
Config
.
Linux
.
ReadonlyPaths
=
append
(
g
.
Config
.
Linux
.
ReadonlyPaths
,
path
)
}
func
addOrReplaceBlockIOThrottleDevice
(
tmpList
[]
rspec
.
LinuxThrottleDevice
,
major
int64
,
minor
int64
,
rate
uint64
)
[]
rspec
.
LinuxThrottleDevice
{
throttleDevices
:=
tmpList
for
i
,
throttleDevice
:=
range
throttleDevices
{
if
throttleDevice
.
Major
==
major
&&
throttleDevice
.
Minor
==
minor
{
throttleDevices
[
i
]
.
Rate
=
rate
return
throttleDevices
}
}
throttleDevice
:=
new
(
rspec
.
LinuxThrottleDevice
)
throttleDevice
.
Major
=
major
throttleDevice
.
Minor
=
minor
throttleDevice
.
Rate
=
rate
throttleDevices
=
append
(
throttleDevices
,
*
throttleDevice
)
return
throttleDevices
}
func
dropBlockIOThrottleDevice
(
tmpList
[]
rspec
.
LinuxThrottleDevice
,
major
int64
,
minor
int64
)
[]
rspec
.
LinuxThrottleDevice
{
throttleDevices
:=
tmpList
for
i
,
throttleDevice
:=
range
throttleDevices
{
if
throttleDevice
.
Major
==
major
&&
throttleDevice
.
Minor
==
minor
{
throttleDevices
=
append
(
throttleDevices
[
:
i
],
throttleDevices
[
i
+
1
:
]
...
)
return
throttleDevices
}
}
return
throttleDevices
}
// AddSolarisAnet adds network into g.Config.Solaris.Anet
func
(
g
*
Generator
)
AddSolarisAnet
(
anet
rspec
.
SolarisAnet
)
{
g
.
initConfigSolaris
()
g
.
Config
.
Solaris
.
Anet
=
append
(
g
.
Config
.
Solaris
.
Anet
,
anet
)
}
// SetSolarisCappedCPUNcpus sets g.Config.Solaris.CappedCPU.Ncpus
func
(
g
*
Generator
)
SetSolarisCappedCPUNcpus
(
ncpus
string
)
{
g
.
initConfigSolarisCappedCPU
()
g
.
Config
.
Solaris
.
CappedCPU
.
Ncpus
=
ncpus
}
// SetSolarisCappedMemoryPhysical sets g.Config.Solaris.CappedMemory.Physical
func
(
g
*
Generator
)
SetSolarisCappedMemoryPhysical
(
physical
string
)
{
g
.
initConfigSolarisCappedMemory
()
g
.
Config
.
Solaris
.
CappedMemory
.
Physical
=
physical
}
// SetSolarisCappedMemorySwap sets g.Config.Solaris.CappedMemory.Swap
func
(
g
*
Generator
)
SetSolarisCappedMemorySwap
(
swap
string
)
{
g
.
initConfigSolarisCappedMemory
()
g
.
Config
.
Solaris
.
CappedMemory
.
Swap
=
swap
}
// SetSolarisLimitPriv sets g.Config.Solaris.LimitPriv
func
(
g
*
Generator
)
SetSolarisLimitPriv
(
limitPriv
string
)
{
g
.
initConfigSolaris
()
g
.
Config
.
Solaris
.
LimitPriv
=
limitPriv
}
// SetSolarisMaxShmMemory sets g.Config.Solaris.MaxShmMemory
func
(
g
*
Generator
)
SetSolarisMaxShmMemory
(
memory
string
)
{
g
.
initConfigSolaris
()
g
.
Config
.
Solaris
.
MaxShmMemory
=
memory
}
// SetSolarisMilestone sets g.Config.Solaris.Milestone
func
(
g
*
Generator
)
SetSolarisMilestone
(
milestone
string
)
{
g
.
initConfigSolaris
()
g
.
Config
.
Solaris
.
Milestone
=
milestone
}
// SetVMHypervisorPath sets g.Config.VM.Hypervisor.Path
func
(
g
*
Generator
)
SetVMHypervisorPath
(
path
string
)
error
{
if
!
strings
.
HasPrefix
(
path
,
"/"
)
{
return
fmt
.
Errorf
(
"hypervisorPath %v is not an absolute path"
,
path
)
}
g
.
initConfigVM
()
g
.
Config
.
VM
.
Hypervisor
.
Path
=
path
return
nil
}
// SetVMHypervisorParameters sets g.Config.VM.Hypervisor.Parameters
func
(
g
*
Generator
)
SetVMHypervisorParameters
(
parameters
[]
string
)
{
g
.
initConfigVM
()
g
.
Config
.
VM
.
Hypervisor
.
Parameters
=
parameters
}
// SetVMKernelPath sets g.Config.VM.Kernel.Path
func
(
g
*
Generator
)
SetVMKernelPath
(
path
string
)
error
{
if
!
strings
.
HasPrefix
(
path
,
"/"
)
{
return
fmt
.
Errorf
(
"kernelPath %v is not an absolute path"
,
path
)
}
g
.
initConfigVM
()
g
.
Config
.
VM
.
Kernel
.
Path
=
path
return
nil
}
// SetVMKernelParameters sets g.Config.VM.Kernel.Parameters
func
(
g
*
Generator
)
SetVMKernelParameters
(
parameters
[]
string
)
{
g
.
initConfigVM
()
g
.
Config
.
VM
.
Kernel
.
Parameters
=
parameters
}
// SetVMKernelInitRD sets g.Config.VM.Kernel.InitRD
func
(
g
*
Generator
)
SetVMKernelInitRD
(
initrd
string
)
error
{
if
!
strings
.
HasPrefix
(
initrd
,
"/"
)
{
return
fmt
.
Errorf
(
"kernelInitrd %v is not an absolute path"
,
initrd
)
}
g
.
initConfigVM
()
g
.
Config
.
VM
.
Kernel
.
InitRD
=
initrd
return
nil
}
// SetVMImagePath sets g.Config.VM.Image.Path
func
(
g
*
Generator
)
SetVMImagePath
(
path
string
)
error
{
if
!
strings
.
HasPrefix
(
path
,
"/"
)
{
return
fmt
.
Errorf
(
"imagePath %v is not an absolute path"
,
path
)
}
g
.
initConfigVM
()
g
.
Config
.
VM
.
Image
.
Path
=
path
return
nil
}
// SetVMImageFormat sets g.Config.VM.Image.Format
func
(
g
*
Generator
)
SetVMImageFormat
(
format
string
)
error
{
switch
format
{
case
"raw"
:
case
"qcow2"
:
case
"vdi"
:
case
"vmdk"
:
case
"vhd"
:
default
:
return
fmt
.
Errorf
(
"Commonly supported formats are: raw, qcow2, vdi, vmdk, vhd"
)
}
g
.
initConfigVM
()
g
.
Config
.
VM
.
Image
.
Format
=
format
return
nil
}
// SetWindowsHypervUntilityVMPath sets g.Config.Windows.HyperV.UtilityVMPath.
func
(
g
*
Generator
)
SetWindowsHypervUntilityVMPath
(
path
string
)
{
g
.
initConfigWindowsHyperV
()
g
.
Config
.
Windows
.
HyperV
.
UtilityVMPath
=
path
}
// SetWindowsIgnoreFlushesDuringBoot sets g.Config.Windows.IgnoreFlushesDuringBoot.
func
(
g
*
Generator
)
SetWindowsIgnoreFlushesDuringBoot
(
ignore
bool
)
{
g
.
initConfigWindows
()
g
.
Config
.
Windows
.
IgnoreFlushesDuringBoot
=
ignore
}
// AddWindowsLayerFolders adds layer folders into g.Config.Windows.LayerFolders.
func
(
g
*
Generator
)
AddWindowsLayerFolders
(
folder
string
)
{
g
.
initConfigWindows
()
g
.
Config
.
Windows
.
LayerFolders
=
append
(
g
.
Config
.
Windows
.
LayerFolders
,
folder
)
}
// AddWindowsDevices adds or sets g.Config.Windwos.Devices
func
(
g
*
Generator
)
AddWindowsDevices
(
id
,
idType
string
)
error
{
if
idType
!=
"class"
{
return
fmt
.
Errorf
(
"Invalid idType value: %s. Windows only supports a value of class"
,
idType
)
}
device
:=
rspec
.
WindowsDevice
{
ID
:
id
,
IDType
:
idType
,
}
g
.
initConfigWindows
()
for
i
,
device
:=
range
g
.
Config
.
Windows
.
Devices
{
if
device
.
ID
==
id
{
g
.
Config
.
Windows
.
Devices
[
i
]
.
IDType
=
idType
return
nil
}
}
g
.
Config
.
Windows
.
Devices
=
append
(
g
.
Config
.
Windows
.
Devices
,
device
)
return
nil
}
// SetWindowsNetwork sets g.Config.Windows.Network.
func
(
g
*
Generator
)
SetWindowsNetwork
(
network
rspec
.
WindowsNetwork
)
{
g
.
initConfigWindows
()
g
.
Config
.
Windows
.
Network
=
&
network
}
// SetWindowsNetworkAllowUnqualifiedDNSQuery sets g.Config.Windows.Network.AllowUnqualifiedDNSQuery
func
(
g
*
Generator
)
SetWindowsNetworkAllowUnqualifiedDNSQuery
(
setting
bool
)
{
g
.
initConfigWindowsNetwork
()
g
.
Config
.
Windows
.
Network
.
AllowUnqualifiedDNSQuery
=
setting
}
// SetWindowsNetworkNamespace sets g.Config.Windows.Network.NetworkNamespace
func
(
g
*
Generator
)
SetWindowsNetworkNamespace
(
path
string
)
{
g
.
initConfigWindowsNetwork
()
g
.
Config
.
Windows
.
Network
.
NetworkNamespace
=
path
}
// SetWindowsResourcesCPU sets g.Config.Windows.Resources.CPU.
func
(
g
*
Generator
)
SetWindowsResourcesCPU
(
cpu
rspec
.
WindowsCPUResources
)
{
g
.
initConfigWindowsResources
()
g
.
Config
.
Windows
.
Resources
.
CPU
=
&
cpu
}
// SetWindowsResourcesMemoryLimit sets g.Config.Windows.Resources.Memory.Limit.
func
(
g
*
Generator
)
SetWindowsResourcesMemoryLimit
(
limit
uint64
)
{
g
.
initConfigWindowsResourcesMemory
()
g
.
Config
.
Windows
.
Resources
.
Memory
.
Limit
=
&
limit
}
// SetWindowsResourcesStorage sets g.Config.Windows.Resources.Storage.
func
(
g
*
Generator
)
SetWindowsResourcesStorage
(
storage
rspec
.
WindowsStorageResources
)
{
g
.
initConfigWindowsResources
()
g
.
Config
.
Windows
.
Resources
.
Storage
=
&
storage
}
// SetWindowsServicing sets g.Config.Windows.Servicing.
func
(
g
*
Generator
)
SetWindowsServicing
(
servicing
bool
)
{
g
.
initConfigWindows
()
g
.
Config
.
Windows
.
Servicing
=
servicing
}
vendor/github.com/opencontainers/runtime-tools/generate/seccomp/consts.go
0 → 100644
View file @
d7e13eb9
package
seccomp
const
(
seccompOverwrite
=
"overwrite"
seccompAppend
=
"append"
nothing
=
"nothing"
)
Prev
1
…
7
8
9
10
11
12
13
14
15
…
18
Next
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