Search in sources :

Example 6 with CustomResourceDefinition

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

the class KafkaUpgradeDowngradeMockTest method initialize.

private Future<Void> initialize(VertxTestContext context, Kafka initialKafka) {
    CustomResourceDefinition kafkaAssemblyCrd = Crds.kafka();
    client = new MockKube().withCustomResourceDefinition(kafkaAssemblyCrd, Kafka.class, KafkaList.class).withInitialInstances(Collections.singleton(initialKafka)).end().withCustomResourceDefinition(Crds.strimziPodSet(), StrimziPodSet.class, StrimziPodSetList.class).end().build();
    ResourceOperatorSupplier supplier = new ResourceOperatorSupplier(vertx, client, ResourceUtils.zookeeperLeaderFinder(vertx, client), ResourceUtils.adminClientProvider(), ResourceUtils.zookeeperScalerProvider(), ResourceUtils.metricsProvider(), pfa, FeatureGates.NONE, 2_000);
    ClusterOperatorConfig config = ResourceUtils.dummyClusterOperatorConfig(VERSIONS);
    operator = new KafkaAssemblyOperator(vertx, pfa, new MockCertManager(), new PasswordGenerator(10, "a", "a"), supplier, config);
    LOGGER.info("Reconciling initially -> create");
    return operator.reconcile(new Reconciliation("initial-reconciliation", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME));
}
Also used : StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) MockKube(io.strimzi.test.mockkube.MockKube) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Reconciliation(io.strimzi.operator.common.Reconciliation) StrimziPodSetList(io.strimzi.api.kafka.StrimziPodSetList)

Example 7 with CustomResourceDefinition

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

the class MockKube method build.

