Search in sources :

Example 26 with Group

use of io.fabric8.kubernetes.model.annotation.Group in project kubernetes-client by fabric8io.

the class PodGroupCreate method main.

public static void main(String[] args) {
    try (NamespacedVolcanoClient volcanoClient = new DefaultVolcanoClient()) {
        String namespace = "default";
        String groupName = "group1";
        PodGroup podGroup = Utils.buildDefaultPodGroups(namespace, groupName);
        // Create PodGroup
        volcanoClient.v1beta1().podGroups().inNamespace(namespace).createOrReplace(podGroup);
        System.out.println("Created: " + podGroup.getMetadata().getName());
        // Wait for status or 5s timeout
        volcanoClient.v1beta1().podGroups().inNamespace(namespace).withName(groupName).waitUntilCondition(group -> Objects.nonNull(group.getStatus()) && group.getStatus().getPhase().equals("Running"), 5, TimeUnit.SECONDS);
        System.out.println("Created: " + podGroup.getMetadata().getName());
        // List PodGroup
        PodGroupList podGroupList = volcanoClient.v1beta1().podGroups().inNamespace(namespace).list();
        System.out.println("There are " + podGroupList.getItems().size() + " PodGroup objects in " + namespace);
        // Delete PodGroup
        volcanoClient.v1beta1().podGroups().inNamespace(namespace).withName(groupName).delete();
    }
}
Also used : NamespacedVolcanoClient(io.fabric8.volcano.client.NamespacedVolcanoClient) DefaultVolcanoClient(io.fabric8.volcano.client.DefaultVolcanoClient) PodGroup(io.fabric8.volcano.scheduling.v1beta1.PodGroup) PodGroupList(io.fabric8.volcano.scheduling.v1beta1.PodGroupList)

Example 27 with Group

use of io.fabric8.kubernetes.model.annotation.Group in project kubernetes-client by fabric8io.

the class ConfigTest method shouldSetImpersonateUsernameAndGroupFromSystemProperty.

@Test
void shouldSetImpersonateUsernameAndGroupFromSystemProperty() {
    System.setProperty(Config.KUBERNETES_IMPERSONATE_USERNAME, "username");
    System.setProperty(Config.KUBERNETES_IMPERSONATE_GROUP, "group");
    final Map<String, List<String>> extras = new HashMap<>();
    extras.put("c", Collections.singletonList("d"));
    final Config config = new ConfigBuilder().withImpersonateUsername("a").withImpersonateExtras(extras).build();
    assertEquals("a", config.getImpersonateUsername());
    assertArrayEquals(new String[] { "group" }, config.getImpersonateGroups());
    assertEquals(Collections.singletonList("d"), config.getImpersonateExtras().get("c"));
}
Also used : HashMap(java.util.HashMap) ExecConfig(io.fabric8.kubernetes.api.model.ExecConfig) ExecConfigBuilder(io.fabric8.kubernetes.api.model.ExecConfigBuilder) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 28 with Group

use of io.fabric8.kubernetes.model.annotation.Group in project kubernetes-client by fabric8io.

the class ListBuildConfigs method main.

public static void main(String[] args) {
    try (OpenShiftClient client = new KubernetesClientBuilder().build().adapt(OpenShiftClient.class)) {
        if (!client.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.BUILD)) {
            logger.warn("This cluster does not support the API Group {}", OpenShiftAPIGroups.BUILD);
            return;
        }
        BuildConfigList list = client.buildConfigs().list();
        if (list == null) {
            logger.error("No list returned!");
            return;
        }
        List<BuildConfig> items = list.getItems();
        for (BuildConfig item : items) {
            logger.info("BuildConfig {} has version: {}", item.getMetadata().getName(), item.getApiVersion());
        }
    } catch (KubernetesClientException e) {
        logger.error("Failed: {}", e.getMessage(), e);
    }
}
Also used : KubernetesClientBuilder(io.fabric8.kubernetes.client.KubernetesClientBuilder) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) BuildConfigList(io.fabric8.openshift.api.model.BuildConfigList) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 29 with Group

use of io.fabric8.kubernetes.model.annotation.Group in project kubernetes-client by fabric8io.

the class ListDeploymentConfigs method main.

public static void main(String[] args) {
    try (OpenShiftClient client = new KubernetesClientBuilder().build().adapt(OpenShiftClient.class)) {
        if (!client.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.APPS)) {
            logger.warn("This cluster does not support the API Group {}", OpenShiftAPIGroups.APPS);
            return;
        }
        DeploymentConfigList list = client.deploymentConfigs().list();
        if (list == null) {
            logger.error("No list returned!");
            return;
        }
        List<DeploymentConfig> items = list.getItems();
        for (DeploymentConfig item : items) {
            logger.info("DeploymentConfig {} has version: {}", item.getMetadata().getName(), item.getApiVersion());
        }
        if (!items.isEmpty()) {
            DeploymentConfig deploymentConfig = items.get(0);
            String name = deploymentConfig.getMetadata().getName();
            deploymentConfig = client.deploymentConfigs().withName(name).get();
            if (deploymentConfig == null) {
                logger.error("No DeploymentConfig found for name {}", name);
                return;
            }
            logger.info("get() DeploymentConfig {} has version: {}", name, deploymentConfig.getApiVersion());
        }
    } catch (KubernetesClientException e) {
        logger.error("Failed: {}", e.getMessage(), e);
    }
}
Also used : KubernetesClientBuilder(io.fabric8.kubernetes.client.KubernetesClientBuilder) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) DeploymentConfigList(io.fabric8.openshift.api.model.DeploymentConfigList) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 30 with Group

use of io.fabric8.kubernetes.model.annotation.Group in project kubernetes-client by fabric8io.

the class SecurityContextConstraintsIT method load.

@Test
public void load() {
    SecurityContextConstraints loadedSCC = client.securityContextConstraints().load(getClass().getResourceAsStream("/test-scc.yml")).get();
    assertNotNull(loadedSCC);
    assertEquals("test-scc", loadedSCC.getMetadata().getName());
    assertTrue(loadedSCC.getAllowPrivilegedContainer());
    assertEquals("RunAsAny", loadedSCC.getRunAsUser().getType());
    assertEquals("RunAsAny", loadedSCC.getSeLinuxContext().getType());
    assertEquals(1, loadedSCC.getUsers().size());
    assertEquals("admin", loadedSCC.getUsers().get(0));
    assertEquals(1, loadedSCC.getGroups().size());
    assertEquals("admin-group", loadedSCC.getGroups().get(0));
}
Also used : SecurityContextConstraints(io.fabric8.openshift.api.model.SecurityContextConstraints) Test(org.junit.Test)

Aggregations

Test (org.junit.jupiter.api.Test)30 Test (org.junit.Test)24 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)16 Map (java.util.Map)15 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)13 HashMap (java.util.HashMap)12 CuratorFramework (org.apache.curator.framework.CuratorFramework)12 File (java.io.File)11 List (java.util.List)11 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)10 ParallelNamespaceTest (io.strimzi.systemtest.annotations.ParallelNamespaceTest)10 Collectors (java.util.stream.Collectors)9 ZooKeeperGroup (io.fabric8.groups.internal.ZooKeeperGroup)8 Pod (io.fabric8.kubernetes.api.model.Pod)8 KubernetesClientBuilder (io.fabric8.kubernetes.client.KubernetesClientBuilder)8 KafkaUser (io.strimzi.api.kafka.model.KafkaUser)8 RetryNTimes (org.apache.curator.retry.RetryNTimes)8 Tag (org.junit.jupiter.api.Tag)8