use of io.kubernetes.client.models.V1beta1Ingress in project java by kubernetes-client.
the class ExtensionsV1beta1Api method readNamespacedIngressAsync.
/**
* (asynchronously)
* read the specified Ingress
* @param name name of the Ingress (required)
* @param namespace object name and auth scope, such as for teams and projects (required)
* @param pretty If 'true', then the output is pretty printed. (optional)
* @param exact Should the export be exact. Exact export maintains cluster-specific fields like 'Namespace'. (optional)
* @param export Should this value be exported. Export strips fields that a user can not specify. (optional)
* @param callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
*/
public com.squareup.okhttp.Call readNamespacedIngressAsync(String name, String namespace, String pretty, Boolean exact, Boolean export, final ApiCallback<V1beta1Ingress> callback) throws ApiException {
ProgressResponseBody.ProgressListener progressListener = null;
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
if (callback != null) {
progressListener = new ProgressResponseBody.ProgressListener() {
@Override
public void update(long bytesRead, long contentLength, boolean done) {
callback.onDownloadProgress(bytesRead, contentLength, done);
}
};
progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
@Override
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
callback.onUploadProgress(bytesWritten, contentLength, done);
}
};
}
com.squareup.okhttp.Call call = readNamespacedIngressValidateBeforeCall(name, namespace, pretty, exact, export, progressListener, progressRequestListener);
Type localVarReturnType = new TypeToken<V1beta1Ingress>() {
}.getType();
apiClient.executeAsync(call, localVarReturnType, callback);
return call;
}
use of io.kubernetes.client.models.V1beta1Ingress in project java by kubernetes-client.
the class ExtensionsV1beta1Api method createNamespacedIngressWithHttpInfo.
/**
* create an Ingress
* @param namespace object name and auth scope, such as for teams and projects (required)
* @param body (required)
* @param pretty If 'true', then the output is pretty printed. (optional)
* @return ApiResponse<V1beta1Ingress>
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public ApiResponse<V1beta1Ingress> createNamespacedIngressWithHttpInfo(String namespace, V1beta1Ingress body, String pretty) throws ApiException {
com.squareup.okhttp.Call call = createNamespacedIngressValidateBeforeCall(namespace, body, pretty, null, null);
Type localVarReturnType = new TypeToken<V1beta1Ingress>() {
}.getType();
return apiClient.execute(call, localVarReturnType);
}
use of io.kubernetes.client.models.V1beta1Ingress in project weblogic-kubernetes-operator by oracle.
the class Main method begin.
private static void begin() {
// read the operator configuration
String namespace = System.getenv("OPERATOR_NAMESPACE");
if (namespace == null) {
namespace = "default";
}
Collection<String> targetNamespaces = getTargetNamespaces(namespace);
String serviceAccountName = tuningAndConfig.get("serviceaccount");
if (serviceAccountName == null) {
serviceAccountName = "default";
}
principal = "system:serviceaccount:" + namespace + ":" + serviceAccountName;
LOGGER.info(MessageKeys.OP_CONFIG_NAMESPACE, namespace);
StringBuilder tns = new StringBuilder();
Iterator<String> it = targetNamespaces.iterator();
while (it.hasNext()) {
tns.append(it.next());
if (it.hasNext()) {
tns.append(", ");
}
}
LOGGER.info(MessageKeys.OP_CONFIG_TARGET_NAMESPACES, tns.toString());
LOGGER.info(MessageKeys.OP_CONFIG_SERVICE_ACCOUNT, serviceAccountName);
try {
// Initialize logging factory with JSON serializer for later logging
// that includes k8s objects
LoggingFactory.setJSON(new JSON());
// start the REST server
startRestServer(principal, targetNamespaces);
// create the Custom Resource Definitions if they are not already there
CRDHelper.checkAndCreateCustomResourceDefinition();
try {
HealthCheckHelper healthCheck = new HealthCheckHelper(namespace, targetNamespaces);
version = healthCheck.performK8sVersionCheck();
healthCheck.performNonSecurityChecks();
healthCheck.performSecurityChecks(serviceAccountName);
} catch (ApiException e) {
LOGGER.warning(MessageKeys.EXCEPTION, e);
}
// check for any existing resources and add the watches on them
// this would happen when the Domain was running BEFORE the Operator starts up
LOGGER.info(MessageKeys.LISTING_DOMAINS);
for (String ns : targetNamespaces) {
initialized.put(ns, Boolean.TRUE);
Step domainList = callBuilderFactory.create().listDomainAsync(ns, new ResponseStep<DomainList>(null) {
@Override
public NextAction onFailure(Packet packet, ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
if (statusCode == CallBuilder.NOT_FOUND) {
return onSuccess(packet, null, statusCode, responseHeaders);
}
return super.onFailure(packet, e, statusCode, responseHeaders);
}
@Override
public NextAction onSuccess(Packet packet, DomainList result, int statusCode, Map<String, List<String>> responseHeaders) {
if (result != null) {
for (Domain dom : result.getItems()) {
doCheckAndCreateDomainPresence(dom);
}
}
// main logic now happens in the watch handlers
domainWatchers.put(ns, createDomainWatcher(ns, result != null ? result.getMetadata().getResourceVersion() : ""));
return doNext(packet);
}
});
Step initialize = ConfigMapHelper.createScriptConfigMapStep(ns, new ConfigMapAfterStep(ns, callBuilderFactory.create().with($ -> {
$.labelSelector = LabelConstants.DOMAINUID_LABEL + "," + LabelConstants.CREATEDBYOPERATOR_LABEL;
}).listPodAsync(ns, new ResponseStep<V1PodList>(callBuilderFactory.create().with($ -> {
$.labelSelector = LabelConstants.DOMAINUID_LABEL + "," + LabelConstants.CREATEDBYOPERATOR_LABEL;
}).listServiceAsync(ns, new ResponseStep<V1ServiceList>(callBuilderFactory.create().with($ -> {
$.labelSelector = LabelConstants.DOMAINUID_LABEL + "," + LabelConstants.CREATEDBYOPERATOR_LABEL;
}).listIngressAsync(ns, new ResponseStep<V1beta1IngressList>(domainList) {
@Override
public NextAction onFailure(Packet packet, ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
if (statusCode == CallBuilder.NOT_FOUND) {
return onSuccess(packet, null, statusCode, responseHeaders);
}
return super.onFailure(packet, e, statusCode, responseHeaders);
}
@Override
public NextAction onSuccess(Packet packet, V1beta1IngressList result, int statusCode, Map<String, List<String>> responseHeaders) {
if (result != null) {
for (V1beta1Ingress ingress : result.getItems()) {
String domainUID = IngressWatcher.getIngressDomainUID(ingress);
String clusterName = IngressWatcher.getIngressClusterName(ingress);
if (domainUID != null && clusterName != null) {
DomainPresenceInfo created = new DomainPresenceInfo(ns);
DomainPresenceInfo info = domains.putIfAbsent(domainUID, created);
if (info == null) {
info = created;
}
info.getIngresses().put(clusterName, ingress);
}
}
}
ingressWatchers.put(ns, createIngressWatcher(ns, result != null ? result.getMetadata().getResourceVersion() : ""));
return doNext(packet);
}
})) {
@Override
public NextAction onFailure(Packet packet, ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
if (statusCode == CallBuilder.NOT_FOUND) {
return onSuccess(packet, null, statusCode, responseHeaders);
}
return super.onFailure(packet, e, statusCode, responseHeaders);
}
@Override
public NextAction onSuccess(Packet packet, V1ServiceList result, int statusCode, Map<String, List<String>> responseHeaders) {
if (result != null) {
for (V1Service service : result.getItems()) {
String domainUID = ServiceWatcher.getServiceDomainUID(service);
String serverName = ServiceWatcher.getServiceServerName(service);
String channelName = ServiceWatcher.getServiceChannelName(service);
if (domainUID != null && serverName != null) {
DomainPresenceInfo created = new DomainPresenceInfo(ns);
DomainPresenceInfo info = domains.putIfAbsent(domainUID, created);
if (info == null) {
info = created;
}
ServerKubernetesObjects csko = new ServerKubernetesObjects();
ServerKubernetesObjects current = info.getServers().putIfAbsent(serverName, csko);
ServerKubernetesObjects sko = current != null ? current : csko;
if (channelName != null) {
sko.getChannels().put(channelName, service);
} else {
sko.getService().set(service);
}
}
}
}
serviceWatchers.put(ns, createServiceWatcher(ns, result != null ? result.getMetadata().getResourceVersion() : ""));
return doNext(packet);
}
})) {
@Override
public NextAction onFailure(Packet packet, ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
if (statusCode == CallBuilder.NOT_FOUND) {
return onSuccess(packet, null, statusCode, responseHeaders);
}
return super.onFailure(packet, e, statusCode, responseHeaders);
}
@Override
public NextAction onSuccess(Packet packet, V1PodList result, int statusCode, Map<String, List<String>> responseHeaders) {
if (result != null) {
for (V1Pod pod : result.getItems()) {
String domainUID = PodWatcher.getPodDomainUID(pod);
String serverName = PodWatcher.getPodServerName(pod);
if (domainUID != null && serverName != null) {
DomainPresenceInfo created = new DomainPresenceInfo(ns);
DomainPresenceInfo info = domains.putIfAbsent(domainUID, created);
if (info == null) {
info = created;
}
ServerKubernetesObjects csko = new ServerKubernetesObjects();
ServerKubernetesObjects current = info.getServers().putIfAbsent(serverName, csko);
ServerKubernetesObjects sko = current != null ? current : csko;
sko.getPod().set(pod);
}
}
}
podWatchers.put(ns, createPodWatcher(ns, result != null ? result.getMetadata().getResourceVersion() : ""));
return doNext(packet);
}
})));
engine.createFiber().start(initialize, new Packet(), new CompletionCallback() {
@Override
public void onCompletion(Packet packet) {
// no-op
}
@Override
public void onThrowable(Packet packet, Throwable throwable) {
LOGGER.severe(MessageKeys.EXCEPTION, throwable);
}
});
}
// delete stranded resources
for (Map.Entry<String, DomainPresenceInfo> entry : domains.entrySet()) {
String domainUID = entry.getKey();
DomainPresenceInfo info = entry.getValue();
if (info != null) {
if (info.getDomain() == null) {
// no domain resource
deleteDomainPresence(info.getNamespace(), domainUID);
}
}
}
} catch (Throwable e) {
LOGGER.warning(MessageKeys.EXCEPTION, e);
} finally {
LOGGER.info(MessageKeys.OPERATOR_SHUTTING_DOWN);
}
}
use of io.kubernetes.client.models.V1beta1Ingress in project weblogic-kubernetes-operator by oracle.
the class IngressHelperTest method testAddThenRemoveServer.
@Test
public void testAddThenRemoveServer() throws Throwable {
Packet p = new Packet();
p.getComponents().put(ProcessingConstants.DOMAIN_COMPONENT_NAME, Component.createFor(info));
p.put(ProcessingConstants.SERVER_SCAN, info.getScan().getServerConfig(server1Name));
p.put(ProcessingConstants.CLUSTER_SCAN, info.getScan().getClusterConfig(clusterName));
p.put(ProcessingConstants.SERVER_NAME, server1Name);
Fiber f = engine.createFiber();
Step s = IngressHelper.createClusterStep(null);
AtomicReference<Throwable> t = new AtomicReference<>();
f.start(s, p, new CompletionCallback() {
@Override
public void onCompletion(Packet packet) {
// no-op
}
@Override
public void onThrowable(Packet packet, Throwable throwable) {
t.set(throwable);
}
});
f.get(30, TimeUnit.SECONDS);
if (t.get() != null) {
throw t.get();
}
// Now check
CallBuilderFactory factory = new CallBuilderFactory(null);
V1beta1Ingress v1beta1Ingress = factory.create().readIngress(ingressName, namespace);
List<V1beta1HTTPIngressPath> v1beta1HTTPIngressPaths = getPathArray(v1beta1Ingress);
Assert.assertEquals("IngressPaths should have one instance of IngressPath", 1, v1beta1HTTPIngressPaths.size());
V1beta1HTTPIngressPath v1beta1HTTPIngressPath = v1beta1HTTPIngressPaths.get(0);
Assert.assertEquals("/", v1beta1HTTPIngressPath.getPath());
V1beta1IngressBackend v1beta1IngressBackend = v1beta1HTTPIngressPath.getBackend();
Assert.assertNotNull("IngressBackend Object should not be null", v1beta1IngressBackend);
Assert.assertEquals("Service name should be " + clusterServiceName, clusterServiceName, v1beta1IngressBackend.getServiceName());
Assert.assertEquals("Service port should be " + server1Port, server1Port, v1beta1IngressBackend.getServicePort().getIntValue());
}
use of io.kubernetes.client.models.V1beta1Ingress in project weblogic-kubernetes-operator by oracle.
the class WatchBuilderTest method whenIngressWatchSpecifiesParameters_verifyAndReturnResponse.
@Test
public void whenIngressWatchSpecifiesParameters_verifyAndReturnResponse() throws Exception {
V1beta1Ingress ingress = new V1beta1Ingress().apiVersion(API_VERSION).kind("Ingress").metadata(createMetaData("ingress", NAMESPACE));
defineHttpResponse(INGRESS_RESOURCE, withResponses(createDeletedResponse(ingress)).andValidations(parameter("pretty").withValue("true"), parameter("timeoutSeconds").withValue("15"), parameter("limit").withValue("500")));
WatchI<V1beta1Ingress> ingressWatch = new WatchBuilder().withTimeoutSeconds(15).withPrettyPrinting().createIngressWatch(NAMESPACE);
assertThat(ingressWatch, contains(deleteEvent(ingress)));
}
Aggregations