summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--pkg/domain/infra/abi/play.go5
-rw-r--r--test/e2e/play_kube_test.go74
-rw-r--r--vendor/modules.txt2
5 files changed, 79 insertions, 8 deletions
diff --git a/go.mod b/go.mod
index fcfd199b9..f923ce21f 100644
--- a/go.mod
+++ b/go.mod
@@ -62,7 +62,7 @@ require (
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a
golang.org/x/sys v0.0.0-20200810151505-1b9f1253b3ed
k8s.io/api v0.0.0-20190620084959-7cf5895f2711
- k8s.io/apimachinery v0.19.1
+ k8s.io/apimachinery v0.19.2
k8s.io/client-go v0.0.0-20190620085101-78d2af792bab
)
diff --git a/go.sum b/go.sum
index 7eb8fe654..320c6263a 100644
--- a/go.sum
+++ b/go.sum
@@ -640,8 +640,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
k8s.io/api v0.0.0-20190620084959-7cf5895f2711 h1:BblVYz/wE5WtBsD/Gvu54KyBUTJMflolzc5I2DTvh50=
k8s.io/api v0.0.0-20190620084959-7cf5895f2711/go.mod h1:TBhBqb1AWbBQbW3XRusr7n7E4v2+5ZY8r8sAMnyFC5A=
k8s.io/apimachinery v0.0.0-20190612205821-1799e75a0719/go.mod h1:I4A+glKBHiTgiEjQiCCQfCAIcIMFGt291SmsvcrFzJA=
-k8s.io/apimachinery v0.19.1 h1:cwsxZazM/LA9aUsBaL4bRS5ygoM6bYp8dFk22DSYQa4=
-k8s.io/apimachinery v0.19.1/go.mod h1:DnPGDnARWFvYa3pMHgSxtbZb7gpzzAZ1pTfaUNDVlmA=
+k8s.io/apimachinery v0.19.2 h1:5Gy9vQpAGTKHPVOh5c4plE274X8D/6cuEiTO2zve7tc=
+k8s.io/apimachinery v0.19.2/go.mod h1:DnPGDnARWFvYa3pMHgSxtbZb7gpzzAZ1pTfaUNDVlmA=
k8s.io/client-go v0.0.0-20190620085101-78d2af792bab h1:E8Fecph0qbNsAbijJJQryKu4Oi9QTp5cVpjTE+nqg6g=
k8s.io/client-go v0.0.0-20190620085101-78d2af792bab/go.mod h1:E95RaSlHr79aHaX0aGSwcPNfygDiPKOVXdmivCIZT0k=
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go
index 6dfb52c63..659cc799c 100644
--- a/pkg/domain/infra/abi/play.go
+++ b/pkg/domain/infra/abi/play.go
@@ -132,6 +132,11 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
libpod.WithInfraContainer(),
libpod.WithPodName(podName),
}
+
+ if podYAML.ObjectMeta.Labels != nil {
+ podOptions = append(podOptions, libpod.WithPodLabels(podYAML.ObjectMeta.Labels))
+ }
+
// TODO we only configure Process namespace. We also need to account for Host{IPC,Network,PID}
// which is not currently possible with pod create
if podYAML.Spec.ShareProcessNamespace != nil && *podYAML.Spec.ShareProcessNamespace {
diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go
index 5e01971cb..87de92357 100644
--- a/test/e2e/play_kube_test.go
+++ b/test/e2e/play_kube_test.go
@@ -30,9 +30,14 @@ apiVersion: v1
kind: Pod
metadata:
creationTimestamp: "2019-07-17T14:44:08Z"
+ name: {{ .Name }}
labels:
app: {{ .Name }}
- name: {{ .Name }}
+{{ with .Labels }}
+ {{ range $key, $value := . }}
+ {{ $key }}: {{ $value }}
+ {{ end }}
+{{ end }}
{{ with .Annotations }}
annotations:
{{ range $key, $value := . }}
@@ -125,9 +130,14 @@ apiVersion: v1
kind: Deployment
metadata:
creationTimestamp: "2019-07-17T14:44:08Z"
+ name: {{ .Name }}
labels:
app: {{ .Name }}
- name: {{ .Name }}
+{{ with .Labels }}
+ {{ range $key, $value := . }}
+ {{ $key }}: {{ $value }}
+ {{ end }}
+{{ end }}
{{ with .Annotations }}
annotations:
{{ range $key, $value := . }}
@@ -145,6 +155,9 @@ spec:
metadata:
labels:
app: {{ .Name }}
+ {{- with .Labels }}{{ range $key, $value := . }}
+ {{ $key }}: {{ $value }}
+ {{- end }}{{ end }}
{{ with .Annotations }}
annotations:
{{ range $key, $value := . }}
@@ -266,6 +279,7 @@ type Pod struct {
HostAliases []HostAlias
Ctrs []*Ctr
Volumes []*Volume
+ Labels map[string]string
Annotations map[string]string
}
@@ -278,7 +292,15 @@ type HostAlias struct {
// and the configured options
// if no containers are added, it will add the default container
func getPod(options ...podOption) *Pod {
- p := Pod{defaultPodName, "", nil, make([]*Ctr, 0), make([]*Volume, 0), make(map[string]string)}
+ p := Pod{
+ Name: defaultPodName,
+ Hostname: "",
+ HostAliases: nil,
+ Ctrs: make([]*Ctr, 0),
+ Volumes: make([]*Volume, 0),
+ Labels: make(map[string]string),
+ Annotations: make(map[string]string),
+ }
for _, option := range options {
option(&p)
}
@@ -311,6 +333,12 @@ func withCtr(c *Ctr) podOption {
}
}
+func withLabel(k, v string) podOption {
+ return func(pod *Pod) {
+ pod.Labels[k] = v
+ }
+}
+
func withAnnotation(k, v string) podOption {
return func(pod *Pod) {
pod.Annotations[k] = v
@@ -327,12 +355,19 @@ func withVolume(v *Volume) podOption {
type Deployment struct {
Name string
Replicas int32
+ Labels map[string]string
Annotations map[string]string
PodTemplate *Pod
}
func getDeployment(options ...deploymentOption) *Deployment {
- d := Deployment{defaultDeploymentName, 1, make(map[string]string), getPod()}
+ d := Deployment{
+ Name: defaultDeploymentName,
+ Replicas: 1,
+ Labels: make(map[string]string),
+ Annotations: make(map[string]string),
+ PodTemplate: getPod(),
+ }
for _, option := range options {
option(&d)
}
@@ -342,6 +377,12 @@ func getDeployment(options ...deploymentOption) *Deployment {
type deploymentOption func(*Deployment)
+func withDeploymentLabel(k, v string) deploymentOption {
+ return func(deployment *Deployment) {
+ deployment.Labels[k] = v
+ }
+}
+
func withDeploymentAnnotation(k, v string) deploymentOption {
return func(deployment *Deployment) {
deployment.Annotations[k] = v
@@ -1077,4 +1118,29 @@ spec:
correct := fmt.Sprintf("%s:%s:%s", hostPathLocation, hostPathLocation, "ro")
Expect(inspect.OutputToString()).To(ContainSubstring(correct))
})
+
+ It("podman play kube applies labels to pods", func() {
+ SkipIfRemote()
+ var numReplicas int32 = 5
+ expectedLabelKey := "key1"
+ expectedLabelValue := "value1"
+ deployment := getDeployment(
+ withReplicas(numReplicas),
+ withPod(getPod(withLabel(expectedLabelKey, expectedLabelValue))),
+ )
+ err := generateDeploymentKubeYaml(deployment, kubeYaml)
+ Expect(err).To(BeNil())
+
+ kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube.ExitCode()).To(Equal(0))
+
+ correctLabels := expectedLabelKey + ":" + expectedLabelValue
+ for _, pod := range getPodNamesInDeployment(deployment) {
+ inspect := podmanTest.Podman([]string{"pod", "inspect", pod.Name, "--format", "'{{ .Labels }}'"})
+ inspect.WaitWithDefaultTimeout()
+ Expect(inspect.ExitCode()).To(Equal(0))
+ Expect(inspect.OutputToString()).To(ContainSubstring(correctLabels))
+ }
+ })
})
diff --git a/vendor/modules.txt b/vendor/modules.txt
index 9959c9efb..186a85883 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -701,7 +701,7 @@ gopkg.in/yaml.v3
# k8s.io/api v0.0.0-20190620084959-7cf5895f2711
k8s.io/api/apps/v1
k8s.io/api/core/v1
-# k8s.io/apimachinery v0.19.1
+# k8s.io/apimachinery v0.19.2
k8s.io/apimachinery/pkg/api/errors
k8s.io/apimachinery/pkg/api/resource
k8s.io/apimachinery/pkg/apis/meta/v1