Skip to content

Commit 10d6efa

Browse files
authored
Merge pull request kubernetes#89032 from tanjunchen/move-GetPodSecretUpdateTimeout
move GetPodSecretUpdateTimeout from framework/utils to test/e2e/framework/pod/
2 parents 05134da + 97db7f4 commit 10d6efa

File tree

6 files changed

+48
-48
lines changed

6 files changed

+48
-48
lines changed

test/e2e/common/configmap_volume.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ var _ = ginkgo.Describe("[sig-storage] ConfigMap", func() {
119119
Description: The ConfigMap that is created MUST be accessible to read from the newly created Pod using the volume mount that is mapped to custom path in the Pod. When the ConfigMap is updated the change to the config map MUST be verified by reading the content from the mounted file in the Pod.
120120
*/
121121
framework.ConformanceIt("updates should be reflected in volume [NodeConformance]", func() {
122-
podLogTimeout := framework.GetPodSecretUpdateTimeout(f.ClientSet)
122+
podLogTimeout := e2epod.GetPodSecretUpdateTimeout(f.ClientSet)
123123
containerTimeoutArg := fmt.Sprintf("--retry_time=%v", int(podLogTimeout.Seconds()))
124124

125125
name := "configmap-test-upd-" + string(uuid.NewUUID())
@@ -202,7 +202,7 @@ var _ = ginkgo.Describe("[sig-storage] ConfigMap", func() {
202202
Description: The ConfigMap that is created with text data and binary data MUST be accessible to read from the newly created Pod using the volume mount that is mapped to custom path in the Pod. ConfigMap's text data and binary data MUST be verified by reading the content from the mounted files in the Pod.
203203
*/
204204
framework.ConformanceIt("binary data should be reflected in volume [NodeConformance]", func() {
205-
podLogTimeout := framework.GetPodSecretUpdateTimeout(f.ClientSet)
205+
podLogTimeout := e2epod.GetPodSecretUpdateTimeout(f.ClientSet)
206206
containerTimeoutArg := fmt.Sprintf("--retry_time=%v", int(podLogTimeout.Seconds()))
207207

208208
name := "configmap-test-upd-" + string(uuid.NewUUID())
@@ -298,7 +298,7 @@ var _ = ginkgo.Describe("[sig-storage] ConfigMap", func() {
298298
Description: The ConfigMap that is created MUST be accessible to read from the newly created Pod using the volume mount that is mapped to custom path in the Pod. When the config map is updated the change to the config map MUST be verified by reading the content from the mounted file in the Pod. Also when the item(file) is deleted from the map that MUST result in a error reading that item(file).
299299
*/
300300
framework.ConformanceIt("optional updates should be reflected in volume [NodeConformance]", func() {
301-
podLogTimeout := framework.GetPodSecretUpdateTimeout(f.ClientSet)
301+
podLogTimeout := e2epod.GetPodSecretUpdateTimeout(f.ClientSet)
302302
containerTimeoutArg := fmt.Sprintf("--retry_time=%v", int(podLogTimeout.Seconds()))
303303
trueVal := true
304304
volumeMountPath := "/etc/configmap-volumes"
@@ -795,7 +795,7 @@ func doConfigMapE2EWithMappings(f *framework.Framework, asUser bool, fsGroup int
795795
}
796796

797797
func createNonOptionalConfigMapPod(f *framework.Framework, volumeMountPath, podName string) error {
798-
podLogTimeout := framework.GetPodSecretUpdateTimeout(f.ClientSet)
798+
podLogTimeout := e2epod.GetPodSecretUpdateTimeout(f.ClientSet)
799799
containerTimeoutArg := fmt.Sprintf("--retry_time=%v", int(podLogTimeout.Seconds()))
800800
falseValue := false
801801

@@ -845,7 +845,7 @@ func createNonOptionalConfigMapPod(f *framework.Framework, volumeMountPath, podN
845845
}
846846

847847
func createNonOptionalConfigMapPodWithConfig(f *framework.Framework, volumeMountPath, podName string) error {
848-
podLogTimeout := framework.GetPodSecretUpdateTimeout(f.ClientSet)
848+
podLogTimeout := e2epod.GetPodSecretUpdateTimeout(f.ClientSet)
849849
containerTimeoutArg := fmt.Sprintf("--retry_time=%v", int(podLogTimeout.Seconds()))
850850
falseValue := false
851851

test/e2e/common/projected_configmap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ var _ = ginkgo.Describe("[sig-storage] Projected configMap", func() {
119119
Description: A Pod is created with projected volume source 'ConfigMap' to store a configMap and performs a create and update to new value. Pod MUST be able to create the configMap with value-1. Pod MUST be able to update the value in the confgiMap to value-2.
120120
*/
121121
framework.ConformanceIt("updates should be reflected in volume [NodeConformance]", func() {
122-
podLogTimeout := framework.GetPodSecretUpdateTimeout(f.ClientSet)
122+
podLogTimeout := e2epod.GetPodSecretUpdateTimeout(f.ClientSet)
123123
containerTimeoutArg := fmt.Sprintf("--retry_time=%v", int(podLogTimeout.Seconds()))
124124

125125
name := "projected-configmap-test-upd-" + string(uuid.NewUUID())
@@ -207,7 +207,7 @@ var _ = ginkgo.Describe("[sig-storage] Projected configMap", func() {
207207
Description: Create a Pod with three containers with ConfigMaps namely a create, update and delete container. Create Container when started MUST not have configMap, update and delete containers MUST be created with a ConfigMap value as 'value-1'. Create a configMap in the create container, the Pod MUST be able to read the configMap from the create container. Update the configMap in the update container, Pod MUST be able to read the updated configMap value. Delete the configMap in the delete container. Pod MUST fail to read the configMap from the delete container.
208208
*/
209209
framework.ConformanceIt("optional updates should be reflected in volume [NodeConformance]", func() {
210-
podLogTimeout := framework.GetPodSecretUpdateTimeout(f.ClientSet)
210+
podLogTimeout := e2epod.GetPodSecretUpdateTimeout(f.ClientSet)
211211
containerTimeoutArg := fmt.Sprintf("--retry_time=%v", int(podLogTimeout.Seconds()))
212212
trueVal := true
213213
volumeMountPath := "/etc/projected-configmap-volumes"

test/e2e/common/projected_secret.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ var _ = ginkgo.Describe("[sig-storage] Projected secret", func() {
209209
Description: Create a Pod with three containers with secrets namely a create, update and delete container. Create Container when started MUST no have a secret, update and delete containers MUST be created with a secret value. Create a secret in the create container, the Pod MUST be able to read the secret from the create container. Update the secret in the update container, Pod MUST be able to read the updated secret value. Delete the secret in the delete container. Pod MUST fail to read the secret from the delete container.
210210
*/
211211
framework.ConformanceIt("optional updates should be reflected in volume [NodeConformance]", func() {
212-
podLogTimeout := framework.GetPodSecretUpdateTimeout(f.ClientSet)
212+
podLogTimeout := e2epod.GetPodSecretUpdateTimeout(f.ClientSet)
213213
containerTimeoutArg := fmt.Sprintf("--retry_time=%v", int(podLogTimeout.Seconds()))
214214
trueVal := true
215215
volumeMountPath := "/etc/projected-secret-volumes"

test/e2e/common/secrets_volume.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ var _ = ginkgo.Describe("[sig-storage] Secrets", func() {
199199
Description: Create a Pod with three containers with secrets volume sources namely a create, update and delete container. Create Container when started MUST not have secret, update and delete containers MUST be created with a secret value. Create a secret in the create container, the Pod MUST be able to read the secret from the create container. Update the secret in the update container, Pod MUST be able to read the updated secret value. Delete the secret in the delete container. Pod MUST fail to read the secret from the delete container.
200200
*/
201201
framework.ConformanceIt("optional updates should be reflected in volume [NodeConformance]", func() {
202-
podLogTimeout := framework.GetPodSecretUpdateTimeout(f.ClientSet)
202+
podLogTimeout := e2epod.GetPodSecretUpdateTimeout(f.ClientSet)
203203
containerTimeoutArg := fmt.Sprintf("--retry_time=%v", int(podLogTimeout.Seconds()))
204204
trueVal := true
205205
volumeMountPath := "/etc/secret-volumes"
@@ -588,7 +588,7 @@ func doSecretE2EWithMapping(f *framework.Framework, mode *int32) {
588588
}
589589

590590
func createNonOptionalSecretPod(f *framework.Framework, volumeMountPath, podName string) error {
591-
podLogTimeout := framework.GetPodSecretUpdateTimeout(f.ClientSet)
591+
podLogTimeout := e2epod.GetPodSecretUpdateTimeout(f.ClientSet)
592592
containerTimeoutArg := fmt.Sprintf("--retry_time=%v", int(podLogTimeout.Seconds()))
593593
falseValue := false
594594

@@ -636,7 +636,7 @@ func createNonOptionalSecretPod(f *framework.Framework, volumeMountPath, podName
636636
}
637637

638638
func createNonOptionalSecretPodWithSecret(f *framework.Framework, volumeMountPath, podName string) error {
639-
podLogTimeout := framework.GetPodSecretUpdateTimeout(f.ClientSet)
639+
podLogTimeout := e2epod.GetPodSecretUpdateTimeout(f.ClientSet)
640640
containerTimeoutArg := fmt.Sprintf("--retry_time=%v", int(podLogTimeout.Seconds()))
641641
falseValue := false
642642

test/e2e/framework/pod/resource.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,40 @@ func GetPodsInNamespace(c clientset.Interface, ns string, ignoreLabels map[strin
543543
}
544544
return filtered, nil
545545
}
546+
547+
// GetPodSecretUpdateTimeout returns the timeout duration for updating pod secret.
548+
func GetPodSecretUpdateTimeout(c clientset.Interface) time.Duration {
549+
// With SecretManager(ConfigMapManager), we may have to wait up to full sync period +
550+
// TTL of secret(configmap) to elapse before the Kubelet projects the update into the
551+
// volume and the container picks it up.
552+
// So this timeout is based on default Kubelet sync period (1 minute) + maximum TTL for
553+
// secret(configmap) that's based on cluster size + additional time as a fudge factor.
554+
secretTTL, err := getNodeTTLAnnotationValue(c)
555+
if err != nil {
556+
e2elog.Logf("Couldn't get node TTL annotation (using default value of 0): %v", err)
557+
}
558+
podLogTimeout := 240*time.Second + secretTTL
559+
return podLogTimeout
560+
}
561+
562+
func getNodeTTLAnnotationValue(c clientset.Interface) (time.Duration, error) {
563+
nodes, err := c.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
564+
if err != nil || len(nodes.Items) == 0 {
565+
return time.Duration(0), fmt.Errorf("Couldn't list any nodes to get TTL annotation: %v", err)
566+
}
567+
// Since TTL the kubelet is using is stored in node object, for the timeout
568+
// purpose we take it from the first node (all of them should be the same).
569+
node := &nodes.Items[0]
570+
if node.Annotations == nil {
571+
return time.Duration(0), fmt.Errorf("No annotations found on the node")
572+
}
573+
value, ok := node.Annotations[v1.ObjectTTLAnnotationKey]
574+
if !ok {
575+
return time.Duration(0), fmt.Errorf("No TTL annotation found on the node")
576+
}
577+
intValue, err := strconv.Atoi(value)
578+
if err != nil {
579+
return time.Duration(0), fmt.Errorf("Cannot convert TTL annotation from %#v to int", *node)
580+
}
581+
return time.Duration(intValue) * time.Second, nil
582+
}

test/e2e/framework/util.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,43 +1020,6 @@ func WaitForAllNodesSchedulable(c clientset.Interface, timeout time.Duration) er
10201020
)
10211021
}
10221022

1023-
// GetPodSecretUpdateTimeout reuturns the timeout duration for updating pod secret.
1024-
func GetPodSecretUpdateTimeout(c clientset.Interface) time.Duration {
1025-
// With SecretManager(ConfigMapManager), we may have to wait up to full sync period +
1026-
// TTL of secret(configmap) to elapse before the Kubelet projects the update into the
1027-
// volume and the container picks it up.
1028-
// So this timeout is based on default Kubelet sync period (1 minute) + maximum TTL for
1029-
// secret(configmap) that's based on cluster size + additional time as a fudge factor.
1030-
secretTTL, err := getNodeTTLAnnotationValue(c)
1031-
if err != nil {
1032-
Logf("Couldn't get node TTL annotation (using default value of 0): %v", err)
1033-
}
1034-
podLogTimeout := 240*time.Second + secretTTL
1035-
return podLogTimeout
1036-
}
1037-
1038-
func getNodeTTLAnnotationValue(c clientset.Interface) (time.Duration, error) {
1039-
nodes, err := c.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
1040-
if err != nil || len(nodes.Items) == 0 {
1041-
return time.Duration(0), fmt.Errorf("Couldn't list any nodes to get TTL annotation: %v", err)
1042-
}
1043-
// Since TTL the kubelet is using is stored in node object, for the timeout
1044-
// purpose we take it from the first node (all of them should be the same).
1045-
node := &nodes.Items[0]
1046-
if node.Annotations == nil {
1047-
return time.Duration(0), fmt.Errorf("No annotations found on the node")
1048-
}
1049-
value, ok := node.Annotations[v1.ObjectTTLAnnotationKey]
1050-
if !ok {
1051-
return time.Duration(0), fmt.Errorf("No TTL annotation found on the node")
1052-
}
1053-
intValue, err := strconv.Atoi(value)
1054-
if err != nil {
1055-
return time.Duration(0), fmt.Errorf("Cannot convert TTL annotation from %#v to int", *node)
1056-
}
1057-
return time.Duration(intValue) * time.Second, nil
1058-
}
1059-
10601023
// AddOrUpdateLabelOnNode adds the given label key and value to the given node or updates value.
10611024
func AddOrUpdateLabelOnNode(c clientset.Interface, nodeName string, labelKey, labelValue string) {
10621025
ExpectNoError(testutils.AddLabelsToNode(c, nodeName, map[string]string{labelKey: labelValue}))

0 commit comments

Comments
 (0)