Search in sources :

Example 6 with Role

use of io.fabric8.openshift.api.model.Role in project jointware by isdream.

the class KubernetesKeyValueStyleGeneratorTest method testOpenShiftWithAllKind.

protected static void testOpenShiftWithAllKind() throws Exception {
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new Policy());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new Group());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new User());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new OAuthClient());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new ClusterRoleBinding());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new ImageStreamTag());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new ImageStream());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new Build());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new BuildConfig());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new RoleBinding());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new Route());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new PolicyBinding());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new OAuthAuthorizeToken());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new Role());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new Project());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new OAuthAccessToken());
    info(OPENSHIFT_KIND, OpenShiftDocumentKeyValueStyleGenerator.class.getName(), new DeploymentConfig());
}
Also used : NetworkPolicy(io.fabric8.kubernetes.api.model.extensions.NetworkPolicy) Policy(io.fabric8.openshift.api.model.Policy) Group(io.fabric8.openshift.api.model.Group) User(io.fabric8.openshift.api.model.User) OAuthClient(io.fabric8.openshift.api.model.OAuthClient) ClusterRoleBinding(io.fabric8.openshift.api.model.ClusterRoleBinding) ImageStreamTag(io.fabric8.openshift.api.model.ImageStreamTag) ImageStream(io.fabric8.openshift.api.model.ImageStream) PolicyBinding(io.fabric8.openshift.api.model.PolicyBinding) OAuthAuthorizeToken(io.fabric8.openshift.api.model.OAuthAuthorizeToken) Role(io.fabric8.openshift.api.model.Role) Project(io.fabric8.openshift.api.model.Project) Build(io.fabric8.openshift.api.model.Build) OpenShiftDocumentKeyValueStyleGenerator(com.github.isdream.chameleon.docs.OpenShiftDocumentKeyValueStyleGenerator) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) OAuthAccessToken(io.fabric8.openshift.api.model.OAuthAccessToken) ClusterRoleBinding(io.fabric8.openshift.api.model.ClusterRoleBinding) RoleBinding(io.fabric8.openshift.api.model.RoleBinding) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) Route(io.fabric8.openshift.api.model.Route)

Example 7 with Role

use of io.fabric8.openshift.api.model.Role in project zalenium by zalando.

the class KubernetesContainerMock method getMockedKubernetesContainerClient.