@SuppressWarnings("unchecked")
@SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
public KubernetesClient build() {
    if (mockClient != null) {
        return mockClient;
    }
    configMapMockBuilder = addMockBuilder("configmaps", new MockBuilder<>(ConfigMap.class, ConfigMapList.class, MockBuilder.castClass(Resource.class), cmDb));
    endpointMockBuilder = addMockBuilder("endpoints", new MockBuilder<>(Endpoints.class, EndpointsList.class, MockBuilder.castClass(Resource.class), endpointDb));
    serviceMockBuilder = addMockBuilder("services", new ServiceMockBuilder(svcDb, endpointDb));
    secretMockBuilder = addMockBuilder("secrets", new MockBuilder<>(Secret.class, SecretList.class, MockBuilder.castClass(Resource.class), secretDb));
    serviceAccountMockBuilder = addMockBuilder("serviceaccounts", new MockBuilder<>(ServiceAccount.class, ServiceAccountList.class, MockBuilder.castClass(Resource.class), serviceAccountDb));
    routeMockBuilder = addMockBuilder("routes", new MockBuilder<>(Route.class, RouteList.class, MockBuilder.castClass(Resource.class), routeDb));
    buildConfigMockBuilder = addMockBuilder("buildConfigs", new MockBuilder<>(BuildConfig.class, BuildConfigList.class, MockBuilder.castClass(Resource.class), buildConfigDb));
    podDisruptionBudgedMockBuilder = addMockBuilder("poddisruptionbudgets", new MockBuilder<>(PodDisruptionBudget.class, PodDisruptionBudgetList.class, MockBuilder.castClass(Resource.class), pdbDb));
    podDisruptionBudgedV1Beta1MockBuilder = addMockBuilder("poddisruptionbudgetsV1Beta1", new MockBuilder<>(io.fabric8.kubernetes.api.model.policy.v1beta1.PodDisruptionBudget.class, io.fabric8.kubernetes.api.model.policy.v1beta1.PodDisruptionBudgetList.class, MockBuilder.castClass(Resource.class), pdbDbV1Beta1));
    roleBindingMockBuilder = addMockBuilder("rolebindings", new MockBuilder<>(RoleBinding.class, RoleBindingList.class, MockBuilder.castClass(Resource.class), pdbRb));
    roleMockBuilder = addMockBuilder("roles", new MockBuilder<>(Role.class, RoleList.class, MockBuilder.castClass(Resource.class), roleDb));
    clusterRoleBindingMockBuilder = addMockBuilder("clusterrolebindings", new MockBuilder<>(ClusterRoleBinding.class, ClusterRoleBindingList.class, MockBuilder.castClass(Resource.class), pdbCrb));
    networkPolicyMockBuilder = addMockBuilder("networkpolicies", new MockBuilder<>(NetworkPolicy.class, NetworkPolicyList.class, MockBuilder.castClass(Resource.class), policyDb));
    ingressMockBuilder = addMockBuilder("ingresses", new MockBuilder<>(Ingress.class, IngressList.class, MockBuilder.castClass(Resource.class), ingressDb));
    ingressV1Beta1MockBuilder = addMockBuilder("ingresses", new MockBuilder<>(io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress.class, io.fabric8.kubernetes.api.model.networking.v1beta1.IngressList.class, MockBuilder.castClass(Resource.class), ingressV1Beta1Db));
    podMockBuilder = addMockBuilder("pods", new MockBuilder<>(Pod.class, PodList.class, MockBuilder.castClass(PodResource.class), podDb));
    MixedOperation<Pod, PodList, PodResource<Pod>> mockPods = podMockBuilder.build();
    persistentVolumeClaimMockBuilder = addMockBuilder("persistentvolumeclaims", new MockBuilder<>(PersistentVolumeClaim.class, PersistentVolumeClaimList.class, MockBuilder.castClass(Resource.class), pvcDb));
    MixedOperation<PersistentVolumeClaim, PersistentVolumeClaimList, Resource<PersistentVolumeClaim>> mockPersistentVolumeClaims = persistentVolumeClaimMockBuilder.build();
    deploymentMockBuilder = addMockBuilder("deployments", new DeploymentMockBuilder(depDb, mockPods));
    MixedOperation<StatefulSet, StatefulSetList, RollableScalableResource<StatefulSet>> mockSs = buildStatefulSets(podMockBuilder, mockPods, mockPersistentVolumeClaims);
    // Top level group
    mockClient = mock(KubernetesClient.class);
    configMapMockBuilder.build2(mockClient::configMaps);
    serviceMockBuilder.build2(mockClient::services);
    secretMockBuilder.build2(mockClient::secrets);
    serviceAccountMockBuilder.build2(mockClient::serviceAccounts);
    when(mockClient.pods()).thenReturn(mockPods);
    endpointMockBuilder.build2(mockClient::endpoints);
    when(mockClient.persistentVolumeClaims()).thenReturn(mockPersistentVolumeClaims);
    // API group
    AppsAPIGroupDSL api = mock(AppsAPIGroupDSL.class);
    when(mockClient.apps()).thenReturn(api);
    when(api.statefulSets()).thenReturn(mockSs);
    deploymentMockBuilder.build2(api::deployments);
    MixedOperation<CustomResourceDefinition, CustomResourceDefinitionList, Resource<CustomResourceDefinition>> mockCrds = mock(MixedOperation.class);
    // Custom Resources
    if (mockedCrds != null && !mockedCrds.isEmpty()) {
        NonNamespaceOperation<CustomResourceDefinition, CustomResourceDefinitionList, Resource<CustomResourceDefinition>> crds = mock(MixedOperation.class);
        for (MockedCrd<?, ?, ?> mockedCrd : this.mockedCrds) {
            CustomResourceDefinition crd = mockedCrd.crd;
            Resource crdResource = mock(Resource.class);
            when(crdResource.get()).thenReturn(crd);
            when(crds.withName(crd.getMetadata().getName())).thenReturn(crdResource);
            String key = crdKey(mockedCrd.crClass);
            CreateOrReplaceable crdMixedOp = crdMixedOps.get(key);
            if (crdMixedOp == null) {
                CustomResourceMockBuilder customResourceMockBuilder = addMockBuilder(crd.getSpec().getNames().getPlural(), new CustomResourceMockBuilder<>((MockedCrd) mockedCrd));
                crdMixedOp = (MixedOperation<CustomResource, ? extends KubernetesResource, Resource<CustomResource>>) customResourceMockBuilder.build();
                crdMixedOps.put(key, crdMixedOp);
            }
            when(mockCrds.withName(eq(crd.getMetadata().getName()))).thenReturn(crdResource);
        }
        ApiextensionsAPIGroupDSL mockApiEx = mock(ApiextensionsAPIGroupDSL.class);
        V1ApiextensionAPIGroupDSL mockv1 = mock(V1ApiextensionAPIGroupDSL.class);
        when(mockClient.apiextensions()).thenReturn(mockApiEx);
        when(mockApiEx.v1()).thenReturn(mockv1);
        when(mockv1.customResourceDefinitions()).thenReturn(mockCrds);
        mockCrs(mockClient);
    }
    // Network group
    NetworkAPIGroupDSL network = mock(NetworkAPIGroupDSL.class);
    V1NetworkAPIGroupDSL networkV1 = mock(V1NetworkAPIGroupDSL.class);
    V1beta1NetworkAPIGroupDSL networkV1beta1 = mock(V1beta1NetworkAPIGroupDSL.class);
    when(mockClient.network()).thenReturn(network);
    when(network.v1()).thenReturn(networkV1);
    when(network.v1beta1()).thenReturn(networkV1beta1);
    networkPolicyMockBuilder.build2(network::networkPolicies);
    ingressMockBuilder.build2(networkV1::ingresses);
    ingressV1Beta1MockBuilder.build2(networkV1beta1::ingresses);
    // Policy group
    PolicyAPIGroupDSL policy = mock(PolicyAPIGroupDSL.class);
    V1PolicyAPIGroupDSL v1policy = mock(V1PolicyAPIGroupDSL.class);
    when(mockClient.policy()).thenReturn(policy);
    when(policy.v1()).thenReturn(v1policy);
    V1beta1PolicyAPIGroupDSL v1beta1policy = mock(V1beta1PolicyAPIGroupDSL.class);
    when(mockClient.policy()).thenReturn(policy);
    when(policy.v1beta1()).thenReturn(v1beta1policy);
    podDisruptionBudgedMockBuilder.build2(mockClient.policy().v1()::podDisruptionBudget);
    podDisruptionBudgedV1Beta1MockBuilder.build2(mockClient.policy().v1beta1()::podDisruptionBudget);
    // RBAC group
    RbacAPIGroupDSL rbac = mock(RbacAPIGroupDSL.class);
    when(mockClient.rbac()).thenReturn(rbac);
    roleBindingMockBuilder.build2(mockClient.rbac()::roleBindings);
    roleMockBuilder.build2(mockClient.rbac()::roles);
    clusterRoleBindingMockBuilder.buildNns(mockClient.rbac()::clusterRoleBindings);
    // Openshift group
    OpenShiftClient mockOpenShiftClient = mock(OpenShiftClient.class);
    when(mockClient.adapt(OpenShiftClient.class)).thenReturn(mockOpenShiftClient);
    routeMockBuilder.build2(mockOpenShiftClient::routes);
    buildConfigMockBuilder.build2(mockOpenShiftClient::buildConfigs);
    if (mockedCrds != null && !mockedCrds.isEmpty()) {
        ApiextensionsAPIGroupDSL mockApiEx = mock(ApiextensionsAPIGroupDSL.class);
        V1ApiextensionAPIGroupDSL mockv1 = mock(V1ApiextensionAPIGroupDSL.class);
        when(mockOpenShiftClient.apiextensions()).thenReturn(mockApiEx);
        when(mockApiEx.v1()).thenReturn(mockv1);
        when(mockv1.customResourceDefinitions()).thenReturn(mockCrds);
        mockCrs(mockOpenShiftClient);
    }
    doAnswer(i -> {
        for (MockBuilder<?, ?, ?> a : mockBuilders.values()) {
            a.assertNoWatchers();
        }
        return null;
    }).when(mockClient).close();
    return mockClient;
}
Also used : PersistentVolumeClaimList(io.fabric8.kubernetes.api.model.PersistentVolumeClaimList) CreateOrReplaceable(io.fabric8.kubernetes.client.dsl.CreateOrReplaceable) StatefulSetList(io.fabric8.kubernetes.api.model.apps.StatefulSetList) Pod(io.fabric8.kubernetes.api.model.Pod) V1ApiextensionAPIGroupDSL(io.fabric8.kubernetes.client.V1ApiextensionAPIGroupDSL) Resource(io.fabric8.kubernetes.client.dsl.Resource) BuildConfigResource(io.fabric8.openshift.client.dsl.BuildConfigResource) CustomResource(io.fabric8.kubernetes.client.CustomResource) RollableScalableResource(io.fabric8.kubernetes.client.dsl.RollableScalableResource) PodResource(io.fabric8.kubernetes.client.dsl.PodResource) KubernetesResource(io.fabric8.kubernetes.api.model.KubernetesResource) CustomResourceDefinitionList(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionList) V1PolicyAPIGroupDSL(io.fabric8.kubernetes.client.dsl.V1PolicyAPIGroupDSL) V1NetworkAPIGroupDSL(io.fabric8.kubernetes.client.V1NetworkAPIGroupDSL) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) RbacAPIGroupDSL(io.fabric8.kubernetes.client.dsl.RbacAPIGroupDSL) PodResource(io.fabric8.kubernetes.client.dsl.PodResource) ApiextensionsAPIGroupDSL(io.fabric8.kubernetes.client.dsl.ApiextensionsAPIGroupDSL) V1beta1PolicyAPIGroupDSL(io.fabric8.kubernetes.client.dsl.V1beta1PolicyAPIGroupDSL) PolicyAPIGroupDSL(io.fabric8.kubernetes.client.dsl.PolicyAPIGroupDSL) V1PolicyAPIGroupDSL(io.fabric8.kubernetes.client.dsl.V1PolicyAPIGroupDSL) PodList(io.fabric8.kubernetes.api.model.PodList) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) CustomResource(io.fabric8.kubernetes.client.CustomResource) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) NetworkAPIGroupDSL(io.fabric8.kubernetes.client.dsl.NetworkAPIGroupDSL) V1NetworkAPIGroupDSL(io.fabric8.kubernetes.client.V1NetworkAPIGroupDSL) V1beta1NetworkAPIGroupDSL(io.fabric8.kubernetes.client.V1beta1NetworkAPIGroupDSL) AppsAPIGroupDSL(io.fabric8.kubernetes.client.dsl.AppsAPIGroupDSL) V1beta1PolicyAPIGroupDSL(io.fabric8.kubernetes.client.dsl.V1beta1PolicyAPIGroupDSL) V1beta1NetworkAPIGroupDSL(io.fabric8.kubernetes.client.V1beta1NetworkAPIGroupDSL) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) RollableScalableResource(io.fabric8.kubernetes.client.dsl.RollableScalableResource) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 8 with CustomResourceDefinition

