New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow env to be updated via specific key in resource #60040

Merged
merged 1 commit into from Feb 22, 2018

Conversation

@PhilipGough
Contributor

PhilipGough commented Feb 19, 2018

What this PR does / why we need it:

This change allows users of the oc client to specify a list of comma-separated keys when running oc set env which should be imported from a resource i.e configmap or secret

This can be useful when a number of applications want to share a configuration object but don't want to pollute a resource with unused environment

Release note:

Allow kubectl env to specify which keys to import from a config map
@soltysh

This comment has been minimized.

Contributor

soltysh commented Feb 19, 2018

/ok-to-test

@soltysh

I'm also missing a test case for the new functionality.

if o.List && len(o.Output) > 0 {
return cmdutil.UsageErrorf(o.Cmd, "--list and --output may not be specified together")
}
if len(o.Keys) > 0 && len(o.From) < 1 {

This comment has been minimized.

@soltysh

soltysh Feb 19, 2018

Contributor

len(o.From) == 0 is the preferred approach.

@@ -278,7 +293,15 @@ func (o *EnvOptions) RunEnv(f cmdutil.Factory) error {
},
},
}
env = append(env, envVar)
if len(o.Keys) > 0 {

This comment has been minimized.

@soltysh

soltysh Feb 19, 2018

Contributor

Can you make a helper out of it, instead of copy&pasting it for secret here and config map below.

@soltysh

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm label Feb 20, 2018

@soltysh

This comment has been minimized.

Contributor

soltysh commented Feb 20, 2018

/retest

@k8s-merge-robot k8s-merge-robot removed the lgtm label Feb 21, 2018

@soltysh

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm label Feb 21, 2018

@soltysh

This comment has been minimized.

Contributor

soltysh commented Feb 21, 2018

/assign @deads2k
for approval

if len(o.Filenames) == 0 && len(resources) < 1 {
return cmdutil.UsageErrorf(cmd, "one or more resources must be specified as <resource> <name> or <resource>/<name>")
func (o *EnvOptions) addEnvVarToList(key string, env []v1.EnvVar, envVar v1.EnvVar) []v1.EnvVar {
if len(o.Keys) > 0 {

This comment has been minimized.

@deads2k

deads2k Feb 21, 2018

Contributor

Seems weird to have the skip here. Why not skip down in the method iterating over keys? This feels like a function that sometimes disobeys me.

A contains(needle string, haystack []string) could hold this logic.

This comment has been minimized.

@PhilipGough

PhilipGough Feb 22, 2018

Contributor

Originally had the code where we iterate over the keys, but was asked to move it to a helper since it was repeated for both configmap and secret

@soltysh

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm label Feb 22, 2018

@deads2k

This comment has been minimized.

Contributor

deads2k commented Feb 22, 2018

/approve

@k8s-ci-robot

This comment has been minimized.

Contributor

k8s-ci-robot commented Feb 22, 2018

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: deads2k, PhilipGough, soltysh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-merge-robot

This comment has been minimized.

Contributor

k8s-merge-robot commented Feb 22, 2018

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-merge-robot

This comment has been minimized.

Contributor

k8s-merge-robot commented Feb 22, 2018

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-merge-robot k8s-merge-robot merged commit c85ede5 into kubernetes:master Feb 22, 2018

12 of 13 checks passed

Submit Queue Required Github CI test is not green: pull-kubernetes-e2e-gce
Details
cla/linuxfoundation PhilipGough authorized
Details
pull-kubernetes-bazel-build Job succeeded.
Details
pull-kubernetes-bazel-test Job succeeded.
Details
pull-kubernetes-cross Skipped
pull-kubernetes-e2e-gce Job succeeded.
Details
pull-kubernetes-e2e-gce-device-plugin-gpu Job succeeded.
Details
pull-kubernetes-e2e-gke Skipped
pull-kubernetes-e2e-kops-aws Job succeeded.
Details
pull-kubernetes-kubemark-e2e-gce Job succeeded.
Details
pull-kubernetes-node-e2e Job succeeded.
Details
pull-kubernetes-unit Job succeeded.
Details
pull-kubernetes-verify Job succeeded.
Details
@m1093782566

This comment has been minimized.

Member

m1093782566 commented Feb 23, 2018

The following test case can easily flakes, I am not clear about neither the root cause nor if this PR breaks it. Just FYI.

=== RUN   TestSetEnvRemote
--- FAIL: TestSetEnvRemote (0.09s)
        Error Trace:    set_env_test.go:523
                        fake.go:41
                        client.go:249
                        client.go:173
                        client.go:602
                        fake.go:119
                        request.go:664
                        request.go:736
                        helper.go:140
                        set_env.go:451
                        set_env_test.go:539
        Error:          "{"apiVersion":"extensions/v1beta1","spec":{"selector":null}}" does not contain ""value":"prod""
        Messages:       env not updated for &v1.Deployment{TypeMeta:v1.TypeMeta{Kind:"", APIVersion:""}, ObjectMeta:v1.ObjectMeta{Name:"nginx", GenerateName:"", Namespace:"", SelfLink:"", UID:"", ResourceVersion:"", Generation:0, CreationTimestamp:v1.Time{Time:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}}, DeletionTimestamp:(*v1.Time)(nil), DeletionGracePeriodSeconds:(*int64)(nil), Labels:map[string]string(nil), Annotations:map[string]string(nil), OwnerReferences:[]v1.OwnerReference(nil), Initializers:(*v1.Initializers)(nil), Finalizers:[]string(nil), ClusterName:""}, Spec:v1.DeploymentSpec{Replicas:(*int32)(nil), Selector:(*v1.LabelSelector)(nil), Template:v1.PodTemplateSpec{ObjectMeta:v1.ObjectMeta{Name:"", GenerateName:"", Namespace:"", SelfLink:"", UID:"", ResourceVersion:"", Generation:0, CreationTimestamp:v1.Time{Time:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}}, DeletionTimestamp:(*v1.Time)(nil), DeletionGracePeriodSeconds:(*int64)(nil), Labels:map[string]string(nil), Annotations:map[string]string(nil), OwnerReferences:[]v1.OwnerReference(nil), Initializers:(*v1.Initializers)(nil), Finalizers:[]string(nil), ClusterName:""}, Spec:v1.PodSpec{Volumes:[]v1.Volume(nil), InitContainers:[]v1.Container(nil), Containers:[]v1.Container{v1.Container{Name:"nginx", Image:"nginx", Command:[]string(nil), Args:[]string(nil), WorkingDir:"", Ports:[]v1.ContainerPort(nil), EnvFrom:[]v1.EnvFromSource(nil), Env:[]v1.EnvVar(nil), Resources:v1.ResourceRequirements{Limits:v1.ResourceList(nil), Requests:v1.ResourceList(nil)}, VolumeMounts:[]v1.VolumeMount(nil), VolumeDevices:[]v1.VolumeDevice(nil), LivenessProbe:(*v1.Probe)(nil), ReadinessProbe:(*v1.Probe)(nil), Lifecycle:(*v1.Lifecycle)(nil), TerminationMessagePath:"", TerminationMessagePolicy:"", ImagePullPolicy:"", SecurityContext:(*v1.SecurityContext)(nil), Stdin:false, StdinOnce:false, TTY:false}}, RestartPolicy:"", TerminationGracePeriodSeconds:(*int64)(nil), ActiveDeadlineSeconds:(*int64)(nil), DNSPolicy:"", NodeSelector:map[string]string(nil), ServiceAccountName:"", DeprecatedServiceAccount:"", AutomountServiceAccountToken:(*bool)(nil), NodeName:"", HostNetwork:false, HostPID:false, HostIPC:false, ShareProcessNamespace:(*bool)(nil), SecurityContext:(*v1.PodSecurityContext)(nil), ImagePullSecrets:[]v1.LocalObjectReference(nil), Hostname:"", Subdomain:"", Affinity:(*v1.Affinity)(nil), SchedulerName:"", Tolerations:[]v1.Toleration(nil), HostAliases:[]v1.HostAlias(nil), PriorityClassName:"", Priority:(*int32)(nil), DNSConfig:(*v1.PodDNSConfig)(nil)}}, Strategy:v1.DeploymentStrategy{Type:"", RollingUpdate:(*v1.RollingUpdateDeployment)(nil)}, MinReadySeconds:0, RevisionHistoryLimit:(*int32)(nil), Paused:false, ProgressDeadlineSeconds:(*int32)(nil)}, Status:v1.DeploymentStatus{ObservedGeneration:0, Replicas:0, UpdatedReplicas:0, ReadyReplicas:0, AvailableReplicas:0, UnavailableReplicas:0, Conditions:[]v1.DeploymentCondition(nil), CollisionCount:(*int32)(nil)}}
        Error Trace:    set_env_test.go:540
        Error:          Received unexpected error:
                        at least one environment variable must be provided

@PhilipGough

This comment has been minimized.

Contributor

PhilipGough commented Feb 23, 2018

@m1093782566 thanks will take a look asap

@deads2k

This comment has been minimized.

Contributor

deads2k commented Feb 23, 2018

The following test case can easily flakes, I am not clear about neither the root cause nor if this PR breaks it. Just FYI.

I just hit this locally. Seems consistent for me.

@deads2k

This comment has been minimized.

Contributor

deads2k commented Feb 23, 2018

opened #60302

@soltysh

This comment has been minimized.

Contributor

soltysh commented Feb 23, 2018

The fix is in #60303

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment