Search in sources :

Example 21 with io.fabric8.kubernetes.api.model.networking.v1

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());
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) TestObjects.newContainer(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.TestObjects.newContainer) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) Volume(io.fabric8.kubernetes.api.model.Volume) Test(org.testng.annotations.Test)

Example 22 with io.fabric8.kubernetes.api.model.networking.v1

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);
    }
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) User(org.eclipse.che.api.core.model.user.User) AuthorizedSubject(org.eclipse.che.multiuser.api.permission.server.AuthorizedSubject) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl)

Example 23 with io.fabric8.kubernetes.api.model.networking.v1

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);
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) KubernetesNamespaceMetaImpl(org.eclipse.che.workspace.infrastructure.kubernetes.api.server.impls.KubernetesNamespaceMetaImpl) HashMap(java.util.HashMap)

Example 24 with io.fabric8.kubernetes.api.model.networking.v1

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);
            }
        });
    }
}
Also used : PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) HashMap(java.util.HashMap) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim)

Example 25 with io.fabric8.kubernetes.api.model.networking.v1

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;
}
Also used : KubernetesObjectUtil.newPVC(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newPVC) Container(io.fabric8.kubernetes.api.model.Container) Collection(java.util.Collection) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) KubernetesObjectUtil.newVolume(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolume) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) Singleton(javax.inject.Singleton) Volume(org.eclipse.che.api.workspace.server.wsplugins.model.Volume) Inject(javax.inject.Inject) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Optional(java.util.Optional) Named(javax.inject.Named) KubernetesObjectUtil.newVolumeMount(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolumeMount) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) KubernetesObjectUtil.newVolume(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.newVolume) Volume(org.eclipse.che.api.workspace.server.wsplugins.model.Volume) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim)

Aggregations

Test (org.junit.Test)48 ParallelTest (io.strimzi.test.annotations.ParallelTest)42 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)40 PodDisruptionBudget (io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget)38 File (java.io.File)32 Kafka (io.strimzi.api.kafka.model.Kafka)28 HashMap (java.util.HashMap)28 FabricService (io.fabric8.api.FabricService)26 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)26 IOException (java.io.IOException)26 Container (io.fabric8.kubernetes.api.model.Container)20 Test (org.junit.jupiter.api.Test)20 Service (io.fabric8.kubernetes.api.model.Service)19 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)18 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)18 ResourceUtils (io.strimzi.operator.cluster.ResourceUtils)18 Reconciliation (io.strimzi.operator.common.Reconciliation)18 Labels (io.strimzi.operator.common.model.Labels)18 CoreMatchers.is (org.hamcrest.CoreMatchers.is)18 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)18