本文整理汇总了Java中io.fabric8.kubernetes.api.KubernetesHelper类的典型用法代码示例。如果您正苦于以下问题:Java KubernetesHelper类的具体用法?Java KubernetesHelper怎么用?Java KubernetesHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KubernetesHelper类属于io.fabric8.kubernetes.api包,在下文中一共展示了KubernetesHelper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getUserName
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
/**
* Returns the current users kubernetes/openshift user name
*/
public String getUserName() {
OpenShiftClient oc = getOpenShiftClientOrNull();
if (oc != null) {
User user = oc.users().withName("~").get();
if (user == null) {
LOG.warn("Failed to find current logged in user!");
} else {
String answer = KubernetesHelper.getName(user);
if (Strings.isNullOrBlank(answer)) {
LOG.warn("No name for User " + user);
} else {
return answer;
}
}
}
// TODO needs to use the current token to find the current user name
return Configs.currentUserName();
}
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:23,代码来源:KubernetesClientHelper.java
示例2: getGogsURL
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
protected String getGogsURL(boolean external) {
StopWatch watch = new StopWatch();
String namespace = kubernetesClient.getNamespace();
if (Strings.isNullOrEmpty(namespace)) {
namespace = KubernetesHelper.defaultNamespace();
}
String serviceName = GOGS;
String answer = KubernetesHelper.getServiceURL(kubernetesClient, serviceName, namespace, "http", external);
if (Strings.isNullOrEmpty(answer)) {
String kind = external ? "external" : "internal";
throw new IllegalStateException("Could not find external URL for " + kind + " service: gogs!");
}
if (!external) {
// lets stick with the service name instead as its easier to grok
return "http://" + serviceName + "/";
}
LOG.info("getGogsURL took " + watch.taken());
return answer;
}
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:22,代码来源:GitUserHelper.java
示例3: printServices
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
private void printServices(ServiceList services, PrintStream out) {
TablePrinter table = new TablePrinter();
table.columns("id", "labels", "selector", "port");
List<Service> items = services.getItems();
if (items == null) {
items = Collections.EMPTY_LIST;
}
Filter<Service> filter = KubernetesHelper.createServiceFilter(filterText.getValue());
for (Service service : items) {
if (filter.matches(service)) {
String labels = KubernetesHelper.toLabelsString(service.getMetadata().getLabels());
String selector = KubernetesHelper.toLabelsString(getSelector(service));
Set<Integer> ports = getPorts(service);
List<Integer> portList = new ArrayList<>(ports);
String portText;
if (portList.size() == 1) {
portText = portList.get(0).toString();
} else {
portText = Strings.join(portList, ", ");
}
table.row(KubernetesHelper.getName(service), labels, selector, portText);
}
}
table.print();
}
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:27,代码来源:ServicesList.java
示例4: initializeUI
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
@Override
public void initializeUI(UIBuilder builder) throws Exception {
super.initializeUI(builder);
// populate autocompletion options
serviceId.setCompleter(new UICompleter<String>() {
@Override
public Iterable<String> getCompletionProposals(UIContext context, InputComponent<?, String> input, String value) {
List<String> list = new ArrayList<String>();
ServiceList services = getKubernetes().services().inNamespace(getNamespace()).list();
if (services != null) {
List<Service> items = services.getItems();
if (items != null) {
for (Service item : items) {
String id = KubernetesHelper.getName(item);
list.add(id);
}
}
}
Collections.sort(list);
return list;
}
});
builder.add(serviceId);
}
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:27,代码来源:ServiceDelete.java
示例5: initializeUI
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
@Override
public void initializeUI(UIBuilder builder) throws Exception {
super.initializeUI(builder);
// populate autocompletion options
replicationControllerId.setCompleter(new UICompleter<String>() {
@Override
public Iterable<String> getCompletionProposals(UIContext context, InputComponent<?, String> input, String value) {
List<String> list = new ArrayList<String>();
ReplicationControllerList replicationControllers = getKubernetes().replicationControllers().inNamespace(getNamespace()).list();
if (replicationControllers != null) {
List<ReplicationController> items = replicationControllers.getItems();
if (items != null) {
for (ReplicationController item : items) {
String id = KubernetesHelper.getName(item);
list.add(id);
}
}
}
Collections.sort(list);
return list;
}
});
builder.add(replicationControllerId);
}
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:27,代码来源:ReplicationControllerDelete.java
示例6: cleanDeployments
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
private void cleanDeployments(Map<String, String> labels) throws Exception {
final ReplicationControllerList rcs = client.replicationControllers().inNamespace(configuration.getNamespace()).withLabels(labels).list();
try {
for (ReplicationController rc : rcs.getItems()) {
String rcId = KubernetesHelper.getName((io.fabric8.kubernetes.api.model.HasMetadata) rc.getMetadata());
client.replicationControllers().inNamespace(configuration.getNamespace()).withName(rcId).scale(0, true);
boolean exists = client.replicationControllers().inNamespace(configuration.getNamespace()).withName(rcId).delete();
log.info(String.format("ReplicationController [%s] delete: %s.", rcId, exists));
}
} catch (Exception e) {
log.log(Level.WARNING, String.format("Exception while deleting rc [%s]: %s", labels, e), e);
}
}
开发者ID:jboss-openshift,项目名称:ce-arq,代码行数:14,代码来源:F8OpenShiftAdapter.java
示例7: onWatchEvent
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
protected void onWatchEvent(io.fabric8.kubernetes.client.Watcher.Action action, HasMetadata entity, NotifyConfig notifyConfig) {
if (!notifyConfig.isEnabled(action)) {
return;
}
String kind = KubernetesHelper.getKind(entity);
String name = KubernetesHelper.getName(entity);
String namespace = getNamespace();
String actionText = action.toString().toLowerCase();
String room = this.roomExpression.replace("${namespace}", namespace).replace("${kind}", kind).replace("${name}", name);
String postfix = "";
if (action.equals(Watcher.Action.ADDED) || action.equals(Watcher.Action.MODIFIED)) {
if (Strings.isNotBlank(consoleLink)) {
postfix += " " + consoleLink + "/kubernetes/namespace/" + namespace + "/" + kind.toLowerCase() + "s/" + name;
}
}
String message = actionText + " " + decapitalize(kind) + " " + namespace + " / " + name + postfix;
notifier.notifyRoom(room, message);
}
开发者ID:fabric8io,项目名称:fabric8-devops,代码行数:22,代码来源:KubernetesHubotNotifier.java
示例8: createMissingContainers
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
/**
* Creates any missing containers; updating the currentState with the new values.
*/
public static String createMissingContainers(final ProcessManager processManager, final KubernetesModel model, final Pod pod,
final PodStatus currentState, List<Container> containers) throws Exception {
Map<String, ContainerStatus> currentContainers = KubernetesHelper.getCurrentContainers(currentState);
for (final Container container : containers) {
// lets update the pod model if we update the ports
podTransaction(model, pod, new Callable<Void>() {
@Override
public Void call() throws Exception {
createContainer(processManager, model, container, pod, currentState);
return null;
}
});
}
return null;
}
开发者ID:fabric8io,项目名称:jube,代码行数:21,代码来源:NodeHelper.java
示例9: findHostPortForService
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
public static int findHostPortForService(Pod pod, int serviceContainerPort) {
List<Container> containers = KubernetesHelper.getContainers(pod);
for (Container container : containers) {
List<ContainerPort> ports = container.getPorts();
if (ports != null) {
for (ContainerPort port : ports) {
Integer containerPort = port.getContainerPort();
Integer hostPort = port.getHostPort();
if (containerPort != null && containerPort == serviceContainerPort) {
if (hostPort != null) {
return hostPort;
}
}
}
}
}
LOG.warn("Could not find host port for service port: {} pod: {}", serviceContainerPort, pod);
return serviceContainerPort;
}
开发者ID:fabric8io,项目名称:jube,代码行数:20,代码来源:NodeHelper.java
示例10: getPodRunningContainers
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
/**
* Returns all the current containers and their pods
*/
@Override
public ImmutableMap<String, PodCurrentContainer> getPodRunningContainers(KubernetesModel model) {
Map<String, PodCurrentContainer> answer = new HashMap<>();
for (Map.Entry<String, Pod> entry : getInternalPodMap(namespace).entrySet()) {
String podId = entry.getKey();
Pod podSchema = entry.getValue();
Map<String, ContainerStatus> currentContainers = KubernetesHelper.getCurrentContainers(podSchema);
for (Map.Entry<String, ContainerStatus> containerEntry : currentContainers.entrySet()) {
String containerId = containerEntry.getKey();
ContainerStatus currentContainer = containerEntry.getValue();
PodCurrentContainer podCurrentContainer = new PodCurrentContainer(model, podId, podSchema, containerId, currentContainer);
answer.put(containerId, podCurrentContainer);
}
}
return ImmutableMap.copyOf(answer);
}
开发者ID:fabric8io,项目名称:jube,代码行数:20,代码来源:LocalKubernetesModel.java
示例11: ServiceInstance
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
public ServiceInstance(Service service) {
this.service = service;
this.id = getName(service);
ServiceSpec spec = KubernetesHelper.getOrCreateSpec(service);
List<ServicePort> ports = spec.getPorts();
if (spec.getPortalIP().equals(HEADLESS_PORTAL_IP)) {
//do nothing service is headless
} else if (ports != null && !ports.isEmpty()) {
for (ServicePort servicePort : ports) {
servicePorts.add(toNamedServicePort(id, servicePort));
}
} else {
throw new IllegalArgumentException("Service: " + id + " doesn't have a valid port configuration.");
}
this.selector = KubernetesHelper.getSelector(service);
Objects.notNull(this.selector, "No selector for service " + id);
if (selector.isEmpty()) {
throw new IllegalArgumentException("Empty selector for service " + id);
}
this.filter = KubernetesHelper.createPodFilter(selector);
// TODO should we use some service metadata to choose the load balancer?
this.loadBalancer = new RoundRobinLoadBalancer();
}
开发者ID:fabric8io,项目名称:jube,代码行数:25,代码来源:ServiceInstance.java
示例12: ContainerService
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
public ContainerService(ServicePort servicePort, Pod pod) throws URISyntaxException {
this.servicePort = servicePort;
this.pod = pod;
int serviceContainerPort = KubernetesHelper.intOrStringToInteger(servicePort.getTargetPort(), this.toString());
int port = NodeHelper.findHostPortForService(pod, serviceContainerPort);
// lets get host / port of the container
String host = null;
PodStatus currentState = pod.getStatus();
if (currentState != null) {
host = currentState.getHostIP();
if (Strings.isBlank(host)) {
host = currentState.getPodIP();
}
}
if (Strings.isBlank(host)) {
throw new IllegalArgumentException("No host for pod " + KubernetesHelper.getName(pod) + " so cannot use it with service port: " + servicePort.getName());
} else {
uri = new URI("tcp://" + host + ":" + port);
}
}
开发者ID:fabric8io,项目名称:jube,代码行数:22,代码来源:ContainerService.java
示例13: updatePod
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
public String updatePod(final @NotNull String podId, final Pod pod) throws Exception {
// TODO needs implementing remotely!
return NodeHelper.excludeFromProcessMonitor(processMonitor, pod, new Callable<String>() {
@Override
public String call() throws Exception {
System.out.println("Updating pod " + pod);
PodSpec desiredState = pod.getSpec();
Objects.notNull(desiredState, "desiredState");
PodStatus currentState = NodeHelper.getOrCreatetStatus(pod);
List<Container> containers = KubernetesHelper.getContainers(pod);
model.updatePod(podId, pod);
return NodeHelper.createMissingContainers(processManager, model, pod, currentState, containers);
}
});
}
开发者ID:fabric8io,项目名称:jube,代码行数:19,代码来源:ApiMasterService.java
示例14: writeEntity
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
protected void writeEntity(String path, Object entity) {
try {
String json = KubernetesHelper.toJson(entity);
if (LOG.isDebugEnabled()) {
LOG.debug("Writing to path: " + path + " json: " + json);
}
if (curator.checkExists().forPath(path) == null) {
curator.create().creatingParentsIfNeeded().forPath(path, json.getBytes());
} else {
curator.setData().forPath(path, json.getBytes());
}
updateLocalModel(entity, false);
} catch (Exception e) {
throw new RuntimeException("Failed to update object at path: " + path + ". " + e, e);
}
}
开发者ID:fabric8io,项目名称:jube,代码行数:17,代码来源:ApiMasterKubernetesModel.java
示例15: getServiceURL
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
@Override
public URL getServiceURL(String serviceName, OpenShiftProject project) throws IllegalArgumentException {
String serviceURL = KubernetesHelper.getServiceURL(client, serviceName, project.getName(), "https", true);
try {
return new URL(serviceURL);
} catch (MalformedURLException e) {
// Should never happen
throw new IllegalStateException("Malformed service URL: " + serviceURL, e);
}
}
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:11,代码来源:Fabric8OpenShiftServiceImpl.java
示例16: validate
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
@Override
public void validate(UIValidationContext context) {
if (github == null || !github.isDetailsValid()) {
// invoked too early before the github account is setup - lets return silently
return;
}
Iterable<GitRepositoryDTO> value = gitRepositoryPattern.getValue();
if (!value.iterator().hasNext()) {
context.addValidationError(gitRepositoryPattern, "You must select a repository to import");
}
// Check for repos with already existing bc
Controller controller = new Controller(kubernetesClientHelper.getKubernetesClient());
OpenShiftClient openShiftClient = controller.getOpenShiftClientOrNull();
if (openShiftClient == null) {
context.addValidationError(gitRepositoryPattern, "Could not create OpenShiftClient. Maybe the Kubernetes server version is older than 1.7?");
}
Iterator<GitRepositoryDTO> it = value.iterator();
String userNameSpace = Tenants.findDefaultUserNamespace(namespaces);
if (userNameSpace == null) {
// Tenant not yet initialised properly!
return;
}
while (it.hasNext()) {
GitRepositoryDTO repo = it.next();
if (repo != null && repo.getName() != null) {
BuildConfig oldBC = openShiftClient.buildConfigs().inNamespace(userNameSpace).withName(repo.getName().toLowerCase()).get();
if (oldBC != null && Strings.isNotBlank(KubernetesHelper.getName(oldBC))) {
context.addValidationError(gitRepositoryPattern, "The repository " + repo.getName() + " has already a build config, please select another repo.");
break;
}
}
}
}
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:36,代码来源:GitHubImportPickRepositoriesStep.java
示例17: getDiscoveryNamespace
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
/**
* Returns the namespace used to discover services like gogs and gitlab when on premise
*/
public String getDiscoveryNamespace(String createInNamespace) {
if (Strings.isNotBlank(createInNamespace)) {
return createInNamespace;
}
String namespace = System.getenv(EnvironmentVariables.NAMESPACE);
if (Strings.isNotBlank(namespace)) {
return namespace;
}
namespace = kubernetesClient.getNamespace();
if (Strings.isNotBlank(namespace)) {
return namespace;
}
return KubernetesHelper.defaultNamespace();
}
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:18,代码来源:KubernetesClientHelper.java
示例18: findBotSecret
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
/**
* Finds the secret token we should use for the web hooks
*/
private String findBotSecret(String discoveryNamespace, String botServiceAccount) {
if (useUiidForBotSecret) {
return UUID.randomUUID().toString();
} else {
SecretList list = getKubernetesClientHelper().getKubernetesClient().secrets()
.inNamespace(discoveryNamespace).list();
if (list != null) {
List<Secret> items = list.getItems();
if (items != null) {
for (Secret item : items) {
String name = KubernetesHelper.getName(item);
if (name.startsWith(botServiceAccount + "-token-")) {
Map<String, String> data = item.getData();
if (data != null) {
String token = data.get("token");
if (token != null) {
return base64decode(token);
}
}
}
}
}
}
}
return null;
}
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:30,代码来源:CreateBuildConfigStep.java
示例19: getNamespace
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
public String getNamespace() {
if (Strings.isNullOrBlank(namespace)) {
namespace = kubernetesClient.getNamespace();
}
if (Strings.isNullOrBlank(namespace)) {
namespace = KubernetesHelper.defaultNamespace();
}
if (Strings.isNullOrBlank(namespace)) {
namespace = "default";
}
return namespace;
}
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:13,代码来源:ForgeClient.java
示例20: initializeUI
import io.fabric8.kubernetes.api.KubernetesHelper; //导入依赖的package包/类
@Override
public void initializeUI(UIBuilder builder) throws Exception {
super.initializeUI(builder);
// populate autocompletion options
podId.setCompleter(new UICompleter<String>() {
@Override
public Iterable<String> getCompletionProposals(UIContext context, InputComponent<?, String> input, String value) {
List<String> list = new ArrayList<String>();
PodList pods = getKubernetes().pods().list();
if (pods != null) {
List<Pod> items = pods.getItems();
if (items != null) {
for (Pod item : items) {
String id = KubernetesHelper.getName(item);
list.add(id);
}
}
}
Collections.sort(list);
System.out.println("Completion list is " + list);
return list;
}
});
builder.add(podId);
}
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:28,代码来源:AbstractPodCommand.java
注:本文中的io.fabric8.kubernetes.api.KubernetesHelper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论