use of io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition in project debezium by debezium.

the class OcpApicurioV2Deployer method registryOperation.

protected NonNamespaceOperation<ApicurioRegistry, ApicurioRegistryList, Resource<ApicurioRegistry>> registryOperation() {
    CustomResourceDefinition crd = ocp.apiextensions().v1().customResourceDefinitions().load(OcpApicurioV2Deployer.class.getResourceAsStream(APICURIO_CRD_DESCRIPTOR)).get();
    CustomResourceDefinitionContext context = CustomResourceDefinitionContext.fromCrd(crd);
    return ocp.customResources(context, ApicurioRegistry.class, ApicurioRegistryList.class).inNamespace(project);
}
Also used : CustomResourceDefinitionContext(io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) ApicurioRegistryList(io.apicurio.registry.operator.api.model.ApicurioRegistryList) ApicurioRegistry(io.apicurio.registry.operator.api.model.ApicurioRegistry)

Example 9 with CustomResourceDefinition

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

the class Crds method crd.

@SuppressWarnings({ "checkstyle:JavaNCSS" })
private static CustomResourceDefinition crd(Class<? extends CustomResource> cls) {
    String scope, plural, singular, group, kind, listKind;
    List<String> versions;
    CustomResourceSubresourceStatus status = null;
    if (cls.equals(Kafka.class)) {
        scope = Kafka.SCOPE;
        plural = Kafka.RESOURCE_PLURAL;
        singular = Kafka.RESOURCE_SINGULAR;
        group = Kafka.RESOURCE_GROUP;
        kind = Kafka.RESOURCE_KIND;
        listKind = Kafka.RESOURCE_LIST_KIND;
        versions = Kafka.VERSIONS;
        status = new CustomResourceSubresourceStatus();
    } else if (cls.equals(KafkaConnect.class)) {
        scope = KafkaConnect.SCOPE;
        plural = KafkaConnect.RESOURCE_PLURAL;
        singular = KafkaConnect.RESOURCE_SINGULAR;
        group = KafkaConnect.RESOURCE_GROUP;
        kind = KafkaConnect.RESOURCE_KIND;
        listKind = KafkaConnect.RESOURCE_LIST_KIND;
        versions = KafkaConnect.VERSIONS;
        status = new CustomResourceSubresourceStatus();
    } else if (cls.equals(KafkaTopic.class)) {
        scope = KafkaTopic.SCOPE;
        plural = KafkaTopic.RESOURCE_PLURAL;
        singular = KafkaTopic.RESOURCE_SINGULAR;
        group = KafkaTopic.RESOURCE_GROUP;
        kind = KafkaTopic.RESOURCE_KIND;
        listKind = KafkaTopic.RESOURCE_LIST_KIND;
        versions = KafkaTopic.VERSIONS;
    } else if (cls.equals(KafkaUser.class)) {
        scope = KafkaUser.SCOPE;
        plural = KafkaUser.RESOURCE_PLURAL;
        singular = KafkaUser.RESOURCE_SINGULAR;
        group = KafkaUser.RESOURCE_GROUP;
        kind = KafkaUser.RESOURCE_KIND;
        listKind = KafkaUser.RESOURCE_LIST_KIND;
        versions = KafkaUser.VERSIONS;
        status = new CustomResourceSubresourceStatus();
    } else if (cls.equals(KafkaMirrorMaker.class)) {
        scope = KafkaMirrorMaker.SCOPE;
        plural = KafkaMirrorMaker.RESOURCE_PLURAL;
        singular = KafkaMirrorMaker.RESOURCE_SINGULAR;
        group = KafkaMirrorMaker.RESOURCE_GROUP;
        kind = KafkaMirrorMaker.RESOURCE_KIND;
        listKind = KafkaMirrorMaker.RESOURCE_LIST_KIND;
        versions = KafkaMirrorMaker.VERSIONS;
        status = new CustomResourceSubresourceStatus();
    } else if (cls.equals(KafkaBridge.class)) {
        scope = KafkaBridge.SCOPE;
        plural = KafkaBridge.RESOURCE_PLURAL;
        singular = KafkaBridge.RESOURCE_SINGULAR;
        group = KafkaBridge.RESOURCE_GROUP;
        kind = KafkaBridge.RESOURCE_KIND;
        listKind = KafkaBridge.RESOURCE_LIST_KIND;
        versions = KafkaBridge.VERSIONS;
        status = new CustomResourceSubresourceStatus();
    } else if (cls.equals(KafkaConnector.class)) {
        scope = KafkaConnector.SCOPE;
        plural = KafkaConnector.RESOURCE_PLURAL;
        singular = KafkaConnector.RESOURCE_SINGULAR;
        group = KafkaConnector.RESOURCE_GROUP;
        kind = KafkaConnector.RESOURCE_KIND;
        listKind = KafkaConnector.RESOURCE_LIST_KIND;
        versions = KafkaConnector.VERSIONS;
        status = new CustomResourceSubresourceStatus();
    } else if (cls.equals(KafkaMirrorMaker2.class)) {
        scope = KafkaMirrorMaker2.SCOPE;
        plural = KafkaMirrorMaker2.RESOURCE_PLURAL;
        singular = KafkaMirrorMaker2.RESOURCE_SINGULAR;
        group = KafkaMirrorMaker2.RESOURCE_GROUP;
        kind = KafkaMirrorMaker2.RESOURCE_KIND;
        listKind = KafkaMirrorMaker2.RESOURCE_LIST_KIND;
        versions = KafkaMirrorMaker2.VERSIONS;
        status = new CustomResourceSubresourceStatus();
    } else if (cls.equals(KafkaRebalance.class)) {
        scope = KafkaRebalance.SCOPE;
        plural = KafkaRebalance.RESOURCE_PLURAL;
        singular = KafkaRebalance.RESOURCE_SINGULAR;
        group = KafkaRebalance.RESOURCE_GROUP;
        kind = KafkaRebalance.RESOURCE_KIND;
        listKind = KafkaRebalance.RESOURCE_LIST_KIND;
        versions = KafkaRebalance.VERSIONS;
        status = new CustomResourceSubresourceStatus();
    } else if (cls.equals(StrimziPodSet.class)) {
        scope = StrimziPodSet.SCOPE;
        plural = StrimziPodSet.RESOURCE_PLURAL;
        singular = StrimziPodSet.RESOURCE_SINGULAR;
        group = StrimziPodSet.RESOURCE_GROUP;
        kind = StrimziPodSet.RESOURCE_KIND;
        listKind = StrimziPodSet.RESOURCE_LIST_KIND;
        versions = StrimziPodSet.VERSIONS;
        status = new CustomResourceSubresourceStatus();
    } else {
        throw new RuntimeException();
    }
    List<CustomResourceDefinitionVersion> crVersions = new ArrayList<>(versions.size());
    for (String apiVersion : versions) {
        crVersions.add(new CustomResourceDefinitionVersionBuilder().withName(apiVersion).withNewSubresources().withStatus(status).endSubresources().withNewSchema().withNewOpenAPIV3Schema().withType("object").withXKubernetesPreserveUnknownFields(true).endOpenAPIV3Schema().endSchema().withStorage("v1beta2".equals(apiVersion)).withServed(true).build());
    }
    return new CustomResourceDefinitionBuilder().withNewMetadata().withName(plural + "." + group).endMetadata().withNewSpec().withScope(scope).withGroup(group).withVersions(crVersions).withNewNames().withSingular(singular).withPlural(plural).withKind(kind).withListKind(listKind).endNames().endSpec().build();
}
Also used : CustomResourceDefinitionBuilder(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionBuilder) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) KafkaBridge(io.strimzi.api.kafka.model.KafkaBridge) ArrayList(java.util.ArrayList) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) CustomResourceDefinitionVersionBuilder(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionVersionBuilder) CustomResourceSubresourceStatus(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceSubresourceStatus) KafkaMirrorMaker2(io.strimzi.api.kafka.model.KafkaMirrorMaker2) CustomResourceDefinitionVersion(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionVersion) KafkaUser(io.strimzi.api.kafka.model.KafkaUser)

