Skip to content

Allow specifying environment variables when installing an engine plugin as a Swarm service#38441

Merged
crosbymichael merged 1 commit intomoby:masterfrom
sirlatrom:swarm_plugin_env
Jul 8, 2019
Merged

Allow specifying environment variables when installing an engine plugin as a Swarm service#38441
crosbymichael merged 1 commit intomoby:masterfrom
sirlatrom:swarm_plugin_env

Conversation

@sirlatrom
Copy link
Contributor

@sirlatrom sirlatrom commented Dec 27, 2018

- What I did
I enabled specifying environment variables when installing a plugin through a Swarm service.

- How I did it

  1. I added an Env []string field to the PluginSpec type by modifying its protobuf file, allowing environment variables (and values) to be specified when a plugin is to be installed as a Swarm service.
  2. I added logic to transfer the environment variables to the resulting plugin task.

- How to verify it
a) Specify Env: []string{"MY_ENV_VAR=my-env-value"} in the TaskTemplate.PluginSpec object of the swarm.ServiceSpec when calling the service/create endpoint.
Example:

...
Env: []string{
    "policy-template={{ .ServiceName }},{{ .TaskImage }},{{ ServiceLabel \"com.docker.ucp.access.label\" }}",
...
},

b) The test TestServicePlugin in integration/service/plugin_test.go now covers the changed code.

- Description for the changelog

Allow specifying environment variables when installing an engine plugin as a Swarm service.

- A picture of a cute animal (not mandatory but encouraged)
68f39a73-bcad-4998-a7c8-ada5e1e8b8ff_1 ecf2088920bbbf3577bfce7402ad521f

@sirlatrom sirlatrom requested a review from cpuguy83 as a code owner December 27, 2018 17:15
@sirlatrom sirlatrom force-pushed the swarm_plugin_env branch 3 times, most recently from b3df338 to 37c3828 Compare December 27, 2018 17:35
@sirlatrom sirlatrom changed the title WIP: Swarm plugin environment variables passing WIP: Allow specifying environment variables when installing an engine plugin as a Swarm service Dec 27, 2018
@codecov
Copy link

codecov bot commented Dec 27, 2018

Codecov Report

Merging #38441 into master will decrease coverage by 0.02%.
The diff coverage is 0%.

@@            Coverage Diff             @@
##           master   #38441      +/-   ##
==========================================
- Coverage   36.89%   36.87%   -0.03%     
==========================================
  Files         613      613              
  Lines       45421    45435      +14     
==========================================
- Hits        16760    16754       -6     
- Misses      26370    26389      +19     
- Partials     2291     2292       +1

@sirlatrom
Copy link
Contributor Author

sirlatrom commented Jan 9, 2019

@thaJeztah I've incorporated your suggested change. I could not find any existing tests covering the WithSwarmService adjacent to my WithEnv function.

@sirlatrom sirlatrom changed the title WIP: Allow specifying environment variables when installing an engine plugin as a Swarm service Allow specifying environment variables when installing an engine plugin as a Swarm service Jan 9, 2019
@cpuguy83
Copy link
Member

cpuguy83 commented Jan 9, 2019

Can you add a test for this (or modify the swarm plugin create test?)

@sirlatrom
Copy link
Contributor Author

@cpuguy Sure thing, thanks for the pointer, I'll see if I can add it to the right place in that test.

@sirlatrom sirlatrom requested a review from vdemeester as a code owner January 9, 2019 23:32
@sirlatrom
Copy link
Contributor Author

@cpuguy83 Currently there's no way for the Docker engine to tell what tasks exist for a plugin Swarm service, since they are in a different namespace. Please advise on how to continue writing a test in integration/service/plugin_test.go when the goal should be to verify the task/container for the plugin has the correct environment variables set.

@cpuguy83
Copy link
Member

@sirlatrom You should be able to query the tasks API with the service ID as the filter.

@sirlatrom
Copy link
Contributor Author

@cpuguy83 That works for regular Docker tasks, but the /tasks endpoint only returns tasks that have a ContainerSpec. So I can inspect the plugin service, since that endpoint does not hide plugin services, but I cannot get its tasks, because the tasks endpoint hides those.

@sirlatrom
Copy link
Contributor Author

More specifically, it is this bit of code that restricts the runtime of the returned tasks:

if !filter.Contains("runtime") {
// default to only showing container tasks
filter.Add("runtime", "container")
filter.Add("runtime", "")
}

I'll extend the test helper for task listing to allow additional filters, including the "runtime" filter.

