mirror of
https://github.com/containers/podman.git
synced 2025-11-30 18:18:18 +08:00
Merge pull request #17950 from umohnani8/deployments
Support Deployment generation with kube generate
This commit is contained in:
@@ -29,6 +29,12 @@ like "$output" ".*metadata:.*" "Check generated kube yaml(service=true) - metada
|
||||
like "$output" ".*spec:.*" "Check generated kube yaml(service=true) - spec"
|
||||
like "$output" ".*kind:\\sService.*" "Check generated kube yaml(service=true) - kind: Service"
|
||||
|
||||
t GET "libpod/generate/kube?type=deployment&names=$cid" 200
|
||||
like "$output" ".*apiVersion:.*" "Check generated kube yaml - apiVersion"
|
||||
like "$output" ".*kind:\\sDeployment.*" "Check generated kube yaml - kind: Deployment"
|
||||
like "$output" ".*metadata:.*" "Check generated kube yaml - metadata"
|
||||
like "$output" ".*spec:.*" "Check generated kube yaml - spec"
|
||||
|
||||
TMPD=$(mktemp -d podman-apiv2-test-kube.XXXXXX)
|
||||
YAML="${TMPD}/kube.yaml"
|
||||
echo "$output" > $YAML
|
||||
|
||||
@@ -531,7 +531,7 @@ var _ = Describe("Podman kube generate", func() {
|
||||
It("podman generate kube on pod with restartPolicy", func() {
|
||||
// podName, set, expect
|
||||
testSli := [][]string{
|
||||
{"testPod1", "", "Never"}, // some pod create from cmdline, so set it to Never
|
||||
{"testPod1", "", ""}, // some pod create from cmdline, so set it to an empty string and let k8s default it to Always
|
||||
{"testPod2", "always", "Always"},
|
||||
{"testPod3", "on-failure", "OnFailure"},
|
||||
{"testPod4", "no", "Never"},
|
||||
@@ -1402,4 +1402,87 @@ USER test1`
|
||||
Expect(inspect.OutputToString()).To(ContainSubstring("1231"))
|
||||
Expect(inspect.OutputToString()).To(ContainSubstring("3123"))
|
||||
})
|
||||
|
||||
It("podman generate kube on pod with --type=deployment", func() {
|
||||
podName := "test-pod"
|
||||
session := podmanTest.Podman([]string{"pod", "create", podName})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(Exit(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"create", "--pod", podName, ALPINE, "top"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(Exit(0))
|
||||
session = podmanTest.Podman([]string{"create", "--pod", podName, ALPINE, "sleep", "100"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(Exit(0))
|
||||
|
||||
kube := podmanTest.Podman([]string{"generate", "kube", "--type", "deployment", podName})
|
||||
kube.WaitWithDefaultTimeout()
|
||||
Expect(kube).Should(Exit(0))
|
||||
|
||||
dep := new(v1.Deployment)
|
||||
err := yaml.Unmarshal(kube.Out.Contents(), dep)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(dep.Name).To(Equal(podName + "-deployment"))
|
||||
Expect(dep.Spec.Selector.MatchLabels).To(HaveKeyWithValue("app", podName))
|
||||
Expect(dep.Spec.Template.Name).To(Equal(podName))
|
||||
|
||||
numContainers := 0
|
||||
for range dep.Spec.Template.Spec.Containers {
|
||||
numContainers++
|
||||
}
|
||||
Expect(numContainers).To(Equal(2))
|
||||
})
|
||||
|
||||
It("podman generate kube on ctr with --type=deployment and --replicas=3", func() {
|
||||
ctrName := "test-ctr"
|
||||
session := podmanTest.Podman([]string{"create", "--name", ctrName, ALPINE, "top"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(Exit(0))
|
||||
|
||||
kube := podmanTest.Podman([]string{"generate", "kube", "--type", "deployment", "--replicas", "3", ctrName})
|
||||
kube.WaitWithDefaultTimeout()
|
||||
Expect(kube).Should(Exit(0))
|
||||
|
||||
dep := new(v1.Deployment)
|
||||
err := yaml.Unmarshal(kube.Out.Contents(), dep)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(dep.Name).To(Equal(ctrName + "-pod-deployment"))
|
||||
Expect(dep.Spec.Selector.MatchLabels).To(HaveKeyWithValue("app", ctrName+"-pod"))
|
||||
Expect(dep.Spec.Template.Name).To(Equal(ctrName + "-pod"))
|
||||
Expect(int(*dep.Spec.Replicas)).To(Equal(3))
|
||||
|
||||
numContainers := 0
|
||||
for range dep.Spec.Template.Spec.Containers {
|
||||
numContainers++
|
||||
}
|
||||
Expect(numContainers).To(Equal(1))
|
||||
})
|
||||
|
||||
It("podman generate kube on ctr with --type=pod and --replicas=3 should fail", func() {
|
||||
ctrName := "test-ctr"
|
||||
session := podmanTest.Podman([]string{"create", "--name", ctrName, ALPINE, "top"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(Exit(0))
|
||||
|
||||
kube := podmanTest.Podman([]string{"generate", "kube", "--type", "pod", "--replicas", "3", ctrName})
|
||||
kube.WaitWithDefaultTimeout()
|
||||
Expect(kube).Should(Exit(125))
|
||||
})
|
||||
|
||||
It("podman generate kube on pod with --type=deployment and --restart=no should fail", func() {
|
||||
// TODO: When we add --restart for pods, fix this test to reflect that
|
||||
podName := "test-pod"
|
||||
session := podmanTest.Podman([]string{"pod", "create", podName})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(Exit(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"create", "--pod", podName, "--restart", "no", ALPINE, "top"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(Exit(0))
|
||||
|
||||
kube := podmanTest.Podman([]string{"generate", "kube", "--type", "deployment", podName})
|
||||
kube.WaitWithDefaultTimeout()
|
||||
Expect(kube).Should(Exit(125))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -162,3 +162,44 @@ load helpers.bash
|
||||
run minikube kubectl delete namespace $project
|
||||
assert $status -eq 0 "delete namespace $project"
|
||||
}
|
||||
|
||||
@test "minikube - deploy generated container yaml to minikube --type=deployment" {
|
||||
cname="test-ctr"
|
||||
fname="/tmp/minikube_deploy_$(random_string 6).yaml"
|
||||
run_podman container create --name $cname $IMAGE top
|
||||
run_podman kube generate --type deployment -f $fname $cname
|
||||
|
||||
# deploy to the minikube cluster
|
||||
project="dep-ctr-ns"
|
||||
run minikube kubectl create namespace $project
|
||||
assert "$status" -eq 0 "create new namespace $project"
|
||||
run minikube kubectl -- apply -f $fname
|
||||
assert "$status" -eq 0 "deploy $fname to the cluster"
|
||||
assert "$output" == "deployment.apps/$cname-pod-deployment created"
|
||||
wait_for_pods_to_start
|
||||
run minikube kubectl delete namespace $project
|
||||
assert $status -eq 0 "delete namespace $project"
|
||||
}
|
||||
|
||||
@test "minikube - deploy generated pod yaml to minikube --type=deployment" {
|
||||
pname="test-pod"
|
||||
cname1="test-ctr1"
|
||||
cname2="test-ctr2"
|
||||
fname="/tmp/minikube_deploy_$(random_string 6).yaml"
|
||||
|
||||
run_podman pod create --name $pname --publish 9999:8888
|
||||
run_podman container create --name $cname1 --pod $pname $IMAGE sleep 1000
|
||||
run_podman container create --name $cname2 --pod $pname $IMAGE sleep 2000
|
||||
run_podman kube generate --type deployment -f $fname $pname
|
||||
|
||||
# deploy to the minikube cluster
|
||||
project="dep-pod-ns"
|
||||
run minikube kubectl create namespace $project
|
||||
assert "$status" -eq 0 "create new namespace $project"
|
||||
run minikube kubectl -- apply -f $fname
|
||||
assert "$status" -eq 0 "deploy $fname to the cluster"
|
||||
assert "$output" == "deployment.apps/$pname-deployment created"
|
||||
wait_for_pods_to_start
|
||||
run minikube kubectl delete namespace $project
|
||||
assert $status -eq 0 "delete namespace $project"
|
||||
}
|
||||
|
||||
@@ -106,24 +106,23 @@ metadata.labels.app | = | ${pname}
|
||||
metadata.name | = | ${pname}
|
||||
|
||||
spec.hostname | = | $pname
|
||||
spec.restartPolicy | = | Never
|
||||
|
||||
spec.containers[0].command | = | [\"top\"]
|
||||
spec.containers[0].image | = | $IMAGE
|
||||
spec.containers[0].name | = | $cname1
|
||||
spec.containers[0].ports[0].containerPort | = | 8888
|
||||
spec.containers[0].ports[0].hostPort | = | 9999
|
||||
spec.containers[0].resources | = | {}
|
||||
spec.containers[0].resources | = | null
|
||||
|
||||
spec.containers[1].command | = | [\"bottom\"]
|
||||
spec.containers[1].image | = | $IMAGE
|
||||
spec.containers[1].name | = | $cname2
|
||||
spec.containers[1].ports | = | null
|
||||
spec.containers[1].resources | = | {}
|
||||
spec.containers[1].resources | = | null
|
||||
|
||||
spec.containers[0].securityContext.capabilities | = | $capabilities
|
||||
|
||||
status | = | {}
|
||||
status | = | null
|
||||
"
|
||||
|
||||
while read key op expect; do
|
||||
|
||||
Reference in New Issue
Block a user