use of org.bf2.cos.fleetshard.support.resources.Namespaces in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class ReSyncTest method namespaceIsProvisioned.
@Test
void namespaceIsProvisioned() {
final String namespacesUrl = "/api/connector_mgmt/v1/agent/kafka_connector_clusters/.*/namespaces";
final String deploymentsUrl = "/api/connector_mgmt/v1/agent/kafka_connector_clusters/.*/deployments";
kubernetesClient.resources(Namespace.class).createOrReplace(new NamespaceBuilder().withMetadata(new ObjectMetaBuilder().withName(Namespaces.generateNamespaceId(DEPLOYMENT_ID)).addToLabels(LABEL_CLUSTER_ID, config.cluster().id()).addToAnnotations(ANNOTATION_NAMESPACE_RESOURCE_VERSION, "20").build()).build());
kubernetesClient.resources(ManagedConnector.class).inNamespace(ns).createOrReplace(new ManagedConnectorBuilder().withMetadata(new ObjectMetaBuilder().withName(Connectors.generateConnectorId(DEPLOYMENT_ID)).addToLabels(LABEL_CLUSTER_ID, config.cluster().id()).build()).withSpec(new ManagedConnectorSpecBuilder().withDeployment(new DeploymentSpecBuilder().withDeploymentResourceVersion(10L).build()).withClusterId(config.cluster().id()).withConnectorId(CONNECTOR_ID).withDeploymentId(DEPLOYMENT_ID).withOperatorSelector(new OperatorSelectorBuilder().withId(uid()).build()).build()).build());
RestAssured.given().contentType(MediaType.TEXT_PLAIN).post("/test/provisioner/sync");
untilAsserted(() -> {
server.verify(1, getRequestedFor(urlPathMatching(namespacesUrl)).withQueryParam("gt_version", equalTo("0")));
server.verify(1, getRequestedFor(urlPathMatching(deploymentsUrl)).withQueryParam("gt_version", equalTo("0")));
});
RestAssured.given().contentType(MediaType.TEXT_PLAIN).post("/test/provisioner/sync");
untilAsserted(() -> {
server.verify(getRequestedFor(urlPathMatching(namespacesUrl)).withQueryParam("gt_version", equalTo("20")));
server.verify(getRequestedFor(urlPathMatching(deploymentsUrl)).withQueryParam("gt_version", equalTo("10")));
});
untilAsserted(() -> {
RestAssured.given().contentType(MediaType.TEXT_PLAIN).post("/test/provisioner/sync");
server.verify(2, getRequestedFor(urlPathMatching(namespacesUrl)).withQueryParam("gt_version", equalTo("0")));
server.verify(2, getRequestedFor(urlPathMatching(deploymentsUrl)).withQueryParam("gt_version", equalTo("0")));
});
}
use of org.bf2.cos.fleetshard.support.resources.Namespaces in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class FleetManagerClient method getNamespaces.
public void getNamespaces(long gv, Consumer<Collection<ConnectorNamespace>> consumer) {
RestClientHelper.run(() -> {
LOGGER.debug("polling namespaces with gv: {}", gv);
final AtomicInteger counter = new AtomicInteger();
final List<ConnectorNamespace> items = new ArrayList<>();
for (int i = 1; i < Integer.MAX_VALUE; i++) {
ConnectorNamespaceList list = controlPlane.getConnectorNamespaces(config.cluster().id(), Integer.toString(i), null, gv);
if (list == null || list.getItems() == null || list.getItems().isEmpty()) {
LOGGER.info("No namespace for cluster {}", config.cluster().id());
break;
}
items.addAll(list.getItems());
consumer.accept(items);
if (counter.addAndGet(items.size()) >= list.getTotal()) {
break;
}
}
});
}
use of org.bf2.cos.fleetshard.support.resources.Namespaces 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();
});
}
use of org.bf2.cos.fleetshard.support.resources.Namespaces in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class KeycloakOperatorManager method installKeycloak.
public static CompletableFuture<Void> installKeycloak(KubeClient kubeClient) throws Exception {
if (SystemTestEnvironment.INSTALL_KEYCLOAK) {
LOGGER.info("Installing Keycloak : {}", OPERATOR_NS);
kubeClient.client().namespaces().createOrReplace(new NamespaceBuilder().withNewMetadata().withName(OPERATOR_NS).endMetadata().build());
SecurityUtils.TlsConfig tls = SecurityUtils.getTLSConfig(OPERATOR_NS + ".svc");
Secret keycloakCert = new SecretBuilder().withNewMetadata().withName("sso-x509-https-secret").withNamespace(OPERATOR_NS).endMetadata().withType("kubernetes.io/tls").withData(Map.of("tls.crt", new String(Base64.getEncoder().encode(tls.getCert().getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8), "tls.key", new String(Base64.getEncoder().encode(tls.getKey().getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8))).build();
kubeClient.client().secrets().inNamespace(OPERATOR_NS).createOrReplace(keycloakCert);
List<String> keycloakInstallFiles = Arrays.asList("https://github.com/keycloak/keycloak-operator/raw/" + SystemTestEnvironment.KEYCLOAK_VERSION + "/deploy/service_account.yaml", "https://github.com/keycloak/keycloak-operator/raw/" + SystemTestEnvironment.KEYCLOAK_VERSION + "/deploy/role_binding.yaml", "https://github.com/keycloak/keycloak-operator/raw/" + SystemTestEnvironment.KEYCLOAK_VERSION + "/deploy/role.yaml", "https://raw.githubusercontent.com/keycloak/keycloak-operator/" + SystemTestEnvironment.KEYCLOAK_VERSION + "/deploy/cluster_roles/cluster_role_binding.yaml", "https://github.com/keycloak/keycloak-operator/raw/" + SystemTestEnvironment.KEYCLOAK_VERSION + "/deploy/cluster_roles/cluster_role.yaml", "https://github.com/keycloak/keycloak-operator/raw/" + SystemTestEnvironment.KEYCLOAK_VERSION + "/deploy/crds/keycloak.org_keycloakbackups_crd.yaml", "https://github.com/keycloak/keycloak-operator/raw/" + SystemTestEnvironment.KEYCLOAK_VERSION + "/deploy/crds/keycloak.org_keycloakclients_crd.yaml", "https://github.com/keycloak/keycloak-operator/raw/" + SystemTestEnvironment.KEYCLOAK_VERSION + "/deploy/crds/keycloak.org_keycloakrealms_crd.yaml", "https://github.com/keycloak/keycloak-operator/raw/" + SystemTestEnvironment.KEYCLOAK_VERSION + "/deploy/crds/keycloak.org_keycloaks_crd.yaml", "https://github.com/keycloak/keycloak-operator/raw/" + SystemTestEnvironment.KEYCLOAK_VERSION + "/deploy/crds/keycloak.org_keycloakusers_crd.yaml", "https://github.com/keycloak/keycloak-operator/raw/" + SystemTestEnvironment.KEYCLOAK_VERSION + "/deploy/operator.yaml");
for (String urlString : keycloakInstallFiles) {
URL url = new URL(urlString);
INSTALLED_RESOURCES.add(kubeClient.client().load(url.openStream()).get().get(0));
}
for (HasMetadata resource : INSTALLED_RESOURCES) {
resource.getMetadata().setNamespace(OPERATOR_NS);
kubeClient.client().resource(resource).inNamespace(OPERATOR_NS).createOrReplace();
}
kubeClient.cmdClient().namespace(OPERATOR_NS).execInCurrentNamespace("apply", "-f", Paths.get(Environment.SUITE_ROOT, "src", "main", "resources", "keycloak.yml").toAbsolutePath().toString());
LOGGER.info("Done installing Keycloak : {}", OPERATOR_NS);
return TestUtils.asyncWaitFor("Keycloak instance ready", 1_000, 600_000, () -> TestUtils.isPodReady(KubeClient.getInstance().client().pods().inNamespace(OPERATOR_NS).list().getItems().stream().filter(pod -> pod.getMetadata().getName().contains("keycloak-0")).findFirst().orElse(null)));
} else {
LOGGER.info("Keycloak is not installed suite will use values from env vars for oauth");
return CompletableFuture.completedFuture(null);
}
}
use of org.bf2.cos.fleetshard.support.resources.Namespaces in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class StrimziOperatorManager method doInstall.
protected CompletableFuture<Void> doInstall(KubeClient kubeClient) throws IOException {
LOGGER.info("Installing Strimzi : {} version: {}", operatorNs, version);
Namespace namespace = new NamespaceBuilder().withNewMetadata().withName(operatorNs).endMetadata().build();
kubeClient.client().namespaces().createOrReplace(namespace);
URL url = new URL(String.format(STRIMZI_URL_FORMAT, version));
// modify namespaces, convert rolebinding to clusterrolebindings, update deployment if needed
String crbID = UUID.randomUUID().toString().substring(0, 5);
kubeClient.apply(operatorNs, url.openStream(), i -> {
if (i instanceof Namespaced) {
i.getMetadata().setNamespace(operatorNs);
}
if (i instanceof ClusterRoleBinding) {
ClusterRoleBinding crb = (ClusterRoleBinding) i;
crb.getSubjects().forEach(sbj -> sbj.setNamespace(operatorNs));
crb.getMetadata().setName(crb.getMetadata().getName() + "." + operatorNs);
clusterWideResourceDeleters.add(unused -> {
kubeClient.client().rbac().clusterRoleBindings().withName(crb.getMetadata().getName()).delete();
});
} else if (i instanceof RoleBinding) {
RoleBinding rb = (RoleBinding) i;
rb.getSubjects().forEach(sbj -> sbj.setNamespace(operatorNs));
ClusterRoleBinding crb = new ClusterRoleBindingBuilder().withNewMetadata().withName(rb.getMetadata().getName() + "-all-ns-" + crbID).withAnnotations(rb.getMetadata().getAnnotations()).withLabels(rb.getMetadata().getLabels()).endMetadata().withRoleRef(rb.getRoleRef()).withSubjects(rb.getSubjects()).build();
LOGGER.info("Creating {} named {}", crb.getKind(), crb.getMetadata().getName());
kubeClient.client().rbac().clusterRoleBindings().createOrReplace(crb);
clusterWideResourceDeleters.add(unused -> {
kubeClient.client().rbac().clusterRoleBindings().withName(crb.getMetadata().getName()).delete();
});
} else if (i instanceof Deployment && "strimzi-cluster-operator".equals(i.getMetadata().getName())) {
modifyDeployment((Deployment) i);
}
return i;
});
LOGGER.info("Done installing Strimzi : {}", operatorNs);
return TestUtils.asyncWaitFor("Strimzi operator ready", 1_000, FleetShardOperatorManager.INSTALL_TIMEOUT_MS, () -> isReady(kubeClient, operatorNs, version));
}
Aggregations