|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +// Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | +// |
| 20 | + |
| 21 | +package v1 |
| 22 | + |
| 23 | +import ( |
| 24 | + core "k8s.io/api/core/v1" |
| 25 | + |
| 26 | + "github.com/arangodb/kube-arangodb/pkg/util" |
| 27 | + "github.com/arangodb/kube-arangodb/pkg/util/errors" |
| 28 | +) |
| 29 | + |
| 30 | +type ServerGroupSpecPodMode struct { |
| 31 | + Network *ServerGroupNetworkMode `json:"network,omitempty"` |
| 32 | + PID *ServerGroupPIDMode `json:"pid,omitempty"` |
| 33 | +} |
| 34 | + |
| 35 | +func (s *ServerGroupSpecPodMode) GetNetwork() *ServerGroupNetworkMode { |
| 36 | + if s == nil { |
| 37 | + return nil |
| 38 | + } |
| 39 | + |
| 40 | + return s.Network |
| 41 | +} |
| 42 | + |
| 43 | +func (s *ServerGroupSpecPodMode) GetPID() *ServerGroupPIDMode { |
| 44 | + if s == nil { |
| 45 | + return nil |
| 46 | + } |
| 47 | + |
| 48 | + return s.PID |
| 49 | +} |
| 50 | + |
| 51 | +func (s *ServerGroupSpecPodMode) Validate() error { |
| 52 | + return errors.Wrapf(errors.Errors(s.GetNetwork().Validate(), s.GetPID().Validate()), "Validation of Pod modes failed") |
| 53 | +} |
| 54 | + |
| 55 | +func (s *ServerGroupSpecPodMode) Apply(p *core.PodSpec) { |
| 56 | + switch s.GetPID().Get() { |
| 57 | + case ServerGroupPIDModeIsolated: |
| 58 | + // Default, no change |
| 59 | + case ServerGroupPIDModePod: |
| 60 | + // Enable Pod shared namespaces |
| 61 | + p.ShareProcessNamespace = util.NewBool(true) |
| 62 | + case ServerGroupPIDModeHost: |
| 63 | + // Enable Host shared namespaces |
| 64 | + p.HostPID = true |
| 65 | + } |
| 66 | + |
| 67 | + switch s.GetNetwork().Get() { |
| 68 | + case ServerGroupNetworkModePod: |
| 69 | + // Default, no change |
| 70 | + case ServerGroupNetworkModeHost: |
| 71 | + // Enable Pod shared namespaces |
| 72 | + p.HostNetwork = true |
| 73 | + } |
| 74 | +} |
0 commit comments