Search in sources :

Example 51 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project syndesis-qe by syndesisio.

the class CamelK method getCamelKCRD.

private CustomResourceDefinitionContext getCamelKCRD() {
    CustomResourceDefinition crd = OpenShiftUtils.getInstance().customResourceDefinitions().withName("integrations.camel.apache.org").get();
    CustomResourceDefinitionContext.Builder builder = new CustomResourceDefinitionContext.Builder().withGroup(crd.getSpec().getGroup()).withPlural(crd.getSpec().getNames().getPlural()).withScope(crd.getSpec().getScope()).withVersion(crd.getSpec().getVersion());
    return builder.build();
}
Also used : CustomResourceDefinitionContext(io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition)

Example 52 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project strimzi by strimzi.

the class MockKube2 method registerCrd.

/**
 * Registers Custom Resource definition in the mock Kubernetes cluster. This registers it for deserialization, but
 * also creates the CRD in the Kubernetes server.
 *
 * @param apiVersion    API version of the Custom Resource
 * @param kind          Kind of the Custom Resource
 * @param crdClass      Class with the Custom Resource model
 * @param crdPath       Path to the YAML with the CRD definition
 */
private void registerCrd(String apiVersion, String kind, Class<? extends KubernetesResource> crdClass, String crdPath) {
    KubernetesDeserializer.registerCustomKind(apiVersion, kind, crdClass);
    CustomResourceDefinition kafkaCrd = client.apiextensions().v1().customResourceDefinitions().load(crdPath).get();
    client.apiextensions().v1().customResourceDefinitions().create(kafkaCrd);
}
Also used : CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition)

Example 53 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project strimzi by strimzi.

the class SetupClusterOperator method applyClusterOperatorInstallFiles.

/**
 * Perform application of ServiceAccount, Roles and CRDs needed for proper cluster operator deployment.
 * Configuration files are loaded from packaging/install/cluster-operator directory.
 */
public void applyClusterOperatorInstallFiles(String namespace) {
    List<File> operatorFiles = Arrays.stream(new File(CO_INSTALL_DIR).listFiles()).sorted().filter(File::isFile).filter(file -> !file.getName().matches(".*(Binding|Deployment)-.*")).collect(Collectors.toList());
    for (File operatorFile : operatorFiles) {
        File createFile = operatorFile;
        if (createFile.getName().contains(Constants.CLUSTER_ROLE + "-")) {
            createFile = switchClusterRolesToRolesIfNeeded(createFile);
        }
        final String resourceType = createFile.getName().split("-")[1];
        LOGGER.debug("Installation resource type: {}", resourceType);
        switch(resourceType) {
            case Constants.ROLE:
                Role role = TestUtils.configFromYaml(createFile, Role.class);
                ResourceManager.getInstance().createResource(extensionContext, new RoleBuilder(role).editMetadata().withNamespace(namespace).endMetadata().build());
                break;
            case Constants.CLUSTER_ROLE:
                ClusterRole clusterRole = TestUtils.configFromYaml(createFile, ClusterRole.class);
                ResourceManager.getInstance().createResource(extensionContext, clusterRole);
                break;
            case Constants.SERVICE_ACCOUNT:
                ServiceAccount serviceAccount = TestUtils.configFromYaml(createFile, ServiceAccount.class);
                ResourceManager.getInstance().createResource(extensionContext, new ServiceAccountBuilder(serviceAccount).editMetadata().withNamespace(namespace).endMetadata().build());
                break;
            case Constants.CONFIG_MAP:
                ConfigMap configMap = TestUtils.configFromYaml(createFile, ConfigMap.class);
                ResourceManager.getInstance().createResource(extensionContext, new ConfigMapBuilder(configMap).editMetadata().withNamespace(namespace).endMetadata().build());
                break;
            case Constants.CUSTOM_RESOURCE_DEFINITION_SHORT:
                CustomResourceDefinition customResourceDefinition = TestUtils.configFromYaml(createFile, CustomResourceDefinition.class);
                ResourceManager.getInstance().createResource(extensionContext, customResourceDefinition);
                break;
            default:
                LOGGER.error("Unknown installation resource type: {}", resourceType);
                throw new RuntimeException("Unknown installation resource type:" + resourceType);
        }
    }
}
Also used : Environment(io.strimzi.systemtest.Environment) ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Arrays(java.util.Arrays) OlmResource(io.strimzi.systemtest.resources.operator.specific.OlmResource) RoleBindingResource(io.strimzi.systemtest.resources.kubernetes.RoleBindingResource) OlmInstallationStrategy(io.strimzi.systemtest.enums.OlmInstallationStrategy) NetworkPolicyResource(io.strimzi.systemtest.resources.kubernetes.NetworkPolicyResource) Role(io.fabric8.kubernetes.api.model.rbac.Role) Level(org.apache.logging.log4j.Level) HashMap(java.util.HashMap) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) ClusterRoleBindingResource(io.strimzi.systemtest.resources.kubernetes.ClusterRoleBindingResource) ArrayList(java.util.ArrayList) RoleBuilder(io.fabric8.kubernetes.api.model.rbac.RoleBuilder) HelmResource(io.strimzi.systemtest.resources.operator.specific.HelmResource) KubeClusterResource(io.strimzi.test.k8s.KubeClusterResource) Map(java.util.Map) TestUtils(io.strimzi.test.TestUtils) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) StUtils(io.strimzi.systemtest.utils.StUtils) ClusterOperatorRBACType(io.strimzi.systemtest.enums.ClusterOperatorRBACType) BeforeAllOnce(io.strimzi.systemtest.BeforeAllOnce) OpenShift(io.strimzi.test.k8s.cluster.OpenShift) Predicate(java.util.function.Predicate) CollectorElement(io.strimzi.test.logs.CollectorElement) ServiceAccountBuilder(io.fabric8.kubernetes.api.model.ServiceAccountBuilder) Constants(io.strimzi.systemtest.Constants) IOException(java.io.IOException) ClusterRoleBindingTemplates(io.strimzi.systemtest.templates.kubernetes.ClusterRoleBindingTemplates) Collectors(java.util.stream.Collectors) File(java.io.File) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KubeClusterResource.kubeClient(io.strimzi.test.k8s.KubeClusterResource.kubeClient) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) Objects(java.util.Objects) RoleResource(io.strimzi.systemtest.resources.kubernetes.RoleResource) List(java.util.List) Exec(io.strimzi.test.executor.Exec) Logger(org.apache.logging.log4j.Logger) ResourceManager(io.strimzi.systemtest.resources.ResourceManager) ClusterRole(io.fabric8.kubernetes.api.model.rbac.ClusterRole) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) ServiceAccountBuilder(io.fabric8.kubernetes.api.model.ServiceAccountBuilder) RoleBuilder(io.fabric8.kubernetes.api.model.rbac.RoleBuilder) ClusterRole(io.fabric8.kubernetes.api.model.rbac.ClusterRole) Role(io.fabric8.kubernetes.api.model.rbac.Role) ClusterRole(io.fabric8.kubernetes.api.model.rbac.ClusterRole) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) File(java.io.File)

