use of io.fabric8.kubernetes.api.model.networking.v1 in project devspaces-images by redhat-developer.
the class SubPathPrefixesTest method shouldPrefixVolumeMountsSubpathsAndUseVolumeNameStoredInLabels.
@Test
public void shouldPrefixVolumeMountsSubpathsAndUseVolumeNameStoredInLabels() {
// given
String volumeName = "userDataVolume";
pvc.getMetadata().getLabels().put(CHE_VOLUME_NAME_LABEL, volumeName);
// when
subpathPrefixes.prefixVolumeMountsSubpaths(k8sEnv, WORKSPACE_ID);
// then
PodSpec podSpec = k8sEnv.getPodsData().get(POD_1_NAME).getSpec();
io.fabric8.kubernetes.api.model.Volume userPodVolume = podSpec.getVolumes().get(0);
assertEquals(userPodVolume.getPersistentVolumeClaim().getClaimName(), USER_DATA_PVC_NAME);
assertEquals(podSpec.getVolumes().get(0).getPersistentVolumeClaim().getClaimName(), USER_DATA_PVC_NAME);
Container initContainer = podSpec.getInitContainers().get(0);
VolumeMount initVolumeMount = initContainer.getVolumeMounts().get(0);
assertEquals(initVolumeMount.getSubPath(), WORKSPACE_ID + "/" + volumeName + "/tmp/init/userData");
assertEquals(initVolumeMount.getName(), userPodVolume.getName());
Container container = podSpec.getContainers().get(0);
VolumeMount volumeMount = container.getVolumeMounts().get(0);
assertEquals(volumeMount.getSubPath(), WORKSPACE_ID + "/" + volumeName + "/home/user/data");
assertEquals(volumeMount.getName(), userPodVolume.getName());
}
use of io.fabric8.kubernetes.api.model.networking.v1 in project devspaces-images by redhat-developer.
the class OpenshiftTokenInitializationFilter method extractSubject.
@Override
protected Subject extractSubject(String token, io.fabric8.openshift.api.model.User osu) {
try {
ObjectMeta userMeta = osu.getMetadata();
User user = userManager.getOrCreateUser(getUserId(osu), userMeta.getName());
return new AuthorizedSubject(new SubjectImpl(user.getName(), user.getId(), token, false), permissionChecker);
} catch (ServerException | ConflictException e) {
throw new RuntimeException(e);
}
}
use of io.fabric8.kubernetes.api.model.networking.v1 in project devspaces-images by redhat-developer.
the class OpenShiftProjectFactory method asNamespaceMeta.
private KubernetesNamespaceMeta asNamespaceMeta(io.fabric8.openshift.api.model.Project project) {
Map<String, String> attributes = new HashMap<>(4);
ObjectMeta metadata = project.getMetadata();
Map<String, String> annotations = metadata.getAnnotations();
String displayName = annotations.get(Constants.PROJECT_DISPLAY_NAME_ANNOTATION);
if (displayName != null) {
attributes.put(Constants.PROJECT_DISPLAY_NAME_ATTRIBUTE, displayName);
}
String description = annotations.get(Constants.PROJECT_DESCRIPTION_ANNOTATION);
if (description != null) {
attributes.put(Constants.PROJECT_DESCRIPTION_ATTRIBUTE, description);
}
if (project.getStatus() != null && project.getStatus().getPhase() != null) {
attributes.put(PHASE_ATTRIBUTE, project.getStatus().getPhase());
}
return new KubernetesNamespaceMetaImpl(metadata.getName(), attributes);
}
use of io.fabric8.kubernetes.api.model.networking.v1 in project devspaces-images by redhat-developer.
the class SubPathPrefixes method prefixVolumeMountsSubpaths.
/**
* Prefixes volumes mounts of containers inside of the specified kubernetes environment.
*
* <p>Subpaths have the following format: '{workspaceId}/{Che Volume name|PVC name}'.<br>
* Where Che Volume is used if it is present in PVC labels, otherwise PVC name will be used.<br>
* Note that logs volume has the special format: '{workspaceId}/{volumeName}/{machineName}'. It is
* done in this way to avoid conflicts e.g. two identical agents inside different machines produce
* the same log file.
*
* @param k8sEnv environment to process
* @param workspaceId workspace id that should be used as prefix
*/
public void prefixVolumeMountsSubpaths(KubernetesEnvironment k8sEnv, String workspaceId) {
for (PodData pod : k8sEnv.getPodsData().values()) {
Map<String, String> volumeToCheVolumeName = new HashMap<>();
for (io.fabric8.kubernetes.api.model.Volume volume : pod.getSpec().getVolumes()) {
if (volume.getPersistentVolumeClaim() == null) {
continue;
}
PersistentVolumeClaim pvc = k8sEnv.getPersistentVolumeClaims().get(volume.getPersistentVolumeClaim().getClaimName());
String cheVolumeName = pvc.getMetadata().getLabels().get(CHE_VOLUME_NAME_LABEL);
if (cheVolumeName == null) {
cheVolumeName = pvc.getMetadata().getName();
pvc.getMetadata().getLabels().put(CHE_VOLUME_NAME_LABEL, cheVolumeName);
}
volumeToCheVolumeName.put(volume.getName(), cheVolumeName);
}
if (volumeToCheVolumeName.isEmpty()) {
// Pod does not have any volume that references PVC
continue;
}
Stream.concat(pod.getSpec().getContainers().stream(), pod.getSpec().getInitContainers().stream()).forEach(c -> {
for (VolumeMount volumeMount : c.getVolumeMounts()) {
String pvcName = volumeToCheVolumeName.get(volumeMount.getName());
if (pvcName == null) {
// validation
continue;
}
String volumeSubPath = getVolumeMountSubpath(volumeMount, pvcName, workspaceId, Names.machineName(pod, c));
volumeMount.setSubPath(volumeSubPath);
}
});
}
}
use of io.fabric8.kubernetes.api.model.networking.v1 in project devspaces-images by redhat-developer.
the class ChePluginsVolumeApplier method provisionPVCPodVolume.
private io.fabric8.kubernetes.api.model.Volume provisionPVCPodVolume(Volume volume, KubernetesEnvironment.PodData pod, KubernetesEnvironment k8sEnv) {
String pvcName = volume.getName();
if (!k8sEnv.getPersistentVolumeClaims().containsKey(pvcName)) {
final PersistentVolumeClaim pvc = newPVC(pvcName, pvcAccessMode, pvcQuantity, pvcStorageClassName);
k8sEnv.getPersistentVolumeClaims().put(pvcName, pvc);
}
PodSpec podSpec = pod.getSpec();
Optional<io.fabric8.kubernetes.api.model.Volume> volumeOpt = podSpec.getVolumes().stream().filter(vm -> vm.getPersistentVolumeClaim() != null && pvcName.equals(vm.getPersistentVolumeClaim().getClaimName())).findAny();
io.fabric8.kubernetes.api.model.Volume podVolume;
if (volumeOpt.isPresent()) {
podVolume = volumeOpt.get();
} else {
podVolume = newVolume(pvcName, pvcName);
podSpec.getVolumes().add(podVolume);
}
return podVolume;
}
Aggregations