Search in sources :

Example 1 with NamespacedName

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)));
    });
}
Also used : ConnectorNamespaceState(org.bf2.cos.fleet.manager.model.ConnectorNamespaceState) Quantity(io.fabric8.kubernetes.api.model.Quantity) ConnectorNamespaceQuota(org.bf2.cos.fleet.manager.model.ConnectorNamespaceQuota) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConnectorNamespace(org.bf2.cos.fleet.manager.model.ConnectorNamespace) WireMock(com.github.tomakehurst.wiremock.client.WireMock) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Inject(javax.inject.Inject) MediaType(javax.ws.rs.core.MediaType) NamespacedName(org.bf2.cos.fleetshard.support.resources.NamespacedName) Resources.uid(org.bf2.cos.fleetshard.support.resources.Resources.uid) Map(java.util.Map) SyncTestSupport(org.bf2.cos.fleetshard.sync.it.support.SyncTestSupport) FleetShardClient(org.bf2.cos.fleetshard.sync.client.FleetShardClient) SyncTestProfile(org.bf2.cos.fleetshard.sync.it.support.SyncTestProfile) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) ConnectorNamespaceStatus1(org.bf2.cos.fleet.manager.model.ConnectorNamespaceStatus1) ConnectorNamespaceTenant(org.bf2.cos.fleet.manager.model.ConnectorNamespaceTenant) ConnectorNamespaceTenantKind(org.bf2.cos.fleet.manager.model.ConnectorNamespaceTenantKind) TestProfile(io.quarkus.test.junit.TestProfile) Config(org.eclipse.microprofile.config.Config) ContentTypeHeader(com.github.tomakehurst.wiremock.http.ContentTypeHeader) Namespaces(org.bf2.cos.fleetshard.support.resources.Namespaces) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) ConnectorNamespaceProvisioner(org.bf2.cos.fleetshard.sync.resources.ConnectorNamespaceProvisioner) Namespace(io.fabric8.kubernetes.api.model.Namespace) ConfigProvider(org.eclipse.microprofile.config.ConfigProvider) ResourceQuota(io.fabric8.kubernetes.api.model.ResourceQuota) Optional(java.util.Optional) RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) FleetManagerMockServer(org.bf2.cos.fleetshard.sync.it.support.FleetManagerMockServer) RestAssured(io.restassured.RestAssured) CollectionUtils.mapOf(org.bf2.cos.fleetshard.support.CollectionUtils.mapOf) Resources(org.bf2.cos.fleetshard.support.resources.Resources) ResourceQuota(io.fabric8.kubernetes.api.model.ResourceQuota) Config(org.eclipse.microprofile.config.Config) Objects(java.util.Objects) Quantity(io.fabric8.kubernetes.api.model.Quantity) NamespacedName(org.bf2.cos.fleetshard.support.resources.NamespacedName) ConnectorNamespace(org.bf2.cos.fleet.manager.model.ConnectorNamespace) Namespace(io.fabric8.kubernetes.api.model.Namespace) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 2 with NamespacedName

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));
    });
}
Also used : ConnectorNamespaceState(org.bf2.cos.fleet.manager.model.ConnectorNamespaceState) Quantity(io.fabric8.kubernetes.api.model.Quantity) ConnectorNamespaceQuota(org.bf2.cos.fleet.manager.model.ConnectorNamespaceQuota) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConnectorNamespace(org.bf2.cos.fleet.manager.model.ConnectorNamespace) WireMock(com.github.tomakehurst.wiremock.client.WireMock) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Inject(javax.inject.Inject) MediaType(javax.ws.rs.core.MediaType) NamespacedName(org.bf2.cos.fleetshard.support.resources.NamespacedName) Resources.uid(org.bf2.cos.fleetshard.support.resources.Resources.uid) Map(java.util.Map) SyncTestSupport(org.bf2.cos.fleetshard.sync.it.support.SyncTestSupport) FleetShardClient(org.bf2.cos.fleetshard.sync.client.FleetShardClient) SyncTestProfile(org.bf2.cos.fleetshard.sync.it.support.SyncTestProfile) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) ConnectorNamespaceStatus1(org.bf2.cos.fleet.manager.model.ConnectorNamespaceStatus1) ConnectorNamespaceTenant(org.bf2.cos.fleet.manager.model.ConnectorNamespaceTenant) ConnectorNamespaceTenantKind(org.bf2.cos.fleet.manager.model.ConnectorNamespaceTenantKind) TestProfile(io.quarkus.test.junit.TestProfile) Config(org.eclipse.microprofile.config.Config) ContentTypeHeader(com.github.tomakehurst.wiremock.http.ContentTypeHeader) Namespaces(org.bf2.cos.fleetshard.support.resources.Namespaces) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) ConnectorNamespaceProvisioner(org.bf2.cos.fleetshard.sync.resources.ConnectorNamespaceProvisioner) Namespace(io.fabric8.kubernetes.api.model.Namespace) ConfigProvider(org.eclipse.microprofile.config.ConfigProvider) ResourceQuota(io.fabric8.kubernetes.api.model.ResourceQuota) Optional(java.util.Optional) RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) FleetManagerMockServer(org.bf2.cos.fleetshard.sync.it.support.FleetManagerMockServer) RestAssured(io.restassured.RestAssured) CollectionUtils.mapOf(org.bf2.cos.fleetshard.support.CollectionUtils.mapOf) Resources(org.bf2.cos.fleetshard.support.resources.Resources) ResourceQuota(io.fabric8.kubernetes.api.model.ResourceQuota) Config(org.eclipse.microprofile.config.Config) Objects(java.util.Objects) Quantity(io.fabric8.kubernetes.api.model.Quantity) NamespacedName(org.bf2.cos.fleetshard.support.resources.NamespacedName) ConnectorNamespace(org.bf2.cos.fleet.manager.model.ConnectorNamespace) Namespace(io.fabric8.kubernetes.api.model.Namespace) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 3 with NamespacedName

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);
}
Also used : ManagedConnector(org.bf2.cos.fleetshard.api.ManagedConnector)

