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

Allow fallback to IPv6 if private network is not available #81

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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