use of io.fabric8.mockwebserver.crud.Attribute in project fabric8-maven-plugin by fabric8io.
the class ImageStreamService method findTagSha.
private String findTagSha(OpenShiftClient client, String imageStreamName, String namespace) throws MojoExecutionException {
ImageStream currentImageStream = null;
for (int i = 0; i < IMAGE_STREAM_TAG_RETRIES; i++) {
if (i > 0) {
log.info("Retrying to find tag on ImageStream %s", imageStreamName);
try {
Thread.sleep(IMAGE_STREAM_TAG_RETRY_TIMEOUT_IN_MILLIS);
} catch (InterruptedException e) {
log.debug("interrupted", e);
}
}
currentImageStream = client.imageStreams().withName(imageStreamName).get();
if (currentImageStream == null) {
continue;
}
ImageStreamStatus status = currentImageStream.getStatus();
if (status == null) {
continue;
}
List<NamedTagEventList> tags = status.getTags();
if (tags == null || tags.isEmpty()) {
continue;
}
// Iterate all imagestream tags and get the latest one by 'created' attribute
TagEvent latestTag = null;
TAG_EVENT_LIST: for (NamedTagEventList list : tags) {
List<TagEvent> items = list.getItems();
if (items == null || items.isEmpty()) {
continue TAG_EVENT_LIST;
}
for (TagEvent tag : items) {
latestTag = latestTag == null ? tag : newerTag(tag, latestTag);
}
}
if (latestTag != null && StringUtils.isNotBlank(latestTag.getImage())) {
String image = latestTag.getImage();
log.info("Found tag on ImageStream " + imageStreamName + " tag: " + image);
return image;
}
}
// No image found, even after several retries:
if (currentImageStream == null) {
throw new MojoExecutionException("Could not find a current ImageStream with name " + imageStreamName + " in namespace " + namespace);
} else {
throw new MojoExecutionException("Could not find a tag in the ImageStream " + imageStreamName);
}
}
use of io.fabric8.mockwebserver.crud.Attribute in project fabric8-maven-plugin by fabric8io.
the class VertxHealthCheckEnricher method getStringValue.
private Optional<String> getStringValue(String attribute, boolean readiness) {
String specific = getSpecificPropertyName(readiness, attribute);
String generic = VERTX_HEALTH + attribute;
// Check if we have the specific user property.
Configuration contextConfig = getContext().getConfiguration();
String property = contextConfig.getProperty(specific);
if (property != null) {
return Optional.of(property).map(TRIM);
}
property = contextConfig.getProperty(generic);
if (property != null) {
return Optional.of(property).map(TRIM);
}
String[] specificPath = new String[] { readiness ? "readiness" : "liveness", attribute };
Optional<String> config = getValueFromConfig(specificPath).map(TRIM);
if (!config.isPresent()) {
// Generic path.
return getValueFromConfig(attribute).map(TRIM);
} else {
return config;
}
}
use of io.fabric8.mockwebserver.crud.Attribute in project che-server by eclipse-che.
the class EnvironmentVariableSecretApplier method applySecret.
/**
* Applies secret as environment variable into workspace containers, respecting automount
* attribute and optional devfile automount property override.
*
* @param env kubernetes environment with workspace containers configuration
* @param runtimeIdentity identity of current runtime
* @param secret source secret to apply
* @throws InfrastructureException on misconfigured secrets or other apply error
*/
@Override
public void applySecret(KubernetesEnvironment env, RuntimeIdentity runtimeIdentity, Secret secret) throws InfrastructureException {
boolean secretAutomount = Boolean.parseBoolean(secret.getMetadata().getAnnotations().get(ANNOTATION_AUTOMOUNT));
for (PodData podData : env.getPodsData().values()) {
if (!podData.getRole().equals(PodRole.DEPLOYMENT)) {
continue;
}
for (Container container : podData.getSpec().getContainers()) {
Optional<ComponentImpl> component = getComponent(env, container.getName());
// skip components that explicitly disable automount
if (component.isPresent() && isComponentAutomountFalse(component.get())) {
continue;
}
// if automount disabled globally and not overridden in component
if (!secretAutomount && (!component.isPresent() || !isComponentAutomountTrue(component.get()))) {
continue;
}
for (Entry<String, String> secretDataEntry : secret.getData().entrySet()) {
final String mountEnvName = envName(secret, secretDataEntry.getKey(), runtimeIdentity);
container.getEnv().add(new EnvVarBuilder().withName(mountEnvName).withValueFrom(new EnvVarSourceBuilder().withSecretKeyRef(new SecretKeySelectorBuilder().withName(secret.getMetadata().getName()).withKey(secretDataEntry.getKey()).build()).build()).build());
}
}
}
}
use of io.fabric8.mockwebserver.crud.Attribute in project che-server by eclipse-che.
the class AsyncStorageProvisioner method provision.
public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
if (!parseBoolean(k8sEnv.getAttributes().get(ASYNC_PERSIST_ATTRIBUTE))) {
return;
}
if (!COMMON_STRATEGY.equals(pvcStrategy)) {
String message = format("Workspace configuration not valid: Asynchronous storage available only for 'common' PVC strategy, but got %s", pvcStrategy);
LOG.warn(message);
k8sEnv.addWarning(new WarningImpl(4200, message));
throw new InfrastructureException(message);
}
if (!isEphemeral(k8sEnv.getAttributes())) {
String message = format("Workspace configuration not valid: Asynchronous storage available only if '%s' attribute set to false", PERSIST_VOLUMES_ATTRIBUTE);
LOG.warn(message);
k8sEnv.addWarning(new WarningImpl(4200, message));
throw new InfrastructureException(message);
}
String namespace = identity.getInfrastructureNamespace();
String userId = identity.getOwnerId();
KubernetesClient k8sClient = kubernetesClientFactory.create(identity.getWorkspaceId());
String configMapName = namespace + ASYNC_STORAGE_CONFIG;
createPvcIfNotExist(k8sClient, namespace, userId);
createConfigMapIfNotExist(k8sClient, namespace, configMapName, userId, k8sEnv);
createAsyncStoragePodIfNotExist(k8sClient, namespace, configMapName, userId);
createStorageServiceIfNotExist(k8sClient, namespace, userId);
}
use of io.fabric8.mockwebserver.crud.Attribute in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplier method prepareMachineConfigs.
/**
* Creates map of machine names and corresponding {@link MachineConfigImpl} with component alias
* attribute set.
*/
private Map<String, MachineConfigImpl> prepareMachineConfigs(List<PodData> podsData, ComponentImpl component) throws DevfileException {
Map<String, MachineConfigImpl> machineConfigs = new HashMap<>();
for (PodData podData : podsData) {
List<Container> containers = new ArrayList<>();
containers.addAll(podData.getSpec().getContainers());
containers.addAll(podData.getSpec().getInitContainers());
for (Container container : containers) {
String machineName = machineName(podData, container);
MachineConfigImpl config = new MachineConfigImpl();
if (!isNullOrEmpty(component.getAlias())) {
config.getAttributes().put(DEVFILE_COMPONENT_ALIAS_ATTRIBUTE, component.getAlias());
}
provisionVolumes(component, container, config);
provisionEndpoints(component, config);
machineConfigs.put(machineName, config);
}
}
return machineConfigs;
}
Aggregations