Skip to content

Commit

Permalink
Allow fallback to IPv6 if private network is not available
Browse files Browse the repository at this point in the history
Related: #77
Signed-off-by: Richard Kosegi <richard.kosegi@gmail.com>
  • Loading branch information
rkosegi committed Apr 29, 2024
1 parent 6362c77 commit 3e433a9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2024 https://dnation.cloud
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cloud.dnation.jenkins.plugins.hetzner.launcher;

import cloud.dnation.hetznerclient.ServerDetail;
import cloud.dnation.jenkins.plugins.hetzner.Messages;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.Descriptor;
import lombok.NoArgsConstructor;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

@NoArgsConstructor(onConstructor = @__({@DataBoundConstructor}))
public class DefaultV6ConnectionMethod extends AbstractConnectionMethod {
@Override
public String getAddress(ServerDetail server) {
if (server.getPrivateNet() != null && !server.getPrivateNet().isEmpty()) {
return server.getPrivateNet().get(0).getIp();
} else {
return server.getPublicNet().getIpv6().getIp();

Check warning on line 34 in src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/DefaultV6ConnectionMethod.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 27-34 are not covered by tests
}
}

@Extension
@Symbol("defaultV6")
public static final class DescriptorImpl extends Descriptor<AbstractConnectionMethod> {
@NonNull
@Override
public String getDisplayName() {
return Messages.connection_method_defaultV6();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ primaryip.default=Use default behavior
primaryip.bylabelselector.failing=Allocate primary IPv4 using label selector, fail if none is available
primaryip.bylabelselector.ignoring=Allocate primary IPv4 using label selector, ignore any error
connection.method.default=Connect using private IPv4 address if available, otherwise using public IPv4 address
connection.method.defaultV6=Connect using private IPv4 address if available, otherwise using public IPv6 address
connection.method.public=Connect using public IPv4 address only
connection.method.publicV6=Connect using public IPv6 address only
connectivity.private-only=Only private networking will be used. Network ID or label expression must be provided as well.
Expand Down

0 comments on commit 3e433a9

Please sign in to comment.