Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Change Log

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

## [1.1.0](https://github.com/arangodb/kube-arangodb/tree/master) (2020-10-14)
- Change NumberOfCores and MemoryOverride flags to be set to true by default
Expand Down
39 changes: 35 additions & 4 deletions pkg/apis/deployment/v1/server_group_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ type ServerGroupSpecVolume struct {

// ConfigMap which should be mounted into pod
ConfigMap *ServerGroupSpecVolumeConfigMap `json:"configMap,omitempty"`

// EmptyDir
EmptyDir *ServerGroupSpecVolumeEmptyDir `json:"emptyDir,omitempty"`
}

// Validate if ServerGroupSpec volume is valid
Expand All @@ -124,6 +127,7 @@ func (s *ServerGroupSpecVolume) Validate() error {
shared.PrefixResourceErrors("name", sharedv1.AsKubernetesResourceName(&s.Name).Validate()),
shared.PrefixResourceErrors("secret", s.Secret.Validate()),
shared.PrefixResourceErrors("configMap", s.ConfigMap.Validate()),
shared.PrefixResourceErrors("emptyDir", s.EmptyDir.Validate()),
s.validate(),
)
}
Expand All @@ -135,22 +139,43 @@ func (s ServerGroupSpecVolume) Volume() core.Volume {
VolumeSource: core.VolumeSource{
ConfigMap: (*core.ConfigMapVolumeSource)(s.ConfigMap),
Secret: (*core.SecretVolumeSource)(s.Secret),
EmptyDir: (*core.EmptyDirVolumeSource)(s.EmptyDir),
},
}
}

func (s *ServerGroupSpecVolume) validate() error {
if s.ConfigMap == nil && s.Secret == nil {
return errors.Errorf("at least one option need to be defined: secret or configMap")
count := s.notNilFields()

if count == 0 {
return errors.Errorf("at least one option need to be defined: secret, configMap or emptyDir")
}

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

return nil
}

func (s *ServerGroupSpecVolume) notNilFields() int {
i := 0

if s.ConfigMap != nil {
i++
}

if s.Secret != nil {
i++
}

if s.EmptyDir != nil {
i++
}

return i
}

type ServerGroupSpecVolumeSecret core.SecretVolumeSource

func (s *ServerGroupSpecVolumeSecret) Validate() error {
Expand All @@ -174,3 +199,9 @@ func (s *ServerGroupSpecVolumeConfigMap) Validate() error {
shared.PrefixResourceError("name", sharedv1.AsKubernetesResourceName(&s.Name).Validate()),
)
}

type ServerGroupSpecVolumeEmptyDir core.EmptyDirVolumeSource

func (s *ServerGroupSpecVolumeEmptyDir) Validate() error {
return nil
}
2 changes: 1 addition & 1 deletion pkg/apis/deployment/v1/server_group_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func Test_Volume_Validation(t *testing.T) {

fail: true,
failedFields: map[string]string{
"0": "only one option can be defined: secret or configMap",
"0": "only one option can be defined: secret, configMap or emptyDir",
},

volumes: []ServerGroupSpecVolume{
Expand Down
26 changes: 26 additions & 0 deletions pkg/apis/deployment/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.