use of com.redhat.service.smartevents.shard.operator.utils.LabelsBuilder in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class BridgeIngressSteps method deployBridgeIngressWithDefaultSecret.
@When("^deploy BridgeIngress with default secret:$")
public void deployBridgeIngressWithDefaultSecret(String bridgeIngressYaml) {
InputStream resourceStream = new ByteArrayInputStream(bridgeIngressYaml.getBytes(StandardCharsets.UTF_8));
BridgeIngress bridgeIngress = context.getClient().resources(BridgeIngress.class).inNamespace(context.getNamespace()).load(resourceStream).createOrReplace();
Secret secret = new SecretBuilder().withMetadata(new ObjectMetaBuilder().withLabels(new LabelsBuilder().withManagedByOperator().withComponent(BridgeIngress.COMPONENT_NAME).build()).withNamespace(bridgeIngress.getMetadata().getNamespace()).withName(bridgeIngress.getMetadata().getName()).build()).build();
context.getClient().secrets().inNamespace(bridgeIngress.getMetadata().getNamespace()).withName(bridgeIngress.getMetadata().getName()).createOrReplace(secret);
}
use of com.redhat.service.smartevents.shard.operator.utils.LabelsBuilder in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class BridgeExecutorServiceImpl method fetchOrCreateBridgeExecutorDeployment.
@Override
public Deployment fetchOrCreateBridgeExecutorDeployment(BridgeExecutor bridgeExecutor, Secret secret) {
Deployment expected = templateProvider.loadBridgeExecutorDeploymentTemplate(bridgeExecutor);
// Specs
expected.getSpec().getSelector().setMatchLabels(new LabelsBuilder().withAppInstance(bridgeExecutor.getMetadata().getName()).build());
expected.getSpec().getTemplate().getMetadata().setLabels(new LabelsBuilder().withAppInstance(bridgeExecutor.getMetadata().getName()).build());
expected.getSpec().getTemplate().getSpec().getContainers().get(0).setName(BridgeExecutor.COMPONENT_NAME);
expected.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(bridgeExecutor.getSpec().getImage());
expected.getSpec().setProgressDeadlineSeconds(deploymentTimeout);
List<EnvVar> environmentVariables = new ArrayList<>();
environmentVariables.add(new EnvVarBuilder().withName(Constants.BRIDGE_EXECUTOR_WEBHOOK_SSO_ENV_VAR).withValue(globalConfigurationsProvider.getSsoUrl()).build());
environmentVariables.add(new EnvVarBuilder().withName(Constants.BRIDGE_EXECUTOR_WEBHOOK_CLIENT_ID_ENV_VAR).withValue(globalConfigurationsProvider.getSsoWebhookClientId()).build());
environmentVariables.add(new EnvVarBuilder().withName(Constants.BRIDGE_EXECUTOR_WEBHOOK_CLIENT_SECRET_ENV_VAR).withValue(globalConfigurationsProvider.getSsoWebhookClientSecret()).build());
// CustomerId is available in the Processor definition however this avoids the need to unnecessarily de-serialise the definition for logging in the Executor
environmentVariables.add(new EnvVarBuilder().withName(Constants.CUSTOMER_ID_CONFIG_ENV_VAR).withValue(bridgeExecutor.getSpec().getCustomerId()).build());
environmentVariables.add(new EnvVarBuilder().withName(Constants.EVENT_BRIDGE_LOGGING_JSON).withValue(globalConfigurationsProvider.isJsonLoggingEnabled().toString()).build());
try {
environmentVariables.add(new EnvVarBuilder().withName(Constants.BRIDGE_EXECUTOR_PROCESSOR_DEFINITION_ENV_VAR).withValue(objectMapper.writeValueAsString(bridgeExecutor.toDTO())).build());
} catch (JsonProcessingException e) {
LOGGER.error("Could not serialize Processor Definition while setting executor deployment environment variables", e);
}
expected.getSpec().getTemplate().getSpec().getContainers().get(0).setEnv(environmentVariables);
expected.getSpec().getTemplate().getSpec().getContainers().get(0).getEnvFrom().get(0).getSecretRef().setName(secret.getMetadata().getName());
Deployment existing = kubernetesClient.apps().deployments().inNamespace(bridgeExecutor.getMetadata().getNamespace()).withName(bridgeExecutor.getMetadata().getName()).get();
if (existing == null || !DeploymentSpecUtils.isDeploymentEqual(expected, existing)) {
return kubernetesClient.apps().deployments().inNamespace(bridgeExecutor.getMetadata().getNamespace()).createOrReplace(expected);
}
return existing;
}
use of com.redhat.service.smartevents.shard.operator.utils.LabelsBuilder in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class BridgeIngressServiceImpl method fetchOrCreateBridgeIngressDeployment.
@Override
public Deployment fetchOrCreateBridgeIngressDeployment(BridgeIngress bridgeIngress, Secret secret) {
Deployment expected = templateProvider.loadBridgeIngressDeploymentTemplate(bridgeIngress);
// Specs
expected.getSpec().getSelector().setMatchLabels(new LabelsBuilder().withAppInstance(bridgeIngress.getMetadata().getName()).build());
expected.getSpec().getTemplate().getMetadata().setLabels(new LabelsBuilder().withAppInstance(bridgeIngress.getMetadata().getName()).build());
expected.getSpec().getTemplate().getSpec().getContainers().get(0).setName(BridgeIngress.COMPONENT_NAME);
expected.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(bridgeIngress.getSpec().getImage());
expected.getSpec().setProgressDeadlineSeconds(deploymentTimeout);
List<EnvVar> environmentVariables = new ArrayList<>();
environmentVariables.add(new EnvVarBuilder().withName(GlobalConfigurationsConstants.SSO_URL_CONFIG_ENV_VAR).withValue(globalConfigurationsProvider.getSsoUrl()).build());
environmentVariables.add(new EnvVarBuilder().withName(GlobalConfigurationsConstants.SSO_CLIENT_ID_CONFIG_ENV_VAR).withValue(globalConfigurationsProvider.getSsoClientId()).build());
environmentVariables.add(new EnvVarBuilder().withName(Constants.CUSTOMER_ID_CONFIG_ENV_VAR).withValue(bridgeIngress.getSpec().getCustomerId()).build());
environmentVariables.add(new EnvVarBuilder().withName(Constants.BRIDGE_INGRESS_WEBHOOK_TECHNICAL_ACCOUNT_ID).withValue(globalConfigurationsProvider.getSsoWebhookClientAccountId()).build());
environmentVariables.add(new EnvVarBuilder().withName(Constants.EVENT_BRIDGE_LOGGING_JSON).withValue(globalConfigurationsProvider.isJsonLoggingEnabled().toString()).build());
expected.getSpec().getTemplate().getSpec().getContainers().get(0).setEnv(environmentVariables);
expected.getSpec().getTemplate().getSpec().getContainers().get(0).getEnvFrom().get(0).getSecretRef().setName(secret.getMetadata().getName());
Deployment existing = kubernetesClient.apps().deployments().inNamespace(bridgeIngress.getMetadata().getNamespace()).withName(bridgeIngress.getMetadata().getName()).get();
if (existing == null || !DeploymentSpecUtils.isDeploymentEqual(expected, existing)) {
return kubernetesClient.apps().deployments().inNamespace(bridgeIngress.getMetadata().getNamespace()).createOrReplace(expected);
}
return existing;
}
use of com.redhat.service.smartevents.shard.operator.utils.LabelsBuilder in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class BridgeExecutorSteps method deployBridgeIngressWithDefaultSecrets.
@When("^deploy BridgeExecutor with default secret:$")
public void deployBridgeIngressWithDefaultSecrets(String bridgeExecutorYaml) {
InputStream resourceStream = new ByteArrayInputStream(bridgeExecutorYaml.getBytes(StandardCharsets.UTF_8));
BridgeExecutor bridgeExecutor = context.getClient().resources(BridgeExecutor.class).inNamespace(context.getNamespace()).load(resourceStream).create();
Secret secret = new SecretBuilder().withMetadata(new ObjectMetaBuilder().withLabels(new LabelsBuilder().withManagedByOperator().withComponent(BridgeExecutor.COMPONENT_NAME).build()).withNamespace(bridgeExecutor.getMetadata().getNamespace()).withName(bridgeExecutor.getMetadata().getName()).build()).build();
context.getClient().secrets().inNamespace(bridgeExecutor.getMetadata().getNamespace()).withName(bridgeExecutor.getMetadata().getName()).createOrReplace(secret);
}
use of com.redhat.service.smartevents.shard.operator.utils.LabelsBuilder in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class BridgeExecutorServiceImpl method fetchOrCreateBridgeExecutorService.
@Override
public Service fetchOrCreateBridgeExecutorService(BridgeExecutor bridgeExecutor, Deployment deployment) {
Service expected = templateProvider.loadBridgeExecutorServiceTemplate(bridgeExecutor);
// Specs
expected.getSpec().setSelector(new LabelsBuilder().withAppInstance(deployment.getMetadata().getName()).build());
Service existing = kubernetesClient.services().inNamespace(bridgeExecutor.getMetadata().getNamespace()).withName(bridgeExecutor.getMetadata().getName()).get();
if (existing == null || !expected.getSpec().getSelector().equals(existing.getSpec().getSelector())) {
return kubernetesClient.services().inNamespace(bridgeExecutor.getMetadata().getNamespace()).createOrReplace(expected);
}
return existing;
}
Aggregations