Skip to content
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

Implement Port Mapping #135

Closed
wants to merge 4 commits into from
Closed

Implement Port Mapping #135

wants to merge 4 commits into from

Conversation

derfred
Copy link

@derfred derfred commented Feb 18, 2017

This adds the capability to expose ports on the pods like this:

podTemplate(label: 'mypod', containers: [
    containerTemplate(
        name: 'mariadb', 
        ports: [portMapping(name: 'mysql', containerPort: 3306)]
    ),
    ...
],

Copy link
Contributor

@carlossg carlossg left a comment

Choose a reason for hiding this comment

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

Can you add the UI for the settings form, not just for pipeline?


@DataBoundSetter
public void setPorts(List<PortMapping> ports) {
this.ports.addAll(ports);
Copy link
Contributor

Choose a reason for hiding this comment

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

this.ports may be null

Choose a reason for hiding this comment

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

by this logic @carlossg the setEnvVars calls could also be null and fail as it just does this

    public void setEnvVars(List<ContainerEnvVar> envVars) {
        this.envVars.addAll(envVars);
    }

Copy link
Author

Choose a reason for hiding this comment

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

I was thinking the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

it's only on upgrades, maybe envVars was there from the beginning

Because ports didn't exist, when deserializing the previous version configuration jenkins will set ports=null

Choose a reason for hiding this comment

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

@carlossg, I upgrade to a version of the plugin with this patched it and I didn't see any errors or nothing anything once jenkins was up again and running jobs.

@jwhitcraft
Copy link

@derfred any update on this? I've recently come into the need of having ports be exposed for e2e testing things.

@derfred
Copy link
Author

derfred commented Mar 29, 2017

@carlossg I have added the UI for exposing the ports.

@@ -83,6 +83,7 @@ The `containerTemplate` is a template of container that will be added to the pod
* **command** The command the container will execute.
* **args** The arugments passed to the command.
* **ttyEnabled** Flag to mark that tty should be enabled.
* **ports** Expose ports on the container.

Choose a reason for hiding this comment

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

@derfred this works great, the only thing that you may want to add to the readme is to outline that you access a port that is open on another container you need to use 127.0.0.1 for the url, as doing it name based is not working for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jwhitcraft in what scenario are you using it? Because I am trying to run some tests with a mariadb database and getting connection refused when trying to connect. My pod template is exactly as the one on readme. I tried to connect to mysql cli from within the container as well, and I get a ´Can't connect to local MySQL server through socket ´ error (commented in the PR as well).

Copy link
Contributor

@andriosrobert andriosrobert Aug 28, 2017

Choose a reason for hiding this comment

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

Found the solution, described in the PR discussion

@gytisgreitai
Copy link

@carlossg can we get this merged?

Copy link
Contributor

@carlossg carlossg left a comment

Choose a reason for hiding this comment

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

public void setPorts(List<PortMapping> ports) {
if (ports != null) {
this.ports.addAll(ports);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

if it is null then you are doing nothing

Choose a reason for hiding this comment

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

What should be done if the value is null? this.ports is already the list as defined above. In my testing of this, this works fine.

Copy link
Contributor

@carlossg carlossg Jun 8, 2017

Choose a reason for hiding this comment

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

I missread. But shouldn't be just

this.ports = ports

otherwise you are adding ports all the time to the existing ones, not clearing up

Copy link

@jwhitcraft jwhitcraft Jun 8, 2017

Choose a reason for hiding this comment

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

@carlossg since the field is final you just can't set it like that.

I'm chaning it to this

this.ports.clear();
this.ports.addAll(ports);

It would also seem that setEnvVars falls into the same problem, but that's another bug.

I've added the fix to #165

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll comment there

@jwhitcraft
Copy link

@derfred any chance of finishing up this?

@jwhitcraft
Copy link

@derfred if you don't have time to fix this, i may cherry-pick your commits in and fix what @carlossg suggested. We really need this in before the next release is cut so we can stop compiling our own.

@jwhitcraft jwhitcraft mentioned this pull request Jun 8, 2017
@carlossg
Copy link
Contributor

carlossg commented Jun 8, 2017

superseded by #165

@carlossg carlossg closed this Jun 8, 2017
@andriosrobert
Copy link
Contributor

andriosrobert commented Jul 11, 2017

I'm getting java.lang.NoSuchMethodError: No such DSL method 'portMapping' found among steps at repo checkout time, when trying to use it on a scripted pipeline, using the exact same definition from the mariadb container template in the readme file.

Jenkins is running on a Kubernetes cluster on aws.
plugin version: 0.11
jenkins version: 2.7.2
Any clue on why is it not working?

@carlossg
Copy link
Contributor

it will be released in 0.12

@derfred derfred deleted the port_mapping branch July 12, 2017 17:51
@andriosrobert
Copy link
Contributor

Im trying to run some application tests using mariadb container and portaMapping, but it does not work for me using neither using 127.0.0.1, localhost or 0.0.0.0. When trying to access mysql cli from within the cointainer I get:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
My template looks exactly the same as the one described on README.md
Any help would be welcome :)

@andriosrobert
Copy link
Contributor

andriosrobert commented Aug 28, 2017

Found the solution that day, just explaining so that other people facing the same issue could benefit from it. Inspecting the container created by Kubernetes, I realized that the container template for Mariadb in the readme does not work, it has two errors:

  1. command: The command for the Mariadb container to start should be mysqld, and not cat as it is in the readme. It indicated the Mariadb deamon binary, without which the container would start without a deamon
  2. args: The arguments should not be empty as it is in the readme, once the Mariadb image uses a shell entrypoint (docker-entrypoint.sh) in order to setup the database, without which a database setup would not work

Im filling a small PR to fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants