本文整理汇总了Java中io.fabric8.kubernetes.api.model.ObjectReference类的典型用法代码示例。如果您正苦于以下问题:Java ObjectReference类的具体用法?Java ObjectReference怎么用?Java ObjectReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObjectReference类属于io.fabric8.kubernetes.api.model包,在下文中一共展示了ObjectReference类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: issueRouteCert
import io.fabric8.kubernetes.api.model.ObjectReference; //导入依赖的package包/类
@Override
public void issueRouteCert(String secretName, String namespace, String ... hostnames) throws Exception {
Secret secret = client.secrets().inNamespace(namespace).withName(secretName).get();
if (secret == null) {
String keyKey = "tls.key";
String certKey = "tls.crt";
log.info("Creating self-signed certificates for {}", secretName);
File key = File.createTempFile("tls", "key");
File cert = File.createTempFile("tls", "crt");
createSelfSignedCert(key, cert);
secret = createSecretFromCertAndKeyFiles(secretName, namespace, keyKey, certKey, key, cert, client);
}
ServiceAccount defaultAccount = client.serviceAccounts().inNamespace(namespace).withName("default").get();
for (ObjectReference reference : defaultAccount.getSecrets()) {
if (reference.getName().equals(secretName)) {
return;
}
}
client.serviceAccounts().inNamespace(namespace).withName("default").edit()
.addToSecrets(new ObjectReferenceBuilder()
.withKind(secret.getKind())
.withName(secret.getMetadata().getName())
.withApiVersion(secret.getApiVersion())
.build())
.done();
}
示例2: watchContainers
import io.fabric8.kubernetes.api.model.ObjectReference; //导入依赖的package包/类
/**
* Registers a specified handler for handling events about changes in pods containers.
*
* @param handler pod container events handler
* @throws InfrastructureException if any error occurs while watcher starting
*/
public void watchContainers(ContainerEventHandler handler) throws InfrastructureException {
if (containerWatch == null) {
final Watcher<Event> watcher =
new Watcher<Event>() {
@Override
public void eventReceived(Action action, Event event) {
ObjectReference involvedObject = event.getInvolvedObject();
String fieldPath = involvedObject.getFieldPath();
// check that event related to
if (POD_OBJECT_KIND.equals(involvedObject.getKind()) && fieldPath != null) {
Matcher containerFieldMatcher = CONTAINER_FIELD_PATH_PATTERN.matcher(fieldPath);
if (containerFieldMatcher.matches()) {
String podName = involvedObject.getName();
String containerName = containerFieldMatcher.group(CONTAINER_NAME_GROUP);
ContainerEvent containerEvent =
new ContainerEvent(
podName,
containerName,
event.getMessage(),
event.getMetadata().getCreationTimestamp());
containerEventsHandlers.forEach(h -> h.handle(containerEvent));
}
}
}
@Override
public void onClose(KubernetesClientException ignored) {}
};
try {
containerWatch = clientFactory.create().events().inNamespace(namespace).watch(watcher);
} catch (KubernetesClientException ex) {
throw new InfrastructureException(ex.getMessage());
}
}
containerEventsHandlers.add(handler);
}
示例3: createEndpointsForService
import io.fabric8.kubernetes.api.model.ObjectReference; //导入依赖的package包/类
protected static Endpoints createEndpointsForService(Service service, List<Pod> pods) {
if (service == null) {
return null;
}
ServiceSpec serviceSpec = service.getSpec();
if (serviceSpec == null) {
return null;
}
List<EndpointAddress> addresses = new ArrayList<>();
String namespace = KubernetesHelper.getNamespace(service);
String serviceName = getName(service);
String qualifiedServiceName = namespace + ":" + serviceName;
List<ServicePort> ports = serviceSpec.getPorts();
for (ServicePort servicePort : ports) {
IntOrString targetPort = servicePort.getTargetPort();
Integer portNumber = KubernetesHelper.intOrStringToInteger(targetPort, qualifiedServiceName);
if (portNumber != null) {
List<Pod> podsForService = KubernetesHelper.getPodsForService(service, pods);
for (Pod pod : podsForService) {
PodStatus currentState = pod.getStatus();
if (currentState != null) {
String podIP = currentState.getPodIP();
if (podIP != null) {
String url = podIP + ":" + portNumber;
EndpointAddress address = new EndpointAddress();
address.setIp(podIP);
ObjectReference ref = new ObjectReference();
ref.setNamespace(namespace);
ref.setName(getName(pod));
address.setTargetRef(ref);
addresses.add(address);
}
}
}
}
}
EndpointSubset subset = new EndpointSubset();
subset.setAddresses(addresses);
return new EndpointsBuilder().
withNewMetadata().withName(serviceName).withNamespace(namespace).endMetadata().
addToSubsets(subset).
build();
}