Skip to content
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 group_add key #739

Merged
merged 1 commit into from
Aug 11, 2017
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 pkg/kobject/kobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type ServiceConfig struct {
TmpFs []string `compose:"tmpfs"`
Dockerfile string `compose:"dockerfile"`
Replicas int `compose:"replicas"`
GroupAdd []int64 `compose:"group_add"`
// Volumes is a struct which contains all information about each volume
Volumes []Volumes `compose:""`
}
Expand Down
22 changes: 22 additions & 0 deletions pkg/loader/compose/v1v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ func libComposeToKomposeMapping(composeObject *project.Project) (kobject.Kompose
serviceConfig.MemLimit = composeServiceConfig.MemLimit
serviceConfig.TmpFs = composeServiceConfig.Tmpfs
serviceConfig.StopGracePeriod = composeServiceConfig.StopGracePeriod

// Get GroupAdd, group should be mentioned in gid format but not the group name
groupAdd, err := getGroupAdd(composeServiceConfig.GroupAdd)
if err != nil {
return kobject.KomposeObject{}, errors.Wrap(err, "GroupAdd should be mentioned in gid format, not a group name")
}
serviceConfig.GroupAdd = groupAdd

komposeObject.ServiceConfigs[normalizeServiceNames(name)] = serviceConfig
if normalizeServiceNames(name) != name {
log.Infof("Service name in docker-compose has been changed from %q to %q", name, normalizeServiceNames(name))
Expand Down Expand Up @@ -390,3 +398,17 @@ func getVol(toFind kobject.Volumes, Vols []kobject.Volumes) (bool, kobject.Volum
}
return false, kobject.Volumes{}
}

// getGroupAdd will return group in int64 format
func getGroupAdd(group []string) ([]int64, error) {
var groupAdd []int64
for _, i := range group {
j, err := strconv.Atoi(i)
if err != nil {
return nil, errors.Wrap(err, "unable to get group_add key")
}
groupAdd = append(groupAdd, int64(j))

}
return groupAdd, nil
}
5 changes: 5 additions & 0 deletions pkg/transformer/kubernetes/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,11 @@ func (k *Kubernetes) UpdateKubernetesObjects(name string, service kobject.Servic
}
}

//set supplementalGroups
if service.GroupAdd != nil {
podSecurityContext.SupplementalGroups = service.GroupAdd
}

// Setup security context
securityContext := &api.SecurityContext{}
if service.Privileged {
Expand Down
1 change: 1 addition & 0 deletions pkg/transformer/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func newServiceConfig() kobject.ServiceConfig {
TmpFs: []string{"/tmp"},
Replicas: 2,
Volumes: []kobject.Volumes{{SvcName: "app", MountPath: "/tmp/volume", PVCName: "app-claim0"}},
GroupAdd: []int64{1003, 1005},
}
}

Expand Down
11 changes: 11 additions & 0 deletions script/test/cmd/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/tty-true/
# openshift test
convert::expect_success "kompose --provider openshift -f $KOMPOSE_ROOT/script/test/fixtures/tty-true/docker-compose.yml convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/tty-true/output-oc.json"

# Test related to "group_add" in docker-compose
# kubernetes test
convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/group-add/docker-compose.yml convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/group-add/output-k8s.json"
# openshift test
convert::expect_success "kompose --provider openshift -f $KOMPOSE_ROOT/script/test/fixtures/group-add/docker-compose.yml convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/group-add/output-os.json"

# Test related to Failing "group_add" in docker-compose
# kubernetes test
convert::expect_failure "kompose -f $KOMPOSE_ROOT/script/test/fixtures/group-add/docker-compose-fail.yml convert --stdout -j"
# openshift test
convert::expect_failure "kompose --provider openshift -f $KOMPOSE_ROOT/script/test/fixtures/group-add/docker-compose-fail.yml convert --stdout -j"

