How to use Create method of configmap Package

Best Testkube code snippet using configmap.Create

configmap_volume.go

Source:configmap_volume.go Github

copy

Full Screen

...26 f := framework.NewDefaultFramework("configmap")27 /*28 Release : v1.929 Testname: ConfigMap Volume, without mapping30 Description: Create a ConfigMap, create a Pod that mounts a volume and populates the volume with data stored in the ConfigMap. The ConfigMap that is created MUST be accessible to read from the newly created Pod using the volume mount. The data content of the file MUST be readable and verified and file modes MUST default to 0x644.31 */32 framework.ConformanceIt("should be consumable from pods in volume [NodeConformance]", func() {33 doConfigMapE2EWithoutMappings(f, 0, 0, nil)34 })35 /*36 Release : v1.937 Testname: ConfigMap Volume, without mapping, volume mode set38 Description: Create a ConfigMap, create a Pod that mounts a volume and populates the volume with data stored in the ConfigMap. File mode is changed to a custom value of '0x400'. The ConfigMap that is created MUST be accessible to read from the newly created Pod using the volume mount. The data content of the file MUST be readable and verified and file modes MUST be set to the custom value of ‘0x400’39 This test is marked LinuxOnly since Windows does not support setting specific file permissions.40 */41 framework.ConformanceIt("should be consumable from pods in volume with defaultMode set [LinuxOnly] [NodeConformance]", func() {42 defaultMode := int32(0400)43 doConfigMapE2EWithoutMappings(f, 0, 0, &defaultMode)44 })45 It("should be consumable from pods in volume as non-root with defaultMode and fsGroup set [NodeFeature:FSGroup]", func() {46 defaultMode := int32(0440) /* setting fsGroup sets mode to at least 440 */47 doConfigMapE2EWithoutMappings(f, 1000, 1001, &defaultMode)48 })49 /*50 Release : v1.951 Testname: ConfigMap Volume, without mapping, non-root user52 Description: Create a ConfigMap, create a Pod that mounts a volume and populates the volume with data stored in the ConfigMap. Pod is run as a non-root user with uid=1000. The ConfigMap that is created MUST be accessible to read from the newly created Pod using the volume mount. The file on the volume MUST have file mode set to default value of 0x644.53 This test is marked LinuxOnly since Windows does not support running as UID / GID.54 */55 framework.ConformanceIt("should be consumable from pods in volume as non-root [LinuxOnly] [NodeConformance]", func() {56 doConfigMapE2EWithoutMappings(f, 1000, 0, nil)57 })58 It("should be consumable from pods in volume as non-root with FSGroup [NodeFeature:FSGroup]", func() {59 doConfigMapE2EWithoutMappings(f, 1000, 1001, nil)60 })61 /*62 Release : v1.963 Testname: ConfigMap Volume, with mapping64 Description: Create a ConfigMap, create a Pod that mounts a volume and populates the volume with data stored in the ConfigMap. Files are mapped to a path in the volume. The ConfigMap that is created MUST be accessible to read from the newly created Pod using the volume mount. The data content of the file MUST be readable and verified and file modes MUST default to 0x644.65 */66 framework.ConformanceIt("should be consumable from pods in volume with mappings [NodeConformance]", func() {67 doConfigMapE2EWithMappings(f, 0, 0, nil)68 })69 /*70 Release : v1.971 Testname: ConfigMap Volume, with mapping, volume mode set72 Description: Create a ConfigMap, create a Pod that mounts a volume and populates the volume with data stored in the ConfigMap. Files are mapped to a path in the volume. File mode is changed to a custom value of '0x400'. The ConfigMap that is created MUST be accessible to read from the newly created Pod using the volume mount. The data content of the file MUST be readable and verified and file modes MUST be set to the custom value of ‘0x400’73 This test is marked LinuxOnly since Windows does not support setting specific file permissions.74 */75 framework.ConformanceIt("should be consumable from pods in volume with mappings and Item mode set [LinuxOnly] [NodeConformance]", func() {76 mode := int32(0400)77 doConfigMapE2EWithMappings(f, 0, 0, &mode)78 })79 /*80 Release : v1.981 Testname: ConfigMap Volume, with mapping, non-root user82 Description: Create a ConfigMap, create a Pod that mounts a volume and populates the volume with data stored in the ConfigMap. Files are mapped to a path in the volume. Pod is run as a non-root user with uid=1000. The ConfigMap that is created MUST be accessible to read from the newly created Pod using the volume mount. The file on the volume MUST have file mode set to default value of 0x644.83 This test is marked LinuxOnly since Windows does not support running as UID / GID.84 */85 framework.ConformanceIt("should be consumable from pods in volume with mappings as non-root [LinuxOnly] [NodeConformance]", func() {86 doConfigMapE2EWithMappings(f, 1000, 0, nil)87 })88 It("should be consumable from pods in volume with mappings as non-root with FSGroup [NodeFeature:FSGroup]", func() {89 doConfigMapE2EWithMappings(f, 1000, 1001, nil)90 })91 /*92 Release : v1.993 Testname: ConfigMap Volume, update94 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.95 */96 framework.ConformanceIt("updates should be reflected in volume [NodeConformance]", func() {97 podLogTimeout := framework.GetPodSecretUpdateTimeout(f.ClientSet)98 containerTimeoutArg := fmt.Sprintf("--retry_time=%v", int(podLogTimeout.Seconds()))99 name := "configmap-test-upd-" + string(uuid.NewUUID())100 volumeName := "configmap-volume"101 volumeMountPath := "/etc/configmap-volume"102 containerName := "configmap-volume-test"103 configMap := &v1.ConfigMap{104 ObjectMeta: metav1.ObjectMeta{105 Namespace: f.Namespace.Name,106 Name: name,107 },108 Data: map[string]string{109 "data-1": "value-1",110 },111 }112 By(fmt.Sprintf("Creating configMap with name %s", configMap.Name))113 var err error114 if configMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(configMap); err != nil {115 framework.Failf("unable to create test configMap %s: %v", configMap.Name, err)116 }117 pod := &v1.Pod{118 ObjectMeta: metav1.ObjectMeta{119 Name: "pod-configmaps-" + string(uuid.NewUUID()),120 },121 Spec: v1.PodSpec{122 Volumes: []v1.Volume{123 {124 Name: volumeName,125 VolumeSource: v1.VolumeSource{126 ConfigMap: &v1.ConfigMapVolumeSource{127 LocalObjectReference: v1.LocalObjectReference{128 Name: name,129 },130 },131 },132 },133 },134 Containers: []v1.Container{135 {136 Name: containerName,137 Image: imageutils.GetE2EImage(imageutils.Mounttest),138 Command: []string{"/mounttest", "--break_on_expected_content=false", containerTimeoutArg, "--file_content_in_loop=/etc/configmap-volume/data-1"},139 VolumeMounts: []v1.VolumeMount{140 {141 Name: volumeName,142 MountPath: volumeMountPath,143 ReadOnly: true,144 },145 },146 },147 },148 RestartPolicy: v1.RestartPolicyNever,149 },150 }151 By("Creating the pod")152 f.PodClient().CreateSync(pod)153 pollLogs := func() (string, error) {154 return framework.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, containerName)155 }156 Eventually(pollLogs, podLogTimeout, framework.Poll).Should(ContainSubstring("value-1"))157 By(fmt.Sprintf("Updating configmap %v", configMap.Name))158 configMap.ResourceVersion = "" // to force update159 configMap.Data["data-1"] = "value-2"160 _, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Update(configMap)161 framework.ExpectNoError(err, "Failed to update configmap %q in namespace %q", configMap.Name, f.Namespace.Name)162 By("waiting to observe update in volume")163 Eventually(pollLogs, podLogTimeout, framework.Poll).Should(ContainSubstring("value-2"))164 })165 /*166 Release: v1.12167 Testname: ConfigMap Volume, text data, binary data168 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.169 */170 framework.ConformanceIt("binary data should be reflected in volume [NodeConformance]", func() {171 podLogTimeout := framework.GetPodSecretUpdateTimeout(f.ClientSet)172 containerTimeoutArg := fmt.Sprintf("--retry_time=%v", int(podLogTimeout.Seconds()))173 name := "configmap-test-upd-" + string(uuid.NewUUID())174 volumeName := "configmap-volume"175 volumeMountPath := "/etc/configmap-volume"176 containerName1 := "configmap-volume-data-test"177 containerName2 := "configmap-volume-binary-test"178 configMap := &v1.ConfigMap{179 ObjectMeta: metav1.ObjectMeta{180 Namespace: f.Namespace.Name,181 Name: name,182 },183 Data: map[string]string{184 "data-1": "value-1",185 },186 BinaryData: map[string][]byte{187 "dump.bin": {0xde, 0xca, 0xfe, 0xba, 0xd0, 0xfe, 0xff},188 },189 }190 By(fmt.Sprintf("Creating configMap with name %s", configMap.Name))191 var err error192 if configMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(configMap); err != nil {193 framework.Failf("unable to create test configMap %s: %v", configMap.Name, err)194 }195 pod := &v1.Pod{196 ObjectMeta: metav1.ObjectMeta{197 Name: "pod-configmaps-" + string(uuid.NewUUID()),198 },199 Spec: v1.PodSpec{200 Volumes: []v1.Volume{201 {202 Name: volumeName,203 VolumeSource: v1.VolumeSource{204 ConfigMap: &v1.ConfigMapVolumeSource{205 LocalObjectReference: v1.LocalObjectReference{206 Name: name,207 },208 },209 },210 },211 },212 Containers: []v1.Container{213 {214 Name: containerName1,215 Image: imageutils.GetE2EImage(imageutils.Mounttest),216 Command: []string{"/mounttest", "--break_on_expected_content=false", containerTimeoutArg, "--file_content_in_loop=/etc/configmap-volume/data-1"},217 VolumeMounts: []v1.VolumeMount{218 {219 Name: volumeName,220 MountPath: volumeMountPath,221 ReadOnly: true,222 },223 },224 },225 {226 Name: containerName2,227 Image: imageutils.GetE2EImage(imageutils.BusyBox),228 Command: []string{"hexdump", "-C", "/etc/configmap-volume/dump.bin"},229 VolumeMounts: []v1.VolumeMount{230 {231 Name: volumeName,232 MountPath: volumeMountPath,233 ReadOnly: true,234 },235 },236 },237 },238 RestartPolicy: v1.RestartPolicyNever,239 },240 }241 By("Creating the pod")242 f.PodClient().CreateSync(pod)243 pollLogs1 := func() (string, error) {244 return framework.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, containerName1)245 }246 pollLogs2 := func() (string, error) {247 return framework.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, containerName2)248 }249 By("Waiting for pod with text data")250 Eventually(pollLogs1, podLogTimeout, framework.Poll).Should(ContainSubstring("value-1"))251 By("Waiting for pod with binary data")252 Eventually(pollLogs2, podLogTimeout, framework.Poll).Should(ContainSubstring("de ca fe ba d0 fe ff"))253 })254 /*255 Release : v1.9256 Testname: ConfigMap Volume, create, update and delete257 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).258 */259 framework.ConformanceIt("optional updates should be reflected in volume [NodeConformance]", func() {260 podLogTimeout := framework.GetPodSecretUpdateTimeout(f.ClientSet)261 containerTimeoutArg := fmt.Sprintf("--retry_time=%v", int(podLogTimeout.Seconds()))262 trueVal := true263 volumeMountPath := "/etc/configmap-volumes"264 deleteName := "cm-test-opt-del-" + string(uuid.NewUUID())265 deleteContainerName := "delcm-volume-test"266 deleteVolumeName := "deletecm-volume"267 deleteConfigMap := &v1.ConfigMap{268 ObjectMeta: metav1.ObjectMeta{269 Namespace: f.Namespace.Name,270 Name: deleteName,271 },272 Data: map[string]string{273 "data-1": "value-1",274 },275 }276 updateName := "cm-test-opt-upd-" + string(uuid.NewUUID())277 updateContainerName := "updcm-volume-test"278 updateVolumeName := "updatecm-volume"279 updateConfigMap := &v1.ConfigMap{280 ObjectMeta: metav1.ObjectMeta{281 Namespace: f.Namespace.Name,282 Name: updateName,283 },284 Data: map[string]string{285 "data-1": "value-1",286 },287 }288 createName := "cm-test-opt-create-" + string(uuid.NewUUID())289 createContainerName := "createcm-volume-test"290 createVolumeName := "createcm-volume"291 createConfigMap := &v1.ConfigMap{292 ObjectMeta: metav1.ObjectMeta{293 Namespace: f.Namespace.Name,294 Name: createName,295 },296 Data: map[string]string{297 "data-1": "value-1",298 },299 }300 By(fmt.Sprintf("Creating configMap with name %s", deleteConfigMap.Name))301 var err error302 if deleteConfigMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(deleteConfigMap); err != nil {303 framework.Failf("unable to create test configMap %s: %v", deleteConfigMap.Name, err)304 }305 By(fmt.Sprintf("Creating configMap with name %s", updateConfigMap.Name))306 if updateConfigMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(updateConfigMap); err != nil {307 framework.Failf("unable to create test configMap %s: %v", updateConfigMap.Name, err)308 }309 pod := &v1.Pod{310 ObjectMeta: metav1.ObjectMeta{311 Name: "pod-configmaps-" + string(uuid.NewUUID()),312 },313 Spec: v1.PodSpec{314 Volumes: []v1.Volume{315 {316 Name: deleteVolumeName,317 VolumeSource: v1.VolumeSource{318 ConfigMap: &v1.ConfigMapVolumeSource{319 LocalObjectReference: v1.LocalObjectReference{320 Name: deleteName,321 },322 Optional: &trueVal,323 },324 },325 },326 {327 Name: updateVolumeName,328 VolumeSource: v1.VolumeSource{329 ConfigMap: &v1.ConfigMapVolumeSource{330 LocalObjectReference: v1.LocalObjectReference{331 Name: updateName,332 },333 Optional: &trueVal,334 },335 },336 },337 {338 Name: createVolumeName,339 VolumeSource: v1.VolumeSource{340 ConfigMap: &v1.ConfigMapVolumeSource{341 LocalObjectReference: v1.LocalObjectReference{342 Name: createName,343 },344 Optional: &trueVal,345 },346 },347 },348 },349 Containers: []v1.Container{350 {351 Name: deleteContainerName,352 Image: imageutils.GetE2EImage(imageutils.Mounttest),353 Command: []string{"/mounttest", "--break_on_expected_content=false", containerTimeoutArg, "--file_content_in_loop=/etc/configmap-volumes/delete/data-1"},354 VolumeMounts: []v1.VolumeMount{355 {356 Name: deleteVolumeName,357 MountPath: path.Join(volumeMountPath, "delete"),358 ReadOnly: true,359 },360 },361 },362 {363 Name: updateContainerName,364 Image: imageutils.GetE2EImage(imageutils.Mounttest),365 Command: []string{"/mounttest", "--break_on_expected_content=false", containerTimeoutArg, "--file_content_in_loop=/etc/configmap-volumes/update/data-3"},366 VolumeMounts: []v1.VolumeMount{367 {368 Name: updateVolumeName,369 MountPath: path.Join(volumeMountPath, "update"),370 ReadOnly: true,371 },372 },373 },374 {375 Name: createContainerName,376 Image: imageutils.GetE2EImage(imageutils.Mounttest),377 Command: []string{"/mounttest", "--break_on_expected_content=false", containerTimeoutArg, "--file_content_in_loop=/etc/configmap-volumes/create/data-1"},378 VolumeMounts: []v1.VolumeMount{379 {380 Name: createVolumeName,381 MountPath: path.Join(volumeMountPath, "create"),382 ReadOnly: true,383 },384 },385 },386 },387 RestartPolicy: v1.RestartPolicyNever,388 },389 }390 By("Creating the pod")391 f.PodClient().CreateSync(pod)392 pollCreateLogs := func() (string, error) {393 return framework.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, createContainerName)394 }395 Eventually(pollCreateLogs, podLogTimeout, framework.Poll).Should(ContainSubstring("Error reading file /etc/configmap-volumes/create/data-1"))396 pollUpdateLogs := func() (string, error) {397 return framework.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, updateContainerName)398 }399 Eventually(pollUpdateLogs, podLogTimeout, framework.Poll).Should(ContainSubstring("Error reading file /etc/configmap-volumes/update/data-3"))400 pollDeleteLogs := func() (string, error) {401 return framework.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, deleteContainerName)402 }403 Eventually(pollDeleteLogs, podLogTimeout, framework.Poll).Should(ContainSubstring("value-1"))404 By(fmt.Sprintf("Deleting configmap %v", deleteConfigMap.Name))405 err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Delete(deleteConfigMap.Name, &metav1.DeleteOptions{})406 framework.ExpectNoError(err, "Failed to delete configmap %q in namespace %q", deleteConfigMap.Name, f.Namespace.Name)407 By(fmt.Sprintf("Updating configmap %v", updateConfigMap.Name))408 updateConfigMap.ResourceVersion = "" // to force update409 delete(updateConfigMap.Data, "data-1")410 updateConfigMap.Data["data-3"] = "value-3"411 _, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Update(updateConfigMap)412 framework.ExpectNoError(err, "Failed to update configmap %q in namespace %q", updateConfigMap.Name, f.Namespace.Name)413 By(fmt.Sprintf("Creating configMap with name %s", createConfigMap.Name))414 if createConfigMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(createConfigMap); err != nil {415 framework.Failf("unable to create test configMap %s: %v", createConfigMap.Name, err)416 }417 By("waiting to observe update in volume")418 Eventually(pollCreateLogs, podLogTimeout, framework.Poll).Should(ContainSubstring("value-1"))419 Eventually(pollUpdateLogs, podLogTimeout, framework.Poll).Should(ContainSubstring("value-3"))420 Eventually(pollDeleteLogs, podLogTimeout, framework.Poll).Should(ContainSubstring("Error reading file /etc/configmap-volumes/delete/data-1"))421 })422 /*423 Release : v1.9424 Testname: ConfigMap Volume, multiple volume maps425 Description: The ConfigMap that is created MUST be accessible to read from the newly created Pod using the volume mount that is mapped to multiple paths in the Pod. The content MUST be accessible from all the mapped volume mounts.426 */427 framework.ConformanceIt("should be consumable in multiple volumes in the same pod [NodeConformance]", func() {428 var (429 name = "configmap-test-volume-" + string(uuid.NewUUID())430 volumeName = "configmap-volume"431 volumeMountPath = "/etc/configmap-volume"432 volumeName2 = "configmap-volume-2"433 volumeMountPath2 = "/etc/configmap-volume-2"434 configMap = newConfigMap(f, name)435 )436 By(fmt.Sprintf("Creating configMap with name %s", configMap.Name))437 var err error438 if configMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(configMap); err != nil {439 framework.Failf("unable to create test configMap %s: %v", configMap.Name, err)440 }441 pod := &v1.Pod{442 ObjectMeta: metav1.ObjectMeta{443 Name: "pod-configmaps-" + string(uuid.NewUUID()),444 },445 Spec: v1.PodSpec{446 Volumes: []v1.Volume{447 {448 Name: volumeName,449 VolumeSource: v1.VolumeSource{450 ConfigMap: &v1.ConfigMapVolumeSource{451 LocalObjectReference: v1.LocalObjectReference{452 Name: name,453 },454 },455 },456 },457 {458 Name: volumeName2,459 VolumeSource: v1.VolumeSource{460 ConfigMap: &v1.ConfigMapVolumeSource{461 LocalObjectReference: v1.LocalObjectReference{462 Name: name,463 },464 },465 },466 },467 },468 Containers: []v1.Container{469 {470 Name: "configmap-volume-test",471 Image: imageutils.GetE2EImage(imageutils.Mounttest),472 Args: []string{"--file_content=/etc/configmap-volume/data-1"},473 VolumeMounts: []v1.VolumeMount{474 {475 Name: volumeName,476 MountPath: volumeMountPath,477 ReadOnly: true,478 },479 {480 Name: volumeName2,481 MountPath: volumeMountPath2,482 ReadOnly: true,483 },484 },485 },486 },487 RestartPolicy: v1.RestartPolicyNever,488 },489 }490 f.TestContainerOutput("consume configMaps", pod, 0, []string{491 "content of file \"/etc/configmap-volume/data-1\": value-1",492 })493 })494 //The pod is in pending during volume creation until the configMap objects are available495 //or until mount the configMap volume times out. There is no configMap object defined for the pod, so it should return timout exception unless it is marked optional.496 //Slow (~5 mins)497 It("Should fail non-optional pod creation due to configMap object does not exist [Slow]", func() {498 volumeMountPath := "/etc/configmap-volumes"499 podName := "pod-configmaps-" + string(uuid.NewUUID())500 err := createNonOptionalConfigMapPod(f, volumeMountPath, podName)501 framework.ExpectError(err, "created pod %q with non-optional configMap in namespace %q", podName, f.Namespace.Name)502 })503 //ConfigMap object defined for the pod, If a key is specified which is not present in the ConfigMap,504 // the volume setup will error unless it is marked optional, during the pod creation.505 //Slow (~5 mins)506 It("Should fail non-optional pod creation due to the key in the configMap object does not exist [Slow]", func() {507 volumeMountPath := "/etc/configmap-volumes"508 podName := "pod-configmaps-" + string(uuid.NewUUID())509 err := createNonOptionalConfigMapPodWithConfig(f, volumeMountPath, podName)510 framework.ExpectError(err, "created pod %q with non-optional configMap in namespace %q", podName, f.Namespace.Name)511 })512})513func newConfigMap(f *framework.Framework, name string) *v1.ConfigMap {514 return &v1.ConfigMap{515 ObjectMeta: metav1.ObjectMeta{516 Namespace: f.Namespace.Name,517 Name: name,518 },519 Data: map[string]string{520 "data-1": "value-1",521 "data-2": "value-2",522 "data-3": "value-3",523 },524 }525}526func doConfigMapE2EWithoutMappings(f *framework.Framework, uid, fsGroup int64, defaultMode *int32) {527 userID := int64(uid)528 groupID := int64(fsGroup)529 var (530 name = "configmap-test-volume-" + string(uuid.NewUUID())531 volumeName = "configmap-volume"532 volumeMountPath = "/etc/configmap-volume"533 configMap = newConfigMap(f, name)534 )535 By(fmt.Sprintf("Creating configMap with name %s", configMap.Name))536 var err error537 if configMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(configMap); err != nil {538 framework.Failf("unable to create test configMap %s: %v", configMap.Name, err)539 }540 one := int64(1)541 pod := &v1.Pod{542 ObjectMeta: metav1.ObjectMeta{543 Name: "pod-configmaps-" + string(uuid.NewUUID()),544 },545 Spec: v1.PodSpec{546 SecurityContext: &v1.PodSecurityContext{},547 Volumes: []v1.Volume{548 {549 Name: volumeName,550 VolumeSource: v1.VolumeSource{551 ConfigMap: &v1.ConfigMapVolumeSource{552 LocalObjectReference: v1.LocalObjectReference{553 Name: name,554 },555 },556 },557 },558 },559 Containers: []v1.Container{560 {561 Name: "configmap-volume-test",562 Image: imageutils.GetE2EImage(imageutils.Mounttest),563 Args: []string{564 "--file_content=/etc/configmap-volume/data-1",565 "--file_mode=/etc/configmap-volume/data-1"},566 VolumeMounts: []v1.VolumeMount{567 {568 Name: volumeName,569 MountPath: volumeMountPath,570 },571 },572 },573 },574 RestartPolicy: v1.RestartPolicyNever,575 TerminationGracePeriodSeconds: &one,576 },577 }578 if userID != 0 {579 pod.Spec.SecurityContext.RunAsUser = &userID580 }581 if groupID != 0 {582 pod.Spec.SecurityContext.FSGroup = &groupID583 }584 if defaultMode != nil {585 pod.Spec.Volumes[0].VolumeSource.ConfigMap.DefaultMode = defaultMode586 }587 fileModeRegexp := framework.GetFileModeRegex("/etc/configmap-volume/data-1", defaultMode)588 output := []string{589 "content of file \"/etc/configmap-volume/data-1\": value-1",590 fileModeRegexp,591 }592 f.TestContainerOutputRegexp("consume configMaps", pod, 0, output)593}594func doConfigMapE2EWithMappings(f *framework.Framework, uid, fsGroup int64, itemMode *int32) {595 userID := int64(uid)596 groupID := int64(fsGroup)597 var (598 name = "configmap-test-volume-map-" + string(uuid.NewUUID())599 volumeName = "configmap-volume"600 volumeMountPath = "/etc/configmap-volume"601 configMap = newConfigMap(f, name)602 )603 By(fmt.Sprintf("Creating configMap with name %s", configMap.Name))604 var err error605 if configMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(configMap); err != nil {606 framework.Failf("unable to create test configMap %s: %v", configMap.Name, err)607 }608 one := int64(1)609 pod := &v1.Pod{610 ObjectMeta: metav1.ObjectMeta{611 Name: "pod-configmaps-" + string(uuid.NewUUID()),612 },613 Spec: v1.PodSpec{614 SecurityContext: &v1.PodSecurityContext{},615 Volumes: []v1.Volume{616 {617 Name: volumeName,618 VolumeSource: v1.VolumeSource{619 ConfigMap: &v1.ConfigMapVolumeSource{620 LocalObjectReference: v1.LocalObjectReference{621 Name: name,622 },623 Items: []v1.KeyToPath{624 {625 Key: "data-2",626 Path: "path/to/data-2",627 },628 },629 },630 },631 },632 },633 Containers: []v1.Container{634 {635 Name: "configmap-volume-test",636 Image: imageutils.GetE2EImage(imageutils.Mounttest),637 Args: []string{"--file_content=/etc/configmap-volume/path/to/data-2",638 "--file_mode=/etc/configmap-volume/path/to/data-2"},639 VolumeMounts: []v1.VolumeMount{640 {641 Name: volumeName,642 MountPath: volumeMountPath,643 ReadOnly: true,644 },645 },646 },647 },648 RestartPolicy: v1.RestartPolicyNever,649 TerminationGracePeriodSeconds: &one,650 },651 }652 if userID != 0 {653 pod.Spec.SecurityContext.RunAsUser = &userID654 }655 if groupID != 0 {656 pod.Spec.SecurityContext.FSGroup = &groupID657 }658 if itemMode != nil {659 pod.Spec.Volumes[0].VolumeSource.ConfigMap.Items[0].Mode = itemMode660 }661 // Just check file mode if fsGroup is not set. If fsGroup is set, the662 // final mode is adjusted and we are not testing that case.663 output := []string{664 "content of file \"/etc/configmap-volume/path/to/data-2\": value-2",665 }666 if fsGroup == 0 {667 fileModeRegexp := framework.GetFileModeRegex("/etc/configmap-volume/path/to/data-2", itemMode)668 output = append(output, fileModeRegexp)669 }670 f.TestContainerOutputRegexp("consume configMaps", pod, 0, output)671}672func createNonOptionalConfigMapPod(f *framework.Framework, volumeMountPath, podName string) error {673 podLogTimeout := framework.GetPodSecretUpdateTimeout(f.ClientSet)674 containerTimeoutArg := fmt.Sprintf("--retry_time=%v", int(podLogTimeout.Seconds()))675 falseValue := false676 createName := "cm-test-opt-create-" + string(uuid.NewUUID())677 createContainerName := "createcm-volume-test"678 createVolumeName := "createcm-volume"679 //creating a pod without configMap object created, by mentioning the configMap volume source's local reference name680 pod := &v1.Pod{681 ObjectMeta: metav1.ObjectMeta{682 Name: podName,683 },684 Spec: v1.PodSpec{685 Volumes: []v1.Volume{686 {687 Name: createVolumeName,688 VolumeSource: v1.VolumeSource{689 ConfigMap: &v1.ConfigMapVolumeSource{690 LocalObjectReference: v1.LocalObjectReference{691 Name: createName,692 },693 Optional: &falseValue,694 },695 },696 },697 },698 Containers: []v1.Container{699 {700 Name: createContainerName,701 Image: imageutils.GetE2EImage(imageutils.Mounttest),702 Command: []string{"/mounttest", "--break_on_expected_content=false", containerTimeoutArg, "--file_content_in_loop=/etc/configmap-volumes/create/data-1"},703 VolumeMounts: []v1.VolumeMount{704 {705 Name: createVolumeName,706 MountPath: path.Join(volumeMountPath, "create"),707 ReadOnly: true,708 },709 },710 },711 },712 RestartPolicy: v1.RestartPolicyNever,713 },714 }715 By("Creating the pod")716 pod = f.PodClient().Create(pod)717 return f.WaitForPodRunning(pod.Name)718}719func createNonOptionalConfigMapPodWithConfig(f *framework.Framework, volumeMountPath, podName string) error {720 podLogTimeout := framework.GetPodSecretUpdateTimeout(f.ClientSet)721 containerTimeoutArg := fmt.Sprintf("--retry_time=%v", int(podLogTimeout.Seconds()))722 falseValue := false723 createName := "cm-test-opt-create-" + string(uuid.NewUUID())724 createContainerName := "createcm-volume-test"725 createVolumeName := "createcm-volume"726 configMap := newConfigMap(f, createName)727 By(fmt.Sprintf("Creating configMap with name %s", configMap.Name))728 var err error729 if configMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(configMap); err != nil {730 framework.Failf("unable to create test configMap %s: %v", configMap.Name, err)731 }732 //creating a pod with configMap object, but with different key which is not present in configMap object.733 pod := &v1.Pod{734 ObjectMeta: metav1.ObjectMeta{735 Name: podName,736 },737 Spec: v1.PodSpec{738 Volumes: []v1.Volume{739 {740 Name: createVolumeName,741 VolumeSource: v1.VolumeSource{742 ConfigMap: &v1.ConfigMapVolumeSource{743 LocalObjectReference: v1.LocalObjectReference{744 Name: createName,745 },746 Items: []v1.KeyToPath{747 {748 Key: "data-4",749 Path: "path/to/data-4",750 },751 },752 Optional: &falseValue,753 },754 },755 },756 },757 Containers: []v1.Container{758 {759 Name: createContainerName,760 Image: imageutils.GetE2EImage(imageutils.Mounttest),761 Command: []string{"/mounttest", "--break_on_expected_content=false", containerTimeoutArg, "--file_content_in_loop=/etc/configmap-volumes/create/data-1"},762 VolumeMounts: []v1.VolumeMount{763 {764 Name: createVolumeName,765 MountPath: path.Join(volumeMountPath, "create"),766 ReadOnly: true,767 },768 },769 },770 },771 RestartPolicy: v1.RestartPolicyNever,772 },773 }774 By("Creating the pod")775 pod = f.PodClient().Create(pod)776 return f.WaitForPodRunning(pod.Name)777}...

Full Screen

Full Screen

projected_configmap.go

Source:projected_configmap.go Github

copy

Full Screen

...110 },111 }112 ginkgo.By(fmt.Sprintf("Creating projection with configMap that has name %s", configMap.Name))113 var err error114 if configMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(configMap); err != nil {115 framework.Failf("unable to create test configMap %s: %v", configMap.Name, err)116 }117 pod := &v1.Pod{118 ObjectMeta: metav1.ObjectMeta{119 Name: "pod-projected-configmaps-" + string(uuid.NewUUID()),120 },121 Spec: v1.PodSpec{122 Volumes: []v1.Volume{123 {124 Name: volumeName,125 VolumeSource: v1.VolumeSource{126 Projected: &v1.ProjectedVolumeSource{127 Sources: []v1.VolumeProjection{128 {129 ConfigMap: &v1.ConfigMapProjection{130 LocalObjectReference: v1.LocalObjectReference{131 Name: name,132 },133 },134 },135 },136 },137 },138 },139 },140 Containers: []v1.Container{141 {142 Name: containerName,143 Image: imageutils.GetE2EImage(imageutils.Mounttest),144 Command: []string{"/mounttest", "--break_on_expected_content=false", containerTimeoutArg, "--file_content_in_loop=/etc/projected-configmap-volume/data-1"},145 VolumeMounts: []v1.VolumeMount{146 {147 Name: volumeName,148 MountPath: volumeMountPath,149 ReadOnly: true,150 },151 },152 },153 },154 RestartPolicy: v1.RestartPolicyNever,155 },156 }157 ginkgo.By("Creating the pod")158 f.PodClient().CreateSync(pod)159 pollLogs := func() (string, error) {160 return framework.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, containerName)161 }162 gomega.Eventually(pollLogs, podLogTimeout, framework.Poll).Should(gomega.ContainSubstring("value-1"))163 ginkgo.By(fmt.Sprintf("Updating configmap %v", configMap.Name))164 configMap.ResourceVersion = "" // to force update165 configMap.Data["data-1"] = "value-2"166 _, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Update(configMap)167 framework.ExpectNoError(err, "Failed to update configmap %q in namespace %q", configMap.Name, f.Namespace.Name)168 ginkgo.By("waiting to observe update in volume")169 gomega.Eventually(pollLogs, podLogTimeout, framework.Poll).Should(gomega.ContainSubstring("value-2"))170 })171 /*172 Release : v1.9173 Testname: Projected Volume, ConfigMap, create, update and delete174 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.175 */176 framework.ConformanceIt("optional updates should be reflected in volume [NodeConformance]", func() {177 podLogTimeout := framework.GetPodSecretUpdateTimeout(f.ClientSet)178 containerTimeoutArg := fmt.Sprintf("--retry_time=%v", int(podLogTimeout.Seconds()))179 trueVal := true180 volumeMountPath := "/etc/projected-configmap-volumes"181 deleteName := "cm-test-opt-del-" + string(uuid.NewUUID())182 deleteContainerName := "delcm-volume-test"183 deleteVolumeName := "deletecm-volume"184 deleteConfigMap := &v1.ConfigMap{185 ObjectMeta: metav1.ObjectMeta{186 Namespace: f.Namespace.Name,187 Name: deleteName,188 },189 Data: map[string]string{190 "data-1": "value-1",191 },192 }193 updateName := "cm-test-opt-upd-" + string(uuid.NewUUID())194 updateContainerName := "updcm-volume-test"195 updateVolumeName := "updatecm-volume"196 updateConfigMap := &v1.ConfigMap{197 ObjectMeta: metav1.ObjectMeta{198 Namespace: f.Namespace.Name,199 Name: updateName,200 },201 Data: map[string]string{202 "data-1": "value-1",203 },204 }205 createName := "cm-test-opt-create-" + string(uuid.NewUUID())206 createContainerName := "createcm-volume-test"207 createVolumeName := "createcm-volume"208 createConfigMap := &v1.ConfigMap{209 ObjectMeta: metav1.ObjectMeta{210 Namespace: f.Namespace.Name,211 Name: createName,212 },213 Data: map[string]string{214 "data-1": "value-1",215 },216 }217 ginkgo.By(fmt.Sprintf("Creating configMap with name %s", deleteConfigMap.Name))218 var err error219 if deleteConfigMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(deleteConfigMap); err != nil {220 framework.Failf("unable to create test configMap %s: %v", deleteConfigMap.Name, err)221 }222 ginkgo.By(fmt.Sprintf("Creating configMap with name %s", updateConfigMap.Name))223 if updateConfigMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(updateConfigMap); err != nil {224 framework.Failf("unable to create test configMap %s: %v", updateConfigMap.Name, err)225 }226 pod := &v1.Pod{227 ObjectMeta: metav1.ObjectMeta{228 Name: "pod-projected-configmaps-" + string(uuid.NewUUID()),229 },230 Spec: v1.PodSpec{231 Volumes: []v1.Volume{232 {233 Name: deleteVolumeName,234 VolumeSource: v1.VolumeSource{235 Projected: &v1.ProjectedVolumeSource{236 Sources: []v1.VolumeProjection{237 {238 ConfigMap: &v1.ConfigMapProjection{239 LocalObjectReference: v1.LocalObjectReference{240 Name: deleteName,241 },242 Optional: &trueVal,243 },244 },245 },246 },247 },248 },249 {250 Name: updateVolumeName,251 VolumeSource: v1.VolumeSource{252 Projected: &v1.ProjectedVolumeSource{253 Sources: []v1.VolumeProjection{254 {255 ConfigMap: &v1.ConfigMapProjection{256 LocalObjectReference: v1.LocalObjectReference{257 Name: updateName,258 },259 Optional: &trueVal,260 },261 },262 },263 },264 },265 },266 {267 Name: createVolumeName,268 VolumeSource: v1.VolumeSource{269 Projected: &v1.ProjectedVolumeSource{270 Sources: []v1.VolumeProjection{271 {272 ConfigMap: &v1.ConfigMapProjection{273 LocalObjectReference: v1.LocalObjectReference{274 Name: createName,275 },276 Optional: &trueVal,277 },278 },279 },280 },281 },282 },283 },284 Containers: []v1.Container{285 {286 Name: deleteContainerName,287 Image: imageutils.GetE2EImage(imageutils.Mounttest),288 Command: []string{"/mounttest", "--break_on_expected_content=false", containerTimeoutArg, "--file_content_in_loop=/etc/projected-configmap-volumes/delete/data-1"},289 VolumeMounts: []v1.VolumeMount{290 {291 Name: deleteVolumeName,292 MountPath: path.Join(volumeMountPath, "delete"),293 ReadOnly: true,294 },295 },296 },297 {298 Name: updateContainerName,299 Image: imageutils.GetE2EImage(imageutils.Mounttest),300 Command: []string{"/mounttest", "--break_on_expected_content=false", containerTimeoutArg, "--file_content_in_loop=/etc/projected-configmap-volumes/update/data-3"},301 VolumeMounts: []v1.VolumeMount{302 {303 Name: updateVolumeName,304 MountPath: path.Join(volumeMountPath, "update"),305 ReadOnly: true,306 },307 },308 },309 {310 Name: createContainerName,311 Image: imageutils.GetE2EImage(imageutils.Mounttest),312 Command: []string{"/mounttest", "--break_on_expected_content=false", containerTimeoutArg, "--file_content_in_loop=/etc/projected-configmap-volumes/create/data-1"},313 VolumeMounts: []v1.VolumeMount{314 {315 Name: createVolumeName,316 MountPath: path.Join(volumeMountPath, "create"),317 ReadOnly: true,318 },319 },320 },321 },322 RestartPolicy: v1.RestartPolicyNever,323 },324 }325 ginkgo.By("Creating the pod")326 f.PodClient().CreateSync(pod)327 pollCreateLogs := func() (string, error) {328 return framework.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, createContainerName)329 }330 gomega.Eventually(pollCreateLogs, podLogTimeout, framework.Poll).Should(gomega.ContainSubstring("Error reading file /etc/projected-configmap-volumes/create/data-1"))331 pollUpdateLogs := func() (string, error) {332 return framework.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, updateContainerName)333 }334 gomega.Eventually(pollUpdateLogs, podLogTimeout, framework.Poll).Should(gomega.ContainSubstring("Error reading file /etc/projected-configmap-volumes/update/data-3"))335 pollDeleteLogs := func() (string, error) {336 return framework.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, deleteContainerName)337 }338 gomega.Eventually(pollDeleteLogs, podLogTimeout, framework.Poll).Should(gomega.ContainSubstring("value-1"))339 ginkgo.By(fmt.Sprintf("Deleting configmap %v", deleteConfigMap.Name))340 err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Delete(deleteConfigMap.Name, &metav1.DeleteOptions{})341 framework.ExpectNoError(err, "Failed to delete configmap %q in namespace %q", deleteConfigMap.Name, f.Namespace.Name)342 ginkgo.By(fmt.Sprintf("Updating configmap %v", updateConfigMap.Name))343 updateConfigMap.ResourceVersion = "" // to force update344 delete(updateConfigMap.Data, "data-1")345 updateConfigMap.Data["data-3"] = "value-3"346 _, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Update(updateConfigMap)347 framework.ExpectNoError(err, "Failed to update configmap %q in namespace %q", updateConfigMap.Name, f.Namespace.Name)348 ginkgo.By(fmt.Sprintf("Creating configMap with name %s", createConfigMap.Name))349 if createConfigMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(createConfigMap); err != nil {350 framework.Failf("unable to create test configMap %s: %v", createConfigMap.Name, err)351 }352 ginkgo.By("waiting to observe update in volume")353 gomega.Eventually(pollCreateLogs, podLogTimeout, framework.Poll).Should(gomega.ContainSubstring("value-1"))354 gomega.Eventually(pollUpdateLogs, podLogTimeout, framework.Poll).Should(gomega.ContainSubstring("value-3"))355 gomega.Eventually(pollDeleteLogs, podLogTimeout, framework.Poll).Should(gomega.ContainSubstring("Error reading file /etc/projected-configmap-volumes/delete/data-1"))356 })357 /*358 Release : v1.9359 Testname: Projected Volume, ConfigMap, multiple volume paths360 Description: A Pod is created with a projected volume source ‘ConfigMap’ to store a configMap. The configMap is mapped to two different volume mounts. Pod MUST be able to read the content of the configMap successfully from the two volume mounts.361 */362 framework.ConformanceIt("should be consumable in multiple volumes in the same pod [NodeConformance]", func() {363 var (364 name = "projected-configmap-test-volume-" + string(uuid.NewUUID())365 volumeName = "projected-configmap-volume"366 volumeMountPath = "/etc/projected-configmap-volume"367 volumeName2 = "projected-configmap-volume-2"368 volumeMountPath2 = "/etc/projected-configmap-volume-2"369 configMap = newConfigMap(f, name)370 )371 ginkgo.By(fmt.Sprintf("Creating configMap with name %s", configMap.Name))372 var err error373 if configMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(configMap); err != nil {374 framework.Failf("unable to create test configMap %s: %v", configMap.Name, err)375 }376 pod := &v1.Pod{377 ObjectMeta: metav1.ObjectMeta{378 Name: "pod-projected-configmaps-" + string(uuid.NewUUID()),379 },380 Spec: v1.PodSpec{381 Volumes: []v1.Volume{382 {383 Name: volumeName,384 VolumeSource: v1.VolumeSource{385 Projected: &v1.ProjectedVolumeSource{386 Sources: []v1.VolumeProjection{387 {388 ConfigMap: &v1.ConfigMapProjection{389 LocalObjectReference: v1.LocalObjectReference{390 Name: name,391 },392 },393 },394 },395 },396 },397 },398 {399 Name: volumeName2,400 VolumeSource: v1.VolumeSource{401 Projected: &v1.ProjectedVolumeSource{402 Sources: []v1.VolumeProjection{403 {404 ConfigMap: &v1.ConfigMapProjection{405 LocalObjectReference: v1.LocalObjectReference{406 Name: name,407 },408 },409 },410 },411 },412 },413 },414 },415 Containers: []v1.Container{416 {417 Name: "projected-configmap-volume-test",418 Image: imageutils.GetE2EImage(imageutils.Mounttest),419 Args: []string{"--file_content=/etc/projected-configmap-volume/data-1"},420 VolumeMounts: []v1.VolumeMount{421 {422 Name: volumeName,423 MountPath: volumeMountPath,424 ReadOnly: true,425 },426 {427 Name: volumeName2,428 MountPath: volumeMountPath2,429 ReadOnly: true,430 },431 },432 },433 },434 RestartPolicy: v1.RestartPolicyNever,435 },436 }437 f.TestContainerOutput("consume configMaps", pod, 0, []string{438 "content of file \"/etc/projected-configmap-volume/data-1\": value-1",439 })440 })441 //The pod is in pending during volume creation until the configMap objects are available442 //or until mount the configMap volume times out. There is no configMap object defined for the pod, so it should return timout exception unless it is marked optional.443 //Slow (~5 mins)444 ginkgo.It("Should fail non-optional pod creation due to configMap object does not exist [Slow]", func() {445 volumeMountPath := "/etc/projected-configmap-volumes"446 podName := "pod-projected-configmaps-" + string(uuid.NewUUID())447 err := createNonOptionalConfigMapPod(f, volumeMountPath, podName)448 framework.ExpectError(err, "created pod %q with non-optional configMap in namespace %q", podName, f.Namespace.Name)449 })450 //ConfigMap object defined for the pod, If a key is specified which is not present in the ConfigMap,451 // the volume setup will error unless it is marked optional, during the pod creation.452 //Slow (~5 mins)453 ginkgo.It("Should fail non-optional pod creation due to the key in the configMap object does not exist [Slow]", func() {454 volumeMountPath := "/etc/configmap-volumes"455 podName := "pod-configmaps-" + string(uuid.NewUUID())456 err := createNonOptionalConfigMapPodWithConfig(f, volumeMountPath, podName)457 framework.ExpectError(err, "created pod %q with non-optional configMap in namespace %q", podName, f.Namespace.Name)458 })459})460func doProjectedConfigMapE2EWithoutMappings(f *framework.Framework, uid, fsGroup int64, defaultMode *int32) {461 userID := int64(uid)462 groupID := int64(fsGroup)463 var (464 name = "projected-configmap-test-volume-" + string(uuid.NewUUID())465 volumeName = "projected-configmap-volume"466 volumeMountPath = "/etc/projected-configmap-volume"467 configMap = newConfigMap(f, name)468 )469 ginkgo.By(fmt.Sprintf("Creating configMap with name %s", configMap.Name))470 var err error471 if configMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(configMap); err != nil {472 framework.Failf("unable to create test configMap %s: %v", configMap.Name, err)473 }474 pod := &v1.Pod{475 ObjectMeta: metav1.ObjectMeta{476 Name: "pod-projected-configmaps-" + string(uuid.NewUUID()),477 },478 Spec: v1.PodSpec{479 SecurityContext: &v1.PodSecurityContext{},480 Volumes: []v1.Volume{481 {482 Name: volumeName,483 VolumeSource: v1.VolumeSource{484 Projected: &v1.ProjectedVolumeSource{485 Sources: []v1.VolumeProjection{486 {487 ConfigMap: &v1.ConfigMapProjection{488 LocalObjectReference: v1.LocalObjectReference{489 Name: name,490 },491 },492 },493 },494 },495 },496 },497 },498 Containers: []v1.Container{499 {500 Name: "projected-configmap-volume-test",501 Image: imageutils.GetE2EImage(imageutils.Mounttest),502 Args: []string{503 "--file_content=/etc/projected-configmap-volume/data-1",504 "--file_mode=/etc/projected-configmap-volume/data-1"},505 VolumeMounts: []v1.VolumeMount{506 {507 Name: volumeName,508 MountPath: volumeMountPath,509 },510 },511 },512 },513 RestartPolicy: v1.RestartPolicyNever,514 },515 }516 if userID != 0 {517 pod.Spec.SecurityContext.RunAsUser = &userID518 }519 if groupID != 0 {520 pod.Spec.SecurityContext.FSGroup = &groupID521 }522 if defaultMode != nil {523 //pod.Spec.Volumes[0].VolumeSource.Projected.Sources[0].ConfigMap.DefaultMode = defaultMode524 pod.Spec.Volumes[0].VolumeSource.Projected.DefaultMode = defaultMode525 }526 fileModeRegexp := framework.GetFileModeRegex("/etc/projected-configmap-volume/data-1", defaultMode)527 output := []string{528 "content of file \"/etc/projected-configmap-volume/data-1\": value-1",529 fileModeRegexp,530 }531 f.TestContainerOutputRegexp("consume configMaps", pod, 0, output)532}533func doProjectedConfigMapE2EWithMappings(f *framework.Framework, uid, fsGroup int64, itemMode *int32) {534 userID := int64(uid)535 groupID := int64(fsGroup)536 var (537 name = "projected-configmap-test-volume-map-" + string(uuid.NewUUID())538 volumeName = "projected-configmap-volume"539 volumeMountPath = "/etc/projected-configmap-volume"540 configMap = newConfigMap(f, name)541 )542 ginkgo.By(fmt.Sprintf("Creating configMap with name %s", configMap.Name))543 var err error544 if configMap, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(configMap); err != nil {545 framework.Failf("unable to create test configMap %s: %v", configMap.Name, err)546 }547 pod := &v1.Pod{548 ObjectMeta: metav1.ObjectMeta{549 Name: "pod-projected-configmaps-" + string(uuid.NewUUID()),550 },551 Spec: v1.PodSpec{552 SecurityContext: &v1.PodSecurityContext{},553 Volumes: []v1.Volume{554 {555 Name: volumeName,556 VolumeSource: v1.VolumeSource{557 Projected: &v1.ProjectedVolumeSource{558 Sources: []v1.VolumeProjection{...

Full Screen

Full Screen

Create

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 config, err := rest.InClusterConfig()4 if err != nil {5 panic(err.Error())6 }7 clientset, err := kubernetes.NewForConfig(config)8 if err != nil {9 panic(err.Error())10 }11 configmap, err := clientset.CoreV1().ConfigMaps("default").Create(context.TODO(), &v1.ConfigMap{12 ObjectMeta: metav1.ObjectMeta{13 },14 Data: map[string]string{15 },16 }, metav1.CreateOptions{})17 if err != nil {18 panic(err.Error())19 }20 fmt.Printf("Configmap created")21}22import (23func main() {24 config, err := rest.InClusterConfig()25 if err != nil {26 panic(err.Error())27 }28 clientset, err := kubernetes.NewForConfig(config)29 if err != nil {30 panic(err.Error())31 }32 configmap, err := clientset.CoreV1().ConfigMaps("default").Get(context.TODO(), "my-config", metav1.GetOptions{})33 if err != nil {34 panic(err.Error())35 }36 fmt.Printf("Configmap data: %v", configmap.Data)37}38import (39func main() {

Full Screen

Full Screen

Create

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 config, err := rest.InClusterConfig()4 if err != nil {5 if config, err = clientcmd.BuildConfigFromFlags("", os.Getenv("HOME")+"/.kube/config"); err != nil {6 panic(err.Error())7 }8 }9 clientset, err := kubernetes.NewForConfig(config)10 if err != nil {11 panic(err.Error())12 }13 configmap := &v1.ConfigMap{14 ObjectMeta: metav1.ObjectMeta{15 },16 Data: map[string]string{17 },18 }19 fmt.Println("Creating configmap...")20 result, err := clientset.CoreV1().ConfigMaps(namespace).Create(configmap)21 if err != nil {22 panic(err)23 }24 fmt.Printf("Created configmap %q.\n", result.GetObjectMeta().GetName())25}26import (27func main() {28 config, err := rest.InClusterConfig()29 if err != nil {30 if config, err = clientcmd.BuildConfigFromFlags("", os.Getenv("HOME")+"/.kube/config"); err != nil {31 panic(err.Error())32 }33 }34 clientset, err := kubernetes.NewForConfig(config)35 if err != nil {

Full Screen

Full Screen

Create

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 kubeconfig := filepath.Join(4 os.Getenv("HOME"), ".kube", "config",5 config, err = clientcmd.BuildConfigFromFlags("", kubeconfig)6 if err != nil {7 panic(err.Error())8 }9 clientset, err := kubernetes.NewForConfig(config)10 if err != nil {11 panic(err.Error())12 }13 configmap := &v1.ConfigMap{14 ObjectMeta: metav1.ObjectMeta{15 },16 Data: map[string]string{17 },18 }19 fmt.Println("Creating configmap...")20 result, err := clientset.CoreV1().ConfigMaps("default").Create(configmap)21 if err != nil {22 panic(err)23 }24 fmt.Printf("Created configmap %q.\n", result.GetObjectMeta().GetName())25}26import (27func main() {28 kubeconfig := filepath.Join(29 os.Getenv("HOME"), ".kube", "config",30 config, err = clientcmd.BuildConfigFromFlags("", kubeconfig)31 if err != nil {32 panic(err.Error())33 }34 clientset, err := kubernetes.NewForConfig(config)35 if err != nil {

Full Screen

Full Screen

Create

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if home := homedir.HomeDir(); home != "" {4 kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")5 } else {6 kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")7 }8 flag.Parse()9 config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)10 if err != nil {11 panic(err.Error())12 }13 clientset, err := kubernetes.NewForConfig(config)14 if err != nil {15 panic(err.Error())16 }17 cm := &v1.ConfigMap{18 ObjectMeta: metav1.ObjectMeta{19 },20 Data: map[string]string{21 },22 }23 _, err = clientset.CoreV1().ConfigMaps("default").Create(cm)24 if err != nil {25 panic(err.Error())26 }27 fmt.Println("Created ConfigMap")28}29import (30func main() {31 if home := homedir.HomeDir(); home != "" {32 kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config

Full Screen

Full Screen

Create

Using AI Code Generation

copy

Full Screen

1 fmt.Println("Creating configmap...")2 configMap := &v1.ConfigMap{3 ObjectMeta: metav1.ObjectMeta{4 },5 Data: map[string]string{6 },7 }8 result, err := clientset.CoreV1().ConfigMaps("default").Create(configMap)9 if err != nil {10 panic(err.Error())11 }12 fmt.Printf("Created configmap %q.\n", result.GetObjectMeta().GetName())13}

Full Screen

Full Screen

Create

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if home := homedir.HomeDir(); home != "" {4 kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")5 } else {6 kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")7 }8 config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)9 if err != nil {10 panic(err.Error())11 }12 clientset, err := kubernetes.NewForConfig(config)13 if err != nil {14 panic(err.Error())15 }16 configmap, err := clientset.CoreV1().ConfigMaps("default").Create(context.TODO(), &v1.ConfigMap{17 ObjectMeta: metav1.ObjectMeta{18 },19 Data: map[string]string{20 },21 }, metav1.CreateOptions{})22 if err != nil {23 panic(err.Error())24 }25 fmt.Printf("Created configmap %q.\n", configmap.GetObjectMeta().GetName())26}27import (28func main() {29 if home := homedir.HomeDir(); home != "" {30 kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")31 } else {

Full Screen

Full Screen

Create

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 filepath.Walk(".", func(path string, info os.FileInfo, err error) error {4 if strings.Contains(path, ".go") {5 fmt.Println(path)6 time.Sleep(1 * time.Second)7 }8 })9}10import (11func main() {12 filepath.Walk(".", func(path string, info os.FileInfo, err error) error {13 if strings.Contains(path, ".go") {14 fmt.Println(path)15 time.Sleep(1 * time.Second)16 }17 })18}19import (20func main() {21 filepath.Walk(".", func(path string, info os.FileInfo, err error) error {22 if strings.Contains(path, ".go") {23 fmt.Println(path)24 time.Sleep(1 * time.Second)25 }26 })27}28import (29func main() {30 filepath.Walk(".", func(path string, info os.FileInfo, err error) error {31 if strings.Contains(path, ".go") {32 fmt.Println(path)33 time.Sleep(1 * time.Second)34 }35 })36}37import (38func main() {39 filepath.Walk(".", func(path string, info os.FileInfo, err error) error {40 if strings.Contains(path, ".go") {41 fmt.Println(path)42 time.Sleep(1 * time.Second)43 }44 })45}46import (

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testkube automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful