Skip to content

Commit 5d1cc4f

Browse files
authored
[Feature] Allow to change Pod Network and PID settings (#1195)
1 parent cf80e85 commit 5d1cc4f

14 files changed

+502
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- (Improvement) Add Resource kerror Type
3131
- (Bugfix) Do not block reconciliation in case of Resource failure
3232
- (Improvement) Multi-arch support for ID member
33+
- (Feature) Allow to change Pod Network and PID settings
3334

3435
## [1.2.20](https://github.com/arangodb/kube-arangodb/tree/1.2.20) (2022-10-25)
3536
- (Feature) Add action progress

pkg/apis/deployment/v1/server_group_spec.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ type ServerGroupSpec struct {
157157
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
158158
// IndexMethod define group Indexing method
159159
IndexMethod *ServerGroupIndexMethod `json:"indexMethod,omitempty"`
160+
161+
// PodModes define additional modes enabled on the Pod level
162+
PodModes *ServerGroupSpecPodMode `json:"podModes,omitempty"`
160163
}
161164

162165
// ServerGroupProbesSpec contains specification for probes for pods of the server group
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 "github.com/arangodb/kube-arangodb/pkg/util/errors"
24+
25+
// ServerGroupNetworkMode is used to define Network mode of the Pod
26+
type ServerGroupNetworkMode string
27+
28+
const (
29+
// ServerGroupNetworkModePod enable Pod level isolation of the network, default
30+
ServerGroupNetworkModePod ServerGroupNetworkMode = "pod"
31+
32+
// ServerGroupNetworkModeHost enable Host level network access to the Pod
33+
ServerGroupNetworkModeHost ServerGroupNetworkMode = "host"
34+
35+
DefaultServerGroupNetworkMode = ServerGroupNetworkModePod
36+
)
37+
38+
func (n *ServerGroupNetworkMode) Validate() error {
39+
switch v := n.Get(); v {
40+
case ServerGroupNetworkModePod, ServerGroupNetworkModeHost:
41+
return nil
42+
default:
43+
return errors.WithStack(errors.Wrapf(ValidationError, "Unknown NetworkMode %s", v.String()))
44+
}
45+
}
46+
47+
func (n *ServerGroupNetworkMode) Get() ServerGroupNetworkMode {
48+
if n == nil {
49+
return DefaultServerGroupNetworkMode
50+
}
51+
52+
return *n
53+
}
54+
55+
func (n *ServerGroupNetworkMode) String() string {
56+
return string(n.Get())
57+
}
58+
59+
func (n *ServerGroupNetworkMode) New() *ServerGroupNetworkMode {
60+
v := n.Get()
61+
62+
return &v
63+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 "github.com/arangodb/kube-arangodb/pkg/util/errors"
24+
25+
// ServerGroupPIDMode define Pod PID share strategy
26+
type ServerGroupPIDMode string
27+
28+
const (
29+
// ServerGroupPIDModeIsolated enable isolation of the Processes within Pod Container, default
30+
ServerGroupPIDModeIsolated ServerGroupPIDMode = "isolated"
31+
// ServerGroupPIDModePod enable isolation of the Processes on the Pod level. Processes started in this mode will have PID different from 1
32+
ServerGroupPIDModePod ServerGroupPIDMode = "pod"
33+
// ServerGroupPIDModeHost disable isolation of the Processes. Processes started in this mode are shared with the entire host
34+
ServerGroupPIDModeHost ServerGroupPIDMode = "host"
35+
36+
DefaultServerGroupPIDMode = ServerGroupPIDModeIsolated
37+
)
38+
39+
func (n *ServerGroupPIDMode) Validate() error {
40+
switch v := n.Get(); v {
41+
case ServerGroupPIDModeIsolated, ServerGroupPIDModePod, ServerGroupPIDModeHost:
42+
return nil
43+
default:
44+
return errors.WithStack(errors.Wrapf(ValidationError, "Unknown PIDMode %s", v.String()))
45+
}
46+
}
47+
48+
func (n *ServerGroupPIDMode) Get() ServerGroupPIDMode {
49+
if n == nil {
50+
return DefaultServerGroupPIDMode
51+
}
52+
53+
return *n
54+
}
55+
56+
func (n *ServerGroupPIDMode) String() string {
57+
return string(n.Get())
58+
}
59+
60+
func (n *ServerGroupPIDMode) New() *ServerGroupPIDMode {
61+
v := n.Get()
62+
63+
return &v
64+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
}

pkg/apis/deployment/v1/zz_generated.deepcopy.go

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/deployment/v2alpha1/architecture.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,28 @@ func (a ArangoDeploymentArchitecture) IsArchAllowed(arch ArangoDeploymentArchite
5959
return false
6060
}
6161

62+
func (a ArangoDeploymentArchitecture) AsNodeSelectorRequirement() core.NodeSelectorTerm {
63+
var archs []string
64+
65+
if len(a) == 0 {
66+
archs = append(archs, ArangoDeploymentArchitectureDefault.String())
67+
} else {
68+
for _, arch := range a {
69+
archs = append(archs, arch.String())
70+
}
71+
}
72+
73+
return core.NodeSelectorTerm{
74+
MatchExpressions: []core.NodeSelectorRequirement{
75+
{
76+
Key: shared.NodeArchAffinityLabel,
77+
Operator: "In",
78+
Values: archs,
79+
},
80+
},
81+
}
82+
}
83+
6284
type ArangoDeploymentArchitectureType string
6385

6486
const (
@@ -83,6 +105,10 @@ func (a ArangoDeploymentArchitectureType) Validate() error {
83105
}
84106
}
85107

108+
func (a ArangoDeploymentArchitectureType) String() string {
109+
return string(a)
110+
}
111+
86112
func (a *ArangoDeploymentArchitectureType) Default(def ArangoDeploymentArchitectureType) ArangoDeploymentArchitectureType {
87113
if a == nil {
88114
return def
@@ -97,7 +123,7 @@ func (a ArangoDeploymentArchitectureType) AsNodeSelectorRequirement() core.NodeS
97123
{
98124
Key: shared.NodeArchAffinityLabel,
99125
Operator: "In",
100-
Values: []string{string(a)},
126+
Values: []string{a.String()},
101127
},
102128
},
103129
}

pkg/apis/deployment/v2alpha1/server_group_spec.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ type ServerGroupSpec struct {
157157
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
158158
// IndexMethod define group Indexing method
159159
IndexMethod *ServerGroupIndexMethod `json:"indexMethod,omitempty"`
160+
161+
// PodModes define additional modes enabled on the Pod level
162+
PodModes *ServerGroupSpecPodMode `json:"podModes,omitempty"`
160163
}
161164

162165
// ServerGroupProbesSpec contains specification for probes for pods of the server group
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 v2alpha1
22+
23+
import "github.com/arangodb/kube-arangodb/pkg/util/errors"
24+
25+
// ServerGroupNetworkMode is used to define Network mode of the Pod
26+
type ServerGroupNetworkMode string
27+
28+
const (
29+
// ServerGroupNetworkModePod enable Pod level isolation of the network, default
30+
ServerGroupNetworkModePod ServerGroupNetworkMode = "pod"
31+
32+
// ServerGroupNetworkModeHost enable Host level network access to the Pod
33+
ServerGroupNetworkModeHost ServerGroupNetworkMode = "host"
34+
35+
DefaultServerGroupNetworkMode = ServerGroupNetworkModePod
36+
)
37+
38+
func (n *ServerGroupNetworkMode) Validate() error {
39+
switch v := n.Get(); v {
40+
case ServerGroupNetworkModePod, ServerGroupNetworkModeHost:
41+
return nil
42+
default:
43+
return errors.WithStack(errors.Wrapf(ValidationError, "Unknown NetworkMode %s", v.String()))
44+
}
45+
}
46+
47+
func (n *ServerGroupNetworkMode) Get() ServerGroupNetworkMode {
48+
if n == nil {
49+
return DefaultServerGroupNetworkMode
50+
}
51+
52+
return *n
53+
}
54+
55+
func (n *ServerGroupNetworkMode) String() string {
56+
return string(n.Get())
57+
}
58+
59+
func (n *ServerGroupNetworkMode) New() *ServerGroupNetworkMode {
60+
v := n.Get()
61+
62+
return &v
63+
}

0 commit comments

Comments
 (0)