Search in sources :

Example 1 with ManagedKafkaAgentSpecBuilder

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaAgentSpecBuilder in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class ManagedKafkaProvisioner method install.

/**
 * Install this Kafka provisioner. This can be called once per test class or per test method.
 */
public void install() throws Exception {
    // delete/create the namespaces to be used
    Map<String, String> nsAnnotations = new HashMap<>();
    if (PerformanceEnvironment.KAFKA_COLLECT_LOG) {
        nsAnnotations.put(Constants.ORG_BF2_KAFKA_PERFORMANCE_COLLECTPODLOG, "true");
    }
    cluster.waitForDeleteNamespace(StrimziOperatorManager.OPERATOR_NS);
    FleetShardOperatorManager.deleteFleetShard(cluster.kubeClient()).get(2, TimeUnit.MINUTES);
    cluster.createNamespace(Constants.KAFKA_NAMESPACE, nsAnnotations, Map.of());
    List<Node> workers = cluster.getWorkerNodes();
    boolean smallNodes = workers.stream().anyMatch(n -> TestUtils.getMaxAvailableResources(n).cpuMillis < 3000);
    if (smallNodes) {
        MixedOperation<Deployment, DeploymentList, RollableScalableResource<Deployment>> deployments = cluster.kubeClient().client().apps().deployments();
        this.informer = deployments.inAnyNamespace().inform(new ResourceEventHandler<Deployment>() {

            @Override
            public void onUpdate(Deployment oldObj, Deployment newObj) {
                onAdd(newObj);
            }

            @Override
            public void onDelete(Deployment obj, boolean deletedFinalStateUnknown) {
            }

            @Override
            public void onAdd(Deployment obj) {
                if (!obj.getMetadata().getNamespace().equals(StrimziOperatorManager.OPERATOR_NS) && !obj.getMetadata().getNamespace().equals(FleetShardOperatorManager.OPERATOR_NS)) {
                    return;
                }
                // patch any deployment that requests a lot of cpu, and make sure it's on the perf infra
                deployments.inNamespace(obj.getMetadata().getNamespace()).withName(obj.getMetadata().getName()).edit(new TypedVisitor<ResourceRequirementsBuilder>() {

                    @Override
                    public void visit(ResourceRequirementsBuilder element) {
                        Quantity cpu = null;
                        if (element.getRequests() != null) {
                            cpu = element.getRequests().get("cpu");
                        }
                        if (cpu == null && element.getLimits() != null) {
                            cpu = element.getLimits().get("cpu");
                        }
                        if (cpu != null && Quantity.getAmountInBytes(cpu).compareTo(BigDecimal.valueOf(1)) > 0) {
                            element.addToRequests("cpu", Quantity.parse("1"));
                        }
                    }
                });
            }
        });
    }
    // installs the Strimzi Operator using the OLM bundle
    CompletableFuture<Void> strimziFuture = strimziManager.deployStrimziOperator();
    cluster.connectNamespaceToMonitoringStack(StrimziOperatorManager.OPERATOR_NS);
    // installs a cluster wide fleetshard operator
    // not looking at the returned futures - it's assumed that we'll eventually wait on the managed kafka deployment
    CompletableFuture<Void> future = FleetShardOperatorManager.deployFleetShardOperator(cluster.kubeClient());
    CompletableFuture.allOf(future, strimziFuture).get(2, TimeUnit.MINUTES);
    var agentResource = this.cluster.kubeClient().client().resource(new ManagedKafkaAgentBuilder().withNewMetadata().withName(ManagedKafkaAgentResourceClient.RESOURCE_NAME).withNamespace(FleetShardOperatorManager.OPERATOR_NS).endMetadata().withSpec(new ManagedKafkaAgentSpecBuilder().withNewObservability().withAccessToken("").withChannel("").withRepository("").withTag("").endObservability().build()).build());
    agentResource.createOrReplace();
    // FleetShardOperatorManager.deployFleetShardSync(cluster.kubeClient());
    cluster.connectNamespaceToMonitoringStack(FleetShardOperatorManager.OPERATOR_NS);
    strimziVersions = SyncApiClient.getSortedAvailableStrimziVersions(() -> agentResource.fromServer().get().getStatus()).collect(Collectors.toList());
}
Also used : HashMap(java.util.HashMap) Node(io.fabric8.kubernetes.api.model.Node) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) ManagedKafkaAgentSpecBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaAgentSpecBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Quantity(io.fabric8.kubernetes.api.model.Quantity) ManagedKafkaAgentBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaAgentBuilder) ResourceEventHandler(io.fabric8.kubernetes.client.informers.ResourceEventHandler) DeploymentList(io.fabric8.kubernetes.api.model.apps.DeploymentList) RollableScalableResource(io.fabric8.kubernetes.client.dsl.RollableScalableResource)

Example 2 with ManagedKafkaAgentSpecBuilder

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaAgentSpecBuilder in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class OperatorST method deploy.

@BeforeAll
void deploy() throws Exception {
    strimziOperatorManager = new OlmBasedStrimziOperatorManager(kube, StrimziOperatorManager.OPERATOR_NS);
    CompletableFuture.allOf(strimziOperatorManager.deployStrimziOperator(), FleetShardOperatorManager.deployFleetShardOperator(kube)).join();
    // since sync is not installed, manually create the agent resource
    var agentResource = kube.client().resource(new ManagedKafkaAgentBuilder().withNewMetadata().withName(ManagedKafkaAgentResourceClient.RESOURCE_NAME).withNamespace(FleetShardOperatorManager.OPERATOR_NS).endMetadata().withSpec(new ManagedKafkaAgentSpecBuilder().withNewObservability().withAccessToken("").withChannel("").withRepository("").withTag("").endObservability().build()).build());
    agentResource.createOrReplace();
    // the operator will update the status after a while
    strimziVersions = SyncApiClient.getSortedAvailableStrimziVersions(() -> agentResource.fromServer().get().getStatus()).collect(Collectors.toList());
    assertTrue(strimziVersions.size() > 1);
    latestStrimziVersion = strimziVersions.get(strimziVersions.size() - 1);
    latestKafkaVersion = SyncApiClient.getLatestAvailableKafkaVersion(() -> agentResource.fromServer().get().getStatus(), latestStrimziVersion);
}
Also used : ManagedKafkaAgentSpecBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaAgentSpecBuilder) ManagedKafkaAgentBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaAgentBuilder) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

ManagedKafkaAgentBuilder (org.bf2.operator.resources.v1alpha1.ManagedKafkaAgentBuilder)2 ManagedKafkaAgentSpecBuilder (org.bf2.operator.resources.v1alpha1.ManagedKafkaAgentSpecBuilder)2 Node (io.fabric8.kubernetes.api.model.Node)1 Quantity (io.fabric8.kubernetes.api.model.Quantity)1 ResourceRequirementsBuilder (io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder)1 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)1 DeploymentList (io.fabric8.kubernetes.api.model.apps.DeploymentList)1 RollableScalableResource (io.fabric8.kubernetes.client.dsl.RollableScalableResource)1 ResourceEventHandler (io.fabric8.kubernetes.client.informers.ResourceEventHandler)1 HashMap (java.util.HashMap)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1