public static KubernetesContainerClient getMockedKubernetesContainerClient() {
    // Mocking the environment variable to return false for video recording enabled
    Environment environment = mock(Environment.class);
    when(environment.getStringEnvVariable("ZALENIUM_KUBERNETES_CPU_REQUEST", null)).thenReturn("250m");
    when(environment.getStringEnvVariable("ZALENIUM_KUBERNETES_CPU_LIMIT", null)).thenReturn("500m");
    when(environment.getStringEnvVariable("ZALENIUM_KUBERNETES_MEMORY_REQUEST", null)).thenReturn("1Gi");
    when(environment.getStringEnvVariable("ZALENIUM_KUBERNETES_MEMORY_LIMIT", null)).thenReturn("4Gi");
    String hostName;
    try {
        hostName = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException e) {
        hostName = "";
    }
    KubernetesServer server = new KubernetesServer();
    server.before();
    Map<String, String> zaleniumPodLabels = new HashMap<>();
    zaleniumPodLabels.put("app", "zalenium");
    zaleniumPodLabels.put("role", "grid");
    Pod zaleniumPod = new PodBuilder().withNewMetadata().withLabels(zaleniumPodLabels).addToLabels(zaleniumPodLabels).withNamespace("test").withGenerateName(hostName).withName(hostName).and().build();
    String videosVolumeName = RandomStringUtils.randomAlphabetic(5).toLowerCase();
    String generalVolumeName = RandomStringUtils.randomAlphabetic(5).toLowerCase();
    VolumeMount volumeMountVideos = new VolumeMountBuilder().withName(videosVolumeName).withMountPath("/tmp/videos").build();
    VolumeMount volumeMountGeneral = new VolumeMountBuilder().withName(generalVolumeName).withMountPath("/tmp/mounted").build();
    Container zaleniumContainer = new ContainerBuilder().withVolumeMounts(volumeMountVideos, volumeMountGeneral).build();
    Volume videosVolume = new VolumeBuilder().withName(videosVolumeName).build();
    Volume generalVolume = new VolumeBuilder().withName(generalVolumeName).build();
    HostAlias hostAlias = new HostAliasBuilder().withHostnames("foo.local").withIp("127.0.0.1").build();
    Map<String, String> nodeSelector = new HashMap<>();
    nodeSelector.put("nodeLabelKey", "nodeLabelValue");
    PodSpec zaleniumPodSpec = new PodSpecBuilder().withContainers(zaleniumContainer).withVolumes(videosVolume, generalVolume).withHostAliases(hostAlias).withNodeSelector(nodeSelector).build();
    zaleniumPod.setSpec(zaleniumPodSpec);
    String podsPath = String.format("/api/v1/namespaces/test/pods/%s", hostName);
    server.expect().withPath(podsPath).andReturn(200, zaleniumPod).once();
    Map<String, String> dockerSeleniumPodLabels = new HashMap<>();
    dockerSeleniumPodLabels.put("createdBy", "zalenium");
    Pod dockerSeleniumPod = new PodBuilder().withNewMetadata().withLabels(dockerSeleniumPodLabels).withNamespace("test").withName(hostName).and().build();
    Container dockerSeleniumContainer = new ContainerBuilder().withEnv(new EnvVarBuilder().withName("NOVNC_PORT").withValue("40000").build()).build();
    PodSpec dockerSeleniumPodSpec = new PodSpecBuilder().withContainers(dockerSeleniumContainer).build();
    dockerSeleniumPod.setSpec(dockerSeleniumPodSpec);
    PodStatus dockerSeleniumPodStatus = new PodStatusBuilder().withPodIP("localhost").build();
    dockerSeleniumPod.setStatus(dockerSeleniumPodStatus);
    server.expect().withPath("/api/v1/namespaces/test/pods?labelSelector=createdBy%3Dzalenium").andReturn(200, new PodListBuilder().withItems(dockerSeleniumPod).build()).always();
    ServiceSpec serviceSpec = new ServiceSpecBuilder().withPorts(new ServicePortBuilder().withNodePort(40000).build()).build();
    Service service = new ServiceBuilder().withSpec(serviceSpec).build();
    server.expect().withPath("/api/v1/namespaces/test/services").andReturn(201, service).always();
    String bashCommand = String.format("/api/v1/namespaces/test/pods/%s/exec?command=bash&command=-c&command=", hostName);
    String tarCommand = String.format("/api/v1/namespaces/test/pods/%s/exec?command=tar&command=-C&command=", hostName);
    String commandSuffix = "&stdout=true&stderr=true";
    String expectedOutput = "test";
    List<String> execPaths = new ArrayList<>();
    execPaths.add(String.format("%stransfer-logs.sh%s", bashCommand, commandSuffix));
    execPaths.add(String.format("%s/var/log/cont/&command=-c&command=.%s", tarCommand, commandSuffix));
    execPaths.add(String.format("%s/videos/&command=-c&command=.%s", tarCommand, commandSuffix));
    execPaths.add(String.format("%s/videos/&command=-C&command=.%s", tarCommand, commandSuffix));
    execPaths.add(String.format("%sstop-video%s", bashCommand, commandSuffix));
    execPaths.add(String.format("%sstart-video%s", bashCommand, commandSuffix));
    execPaths.add(String.format("%stransfer-logs.sh%s", bashCommand, commandSuffix));
    execPaths.add(String.format("%scleanup-container.sh%s", bashCommand, commandSuffix));
    String notifyComplete = bashCommand.concat("notify%20%27Zalenium%27,%20%27TEST%20COMPLETED%27,%20--icon=/home/seluser/images/completed.png").concat(commandSuffix);
    String notifyTimeout = bashCommand.concat("notify%20%27Zalenium%27,%20%27TEST%20TIMED%20OUT%27,%20--icon=/home/seluser/images/timeout.png").concat(commandSuffix);
    execPaths.add(notifyComplete);
    execPaths.add(notifyTimeout);
    for (String execPath : execPaths) {
        server.expect().withPath(execPath).andUpgradeToWebSocket().open(new OutputStreamMessage(expectedOutput)).done().once();
    }
    server.expect().withPath("/api/v1/namespaces/test/pods").andReturn(201, new PodBuilder().build()).always();
    KubernetesClient client = server.getClient();
    return new KubernetesContainerClient(environment, KubernetesContainerClient::createDoneablePodDefaultImpl, client);
}
Also used : HashMap(java.util.HashMap) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) ArrayList(java.util.ArrayList) OutputStreamMessage(io.fabric8.kubernetes.client.server.mock.OutputStreamMessage) PodStatusBuilder(io.fabric8.kubernetes.api.model.PodStatusBuilder) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) PodStatus(io.fabric8.kubernetes.api.model.PodStatus) Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) HostAliasBuilder(io.fabric8.kubernetes.api.model.HostAliasBuilder) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) UnknownHostException(java.net.UnknownHostException) Pod(io.fabric8.kubernetes.api.model.Pod) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Service(io.fabric8.kubernetes.api.model.Service) KubernetesServer(io.fabric8.kubernetes.client.server.mock.KubernetesServer) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) KubernetesContainerClient(de.zalando.ep.zalenium.container.kubernetes.KubernetesContainerClient) HostAlias(io.fabric8.kubernetes.api.model.HostAlias) ServiceSpecBuilder(io.fabric8.kubernetes.api.model.ServiceSpecBuilder) PodListBuilder(io.fabric8.kubernetes.api.model.PodListBuilder) Volume(io.fabric8.kubernetes.api.model.Volume) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount)

Aggregations

PolicyBinding (io.fabric8.openshift.api.model.PolicyBinding)3 Pod (io.fabric8.kubernetes.api.model.Pod)2 Service (io.fabric8.kubernetes.api.model.Service)2 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)2 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)2 DoneablePolicyBinding (io.fabric8.openshift.api.model.DoneablePolicyBinding)2 ImageStream (io.fabric8.openshift.api.model.ImageStream)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 OpenShiftDocumentKeyValueStyleGenerator (com.github.isdream.chameleon.docs.OpenShiftDocumentKeyValueStyleGenerator)1 KubernetesContainerClient (de.zalando.ep.zalenium.container.kubernetes.KubernetesContainerClient)1 CreateEnsembleOptions (io.fabric8.api.CreateEnsembleOptions)1 FabricException (io.fabric8.api.FabricException)1 RuntimeProperties (io.fabric8.api.RuntimeProperties)1 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1 Container (io.fabric8.kubernetes.api.model.Container)1 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)1 EnvVarBuilder (io.fabric8.kubernetes.api.model.EnvVarBuilder)1 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 HostAlias (io.fabric8.kubernetes.api.model.HostAlias)1