Example 54 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class PrometheusRegisterInterceptor method registerPrometheus.

@AroundInvoke
public Object registerPrometheus(InvocationContext context) throws Exception {
    if (!ServiceMonitorClient.isServiceMonitorAvailable(kubernetesClient)) {
        final CustomResourceDefinition serviceMonitorCRD = kubernetesClient.apiextensions().v1().customResourceDefinitions().load(this.getClass().getResourceAsStream("/k8s/servicemonitor.v1.crd.yaml")).get();
        kubernetesClient.apiextensions().v1().customResourceDefinitions().withName(SERVICE_MONITOR_CRD_NAME).create(serviceMonitorCRD);
    }
    return context.proceed();
}
Also used : CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) AroundInvoke(javax.interceptor.AroundInvoke)

Example 55 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project entando-k8s-controller-coordinator by entando-k8s.

the class DefaultSimpleKubernetesClientTest method shouldNotlistCustomResourceDefintionsWithoutCrdOfInterestLabel.

@Test
@Description("Should not list CustomResourceDefinitions without the label 'entando.org/crd-of-interest'")
void shouldNotlistCustomResourceDefintionsWithoutCrdOfInterestLabel() {
    step("Given I have removed the CustomResourceDefinition MyCRD", this::deleteMyCrd);
    step("And I have created the CustomResourceDefinition MyCRD without the label 'entando.org/crd-of-interest'", () -> {
        final CustomResourceDefinition value = objectMapper.readValue(Thread.currentThread().getContextClassLoader().getResource("mycrds.test.org.crd.yaml"), CustomResourceDefinition.class);
        getFabric8Client().apiextensions().v1beta1().customResourceDefinitions().create(value);
    });
    List<CustomResourceDefinition> crds = new ArrayList<>();
    step("When I list the CustomResourceDefinitions of interest", () -> {
        crds.addAll(myClient.loadCustomResourceDefinitionsOfInterest());
    });
    step("Then the CustomResourceDefinition without the entando.org/crd-of-interest label was not inluded in the list", () -> {
        assertThat(crds).noneMatch(crd -> crd.getMetadata().getName().equals("mycrds.test.org"));
    });
}
Also used : CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition) ArrayList(java.util.ArrayList) Description(io.qameta.allure.Description) Test(org.junit.jupiter.api.Test)

Aggregations

CustomResourceDefinition (io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition)60 Test (org.junit.jupiter.api.Test)49 CustomResourceDefinition (io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition)30 Description (io.qameta.allure.Description)12 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)11 IOException (java.io.IOException)11 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)10 CustomResourceDefinitionBuilder (io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionBuilder)10 Resource (io.fabric8.kubernetes.client.dsl.Resource)10 CustomResourceDefinitionContext (io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext)10 ArrayList (java.util.ArrayList)10 BeforeEach (org.junit.jupiter.api.BeforeEach)10 CustomResource (io.fabric8.kubernetes.client.CustomResource)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)7 StartupEvent (io.quarkus.runtime.StartupEvent)7 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)6 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)6 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)6 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)6