@sirlatrom sirlatrom force-pushed the swarm_plugin_env branch 3 times, most recently from e16a0de to 11fb7d1 Compare January 14, 2019 16:48
@sirlatrom
Copy link
Contributor Author

Flaky test is flaky. DockerHubPullSuite.TestPullFromCentralRegistry passed in experimental, powerpc and z, but failed on janky. DockerSuite.TestRunStoppedLoggingDriverNoLeak failed on windowsRS1.

@sirlatrom
Copy link
Contributor Author

I force pushed to get checks to pass, but windowsRS1 still fails. @cpuguy83 Is that test unrelated? I feel like it is.

@olljanat
Copy link
Contributor

olljanat commented Jan 15, 2019

(reserved for my derek commands)

@sirlatrom sirlatrom force-pushed the swarm_plugin_env branch 2 times, most recently from 6c8266f to 8908c31 Compare January 15, 2019 19:52
@sirlatrom sirlatrom force-pushed the swarm_plugin_env branch 2 times, most recently from 399a198 to 7ac049a Compare March 27, 2019 11:09
@sirlatrom
Copy link
Contributor Author

Rebased on moby/moby master.

Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sirlatrom
Copy link
Contributor Author

Looks like experimental build fails because of this CRIU test, which I hope is unrelated:

Running /go/src/github.com/docker/docker/integration/container
INFO: Testing against a local daemon
=== RUN   TestCheckpoint
--- FAIL: TestCheckpoint (1.55s)
    checkpoint_test.go:40: Error (criu/util.c:816): exited, status=3
        Warn  (criu/net.c:2840): Unable to get socket network namespace
        Warn  (criu/net.c:2840): Unable to get tun network namespace
        Warn  (criu/sk-unix.c:229): unix: Unable to open a socket file: Bad address
        Warn  (criu/net.c:2840): Unable to get socket network namespace
        Warn  (criu/kerndat.c:881): Can't keep kdat cache on non-tempfs
        Looks good.
    checkpoint_test.go:51: Start a container
    checkpoint_test.go:69: ++ type -P true
        ++ type -P ip6tables-restore
        + mount --bind /bin/true /sbin/ip6tables-restore
        ++ type -P true
        ++ type -P ip6tables-save
        + mount --bind /bin/true /sbin/ip6tables-save
    checkpoint_test.go:81: Do a checkpoint and leave the container running
    checkpoint_test.go:24: Exec: [touch /tmp/test-file]
    checkpoint_test.go:28: 
    checkpoint_test.go:115: Do a checkpoint and stop the container
    checkpoint_test.go:117: assertion failed: error is not nil: Error response from daemon: Cannot checkpoint container 1239a021c72845fc2ed944e75b6e41bf691bb2542b7f329aa9e09a76976cbf13: cannot checkpoint a stopped container: unknown
    checkpoint_test.go:77: ++ type -P ip6tables-restore
        + umount -c -i -l /sbin/ip6tables-restore
        ++ type -P ip6tables-save
        + umount -c -i -l /sbin/ip6tables-save
    main_test.go:32: assertion failed: error is not nil: Error response from daemon: Container 1239a021c72845fc2ed944e75b6e41bf691bb2542b7f329aa9e09a76976cbf13 is not paused: failed to unpause container 1239a021c72845fc2ed944e75b6e41bf691bb2542b7f329aa9e09a76976cbf13

The tests failing for z are TestCreateWithDuplicateNetworkNames and TestDockerNetworkConnectAlias, which I would also argue are unrelated.

I don't even know why the Windows tests are failing, but I'm hoping it's also unrelated.

@sirlatrom sirlatrom force-pushed the swarm_plugin_env branch 4 times, most recently from 9f37ce8 to 32bf388 Compare April 5, 2019 09:59
Allow specifying environment variables when installing an engine plugin
as a Swarm service. Invalid environment variable entries (without an
equals (`=`) char) will be ignored.

Signed-off-by: Sune Keller <[email protected]>
@sirlatrom
Copy link
Contributor Author

@thaJeztah Any chance the "experimental" build could be retried?

@thaJeztah
Copy link
Member

Restarted 👍

@sirlatrom
Copy link
Contributor Author

Thanks @thaJeztah, looks like it passed the flaky tests this time 😅

Any chance the appropriate maintainers will give this their final judgement?

@crosbymichael
Copy link
Contributor

LGTM

@crosbymichael crosbymichael merged commit fb459f6 into moby:master Jul 8, 2019
@sirlatrom sirlatrom deleted the swarm_plugin_env branch July 9, 2019 19:17
@thaJeztah thaJeztah added this to the 20.03.0 milestone Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants