Add support for negated placement constraint (#1419)

This commit is contained in:
ichx
2021-08-27 22:49:55 +08:00
committed by GitHub
parent e3c78d7419
commit e82fe96c38
18 changed files with 529 additions and 40 deletions
+9
View File
@@ -115,3 +115,12 @@ k8s_output="$KOMPOSE_ROOT/script/test/fixtures/volume-mounts/windows/output-k8s.
os_output="$KOMPOSE_ROOT/script/test/fixtures/volume-mounts/windows/output-os.json"
convert::expect_success "$k8s_cmd" "$k8s_output"
convert::expect_success "$os_cmd" "$os_output"
# TEST the placement
# should convert placement to affinity
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/deploy/placement/docker-compose-placement.yaml convert --stdout -j --with-kompose-annotation=false"
os_cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/deploy/placement/docker-compose-placement.yaml convert --stdout -j --with-kompose-annotation=false"
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/deploy/placement/output-placement-k8s.json"
os_output="$KOMPOSE_ROOT/script/test/fixtures/deploy/placement/output-placement-os.json"
convert::expect_success_and_warning "$k8s_cmd" "$k8s_output"
convert::expect_success_and_warning "$os_cmd" "$os_output"
+2 -2
View File
@@ -145,7 +145,7 @@
},
"resources": {},
"postCommit": {},
"nodeSelector": null
"affinity": null
},
"status": {
"lastVersion": 0
@@ -297,7 +297,7 @@
},
"resources": {},
"postCommit": {},
"nodeSelector": null
"affinity": null
},
"status": {
"lastVersion": 0
@@ -0,0 +1,13 @@
version: "3"
services:
redis:
image: redis
ports:
- "6379"
deploy:
placement:
constraints:
- node.hostname == machine
- engine.labels.operatingsystem == ubuntu 14.04
- node.labels.foo != bar
- baz != qux
@@ -0,0 +1,104 @@
{
"kind": "List",
"apiVersion": "v1",
"metadata": {},
"items": [
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "redis",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
}
},
"spec": {
"ports": [
{
"name": "6379",
"port": 6379,
"targetPort": 6379
}
],
"selector": {
"io.kompose.service": "redis"
}
},
"status": {
"loadBalancer": {}
}
},
{
"kind": "Deployment",
"apiVersion": "apps/v1",
"metadata": {
"name": "redis",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
}
},
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"io.kompose.service": "redis"
}
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
}
},
"spec": {
"containers": [
{
"name": "redis",
"image": "redis",
"ports": [
{
"containerPort": 6379
}
],
"resources": {}
}
],
"restartPolicy": "Always",
"affinity": {
"nodeAffinity": {
"requiredDuringSchedulingIgnoredDuringExecution": {
"nodeSelectorTerms": [
{
"matchExpressions": [
{
"key": "kubernetes.io/hostname",
"operator": "In",
"values": ["machine"]
},
{
"key": "beta.kubernetes.io/os",
"operator": "In",
"values": ["ubuntu 14.04"]
},
{
"key": "foo",
"operator": "NotIn",
"values": ["bar"]
}
]
}
]
}
}
}
}
},
"strategy": {}
},
"status": {}
}
]
}
@@ -0,0 +1,164 @@
{
"kind": "List",
"apiVersion": "v1",
"metadata": {},
"items": [
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "redis",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
}
},
"spec": {
"ports": [
{
"name": "6379",
"port": 6379,
"targetPort": 6379
}
],
"selector": {
"io.kompose.service": "redis"
}
},
"status": {
"loadBalancer": {}
}
},
{
"kind": "DeploymentConfig",
"apiVersion": "v1",
"metadata": {
"name": "redis",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
}
},
"spec": {
"strategy": {
"resources": {}
},
"triggers": [
{
"type": "ConfigChange"
},
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"redis"
],
"from": {
"kind": "ImageStreamTag",
"name": "redis:latest"
}
}
}
],
"replicas": 1,
"test": false,
"selector": {
"io.kompose.service": "redis"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
}
},
"spec": {
"containers": [
{
"name": "redis",
"image": " ",
"ports": [
{
"containerPort": 6379
}
],
"resources": {}
}
],
"restartPolicy": "Always",
"affinity": {
"nodeAffinity": {
"requiredDuringSchedulingIgnoredDuringExecution": {
"nodeSelectorTerms": [
{
"matchExpressions": [
{
"key": "kubernetes.io/hostname",
"operator": "In",
"values": ["machine"]
},
{
"key": "beta.kubernetes.io/os",
"operator": "In",
"values": ["ubuntu 14.04"]
},
{
"key": "foo",
"operator": "NotIn",
"values": ["bar"]
}
]
}
]
}
}
}
}
}
},
"status": {
"latestVersion": 0,
"observedGeneration": 0,
"replicas": 0,
"updatedReplicas": 0,
"availableReplicas": 0,
"unavailableReplicas": 0
}
},
{
"kind": "ImageStream",
"apiVersion": "v1",
"metadata": {
"name": "redis",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
}
},
"spec": {
"lookupPolicy": {
"local": false
},
"tags": [
{
"name": "",
"annotations": null,
"from": {
"kind": "DockerImage",
"name": "redis"
},
"generation": null,
"importPolicy": {},
"referencePolicy": {
"type": ""
}
}
]
},
"status": {
"dockerImageRepository": ""
}
}
]
}
@@ -289,7 +289,7 @@
},
"resources": {},
"postCommit": {},
"nodeSelector": null
"affinity": null
},
"status": {
"lastVersion": 0
@@ -431,7 +431,7 @@
},
"resources": {},
"postCommit": {},
"nodeSelector": null
"affinity": null
},
"status": {
"lastVersion": 0
@@ -573,7 +573,7 @@
},
"resources": {},
"postCommit": {},
"nodeSelector": null
"affinity": null
},
"status": {
"lastVersion": 0
@@ -715,7 +715,7 @@
},
"resources": {},
"postCommit": {},
"nodeSelector": null
"affinity": null
},
"status": {
"lastVersion": 0
@@ -289,7 +289,7 @@
},
"resources": {},
"postCommit": {},
"nodeSelector": null
"affinity": null
},
"status": {
"lastVersion": 0
@@ -431,7 +431,7 @@
},
"resources": {},
"postCommit": {},
"nodeSelector": null
"affinity": null
},
"status": {
"lastVersion": 0
@@ -573,7 +573,7 @@
},
"resources": {},
"postCommit": {},
"nodeSelector": null
"affinity": null
},
"status": {
"lastVersion": 0
@@ -715,7 +715,7 @@
},
"resources": {},
"postCommit": {},
"nodeSelector": null
"affinity": null
},
"status": {
"lastVersion": 0
+1
View File
@@ -19,6 +19,7 @@ services:
constraints:
- node.hostname == machine
- engine.labels.operatingsystem == ubuntu 14.04
- node.labels.foo != bar
foo: # test labels
labels:
kompose.service.type: headless
+42 -5
View File
@@ -77,9 +77,32 @@
"resources": {}
}
],
"nodeSelector": {
"beta.kubernetes.io/os": "ubuntu 14.04",
"kubernetes.io/hostname": "machine"
"affinity": {
"nodeAffinity": {
"requiredDuringSchedulingIgnoredDuringExecution": {
"nodeSelectorTerms": [
{
"matchExpressions": [
{
"key": "kubernetes.io/hostname",
"operator": "In",
"values": ["machine"]
},
{
"key": "beta.kubernetes.io/os",
"operator": "In",
"values": ["ubuntu 14.04"]
},
{
"key": "foo",
"operator": "NotIn",
"values": ["bar"]
}
]
}
]
}
}
},
"restartPolicy": "Always",
"serviceAccountName": "",
@@ -182,8 +205,22 @@
"resources": {}
}
],
"nodeSelector": {
"kubernetes.io/hostname": "machine"
"affinity": {
"nodeAffinity": {
"requiredDuringSchedulingIgnoredDuringExecution": {
"nodeSelectorTerms": [
{
"matchExpressions": [
{
"key": "kubernetes.io/hostname",
"operator": "In",
"values": ["machine"]
}
]
}
]
}
}
},
"restartPolicy": "Always",
"serviceAccountName": "",
+42 -5
View File
@@ -92,9 +92,32 @@
}
],
"restartPolicy": "Always",
"nodeSelector": {
"beta.kubernetes.io/os": "ubuntu 14.04",
"kubernetes.io/hostname": "machine"
"affinity": {
"nodeAffinity": {
"requiredDuringSchedulingIgnoredDuringExecution": {
"nodeSelectorTerms": [
{
"matchExpressions": [
{
"key": "kubernetes.io/hostname",
"operator": "In",
"values": ["machine"]
},
{
"key": "beta.kubernetes.io/os",
"operator": "In",
"values": ["ubuntu 14.04"]
},
{
"key": "foo",
"operator": "NotIn",
"values": ["bar"]
}
]
}
]
}
}
}
}
}
@@ -334,8 +357,22 @@
}
],
"restartPolicy": "Always",
"nodeSelector": {
"kubernetes.io/hostname": "machine"
"affinity": {
"nodeAffinity": {
"requiredDuringSchedulingIgnoredDuringExecution": {
"nodeSelectorTerms": [
{
"matchExpressions": [
{
"key": "kubernetes.io/hostname",
"operator": "In",
"values": ["machine"]
}
]
}
]
}
}
}
}
}