Example 4 with NamespacedName

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);
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) Objects(java.util.Objects) NamespacedName(org.bf2.cos.fleetshard.support.resources.NamespacedName)

Example 5 with NamespacedName

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();
    });
}
Also used : LimitRange(io.fabric8.kubernetes.api.model.LimitRange) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.eclipse.microprofile.config.Config) Objects(java.util.Objects) Inject(javax.inject.Inject) Test(org.junit.jupiter.api.Test) MediaType(javax.ws.rs.core.MediaType) NamespacedName(org.bf2.cos.fleetshard.support.resources.NamespacedName) Namespace(io.fabric8.kubernetes.api.model.Namespace) ConfigProvider(org.eclipse.microprofile.config.ConfigProvider) ResourceQuota(io.fabric8.kubernetes.api.model.ResourceQuota) SyncTestSupport(org.bf2.cos.fleetshard.sync.it.support.SyncTestSupport) FleetShardClient(org.bf2.cos.fleetshard.sync.client.FleetShardClient) RestAssured(io.restassured.RestAssured) Resources(org.bf2.cos.fleetshard.support.resources.Resources) LimitRange(io.fabric8.kubernetes.api.model.LimitRange) ResourceQuota(io.fabric8.kubernetes.api.model.ResourceQuota) Config(org.eclipse.microprofile.config.Config) Objects(java.util.Objects) NamespacedName(org.bf2.cos.fleetshard.support.resources.NamespacedName) Namespace(io.fabric8.kubernetes.api.model.Namespace) Test(org.junit.jupiter.api.Test)

Aggregations

Objects (java.util.Objects)4 NamespacedName (org.bf2.cos.fleetshard.support.resources.NamespacedName)4 Namespace (io.fabric8.kubernetes.api.model.Namespace)3 ResourceQuota (io.fabric8.kubernetes.api.model.ResourceQuota)3 RestAssured (io.restassured.RestAssured)3 Inject (javax.inject.Inject)3 MediaType (javax.ws.rs.core.MediaType)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Resources (org.bf2.cos.fleetshard.support.resources.Resources)3 FleetShardClient (org.bf2.cos.fleetshard.sync.client.FleetShardClient)3 SyncTestSupport (org.bf2.cos.fleetshard.sync.it.support.SyncTestSupport)3 Config (org.eclipse.microprofile.config.Config)3 ConfigProvider (org.eclipse.microprofile.config.ConfigProvider)3 Test (org.junit.jupiter.api.Test)3 WireMock (com.github.tomakehurst.wiremock.client.WireMock)2 ContentTypeHeader (com.github.tomakehurst.wiremock.http.ContentTypeHeader)2 RequestMethod (com.github.tomakehurst.wiremock.http.RequestMethod)2 Quantity (io.fabric8.kubernetes.api.model.Quantity)2 QuarkusTest (io.quarkus.test.junit.QuarkusTest)2 TestProfile (io.quarkus.test.junit.TestProfile)2