diff --git a/CHANGELOG.md b/CHANGELOG.md index f3b7397a2..7ffbebc3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pkg/apis/deployment/v1/server_group_volume.go b/pkg/apis/deployment/v1/server_group_volume.go index 09330da8f..40b309435 100644 --- a/pkg/apis/deployment/v1/server_group_volume.go +++ b/pkg/apis/deployment/v1/server_group_volume.go @@ -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 @@ -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(), ) } @@ -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 { @@ -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 +} diff --git a/pkg/apis/deployment/v1/server_group_volume_test.go b/pkg/apis/deployment/v1/server_group_volume_test.go index cc4466e5b..8d040cfce 100644 --- a/pkg/apis/deployment/v1/server_group_volume_test.go +++ b/pkg/apis/deployment/v1/server_group_volume_test.go @@ -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{ diff --git a/pkg/apis/deployment/v1/zz_generated.deepcopy.go b/pkg/apis/deployment/v1/zz_generated.deepcopy.go index 05ec32228..bb586bba9 100644 --- a/pkg/apis/deployment/v1/zz_generated.deepcopy.go +++ b/pkg/apis/deployment/v1/zz_generated.deepcopy.go @@ -1412,6 +1412,11 @@ func (in *ServerGroupSpecVolume) DeepCopyInto(out *ServerGroupSpecVolume) { *out = new(ServerGroupSpecVolumeConfigMap) (*in).DeepCopyInto(*out) } + if in.EmptyDir != nil { + in, out := &in.EmptyDir, &out.EmptyDir + *out = new(ServerGroupSpecVolumeEmptyDir) + (*in).DeepCopyInto(*out) + } return } @@ -1459,6 +1464,27 @@ func (in *ServerGroupSpecVolumeConfigMap) DeepCopy() *ServerGroupSpecVolumeConfi return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServerGroupSpecVolumeEmptyDir) DeepCopyInto(out *ServerGroupSpecVolumeEmptyDir) { + *out = *in + if in.SizeLimit != nil { + in, out := &in.SizeLimit, &out.SizeLimit + x := (*in).DeepCopy() + *out = &x + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServerGroupSpecVolumeEmptyDir. +func (in *ServerGroupSpecVolumeEmptyDir) DeepCopy() *ServerGroupSpecVolumeEmptyDir { + if in == nil { + return nil + } + out := new(ServerGroupSpecVolumeEmptyDir) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ServerGroupSpecVolumeMount) DeepCopyInto(out *ServerGroupSpecVolumeMount) { *out = *in