# Test related to kompose.expose.service label in docker compose file to ensure that services are exposed properly
#kubernetes tests
Expand Down
8 changes: 4 additions & 4 deletions script/test/fixtures/envvars-separators/output-k8s.json
Original file line number Diff line number Diff line change
Expand Up @@ -1047,17 +1047,17 @@
"name": "hygieia-udeploy",
"image": "hygieia-udeploy-collector:latest",
"env": [
{
"name": "UDEPLOY_PASSWORD",
"value": "-s3cr3t"
},
{
"name": "UDEPLOY_URL",
"value": "-http://udeploy.company.com"
},
{
"name": "UDEPLOY_USERNAME",
"value": "-bobama"
},
{
"name": "UDEPLOY_PASSWORD",
"value": "-s3cr3t"
}
],
"resources": {},
Expand Down
16 changes: 8 additions & 8 deletions script/test/fixtures/etherpad/output-os.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,24 @@
],
"env": [
{
"name": "DB_PASS",
"name": "DB_DBID",
"value": "etherpad"
},
{
"name": "DB_PORT",
"value": "3306"
"name": "DB_HOST",
"value": "mariadb"
},
{
"name": "DB_USER",
"name": "DB_PASS",
"value": "etherpad"
},
{
"name": "DB_DBID",
"value": "etherpad"
"name": "DB_PORT",
"value": "3306"
},
{
"name": "DB_HOST",
"value": "mariadb"
"name": "DB_USER",
"value": "etherpad"
}
],
"resources": {}
Expand Down
6 changes: 6 additions & 0 deletions script/test/fixtures/group-add/docker-compose-fail.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '2'
services:
myservice:
image: alpine
group_add:
- "mail"
6 changes: 6 additions & 0 deletions script/test/fixtures/group-add/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '2'
services:
myservice:
image: alpine
group_add:
- "1234"
73 changes: 73 additions & 0 deletions script/test/fixtures/group-add/output-k8s.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"kind": "List",
"apiVersion": "v1",
"metadata": {},
"items": [
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "myservice",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "myservice"
}
},
"spec": {
"ports": [
{
"name": "headless",
"port": 55555,
"targetPort": 0
}
],
"selector": {
"io.kompose.service": "myservice"
},
"clusterIP": "None"
},
"status": {
"loadBalancer": {}
}
},
{
"kind": "Deployment",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "myservice",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "myservice"
}
},
"spec": {
"replicas": 1,
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "myservice"
}
},
"spec": {
"containers": [
{
"name": "myservice",
"image": "alpine",
"resources": {}
}
],
"restartPolicy": "Always",
"securityContext": {
"supplementalGroups": [
1234
]
}
}
},
"strategy": {}
},
"status": {}
}
]
}
125 changes: 125 additions & 0 deletions script/test/fixtures/group-add/output-os.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"kind": "List",
"apiVersion": "v1",
"metadata": {},
"items": [
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "myservice",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "myservice"
}
},
"spec": {
"ports": [
{
"name": "headless",
"port": 55555,
"targetPort": 0
}
],
"selector": {
"io.kompose.service": "myservice"
},
"clusterIP": "None"
},
"status": {
"loadBalancer": {}
}
},
{
"kind": "DeploymentConfig",
"apiVersion": "v1",
"metadata": {
"name": "myservice",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "myservice"
}
},
"spec": {
"strategy": {
"resources": {}
},
"triggers": [
{
"type": "ConfigChange"
},
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"myservice"
],
"from": {
"kind": "ImageStreamTag",
"name": "myservice:latest"
}
}
}
],
"replicas": 1,
"test": false,
"selector": {
"io.kompose.service": "myservice"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "myservice"
}
},
"spec": {
"containers": [
{
"name": "myservice",
"image": " ",
"resources": {}
}
],
"restartPolicy": "Always",
"securityContext": {
"supplementalGroups": [
1234
]
}
}
}
},
"status": {}
},
{
"kind": "ImageStream",
"apiVersion": "v1",
"metadata": {
"name": "myservice",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "myservice"
}
},
"spec": {
"tags": [
{
"name": "latest",
"annotations": null,
"from": {
"kind": "DockerImage",
"name": "alpine"
},
"generation": null,
"importPolicy": {}
}
]
},
"status": {
"dockerImageRepository": ""
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@
}
]
}

Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@
"spec": {
"volumes": [
{
"name": "bar-claim1",
"name": "foo-claim0",
"persistentVolumeClaim": {
"claimName": "bar-claim1"
"claimName": "foo-claim0"
}
},
{
"name": "foo-claim0",
"name": "bar-claim1",
"persistentVolumeClaim": {
"claimName": "foo-claim0"
"claimName": "bar-claim1"
}
},
{
Expand All @@ -140,14 +140,14 @@
],
"resources": {},
"volumeMounts": [
{
"name": "bar-claim1",
"mountPath": "/bar"
},
{
"name": "foo-claim0",
"mountPath": "/foo1"
},
{
"name": "bar-claim1",
"mountPath": "/bar"
},
{
"name": "foo-claim1",
"mountPath": "/foo2"
Expand Down
Loading