Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
1a33dffa
Commit
1a33dffa
authored
Jul 22, 2016
by
Random-Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move configmap, docker_containers, downward_api, expansion and secrets
test into common directory.
parent
9189c2f7
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
13 additions
and
512 deletions
+13
-512
exceptions.txt
hack/verify-flags/exceptions.txt
+1
-1
configmap.go
test/e2e/common/configmap.go
+4
-7
docker_containers.go
test/e2e/common/docker_containers.go
+2
-2
downward_api.go
test/e2e/common/downward_api.go
+2
-2
expansion.go
test/e2e/common/expansion.go
+2
-2
secrets.go
test/e2e/common/secrets.go
+1
-1
util.go
test/e2e/framework/util.go
+1
-0
configmap_test.go
test/e2e_node/configmap_test.go
+0
-335
downward_api_test.go
test/e2e_node/downward_api_test.go
+0
-162
No files found.
hack/verify-flags/exceptions.txt
View file @
1a33dffa
...
@@ -94,7 +94,7 @@ pkg/util/oom/oom_linux.go: return fmt.Errorf("invalid PID %d specified for oom_
...
@@ -94,7 +94,7 @@ pkg/util/oom/oom_linux.go: return fmt.Errorf("invalid PID %d specified for oom_
pkg/util/oom/oom_linux.go: oomScoreAdjPath := path.Join("/proc", pidStr, "oom_score_adj")
pkg/util/oom/oom_linux.go: oomScoreAdjPath := path.Join("/proc", pidStr, "oom_score_adj")
pkg/util/oom/oom_linux.go:// Writes 'value' to /proc/<pid>/oom_score_adj for all processes in cgroup cgroupName.
pkg/util/oom/oom_linux.go:// Writes 'value' to /proc/<pid>/oom_score_adj for all processes in cgroup cgroupName.
pkg/util/oom/oom_linux.go:// Writes 'value' to /proc/<pid>/oom_score_adj. PID = 0 means self
pkg/util/oom/oom_linux.go:// Writes 'value' to /proc/<pid>/oom_score_adj. PID = 0 means self
test/e2e/configmap.go: Command: []string{"/mt", "--break_on_expected_content=false", "--retry_time=120", "--file_content_in_loop=/etc/configmap-volume/data-1"},
test/e2e/co
mmon/co
nfigmap.go: Command: []string{"/mt", "--break_on_expected_content=false", "--retry_time=120", "--file_content_in_loop=/etc/configmap-volume/data-1"},
test/e2e/common/downwardapi_volume.go: Command: []string{"/mt", "--break_on_expected_content=false", "--retry_time=120", "--file_content_in_loop=" + filePath},
test/e2e/common/downwardapi_volume.go: Command: []string{"/mt", "--break_on_expected_content=false", "--retry_time=120", "--file_content_in_loop=" + filePath},
test/e2e/es_cluster_logging.go: framework.Failf("No cluster_name field in Elasticsearch response: %v", esResponse)
test/e2e/es_cluster_logging.go: framework.Failf("No cluster_name field in Elasticsearch response: %v", esResponse)
test/e2e/es_cluster_logging.go: // Check to see if have a cluster_name field.
test/e2e/es_cluster_logging.go: // Check to see if have a cluster_name field.
...
...
test/e2e/configmap.go
→
test/e2e/co
mmon/co
nfigmap.go
View file @
1a33dffa
/*
/*
Copyright 201
4
The Kubernetes Authors.
Copyright 201
6
The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
you may not use this file except in compliance with the License.
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
package
e2e
package
common
import
(
import
(
"fmt"
"fmt"
...
@@ -127,13 +127,10 @@ var _ = framework.KubeDescribe("ConfigMap", func() {
...
@@ -127,13 +127,10 @@ var _ = framework.KubeDescribe("ConfigMap", func() {
defer
func
()
{
defer
func
()
{
By
(
"Deleting the pod"
)
By
(
"Deleting the pod"
)
f
.
Client
.
Pods
(
f
.
Namespace
.
Name
)
.
Delete
(
pod
.
Name
,
api
.
NewDeleteOptions
(
0
))
f
.
PodClient
(
)
.
Delete
(
pod
.
Name
,
api
.
NewDeleteOptions
(
0
))
}()
}()
By
(
"Creating the pod"
)
By
(
"Creating the pod"
)
pod
,
err
=
f
.
Client
.
Pods
(
f
.
Namespace
.
Name
)
.
Create
(
pod
)
f
.
PodClient
()
.
CreateSync
(
pod
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
framework
.
ExpectNoError
(
framework
.
WaitForPodRunningInNamespace
(
f
.
Client
,
pod
))
pollLogs
:=
func
()
(
string
,
error
)
{
pollLogs
:=
func
()
(
string
,
error
)
{
return
framework
.
GetPodLogs
(
f
.
Client
,
f
.
Namespace
.
Name
,
pod
.
Name
,
containerName
)
return
framework
.
GetPodLogs
(
f
.
Client
,
f
.
Namespace
.
Name
,
pod
.
Name
,
containerName
)
...
...
test/e2e/docker_containers.go
→
test/e2e/
common/
docker_containers.go
View file @
1a33dffa
/*
/*
Copyright 201
5
The Kubernetes Authors.
Copyright 201
6
The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
you may not use this file except in compliance with the License.
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
package
e2e
package
common
import
(
import
(
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
...
...
test/e2e/downward_api.go
→
test/e2e/
common/
downward_api.go
View file @
1a33dffa
/*
/*
Copyright 201
5
The Kubernetes Authors.
Copyright 201
6
The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
you may not use this file except in compliance with the License.
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
package
e2e
package
common
import
(
import
(
"fmt"
"fmt"
...
...
test/e2e/expansion.go
→
test/e2e/
common/
expansion.go
View file @
1a33dffa
/*
/*
Copyright 201
5
The Kubernetes Authors.
Copyright 201
6
The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
you may not use this file except in compliance with the License.
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
package
e2e
package
common
import
(
import
(
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
...
...
test/e2e/secrets.go
→
test/e2e/
common/
secrets.go
View file @
1a33dffa
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
package
e2e
package
common
import
(
import
(
"fmt"
"fmt"
...
...
test/e2e/framework/util.go
View file @
1a33dffa
...
@@ -4319,6 +4319,7 @@ func ScaleRCByLabels(client *client.Client, ns string, l map[string]string, repl
...
@@ -4319,6 +4319,7 @@ func ScaleRCByLabels(client *client.Client, ns string, l map[string]string, repl
return
nil
return
nil
}
}
// TODO(random-liu): Change this to be a member function of the framework.
func
GetPodLogs
(
c
*
client
.
Client
,
namespace
,
podName
,
containerName
string
)
(
string
,
error
)
{
func
GetPodLogs
(
c
*
client
.
Client
,
namespace
,
podName
,
containerName
string
)
(
string
,
error
)
{
return
getPodLogsInternal
(
c
,
namespace
,
podName
,
containerName
,
false
)
return
getPodLogsInternal
(
c
,
namespace
,
podName
,
containerName
,
false
)
}
}
...
...
test/e2e_node/configmap_test.go
deleted
100644 → 0
View file @
9189c2f7
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
e2e_node
import
(
"fmt"
"time"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util/uuid"
"k8s.io/kubernetes/test/e2e/framework"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
)
var
_
=
framework
.
KubeDescribe
(
"ConfigMap"
,
func
()
{
f
:=
framework
.
NewDefaultFramework
(
"configmap"
)
It
(
"should be consumable from pods in volume [Conformance]"
,
func
()
{
doConfigMapE2EWithoutMappings
(
f
,
0
,
0
)
})
It
(
"should be consumable from pods in volume as non-root [Conformance]"
,
func
()
{
doConfigMapE2EWithoutMappings
(
f
,
1000
,
0
)
})
It
(
"should be consumable from pods in volume as non-root with FSGroup [Feature:FSGroup]"
,
func
()
{
doConfigMapE2EWithoutMappings
(
f
,
1000
,
1001
)
})
It
(
"should be consumable from pods in volume with mappings [Conformance]"
,
func
()
{
doConfigMapE2EWithMappings
(
f
,
0
,
0
)
})
It
(
"should be consumable from pods in volume with mappings as non-root [Conformance]"
,
func
()
{
doConfigMapE2EWithMappings
(
f
,
1000
,
0
)
})
It
(
"should be consumable from pods in volume with mappings as non-root with FSGroup [Feature:FSGroup]"
,
func
()
{
doConfigMapE2EWithMappings
(
f
,
1000
,
1001
)
})
It
(
"updates should be reflected in volume [Conformance]"
,
func
()
{
// We may have to wait or a full sync period to elapse before the
// Kubelet projects the update into the volume and the container picks
// it up. This timeout is based on the default Kubelet sync period (1
// minute) plus additional time for fudge factor.
const
podLogTimeout
=
300
*
time
.
Second
name
:=
"configmap-test-upd-"
+
string
(
uuid
.
NewUUID
())
volumeName
:=
"configmap-volume"
volumeMountPath
:=
"/etc/configmap-volume"
containerName
:=
"configmap-volume-test"
configMap
:=
&
api
.
ConfigMap
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
f
.
Namespace
.
Name
,
Name
:
name
,
},
Data
:
map
[
string
]
string
{
"data-1"
:
"value-1"
,
},
}
By
(
fmt
.
Sprintf
(
"Creating configMap with name %s"
,
configMap
.
Name
))
var
err
error
if
configMap
,
err
=
f
.
Client
.
ConfigMaps
(
f
.
Namespace
.
Name
)
.
Create
(
configMap
);
err
!=
nil
{
framework
.
Failf
(
"unable to create test configMap %s: %v"
,
configMap
.
Name
,
err
)
}
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"pod-configmaps-"
+
string
(
uuid
.
NewUUID
()),
},
Spec
:
api
.
PodSpec
{
Volumes
:
[]
api
.
Volume
{
{
Name
:
volumeName
,
VolumeSource
:
api
.
VolumeSource
{
ConfigMap
:
&
api
.
ConfigMapVolumeSource
{
LocalObjectReference
:
api
.
LocalObjectReference
{
Name
:
name
,
},
},
},
},
},
Containers
:
[]
api
.
Container
{
{
Name
:
containerName
,
Image
:
ImageRegistry
[
mountTestImage
],
Command
:
[]
string
{
"/mt"
,
"--break_on_expected_content=false"
,
"--retry_time=120"
,
"--file_content_in_loop=/etc/configmap-volume/data-1"
},
VolumeMounts
:
[]
api
.
VolumeMount
{
{
Name
:
volumeName
,
MountPath
:
volumeMountPath
,
ReadOnly
:
true
,
},
},
},
},
RestartPolicy
:
api
.
RestartPolicyNever
,
},
}
By
(
"Creating the pod"
)
f
.
PodClient
()
.
CreateSync
(
pod
)
pollLogs
:=
func
()
(
string
,
error
)
{
return
framework
.
GetPodLogs
(
f
.
Client
,
f
.
Namespace
.
Name
,
pod
.
Name
,
containerName
)
}
Eventually
(
pollLogs
,
podLogTimeout
,
framework
.
Poll
)
.
Should
(
ContainSubstring
(
"value-1"
))
By
(
fmt
.
Sprintf
(
"Updating configmap %v"
,
configMap
.
Name
))
configMap
.
ResourceVersion
=
""
// to force update
configMap
.
Data
[
"data-1"
]
=
"value-2"
_
,
err
=
f
.
Client
.
ConfigMaps
(
f
.
Namespace
.
Name
)
.
Update
(
configMap
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"waiting to observe update in volume"
)
Eventually
(
pollLogs
,
podLogTimeout
,
framework
.
Poll
)
.
Should
(
ContainSubstring
(
"value-2"
))
})
It
(
"should be consumable via environment variable [Conformance]"
,
func
()
{
name
:=
"configmap-test-"
+
string
(
uuid
.
NewUUID
())
configMap
:=
newConfigMap
(
f
,
name
)
By
(
fmt
.
Sprintf
(
"Creating configMap %v/%v"
,
f
.
Namespace
.
Name
,
configMap
.
Name
))
var
err
error
if
configMap
,
err
=
f
.
Client
.
ConfigMaps
(
f
.
Namespace
.
Name
)
.
Create
(
configMap
);
err
!=
nil
{
framework
.
Failf
(
"unable to create test configMap %s: %v"
,
configMap
.
Name
,
err
)
}
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"pod-configmaps-"
+
string
(
uuid
.
NewUUID
()),
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"env-test"
,
Image
:
ImageRegistry
[
busyBoxImage
],
Command
:
[]
string
{
"sh"
,
"-c"
,
"env"
},
Env
:
[]
api
.
EnvVar
{
{
Name
:
"CONFIG_DATA_1"
,
ValueFrom
:
&
api
.
EnvVarSource
{
ConfigMapKeyRef
:
&
api
.
ConfigMapKeySelector
{
LocalObjectReference
:
api
.
LocalObjectReference
{
Name
:
name
,
},
Key
:
"data-1"
,
},
},
},
},
},
},
RestartPolicy
:
api
.
RestartPolicyNever
,
},
}
f
.
TestContainerOutput
(
"consume configMaps"
,
pod
,
0
,
[]
string
{
"CONFIG_DATA_1=value-1"
,
})
})
})
func
newConfigMap
(
f
*
framework
.
Framework
,
name
string
)
*
api
.
ConfigMap
{
return
&
api
.
ConfigMap
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
f
.
Namespace
.
Name
,
Name
:
name
,
},
Data
:
map
[
string
]
string
{
"data-1"
:
"value-1"
,
"data-2"
:
"value-2"
,
"data-3"
:
"value-3"
,
},
}
}
func
doConfigMapE2EWithoutMappings
(
f
*
framework
.
Framework
,
uid
,
fsGroup
int64
)
{
var
(
name
=
"configmap-test-volume-"
+
string
(
uuid
.
NewUUID
())
volumeName
=
"configmap-volume"
volumeMountPath
=
"/etc/configmap-volume"
configMap
=
newConfigMap
(
f
,
name
)
)
By
(
fmt
.
Sprintf
(
"Creating configMap with name %s"
,
configMap
.
Name
))
var
err
error
if
configMap
,
err
=
f
.
Client
.
ConfigMaps
(
f
.
Namespace
.
Name
)
.
Create
(
configMap
);
err
!=
nil
{
framework
.
Failf
(
"unable to create test configMap %s: %v"
,
configMap
.
Name
,
err
)
}
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"pod-configmaps-"
+
string
(
uuid
.
NewUUID
()),
},
Spec
:
api
.
PodSpec
{
SecurityContext
:
&
api
.
PodSecurityContext
{},
Volumes
:
[]
api
.
Volume
{
{
Name
:
volumeName
,
VolumeSource
:
api
.
VolumeSource
{
ConfigMap
:
&
api
.
ConfigMapVolumeSource
{
LocalObjectReference
:
api
.
LocalObjectReference
{
Name
:
name
,
},
},
},
},
},
Containers
:
[]
api
.
Container
{
{
Name
:
"configmap-volume-test"
,
Image
:
ImageRegistry
[
mountTestImage
],
Args
:
[]
string
{
"--file_content=/etc/configmap-volume/data-1"
},
VolumeMounts
:
[]
api
.
VolumeMount
{
{
Name
:
volumeName
,
MountPath
:
volumeMountPath
,
ReadOnly
:
true
,
},
},
},
},
RestartPolicy
:
api
.
RestartPolicyNever
,
},
}
if
uid
!=
0
{
pod
.
Spec
.
SecurityContext
.
RunAsUser
=
&
uid
}
if
fsGroup
!=
0
{
pod
.
Spec
.
SecurityContext
.
FSGroup
=
&
fsGroup
}
f
.
TestContainerOutput
(
"consume configMaps"
,
pod
,
0
,
[]
string
{
"content of file
\"
/etc/configmap-volume/data-1
\"
: value-1"
,
})
}
func
doConfigMapE2EWithMappings
(
f
*
framework
.
Framework
,
uid
,
fsGroup
int64
)
{
var
(
name
=
"configmap-test-volume-map-"
+
string
(
uuid
.
NewUUID
())
volumeName
=
"configmap-volume"
volumeMountPath
=
"/etc/configmap-volume"
configMap
=
newConfigMap
(
f
,
name
)
)
By
(
fmt
.
Sprintf
(
"Creating configMap with name %s"
,
configMap
.
Name
))
var
err
error
if
configMap
,
err
=
f
.
Client
.
ConfigMaps
(
f
.
Namespace
.
Name
)
.
Create
(
configMap
);
err
!=
nil
{
framework
.
Failf
(
"unable to create test configMap %s: %v"
,
configMap
.
Name
,
err
)
}
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"pod-configmaps-"
+
string
(
uuid
.
NewUUID
()),
},
Spec
:
api
.
PodSpec
{
SecurityContext
:
&
api
.
PodSecurityContext
{},
Volumes
:
[]
api
.
Volume
{
{
Name
:
volumeName
,
VolumeSource
:
api
.
VolumeSource
{
ConfigMap
:
&
api
.
ConfigMapVolumeSource
{
LocalObjectReference
:
api
.
LocalObjectReference
{
Name
:
name
,
},
Items
:
[]
api
.
KeyToPath
{
{
Key
:
"data-2"
,
Path
:
"path/to/data-2"
,
},
},
},
},
},
},
Containers
:
[]
api
.
Container
{
{
Name
:
"configmap-volume-test"
,
Image
:
ImageRegistry
[
mountTestImage
],
Args
:
[]
string
{
"--file_content=/etc/configmap-volume/path/to/data-2"
},
VolumeMounts
:
[]
api
.
VolumeMount
{
{
Name
:
volumeName
,
MountPath
:
volumeMountPath
,
ReadOnly
:
true
,
},
},
},
},
RestartPolicy
:
api
.
RestartPolicyNever
,
},
}
if
uid
!=
0
{
pod
.
Spec
.
SecurityContext
.
RunAsUser
=
&
uid
}
if
fsGroup
!=
0
{
pod
.
Spec
.
SecurityContext
.
FSGroup
=
&
fsGroup
}
f
.
TestContainerOutput
(
"consume configMaps"
,
pod
,
0
,
[]
string
{
"content of file
\"
/etc/configmap-volume/path/to/data-2
\"
: value-2"
,
})
}
test/e2e_node/downward_api_test.go
deleted
100644 → 0
View file @
9189c2f7
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
e2e_node
import
(
"fmt"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/util/uuid"
"k8s.io/kubernetes/test/e2e/framework"
.
"github.com/onsi/ginkgo"
)
// Ported from test/e2e/downard_api_test.go
var
_
=
framework
.
KubeDescribe
(
"Downward API"
,
func
()
{
f
:=
framework
.
NewDefaultFramework
(
"downward-api"
)
It
(
"should provide pod name and namespace as env vars [Conformance]"
,
func
()
{
podName
:=
"downward-api-"
+
string
(
uuid
.
NewUUID
())
env
:=
[]
api
.
EnvVar
{
{
Name
:
"POD_NAME"
,
ValueFrom
:
&
api
.
EnvVarSource
{
FieldRef
:
&
api
.
ObjectFieldSelector
{
APIVersion
:
"v1"
,
FieldPath
:
"metadata.name"
,
},
},
},
{
Name
:
"POD_NAMESPACE"
,
ValueFrom
:
&
api
.
EnvVarSource
{
FieldRef
:
&
api
.
ObjectFieldSelector
{
APIVersion
:
"v1"
,
FieldPath
:
"metadata.namespace"
,
},
},
},
}
expectations
:=
[]
string
{
fmt
.
Sprintf
(
"POD_NAME=%v"
,
podName
),
fmt
.
Sprintf
(
"POD_NAMESPACE=%v"
,
f
.
Namespace
.
Name
),
}
testDownwardAPI
(
f
,
podName
,
env
,
expectations
)
})
It
(
"should provide pod IP as an env var"
,
func
()
{
podName
:=
"downward-api-"
+
string
(
uuid
.
NewUUID
())
env
:=
[]
api
.
EnvVar
{
{
Name
:
"POD_IP"
,
ValueFrom
:
&
api
.
EnvVarSource
{
FieldRef
:
&
api
.
ObjectFieldSelector
{
APIVersion
:
"v1"
,
FieldPath
:
"status.podIP"
,
},
},
},
}
expectations
:=
[]
string
{
"POD_IP=(?:
\\
d+)
\\
.(?:
\\
d+)
\\
.(?:
\\
d+)
\\
.(?:
\\
d+)"
,
}
testDownwardAPI
(
f
,
podName
,
env
,
expectations
)
})
It
(
"should provide container's limits.cpu/memory and requests.cpu/memory as env vars"
,
func
()
{
podName
:=
"downward-api-"
+
string
(
uuid
.
NewUUID
())
env
:=
[]
api
.
EnvVar
{
{
Name
:
"CPU_LIMIT"
,
ValueFrom
:
&
api
.
EnvVarSource
{
ResourceFieldRef
:
&
api
.
ResourceFieldSelector
{
Resource
:
"limits.cpu"
,
},
},
},
{
Name
:
"MEMORY_LIMIT"
,
ValueFrom
:
&
api
.
EnvVarSource
{
ResourceFieldRef
:
&
api
.
ResourceFieldSelector
{
Resource
:
"limits.memory"
,
},
},
},
{
Name
:
"CPU_REQUEST"
,
ValueFrom
:
&
api
.
EnvVarSource
{
ResourceFieldRef
:
&
api
.
ResourceFieldSelector
{
Resource
:
"requests.cpu"
,
},
},
},
{
Name
:
"MEMORY_REQUEST"
,
ValueFrom
:
&
api
.
EnvVarSource
{
ResourceFieldRef
:
&
api
.
ResourceFieldSelector
{
Resource
:
"requests.memory"
,
},
},
},
}
expectations
:=
[]
string
{
fmt
.
Sprintf
(
"CPU_LIMIT=2"
),
fmt
.
Sprintf
(
"MEMORY_LIMIT=67108864"
),
fmt
.
Sprintf
(
"CPU_REQUEST=1"
),
fmt
.
Sprintf
(
"MEMORY_REQUEST=33554432"
),
}
testDownwardAPI
(
f
,
podName
,
env
,
expectations
)
})
})
func
testDownwardAPI
(
f
*
framework
.
Framework
,
podName
string
,
env
[]
api
.
EnvVar
,
expectations
[]
string
)
{
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
podName
,
Labels
:
map
[
string
]
string
{
"name"
:
podName
},
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"dapi-container"
,
Image
:
ImageRegistry
[
busyBoxImage
],
Command
:
[]
string
{
"sh"
,
"-c"
,
"env"
},
Resources
:
api
.
ResourceRequirements
{
Requests
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"250m"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"32Mi"
),
},
Limits
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"1250m"
),
api
.
ResourceMemory
:
resource
.
MustParse
(
"64Mi"
),
},
},
Env
:
env
,
},
},
RestartPolicy
:
api
.
RestartPolicyNever
,
},
}
f
.
TestContainerOutputRegexp
(
"downward api env vars"
,
pod
,
0
,
expectations
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment