Skip to content

Commit

Permalink
Add EnvironmentVariables to PodOptions (#1690)
Browse files Browse the repository at this point in the history
* Add utility to read file and directory from a pod

* Add copyright to new files

* Address review comments - fix error message and add comments

* Add Environment to PodOptions

* Add SecretMounts to PodOptions

* Add tests for new fields added to PodOptions

* Add function comment

* Revert file reader and SecretMounts implementation

* Remove stale test

* Remove stale code
  • Loading branch information
ankitjain235 committed Nov 11, 2022
1 parent 125a7a8 commit 246435b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/kube/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type PodOptions struct {
Resources v1.ResourceRequirements
RestartPolicy v1.RestartPolicy
OwnerReferences []metav1.OwnerReference
EnvironmentVariables []v1.EnvVar
}

func GetPodObjectFromPodOptions(cli kubernetes.Interface, opts *PodOptions) (*v1.Pod, error) {
Expand Down Expand Up @@ -109,6 +110,7 @@ func GetPodObjectFromPodOptions(cli kubernetes.Interface, opts *PodOptions) (*v1
ImagePullPolicy: v1.PullPolicy(v1.PullIfNotPresent),
VolumeMounts: volumeMounts,
Resources: opts.Resources,
Env: opts.EnvironmentVariables,
},
},
// RestartPolicy dictates when the containers of the pod should be
Expand Down
16 changes: 16 additions & 0 deletions pkg/kube/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ func (s *PodSuite) TestPod(c *C) {
"run": "pod",
},
},
{
Namespace: s.namespace,
GenerateName: "test-",
Image: consts.LatestKanisterToolsImage,
Command: []string{"sh", "-c", "tail -f /dev/null"},
EnvironmentVariables: []v1.EnvVar{
{
Name: "test-env",
Value: "test-value",
},
},
},
}

for _, po := range podOptions {
Expand Down Expand Up @@ -232,6 +244,10 @@ func (s *PodSuite) TestPod(c *C) {
c.Assert(pod.Spec.RestartPolicy, Equals, po.RestartPolicy)
}

if po.EnvironmentVariables != nil && len(po.EnvironmentVariables) > 0 {
c.Assert(pod.Spec.Containers[0].Env, DeepEquals, po.EnvironmentVariables)
}

c.Assert(err, IsNil)
c.Assert(WaitForPodReady(ctx, s.cli, po.Namespace, pod.Name), IsNil)
c.Assert(DeletePod(context.Background(), s.cli, pod), IsNil)
Expand Down

0 comments on commit 246435b

Please sign in to comment.