use of org.bf2.operator.clients.canary.Status in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class ObservabilityManagerTest method testObservabilitySecret.
@Test
public void testObservabilitySecret() {
client.getConfiguration().setNamespace("test");
ObservabilityConfiguration config = new ObservabilityConfigurationBuilder().withAccessToken("test-token").withChannel("test").withRepository("test-repo").withTag("tag").build();
String ownerName = "SampleOwner";
Secret owner = client.secrets().inNamespace(client.getNamespace()).withName(ownerName).create(new SecretBuilder().withNewMetadata().withNamespace(client.getNamespace()).withName(ownerName).endMetadata().addToData("key", "value").build());
this.observabilityManager.createOrUpdateObservabilitySecret(config, owner);
// lets call event handler
Secret secret = observabilityManager.observabilitySecretResource().get();
assertNotNull(secret);
// the mock informermanager should be immediately updated, but it should
// not be seen as running
assertNotNull(observabilityManager.cachedObservabilitySecret());
assertFalse(observabilityManager.isObservabilityRunning());
assertFalse(secret.getMetadata().getOwnerReferences().isEmpty());
ObservabilityConfiguration secretConfig = new ObservabilityConfigurationBuilder().withAccessToken(new String(decoder.decode(secret.getData().get(ObservabilityManager.OBSERVABILITY_ACCESS_TOKEN)))).withChannel(new String(decoder.decode(secret.getData().get(ObservabilityManager.OBSERVABILITY_CHANNEL)))).withTag(new String(decoder.decode(secret.getData().get(ObservabilityManager.OBSERVABILITY_TAG)))).withRepository(new String(decoder.decode(secret.getData().get(ObservabilityManager.OBSERVABILITY_REPOSITORY)))).build();
// secret verification
assertEquals(secretConfig, config);
assertEquals("observability-operator", secret.getMetadata().getLabels().get("configures"));
// status verification, the Informers do not work in test framework thus direct verification
secret = ObservabilityManager.createObservabilitySecretBuilder(client.getNamespace(), config).editMetadata().addToAnnotations(ObservabilityManager.OBSERVABILITY_OPERATOR_STATUS, ObservabilityManager.ACCEPTED).endMetadata().build();
observabilityManager.observabilitySecretResource().createOrReplace(secret);
secret = observabilityManager.observabilitySecretResource().get();
assertTrue(ObservabilityManager.isObservabilityStatusAccepted(secret));
this.observabilityManager.createOrUpdateObservabilitySecret(config, owner);
// no-op update and make sure the flag is not flipped
secret = observabilityManager.observabilitySecretResource().get();
assertTrue(ObservabilityManager.isObservabilityStatusAccepted(secret));
}
use of org.bf2.operator.clients.canary.Status 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);
}
use of org.bf2.operator.clients.canary.Status in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class ManagedKafkaSync method syncKafkaClusters.
/**
* Update the local state based upon the remote ManagedKafkas
* The strategy here is to take a pass over the list and find any deferred work
* Then execute that deferred work using the {@link ManagedExecutor} but with
* a refresh of the state to ensure we're still acting appropriately.
*/
@Timed(value = "sync.poll", extraTags = { "resource", "ManagedKafka" }, description = "The time spent processing polling calls")
@Counted(value = "sync.poll", extraTags = { "resource", "ManagedKafka" }, description = "The number of polling calls")
public void syncKafkaClusters() {
Map<String, ManagedKafka> remotes = new HashMap<>();
for (ManagedKafka remoteManagedKafka : controlPlane.getKafkaClusters()) {
Objects.requireNonNull(remoteManagedKafka.getId());
Objects.requireNonNull(remoteManagedKafka.getMetadata().getNamespace());
remotes.put(ControlPlane.managedKafkaKey(remoteManagedKafka), remoteManagedKafka);
ManagedKafkaSpec remoteSpec = remoteManagedKafka.getSpec();
Objects.requireNonNull(remoteSpec);
String localKey = Cache.namespaceKeyFunc(remoteManagedKafka.getMetadata().getNamespace(), remoteManagedKafka.getMetadata().getName());
ManagedKafka existing = lookup.getLocalManagedKafka(localKey);
if (existing == null) {
if (!remoteSpec.isDeleted()) {
reconcileAsync(ControlPlane.managedKafkaKey(remoteManagedKafka), localKey);
} else {
// we've successfully removed locally, but control plane is not aware
// we need to send another status update to let them know
ManagedKafkaStatusBuilder statusBuilder = new ManagedKafkaStatusBuilder();
statusBuilder.withConditions(ConditionUtils.buildCondition(Type.Ready, Status.False).reason(Reason.Deleted));
// fire and forget the async call - if it fails, we'll retry on the next poll
controlPlane.updateKafkaClusterStatus(() -> {
return Map.of(remoteManagedKafka.getId(), statusBuilder.build());
});
}
} else {
final String localNamespace = existing.getMetadata().getNamespace();
final String managedKafkaId = existing.getMetadata().getAnnotations() == null ? null : existing.getMetadata().getAnnotations().get(MANAGEDKAFKA_ID_LABEL);
Namespace n = kubeClient.namespaces().withName(localNamespace).get();
if (n != null) {
String namespaceLabel = Optional.ofNullable(n.getMetadata().getLabels()).map(m -> m.get(MANAGEDKAFKA_ID_NAMESPACE_LABEL)).orElse("");
if (managedKafkaId != null && !namespaceLabel.equals(managedKafkaId)) {
kubeClient.namespaces().withName(localNamespace).edit(namespace -> new NamespaceBuilder(namespace).editMetadata().addToLabels(MANAGEDKAFKA_ID_NAMESPACE_LABEL, managedKafkaId).endMetadata().build());
}
}
if (specChanged(remoteSpec, existing) || !Objects.equals(existing.getPlacementId(), remoteManagedKafka.getPlacementId())) {
reconcileAsync(ControlPlane.managedKafkaKey(remoteManagedKafka), localKey);
}
}
}
// process final removals
for (ManagedKafka local : lookup.getLocalManagedKafkas()) {
if (remotes.get(ControlPlane.managedKafkaKey(local)) != null || !deleteAllowed(local)) {
continue;
}
reconcileAsync(null, Cache.metaNamespaceKeyFunc(local));
}
}
use of org.bf2.operator.clients.canary.Status in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class RegistryDeprovisioningIT method testDeprovisionRegistryBasic.
@Test
void testDeprovisionRegistryBasic() {
FleetManagerApi.verifyApiIsSecured();
var alice = new AccountInfo("testDeprovisionRegistry", "alice", false, 10L);
var registry1 = new RegistryCreate();
registry1.setName("registry1");
var createdRegistry1 = FleetManagerApi.createRegistry(registry1, alice);
assertNotEquals(RegistryStatusValue.failed, createdRegistry1.getStatus());
Awaitility.await("registry1 available").atMost(30, SECONDS).pollInterval(5, SECONDS).until(() -> {
var reg = FleetManagerApi.getRegistry(createdRegistry1.getId(), alice);
return reg.getStatus().equals(RegistryStatusValue.ready);
});
Registry registry = FleetManagerApi.getRegistry(createdRegistry1.getId(), alice);
TenantManagerClient tenantManager = Utils.createTenantManagerClient();
var internalTenant = tenantManager.getTenant(registry.getId());
assertEquals(TenantStatusValue.READY, internalTenant.getStatus());
FleetManagerApi.deleteRegistry(createdRegistry1.getId(), alice);
// We don't have to wait for the status to be RegistryStatusValueRest.deleting, since that happens almost immediately now.
Awaitility.await("registry1 deleting initiated").atMost(5, SECONDS).pollInterval(1, SECONDS).until(() -> {
var tenant1 = tenantManager.getTenant(registry.getId());
return TenantStatusValue.TO_BE_DELETED.equals(tenant1.getStatus());
});
var req = new UpdateRegistryTenantRequest();
req.setStatus(TenantStatusValue.DELETED);
tenantManager.updateTenant(registry.getId(), req);
Awaitility.await("registry1 deleted").atMost(5, SECONDS).pollInterval(1, SECONDS).until(() -> {
try {
FleetManagerApi.verifyRegistryNotExists(createdRegistry1.getId(), alice);
return true;
} catch (AssertionError ex) {
return false;
}
});
}
use of org.bf2.operator.clients.canary.Status in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class UsageMetrics method init.
public synchronized void init() {
expirationPeriod = Duration.ofSeconds(expirationPeriodSeconds);
int stagger = 0;
// Only stagger if the expiration period is at least 1 minute (testing support).
if (expirationPeriod.compareTo(Duration.ofMinutes(1)) >= 0) {
stagger = new Random().nextInt(expirationPeriodSeconds) + 1;
log.debug("Staggering usage metrics cache expiration by {} seconds", stagger);
}
nextExpiration = Instant.now().plus(Duration.ofSeconds(stagger));
for (RegistryStatusValueDto status : RegistryStatusValueDto.values()) {
Gauge.builder(USAGE_STATISTICS_REGISTRIES_STATUS, () -> {
Arc.initialize();
var ctx = Arc.container().requestContext();
ctx.activate();
try {
return getUsageStatisticsCached().getRegistryCountPerStatus().get(status);
} finally {
ctx.deactivate();
}
}).tags(Tags.of(TAG_USAGE_STATISTICS_STATUS, status.value())).register(metrics);
}
for (RegistryInstanceTypeValueDto type : RegistryInstanceTypeValueDto.values()) {
Gauge.builder(USAGE_STATISTICS_REGISTRIES_TYPE, () -> {
Arc.initialize();
var ctx = Arc.container().requestContext();
ctx.activate();
try {
return getUsageStatisticsCached().getRegistryCountPerType().get(type);
} finally {
ctx.deactivate();
}
}).tags(Tags.of(TAG_USAGE_STATISTICS_TYPE, type.value())).register(metrics);
}
Gauge.builder(USAGE_STATISTICS_ACTIVE_USERS, () -> {
Arc.initialize();
var ctx = Arc.container().requestContext();
ctx.activate();
try {
return getUsageStatisticsCached().getActiveUserCount();
} finally {
ctx.deactivate();
}
}).register(metrics);
Gauge.builder(USAGE_STATISTICS_ACTIVE_ORGANISATIONS, () -> {
Arc.initialize();
var ctx = Arc.container().requestContext();
ctx.activate();
try {
return getUsageStatisticsCached().getActiveOrganisationCount();
} finally {
ctx.deactivate();
}
}).register(metrics);
}
Aggregations