task_opts_unix.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // +build !windows
  2. /*
  3. Copyright The containerd Authors.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. package containerd
  15. import (
  16. "context"
  17. "github.com/containerd/containerd/runtime/linux/runctypes"
  18. "github.com/pkg/errors"
  19. )
  20. // WithNoNewKeyring causes tasks not to be created with a new keyring for secret storage.
  21. // There is an upper limit on the number of keyrings in a linux system
  22. func WithNoNewKeyring(ctx context.Context, c *Client, ti *TaskInfo) error {
  23. if ti.Options == nil {
  24. ti.Options = &runctypes.CreateOptions{}
  25. }
  26. opts, ok := ti.Options.(*runctypes.CreateOptions)
  27. if !ok {
  28. return errors.New("could not cast TaskInfo Options to CreateOptions")
  29. }
  30. opts.NoNewKeyring = true
  31. return nil
  32. }
  33. // WithNoPivotRoot instructs the runtime not to you pivot_root
  34. func WithNoPivotRoot(_ context.Context, _ *Client, info *TaskInfo) error {
  35. if info.Options == nil {
  36. info.Options = &runctypes.CreateOptions{
  37. NoPivotRoot: true,
  38. }
  39. return nil
  40. }
  41. opts, ok := info.Options.(*runctypes.CreateOptions)
  42. if !ok {
  43. return errors.New("invalid options type, expected runctypes.CreateOptions")
  44. }
  45. opts.NoPivotRoot = true
  46. return nil
  47. }