Merge pull request #1670 from AhmedGrati/feat-add-read-only-support
Feat: add read only containers support
This commit is contained in:
@@ -110,6 +110,7 @@ type ServiceConfig struct {
|
||||
WorkingDir string `compose:""`
|
||||
DomainName string `compose:"domainname"`
|
||||
HostName string `compose:"hostname"`
|
||||
ReadOnly bool `compose:"read_only"`
|
||||
Args []string `compose:"args"`
|
||||
VolList []string `compose:"volumes"`
|
||||
Network []string `compose:"network"`
|
||||
|
||||
@@ -462,6 +462,7 @@ func dockerComposeToKomposeMapping(composeObject *types.Project) (kobject.Kompos
|
||||
serviceConfig.Expose = composeServiceConfig.Expose
|
||||
serviceConfig.Privileged = composeServiceConfig.Privileged
|
||||
serviceConfig.User = composeServiceConfig.User
|
||||
serviceConfig.ReadOnly = composeServiceConfig.ReadOnly
|
||||
serviceConfig.Stdin = composeServiceConfig.StdinOpen
|
||||
serviceConfig.Tty = composeServiceConfig.Tty
|
||||
serviceConfig.TmpFs = composeServiceConfig.Tmpfs
|
||||
|
||||
@@ -573,6 +573,11 @@ func (k *Kubernetes) UpdateKubernetesObjects(name string, service kobject.Servic
|
||||
securityContext.Capabilities = capabilities
|
||||
}
|
||||
|
||||
//set readOnlyRootFilesystem if it is enabled
|
||||
if service.ReadOnly {
|
||||
securityContext.ReadOnlyRootFilesystem = &service.ReadOnly
|
||||
}
|
||||
|
||||
// update template only if securityContext is not empty
|
||||
if *securityContext != (api.SecurityContext{}) {
|
||||
template.Spec.Containers[0].SecurityContext = securityContext
|
||||
|
||||
@@ -629,3 +629,31 @@ func TestArgsInterpolation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadOnlyRootFS(t *testing.T) {
|
||||
// An example service
|
||||
service := kobject.ServiceConfig{
|
||||
ContainerName: "name",
|
||||
Image: "image",
|
||||
ReadOnly: true,
|
||||
}
|
||||
|
||||
// An example object generated via k8s runtime.Objects()
|
||||
komposeObject := kobject.KomposeObject{
|
||||
ServiceConfigs: map[string]kobject.ServiceConfig{"app": service},
|
||||
}
|
||||
k := Kubernetes{}
|
||||
objects, err := k.Transform(komposeObject, kobject.ConvertOptions{CreateD: true})
|
||||
if err != nil {
|
||||
t.Error(errors.Wrap(err, "k.Transform failed"))
|
||||
}
|
||||
|
||||
for _, obj := range objects {
|
||||
if deployment, ok := obj.(*appsv1.Deployment); ok {
|
||||
readOnlyFS := deployment.Spec.Template.Spec.Containers[0].SecurityContext.ReadOnlyRootFilesystem
|
||||
if *readOnlyFS != true {
|
||||
t.Errorf("Expected ReadOnlyRootFileSystem %v upon conversion, actual %v", true, readOnlyFS)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user