Example 10 with CustomResourceDefinition

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

the class StructuralCrdIT method assertApiVersionsAreStructuralInApiextensionsV1.

private void assertApiVersionsAreStructuralInApiextensionsV1(String api, VersionRange<ApiVersion> shouldBeStructural) {
    Pattern pattern = Pattern.compile("[^.]spec\\.versions\\[([0-9]+)\\]\\.[^,]*?");
    CustomResourceDefinition crd = cluster.client().getClient().apiextensions().v1().customResourceDefinitions().withName(api).get();
    // We can't make the following assertion because the current version of fabric8 always requests
    // the CRD using v1beta1 api version, so the apiserver just replaces it and serves it.
    // assertEquals(crdApiVersion, ApiVersion.parse(crd.getApiVersion().replace("apiextensions.k8s.io/", "")));
    Set<ApiVersion> presentCrdApiVersions = crd.getSpec().getVersions().stream().map(v -> ApiVersion.parse(v.getName())).collect(Collectors.toSet());
    assertTrue(presentCrdApiVersions.contains(shouldBeStructural.lower()), "CRD has versions " + presentCrdApiVersions + " which doesn't include " + shouldBeStructural.lower() + " which should be structural");
    Map<Integer, ApiVersion> indexedVersions = new HashMap<>();
    int i = 0;
    for (CustomResourceDefinitionVersion version : crd.getSpec().getVersions()) {
        indexedVersions.put(i, ApiVersion.parse(version.getName()));
    }
    Optional<CustomResourceDefinitionCondition> first = crd.getStatus().getConditions().stream().filter(cond -> "NonStructuralSchema".equals(cond.getType()) && "True".equals(cond.getStatus())).findFirst();
    if (first.isPresent()) {
        Matcher matcher = pattern.matcher(first.get().getMessage());
        while (matcher.find()) {
            Integer index = Integer.valueOf(matcher.group(1));
            ApiVersion nonStructuralVersion = indexedVersions.get(index);
            if (shouldBeStructural.contains(nonStructuralVersion)) {
                fail(api + "/ " + nonStructuralVersion + " should be structural but there's a complaint about " + matcher.group());
            }
        }
    }
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Set(java.util.Set) HashMap(java.util.HashMap) VersionRange(io.strimzi.api.annotations.VersionRange) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) CustomResourceDefinitionCondition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionCondition) Matcher(java.util.regex.Matcher) CustomResourceDefinitionVersion(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionVersion) Map(java.util.Map) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TestUtils(io.strimzi.test.TestUtils) Optional(java.util.Optional) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) Pattern(java.util.regex.Pattern) ApiVersion(io.strimzi.api.annotations.ApiVersion) Pattern(java.util.regex.Pattern) ApiVersion(io.strimzi.api.annotations.ApiVersion) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) CustomResourceDefinitionCondition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionCondition) CustomResourceDefinitionVersion(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionVersion)

Aggregations

CustomResourceDefinition (io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition)18 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)10 PasswordGenerator (io.strimzi.operator.common.PasswordGenerator)10 MockCertManager (io.strimzi.operator.common.operator.MockCertManager)10 MockKube (io.strimzi.test.mockkube.MockKube)10 StrimziPodSet (io.strimzi.api.kafka.model.StrimziPodSet)8 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)8 CustomResourceDefinition (io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition)6 KafkaList (io.strimzi.api.kafka.KafkaList)6 StrimziPodSetList (io.strimzi.api.kafka.StrimziPodSetList)6 Kafka (io.strimzi.api.kafka.model.Kafka)6 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)6 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)6 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)4 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)4 Pod (io.fabric8.kubernetes.api.model.Pod)4 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)4 CustomResourceDefinitionVersion (io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionVersion)4 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)4