-
Notifications
You must be signed in to change notification settings - Fork 771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for tmpfs #484
Conversation
5b08fe1
to
db527f1
Compare
Missing tests! Will do a review now however. |
This doesn't work..
|
@@ -315,6 +315,19 @@ func (k *Kubernetes) UpdateKubernetesObjects(name string, service kobject.Servic | |||
|
|||
// Configure the container volumes. | |||
volumesMount, volumes, pvc := k.ConfigVolumes(name, service) | |||
// Configure Tmpfs | |||
if len(service.TmpFs) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this check if service.TmpFs != nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is better than just !=nil
if you test only for !=nil
than it would be false
if service.Tmpfs
is empty array.
@@ -83,6 +83,7 @@ type ServiceConfig struct { | |||
Stdin bool `compose:"stdin_open" bundle:""` | |||
Tty bool `compose:"tty" bundle:""` | |||
MemLimit yaml.MemStringorInt `compose:"mem_limit" bundle:""` | |||
TmpFs []string `compose:"tmpfs" bundle:""` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There may be some issues with this, see https://github.com/docker/libcompose/blob/f12d14623f73a0ca0d7fc37253a99165ae48d39f/config/types.go
It can either be a slice of a string, see: https://docs.docker.com/compose/compose-file/compose-file-v2/#tmpfs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind! I confirmed that both work regardless of string slice or normal string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is ok
[]string
is hidden under yaml.Stringorslice
;-)
#types_yaml.go
type Stringorslice strslice.StrSlice
#strslice.go
type StrSlice []string
@@ -369,7 +369,7 @@ func (c *Compose) LoadFile(files []string) kobject.KomposeObject { | |||
serviceConfig.Stdin = composeServiceConfig.StdinOpen | |||
serviceConfig.Tty = composeServiceConfig.Tty | |||
serviceConfig.MemLimit = composeServiceConfig.MemLimit | |||
|
|||
serviceConfig.TmpFs = composeServiceConfig.Tmpfs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
func (k *Kubernetes) ConfigTmpfs(name string, service kobject.ServiceConfig) ([]api.VolumeMount, []api.Volume) { | ||
volumeMounts := []api.VolumeMount{} | ||
volumes := []api.Volume{} | ||
var count int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for count
for _, volume := range service.TmpFs { | ||
|
||
volumeName = fmt.Sprintf("%s-tmpfs%d", name, count) | ||
count++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for count, you can use the range loop for the index value..
for index, volume := range service.TmpFs {
} | ||
volumeMounts = append(volumeMounts, volmount) | ||
|
||
var volsource *api.VolumeSource |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need, use implicit, much cleaner
|
||
var volsource *api.VolumeSource | ||
//create tmpfs specific empty volumes | ||
volsource = k.ConfigEmptyVolumeSource("tmpfs") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
volSource := ...
// create a new volume object using the volsource and add to list | ||
vol := api.Volume{ | ||
Name: volumeName, | ||
VolumeSource: *volsource, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
volSource for value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no it has to passed like as it is mentioned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@surajnarwade what I mean is that it's suppose to be Go conventions for naming, so volSource instead of volsource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cdrage oh got it
@@ -368,7 +400,7 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) ( | |||
// For PVC we will also create a PVC object and add to list | |||
var volsource *api.VolumeSource | |||
if useEmptyVolumes { | |||
volsource = k.ConfigEmptyVolumeSource() | |||
volsource = k.ConfigEmptyVolumeSource("volume") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, can be implied, using volSource := ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't implied here, because volsource is used in if
and else
and outside of that too
@@ -389,10 +421,19 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) ( | |||
} | |||
|
|||
// ConfigEmptyVolumeSource is helper function to create an EmptyDir api.VolumeSource | |||
func (k *Kubernetes) ConfigEmptyVolumeSource() *api.VolumeSource { | |||
func (k *Kubernetes) ConfigEmptyVolumeSource(key string) *api.VolumeSource { | |||
if key == "tmpfs" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comments
Hiya @surajnarwade So a few things! Great code, but there's a lot of missing comments, explaining what's happening in a few sentences would really help with some parts of the code. The commit description is lacking, please type up what you do, why it's necessary and link the issue (like you already did), you can modify it with |
A good example for a descriptive git message is @containscafeine 's one he used on a recent PR:
|
|
There we go, my mistake!
|
And I can confirm it works with a list:
|
db527f1
to
be6ce08
Compare
Saw the new comments added to the code, thanks! This LGTM. |
@@ -511,3 +512,14 @@ func TestInitPodSpec(t *testing.T) { | |||
t.Fatalf("Pod object not found") | |||
} | |||
} | |||
|
|||
func TestKubernetes_ConfigTmpfs(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last change here ;-)
Can you please rename this? Its in Kubernetes package so it doesn't have to to have Kubernetes in name and _
is not GOlangy :-)
just TestConfigTmpfs
says everything about what it is doing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I will make it GOlangy ;-)
be6ce08
to
99d612e
Compare
@kadel , done with correction. |
Almost there! Just need to resolve the conflicts from me merging in #416 After that, I think it's ready to be merged! Cause as of right now, the code LGTM 👍 |
99d612e
to
eb4f7df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be also last thing from me ;-)
k := Kubernetes{} | ||
resultVolumeMount, resultVolume := k.ConfigTmpfs(name, newServiceConfig()) | ||
|
||
if resultVolumeMount[0].Name != "foo-tmpfs0" && resultVolume[0].EmptyDir.Medium != "Memory" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last thing. Should it be ||
instead of &&
?
What if only one of them is wrong?
fixes kubernetes#436 This commit will add support for tmpfs, configEmptyVolumeSource function is being modified as it have to work in two ways now. (For emptyvols and tmpfs) Added unit test for tmpfs too.
eb4f7df
to
4941334
Compare
@kadel , last thing updated ;-) |
fixes #436