use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition in project strimzi by strimzi.
the class JbodStorageTest method init.
@BeforeEach
private void init() {
this.volumes = new ArrayList<>(2);
volumes.add(new PersistentClaimStorageBuilder().withId(0).withDeleteClaim(true).withSize("100Gi").build());
volumes.add(new PersistentClaimStorageBuilder().withId(1).withDeleteClaim(false).withSize("100Gi").build());
this.kafka = new KafkaBuilder().withNewMetadata().withNamespace(NAMESPACE).withName(NAME).endMetadata().withNewSpec().withNewKafka().withReplicas(3).withListeners(new GenericKafkaListenerBuilder().withName("plain").withPort(9092).withType(KafkaListenerType.INTERNAL).withTls(false).build()).withNewJbodStorage().withVolumes(volumes).endJbodStorage().endKafka().withNewZookeeper().withReplicas(1).endZookeeper().endSpec().build();
// setting up the Kafka CRD
CustomResourceDefinition kafkaAssemblyCrd = Crds.kafka();
// setting up a mock Kubernetes client
this.mockClient = new MockKube().withCustomResourceDefinition(kafkaAssemblyCrd, Kafka.class, KafkaList.class).end().withCustomResourceDefinition(Crds.strimziPodSet(), StrimziPodSet.class, StrimziPodSetList.class).end().build();
// initialize a Kafka in MockKube
Crds.kafkaOperation(this.mockClient).inNamespace(NAMESPACE).withName(NAME).create(this.kafka);
PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(false, KubernetesVersion.V1_16);
// creating the Kafka operator
ResourceOperatorSupplier ros = new ResourceOperatorSupplier(this.vertx, this.mockClient, ResourceUtils.zookeeperLeaderFinder(this.vertx, this.mockClient), ResourceUtils.adminClientProvider(), ResourceUtils.zookeeperScalerProvider(), ResourceUtils.metricsProvider(), pfa, FeatureGates.NONE, 60_000L);
this.operator = new KafkaAssemblyOperator(this.vertx, pfa, new MockCertManager(), new PasswordGenerator(10, "a", "a"), ros, ResourceUtils.dummyClusterOperatorConfig(VERSIONS, 2_000));
}
use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.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;
}
use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.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);
}
use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.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();
}
use of io.fabric8.kubernetes.api.model.apiextensions.v1beta1.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());
}
}
}
}
Aggregations