use of io.fabric8.kubernetes.api.model.Namespace in project fabric8 by fabric8io.
the class Controller method applyReplicationController.
public void applyReplicationController(ReplicationController replicationController, String sourceName) throws Exception {
String namespace = getNamespace();
String id = getName(replicationController);
Objects.notNull(id, "No name for " + replicationController + " " + sourceName);
if (isServicesOnlyMode()) {
LOG.debug("Only processing Services right now so ignoring ReplicationController: " + namespace + ":" + id);
return;
}
ReplicationController old = kubernetesClient.replicationControllers().inNamespace(namespace).withName(id).get();
if (isRunning(old)) {
if (UserConfigurationCompare.configEqual(replicationController, old)) {
LOG.info("ReplicationController has not changed so not doing anything");
} else {
ReplicationControllerSpec newSpec = replicationController.getSpec();
ReplicationControllerSpec oldSpec = old.getSpec();
if (rollingUpgrade) {
LOG.info("Rolling upgrade of the ReplicationController: " + namespace + "/" + id);
// lets preserve the number of replicas currently running in the environment we are about to upgrade
if (rollingUpgradePreserveScale && newSpec != null && oldSpec != null) {
Integer replicas = oldSpec.getReplicas();
if (replicas != null) {
newSpec.setReplicas(replicas);
}
}
LOG.info("rollingUpgradePreserveScale " + rollingUpgradePreserveScale + " new replicas is " + (newSpec != null ? newSpec.getReplicas() : "<null>"));
kubernetesClient.replicationControllers().inNamespace(namespace).withName(id).rolling().replace(replicationController);
} else if (isRecreateMode()) {
LOG.info("Deleting ReplicationController: " + id);
kubernetesClient.replicationControllers().inNamespace(namespace).withName(id).delete();
doCreateReplicationController(replicationController, namespace, sourceName);
} else {
LOG.info("Updating ReplicationController from " + sourceName + " namespace " + namespace + " name " + getName(replicationController));
try {
Object answer = kubernetesClient.replicationControllers().inNamespace(namespace).withName(id).replace(replicationController);
logGeneratedEntity("Updated replicationController: ", namespace, replicationController, answer);
if (deletePodsOnReplicationControllerUpdate) {
kubernetesClient.pods().inNamespace(namespace).withLabels(newSpec.getSelector()).delete();
LOG.info("Deleting any pods for the replication controller to ensure they use the new configuration");
} else {
LOG.info("Warning not deleted any pods so they could well be running with the old configuration!");
}
} catch (Exception e) {
onApplyError("Failed to update ReplicationController from " + sourceName + ". " + e + ". " + replicationController, e);
}
}
}
} else {
if (!isAllowCreate()) {
LOG.warn("Creation disabled so not creating a ReplicationController from " + sourceName + " namespace " + namespace + " name " + getName(replicationController));
} else {
doCreateReplicationController(replicationController, namespace, sourceName);
}
}
}
use of io.fabric8.kubernetes.api.model.Namespace in project fabric8 by fabric8io.
the class Controller method doCreateSecret.
protected void doCreateSecret(Secret secret, String namespace, String sourceName) {
LOG.info("Creating a Secret from " + sourceName + " namespace " + namespace + " name " + getName(secret));
try {
Object answer;
if (Strings.isNotBlank(namespace)) {
answer = kubernetesClient.secrets().inNamespace(namespace).create(secret);
} else {
answer = kubernetesClient.secrets().inNamespace(getNamespace()).create(secret);
}
logGeneratedEntity("Created Secret: ", namespace, secret, answer);
} catch (Exception e) {
onApplyError("Failed to create Secret from " + sourceName + ". " + e + ". " + secret, e);
}
}
use of io.fabric8.kubernetes.api.model.Namespace 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.kubernetes.api.model.Namespace 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.kubernetes.api.model.Namespace in project fabric8 by fabric8io.
the class Controller method doCreateReplicationController.
protected void doCreateReplicationController(ReplicationController replicationController, String namespace, String sourceName) {
LOG.info("Creating a ReplicationController from " + sourceName + " namespace " + namespace + " name " + getName(replicationController));
try {
// lets check that if secrets are required they exist
ReplicationControllerSpec spec = replicationController.getSpec();
if (spec != null) {
PodTemplateSpec template = spec.getTemplate();
if (template != null) {
PodSpec podSpec = template.getSpec();
validatePodSpec(podSpec, namespace);
}
}
Object answer;
if (Strings.isNotBlank(namespace)) {
answer = kubernetesClient.replicationControllers().inNamespace(namespace).create(replicationController);
} else {
answer = kubernetesClient.replicationControllers().inNamespace(getNamespace()).create(replicationController);
}
logGeneratedEntity("Created ReplicationController: ", namespace, replicationController, answer);
} catch (Exception e) {
onApplyError("Failed to create ReplicationController from " + sourceName + ". " + e + ". " + replicationController, e);
}
}
Aggregations