use of org.bf2.cos.fleetshard.support.resources.NamespacedName 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.NamespacedName 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.NamespacedName in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class FleetShardClient method getConnector.
public Optional<ManagedConnector> getConnector(NamespacedName id) {
if (connectorsInformer == null) {
throw new IllegalStateException("Informer must be started before adding handlers");
}
final String key = Cache.namespaceKeyFunc(id.getNamespace(), id.getName());
final ManagedConnector val = connectorsInformer.getIndexer().getByKey(key);
return Optional.ofNullable(val);
}
use of org.bf2.cos.fleetshard.support.resources.NamespacedName in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class NamespaceProvisionerTestBase method checkAddonPullSecretCopiedSuccessfullyToNamespace.
void checkAddonPullSecretCopiedSuccessfullyToNamespace(Namespace ns) {
//
// check copied addon-pullsecret exists
//
Secret copiedAddonPullSecret = until(() -> fleetShardClient.getSecret(new NamespacedName(config.namespace(), config.imagePullSecretsName())), Objects::nonNull);
assertThat(copiedAddonPullSecret.getType()).isEqualTo(TestFleetShardSync.ADDON_SECRET_TYPE);
assertThat(copiedAddonPullSecret.getData().get(TestFleetShardSync.ADDON_SECRET_FIELD)).isEqualTo(TestFleetShardSync.ADDON_SECRET_VALUE);
}
use of org.bf2.cos.fleetshard.support.resources.NamespacedName in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class NamespaceProvisionerWithNoQuotaTestBase 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, "false");
});
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(() -> {
ResourceQuota answer = fleetShardClient.getKubernetesClient().resourceQuotas().inNamespace(ns.getMetadata().getName()).withName(ns.getMetadata().getName() + "-quota").get();
assertThat(answer).isNull();
});
untilAsserted(() -> {
LimitRange answer = fleetShardClient.getKubernetesClient().limitRanges().inNamespace(ns.getMetadata().getName()).withName(ns.getMetadata().getName() + "-limits").get();
assertThat(answer).isNull();
});
}
Aggregations