Skip to content

Commit 6db28e8

Browse files
authored
[Feature] Add EmptyDir to Volumes (#648)
1 parent 14a0c9b commit 6db28e8

File tree

4 files changed

+63
-5
lines changed

4 files changed

+63
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Change Log
22

33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
4+
- Allow to mount EmptyDir
45

56
## [1.1.0](https://github.com/arangodb/kube-arangodb/tree/master) (2020-10-14)
67
- Change NumberOfCores and MemoryOverride flags to be set to true by default

pkg/apis/deployment/v1/server_group_volume.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ type ServerGroupSpecVolume struct {
112112

113113
// ConfigMap which should be mounted into pod
114114
ConfigMap *ServerGroupSpecVolumeConfigMap `json:"configMap,omitempty"`
115+
116+
// EmptyDir
117+
EmptyDir *ServerGroupSpecVolumeEmptyDir `json:"emptyDir,omitempty"`
115118
}
116119

117120
// Validate if ServerGroupSpec volume is valid
@@ -124,6 +127,7 @@ func (s *ServerGroupSpecVolume) Validate() error {
124127
shared.PrefixResourceErrors("name", sharedv1.AsKubernetesResourceName(&s.Name).Validate()),
125128
shared.PrefixResourceErrors("secret", s.Secret.Validate()),
126129
shared.PrefixResourceErrors("configMap", s.ConfigMap.Validate()),
130+
shared.PrefixResourceErrors("emptyDir", s.EmptyDir.Validate()),
127131
s.validate(),
128132
)
129133
}
@@ -135,22 +139,43 @@ func (s ServerGroupSpecVolume) Volume() core.Volume {
135139
VolumeSource: core.VolumeSource{
136140
ConfigMap: (*core.ConfigMapVolumeSource)(s.ConfigMap),
137141
Secret: (*core.SecretVolumeSource)(s.Secret),
142+
EmptyDir: (*core.EmptyDirVolumeSource)(s.EmptyDir),
138143
},
139144
}
140145
}
141146

142147
func (s *ServerGroupSpecVolume) validate() error {
143-
if s.ConfigMap == nil && s.Secret == nil {
144-
return errors.Errorf("at least one option need to be defined: secret or configMap")
148+
count := s.notNilFields()
149+
150+
if count == 0 {
151+
return errors.Errorf("at least one option need to be defined: secret, configMap or emptyDir")
145152
}
146153

147-
if s.ConfigMap != nil && s.Secret != nil {
148-
return errors.Errorf("only one option can be defined: secret or configMap")
154+
if count > 1 {
155+
return errors.Errorf("only one option can be defined: secret, configMap or emptyDir")
149156
}
150157

151158
return nil
152159
}
153160

161+
func (s *ServerGroupSpecVolume) notNilFields() int {
162+
i := 0
163+
164+
if s.ConfigMap != nil {
165+
i++
166+
}
167+
168+
if s.Secret != nil {
169+
i++
170+
}
171+
172+
if s.EmptyDir != nil {
173+
i++
174+
}
175+
176+
return i
177+
}
178+
154179
type ServerGroupSpecVolumeSecret core.SecretVolumeSource
155180

156181
func (s *ServerGroupSpecVolumeSecret) Validate() error {
@@ -174,3 +199,9 @@ func (s *ServerGroupSpecVolumeConfigMap) Validate() error {
174199
shared.PrefixResourceError("name", sharedv1.AsKubernetesResourceName(&s.Name).Validate()),
175200
)
176201
}
202+
203+
type ServerGroupSpecVolumeEmptyDir core.EmptyDirVolumeSource
204+
205+
func (s *ServerGroupSpecVolumeEmptyDir) Validate() error {
206+
return nil
207+
}

pkg/apis/deployment/v1/server_group_volume_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func Test_Volume_Validation(t *testing.T) {
8888

8989
fail: true,
9090
failedFields: map[string]string{
91-
"0": "only one option can be defined: secret or configMap",
91+
"0": "only one option can be defined: secret, configMap or emptyDir",
9292
},
9393

9494
volumes: []ServerGroupSpecVolume{

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

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

0 commit comments

Comments
 (0)