use of org.bf2.cos.fleetshard.support.resources.Namespaces in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class NamespaceProvisionerBadIdTestBase method namespaceIsProvisioned.
@Test
void namespaceIsProvisioned() {
final String deployment1 = ConfigProvider.getConfig().getValue("test.deployment.id.1", String.class);
final String deployment2 = ConfigProvider.getConfig().getValue("test.deployment.id.2", String.class);
given().contentType(MediaType.TEXT_PLAIN).body(0L).post("/test/provisioner/namespaces");
server.until(putRequestedFor(urlPathMatching("/api/connector_mgmt/v1/agent/kafka_connector_clusters/.*/namespaces/.*/status")).withHeader(ContentTypeHeader.KEY, equalTo(APPLICATION_JSON)).withRequestBody(jp("$.id", deployment1)).withRequestBody(jp("$.version", "1")).withRequestBody(jp("$.phase", ConnectorNamespaceState.DISCONNECTED.getValue())).withRequestBody(jp("$.conditions.size()", "1")).withRequestBody(jp("$.conditions[0].type", Conditions.TYPE_READY)).withRequestBody(jp("$.conditions[0].status", Conditions.STATUS_FALSE)).withRequestBody(jp("$.conditions[0].reason", Conditions.FAILED_TO_CREATE_OR_UPDATE_RESOURCE_REASON)));
untilAsserted(() -> {
assertThat(fleetShardClient.getKubernetesClient().v1().events().inNamespace(config.namespace()).list().getItems()).anySatisfy(e -> {
assertThat(e.getInvolvedObject().getKind()).isEqualTo(ManagedConnectorCluster.class.getSimpleName());
assertThat(e.getType()).isEqualTo("Warning");
assertThat(e.getReason()).isEqualTo("FailedToCreateOrUpdateResource");
assertThat(e.getMessage()).contains("Unable to create or update namespace " + deployment1);
});
});
Namespace ns2 = until(() -> fleetShardClient.getNamespace(deployment2), Objects::nonNull);
assertThat(ns2).satisfies(item -> {
assertThat(item.getMetadata().getName()).isEqualTo(client.generateNamespaceId(deployment2));
assertThat(item.getMetadata().getLabels()).containsEntry(Resources.LABEL_CLUSTER_ID, fleetShardClient.getClusterId()).containsEntry(Resources.LABEL_NAMESPACE_ID, deployment2).containsEntry(Resources.LABEL_KUBERNETES_MANAGED_BY, fleetShardClient.getClusterId()).containsEntry(Resources.LABEL_KUBERNETES_CREATED_BY, fleetShardClient.getClusterId()).containsEntry(Resources.LABEL_KUBERNETES_PART_OF, fleetShardClient.getClusterId()).containsEntry(Resources.LABEL_KUBERNETES_COMPONENT, Resources.COMPONENT_NAMESPACE).containsEntry(Resources.LABEL_KUBERNETES_INSTANCE, deployment2).containsEntry(Resources.LABEL_NAMESPACE_TENANT_KIND, ConnectorNamespaceTenantKind.ORGANISATION.getValue()).containsKey(Resources.LABEL_NAMESPACE_TENANT_ID);
});
}
use of org.bf2.cos.fleetshard.support.resources.Namespaces in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class NamespaceProvisionerWithQuotaAndCustomLimitsTest method namespaceIsProvisioned.
@Test
void namespaceIsProvisioned() {
final Config cfg = ConfigProvider.getConfig();
final String nsId1 = cfg.getValue("test.ns.id.1", String.class);
final NamespacedName pullSecret = new NamespacedName(client.generateNamespaceId(nsId1), config.imagePullSecretsName());
RestAssured.given().contentType(MediaType.TEXT_PLAIN).body(0L).post("/test/provisioner/namespaces");
Namespace ns = until(() -> fleetShardClient.getNamespace(nsId1), Objects::nonNull);
assertThat(ns).satisfies(item -> {
assertThat(item.getMetadata().getName()).isEqualTo(client.generateNamespaceId(nsId1));
assertThat(item.getMetadata().getLabels()).containsEntry(Resources.LABEL_CLUSTER_ID, fleetShardClient.getClusterId()).containsEntry(Resources.LABEL_NAMESPACE_ID, nsId1).containsEntry(Resources.LABEL_KUBERNETES_MANAGED_BY, fleetShardClient.getClusterId()).containsEntry(Resources.LABEL_KUBERNETES_CREATED_BY, fleetShardClient.getClusterId()).containsEntry(Resources.LABEL_KUBERNETES_PART_OF, fleetShardClient.getClusterId()).containsEntry(Resources.LABEL_KUBERNETES_COMPONENT, Resources.COMPONENT_NAMESPACE).containsEntry(Resources.LABEL_KUBERNETES_INSTANCE, nsId1).containsKey(Resources.LABEL_UOW);
assertThat(item.getMetadata().getAnnotations()).containsEntry(Resources.ANNOTATION_NAMESPACE_QUOTA, "true");
});
until(() -> fleetShardClient.getSecret(pullSecret).filter(ps -> {
return Objects.equals(ps.getMetadata().getLabels().get(Resources.LABEL_UOW), ns.getMetadata().getLabels().get(Resources.LABEL_UOW));
}), Objects::nonNull);
untilAsserted(() -> {
return Optional.ofNullable(fleetShardClient.getKubernetesClient().limitRanges().inNamespace(ns.getMetadata().getName()).withName(ns.getMetadata().getName() + "-limits").get());
}, lr -> {
assertThat(lr).satisfies(item -> {
assertThat(item.getMetadata().getLabels()).containsEntry(Resources.LABEL_UOW, ns.getMetadata().getLabels().get(Resources.LABEL_UOW));
assertThat(item.getSpec().getLimits()).hasSize(1);
assertThat(item.getSpec().getLimits().get(0).getDefault()).describedAs("LimitRanges (limits)").containsEntry(ConnectorNamespaceProvisioner.LIMITS_CPU, cfg.getValue("cos.quota.default-limits.cpu", Quantity.class)).containsEntry(ConnectorNamespaceProvisioner.LIMITS_MEMORY, cfg.getValue("cos.quota.default-limits.memory", Quantity.class));
assertThat(item.getSpec().getLimits().get(0).getDefaultRequest()).describedAs("LimitRanges (request)").containsEntry(ConnectorNamespaceProvisioner.LIMITS_CPU, cfg.getValue("cos.quota.default-request.cpu", Quantity.class)).containsEntry(ConnectorNamespaceProvisioner.LIMITS_MEMORY, cfg.getValue("cos.quota.default-request.memory", Quantity.class));
});
});
ResourceQuota rq = until(() -> {
ResourceQuota answer = fleetShardClient.getKubernetesClient().resourceQuotas().inNamespace(ns.getMetadata().getName()).withName(ns.getMetadata().getName() + "-quota").get();
return Optional.ofNullable(answer);
}, Objects::nonNull);
assertThat(rq).satisfies(item -> {
assertThat(item.getMetadata().getLabels()).containsEntry(Resources.LABEL_UOW, ns.getMetadata().getLabels().get(Resources.LABEL_UOW));
assertThat(item.getSpec().getHard()).containsEntry(ConnectorNamespaceProvisioner.RESOURCE_QUOTA_LIMITS_CPU, new Quantity(cfg.getValue("test.ns.id.1.limits.cpu", String.class))).containsEntry(ConnectorNamespaceProvisioner.RESOURCE_QUOTA_REQUESTS_CPU, new Quantity(cfg.getValue("test.ns.id.1.requests.cpu", String.class))).containsEntry(ConnectorNamespaceProvisioner.RESOURCE_QUOTA_LIMITS_MEMORY, new Quantity(cfg.getValue("test.ns.id.1.limits.memory", String.class))).containsEntry(ConnectorNamespaceProvisioner.RESOURCE_QUOTA_REQUESTS_MEMORY, new Quantity(cfg.getValue("test.ns.id.1.requests.memory", String.class)));
});
}
use of org.bf2.cos.fleetshard.support.resources.Namespaces in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class NamespaceProvisionerWithQuotaTest method namespaceIsProvisioned.
@Test
void namespaceIsProvisioned() {
final Config cfg = ConfigProvider.getConfig();
final String nsId1 = cfg.getValue("test.ns.id.1", String.class);
final NamespacedName pullSecret = new NamespacedName(client.generateNamespaceId(nsId1), config.imagePullSecretsName());
RestAssured.given().contentType(MediaType.TEXT_PLAIN).body(0L).post("/test/provisioner/namespaces");
Namespace ns = until(() -> fleetShardClient.getNamespace(nsId1), Objects::nonNull);
assertThat(ns).satisfies(item -> {
assertThat(item.getMetadata().getName()).isEqualTo(client.generateNamespaceId(nsId1));
assertThat(item.getMetadata().getLabels()).containsEntry(Resources.LABEL_CLUSTER_ID, fleetShardClient.getClusterId()).containsEntry(Resources.LABEL_NAMESPACE_ID, nsId1).containsEntry(Resources.LABEL_KUBERNETES_MANAGED_BY, fleetShardClient.getClusterId()).containsEntry(Resources.LABEL_KUBERNETES_CREATED_BY, fleetShardClient.getClusterId()).containsEntry(Resources.LABEL_KUBERNETES_PART_OF, fleetShardClient.getClusterId()).containsEntry(Resources.LABEL_KUBERNETES_COMPONENT, Resources.COMPONENT_NAMESPACE).containsEntry(Resources.LABEL_KUBERNETES_INSTANCE, nsId1).containsKey(Resources.LABEL_UOW);
assertThat(item.getMetadata().getAnnotations()).containsEntry(Resources.ANNOTATION_NAMESPACE_QUOTA, "true");
});
until(() -> fleetShardClient.getSecret(pullSecret).filter(ps -> {
return Objects.equals(ps.getMetadata().getLabels().get(Resources.LABEL_UOW), ns.getMetadata().getLabels().get(Resources.LABEL_UOW));
}), Objects::nonNull);
untilAsserted(() -> {
return Optional.ofNullable(fleetShardClient.getKubernetesClient().limitRanges().inNamespace(ns.getMetadata().getName()).withName(ns.getMetadata().getName() + "-limits").get());
}, lr -> {
assertThat(lr).satisfies(item -> {
assertThat(item.getMetadata().getLabels()).containsEntry(Resources.LABEL_UOW, ns.getMetadata().getLabels().get(Resources.LABEL_UOW));
assertThat(item.getSpec().getLimits()).hasSize(1);
assertThat(item.getSpec().getLimits().get(0).getDefault()).describedAs("LimitRanges (limits)").containsEntry(ConnectorNamespaceProvisioner.LIMITS_CPU, new Quantity("0.5")).containsEntry(ConnectorNamespaceProvisioner.LIMITS_MEMORY, new Quantity("0.5G"));
assertThat(item.getSpec().getLimits().get(0).getDefaultRequest()).describedAs("LimitRanges (request)").containsEntry(ConnectorNamespaceProvisioner.LIMITS_CPU, new Quantity("200m")).containsEntry(ConnectorNamespaceProvisioner.LIMITS_MEMORY, new Quantity("128m"));
});
});
ResourceQuota rq = until(() -> {
ResourceQuota answer = fleetShardClient.getKubernetesClient().resourceQuotas().inNamespace(ns.getMetadata().getName()).withName(ns.getMetadata().getName() + "-quota").get();
return Optional.ofNullable(answer);
}, Objects::nonNull);
assertThat(rq).satisfies(item -> {
assertThat(item.getMetadata().getLabels()).containsEntry(Resources.LABEL_UOW, ns.getMetadata().getLabels().get(Resources.LABEL_UOW));
assertThat(item.getSpec().getHard()).containsEntry(ConnectorNamespaceProvisioner.RESOURCE_QUOTA_LIMITS_CPU, cfg.getValue("test.ns.id.1.limits.cpu", Quantity.class)).containsEntry(ConnectorNamespaceProvisioner.RESOURCE_QUOTA_REQUESTS_CPU, cfg.getValue("test.ns.id.1.requests.cpu", Quantity.class)).containsEntry(ConnectorNamespaceProvisioner.RESOURCE_QUOTA_LIMITS_MEMORY, cfg.getValue("test.ns.id.1.limits.memory", Quantity.class)).containsEntry(ConnectorNamespaceProvisioner.RESOURCE_QUOTA_REQUESTS_MEMORY, cfg.getValue("test.ns.id.1.requests.memory", Quantity.class));
});
}
use of org.bf2.cos.fleetshard.support.resources.Namespaces in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class SyncTestSupport method namespaceList.
public static ObjectNode namespaceList(ConnectorNamespace... namespaces) {
var items = new ConnectorNamespaceList();
items.page(1);
items.size(namespaces.length);
items.total(namespaces.length);
for (ConnectorNamespace namespace : namespaces) {
items.addItemsItem(namespace);
}
return Serialization.jsonMapper().convertValue(items, ObjectNode.class);
}
use of org.bf2.cos.fleetshard.support.resources.Namespaces in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class NamespaceReaperWithLeftoversTest method namespaceIsProvisioned.
@Test
void namespaceIsProvisioned() {
final String deploymentId = ConfigProvider.getConfig().getValue("test.deployment.id", String.class);
final String statusUrl = "/api/connector_mgmt/v1/agent/kafka_connector_clusters/" + config.cluster().id() + "/status";
final String namespaceName = fleetShardClient.generateNamespaceId(deploymentId);
given().contentType(MediaType.TEXT_PLAIN).body(0L).post("/test/provisioner/namespaces");
until(() -> fleetShardClient.getNamespace(deploymentId), Objects::nonNull);
server.until(putRequestedFor(urlEqualTo(statusUrl)).withHeader(ContentTypeHeader.KEY, equalTo(APPLICATION_JSON)).withRequestBody(jp("$.namespaces.size()", "1")).withRequestBody(jp("$.namespaces[0].phase", Namespaces.PHASE_READY)).withRequestBody(jp("$.namespaces[0].version", "0")).withRequestBody(jp("$.namespaces[0].connectors_deployed", "0")));
final ManagedConnector connector = new ManagedConnectorBuilder().withMetadata(new ObjectMetaBuilder().withName(Connectors.generateConnectorId(deploymentId)).withNamespace(namespaceName).addToLabels(LABEL_CLUSTER_ID, config.cluster().id()).addToLabels(LABEL_CONNECTOR_ID, deploymentId).addToLabels(LABEL_DEPLOYMENT_ID, deploymentId).build()).withSpec(new ManagedConnectorSpecBuilder().withClusterId(config.cluster().id()).withConnectorId(deploymentId).withDeploymentId(deploymentId).withOperatorSelector(new OperatorSelectorBuilder().withId(deploymentId).build()).build()).build();
kubernetesClient.resources(ManagedConnector.class).inNamespace(connector.getMetadata().getNamespace()).create(connector);
untilAsserted(() -> {
assertThat(fleetShardClient.getAllConnectors()).isNotEmpty();
assertThat(fleetShardClient.getConnectors(connector.getMetadata().getNamespace())).isNotEmpty();
});
given().contentType(MediaType.TEXT_PLAIN).body(1L).post("/test/provisioner/namespaces");
server.until(putRequestedFor(urlEqualTo(statusUrl)).withHeader(ContentTypeHeader.KEY, equalTo(APPLICATION_JSON)).withRequestBody(matchingJsonPath("$.namespaces", WireMock.absent())));
}
Aggregations