use of io.fabric8.openshift.client.OpenShiftClient in project fabric8 by fabric8io.
the class Controller method applyOAuthClient.
public void applyOAuthClient(OAuthClient entity, String sourceName) {
OpenShiftClient openShiftClient = getOpenShiftClientOrNull();
if (openShiftClient != null && openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.OAUTH)) {
if (supportOAuthClients) {
String id = getName(entity);
Objects.notNull(id, "No name for " + entity + " " + sourceName);
if (isServicesOnlyMode()) {
LOG.debug("Only processing Services right now so ignoring OAuthClient: " + id);
return;
}
OAuthClient old = openShiftClient.oAuthClients().withName(id).get();
if (isRunning(old)) {
if (isIgnoreRunningOAuthClients()) {
LOG.info("Not updating the OAuthClient which are shared across namespaces as its already running");
return;
}
if (UserConfigurationCompare.configEqual(entity, old)) {
LOG.info("OAuthClient has not changed so not doing anything");
} else {
if (isRecreateMode()) {
openShiftClient.oAuthClients().withName(id).delete();
doCreateOAuthClient(entity, sourceName);
} else {
try {
Object answer = openShiftClient.oAuthClients().withName(id).replace(entity);
LOG.info("Updated OAuthClient result: " + answer);
} catch (Exception e) {
onApplyError("Failed to update OAuthClient from " + sourceName + ". " + e + ". " + entity, e);
}
}
}
} else {
if (!isAllowCreate()) {
LOG.warn("Creation disabled so not creating an OAuthClient from " + sourceName + " name " + getName(entity));
} else {
doCreateOAuthClient(entity, sourceName);
}
}
}
}
}
use of io.fabric8.openshift.client.OpenShiftClient in project fabric8 by fabric8io.
the class Controller method applyProjectRequest.
/**
* Returns true if the ProjectRequest is created
*/
public boolean applyProjectRequest(ProjectRequest entity) {
String namespace = getOrCreateMetadata(entity).getName();
LOG.info("Using project: " + namespace);
String name = getName(entity);
Objects.notNull(name, "No name for " + entity);
OpenShiftClient openshiftClient = getOpenShiftClientOrNull();
if (openshiftClient == null || !openshiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.PROJECT)) {
LOG.warn("Cannot check for Project " + namespace + " as not running against OpenShift!");
return false;
}
boolean exists = checkNamespace(name);
// We may want to be more fine-grained on the phase of the project
if (!exists) {
try {
Object answer = openshiftClient.projectrequests().create(entity);
logGeneratedEntity("Created ProjectRequest: ", namespace, entity, answer);
return true;
} catch (Exception e) {
onApplyError("Failed to create ProjectRequest: " + name + " due " + e.getMessage(), e);
}
}
return false;
}
use of io.fabric8.openshift.client.OpenShiftClient in project fabric8 by fabric8io.
the class Controller method getOpenShiftClientOrJenkinshift.
public OpenShiftClient getOpenShiftClientOrJenkinshift() {
OpenShiftClient openShiftClient = getOpenShiftClientOrNull();
if (openShiftClient == null) {
// lets try talk to the jenkinshift service which provides a BuildConfig REST API based on Jenkins
// for when using vanilla Kubernetes
String jenkinshiftUrl = Systems.getEnvVar("JENKINSHIFT_URL", "http://jenkinshift/");
LOG.debug("Using jenknshift URL: " + jenkinshiftUrl);
openShiftClient = KubernetesHelper.createJenkinshiftOpenShiftClient(jenkinshiftUrl);
}
return openShiftClient;
}
use of io.fabric8.openshift.client.OpenShiftClient in project fabric8 by fabric8io.
the class Controller method applyImageStream.
public void applyImageStream(ImageStream entity, String sourceName) {
OpenShiftClient openShiftClient = getOpenShiftClientOrNull();
if (openShiftClient != null && openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.IMAGE)) {
String kind = getKind(entity);
String name = getName(entity);
String namespace = getNamespace();
try {
Resource<ImageStream, DoneableImageStream> resource = openShiftClient.imageStreams().inNamespace(namespace).withName(name);
ImageStream old = resource.get();
if (old == null) {
LOG.info("Creating " + kind + " " + name + " from " + sourceName);
resource.create(entity);
} else {
LOG.info("Updating " + kind + " " + name + " from " + sourceName);
copyAllImageStreamTags(entity, old);
resource.replace(old);
}
openShiftClient.resource(entity).inNamespace(namespace).apply();
} catch (Exception e) {
onApplyError("Failed to create " + kind + " from " + sourceName + ". " + e, e);
}
}
}
use of io.fabric8.openshift.client.OpenShiftClient in project fabric8 by fabric8io.
the class Controller method applyNamespace.
public void applyNamespace(String namespaceName, Map<String, String> labels) {
if (Strings.isNullOrBlank(namespaceName)) {
return;
}
OpenShiftClient openshiftClient = getOpenShiftClientOrNull();
if (openshiftClient != null && openshiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.PROJECT)) {
ProjectRequest entity = new ProjectRequest();
ObjectMeta metadata = getOrCreateMetadata(entity);
metadata.setName(namespaceName);
String namespace = kubernetesClient.getNamespace();
if (Strings.isNotBlank(namespace)) {
Map<String, String> entityLabels = getOrCreateLabels(entity);
if (labels != null) {
entityLabels.putAll(labels);
} else {
// lets associate this new namespace with the project that it was created from
entityLabels.put("project", namespace);
}
}
applyProjectRequest(entity);
} else {
Namespace entity = new Namespace();
ObjectMeta metadata = getOrCreateMetadata(entity);
metadata.setName(namespaceName);
String namespace = kubernetesClient.getNamespace();
if (Strings.isNotBlank(namespace)) {
Map<String, String> entityLabels = getOrCreateLabels(entity);
if (labels != null) {
entityLabels.putAll(labels);
} else {
// lets associate this new namespace with the project that it was created from
entityLabels.put("project", namespace);
}
}
applyNamespace(entity);
}
}
Aggregations