Search in sources :

Example 1 with LabelsBuilder

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);
}
Also used : BridgeIngress(com.redhat.service.smartevents.shard.operator.resources.BridgeIngress) Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) LabelsBuilder(com.redhat.service.smartevents.shard.operator.utils.LabelsBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) When(io.cucumber.java.en.When)

Example 2 with LabelsBuilder

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;
}
Also used : LabelsBuilder(com.redhat.service.smartevents.shard.operator.utils.LabelsBuilder) ArrayList(java.util.ArrayList) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with LabelsBuilder

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;
}
Also used : LabelsBuilder(com.redhat.service.smartevents.shard.operator.utils.LabelsBuilder) ArrayList(java.util.ArrayList) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder)

Example 4 with LabelsBuilder

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);
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) LabelsBuilder(com.redhat.service.smartevents.shard.operator.utils.LabelsBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BridgeExecutor(com.redhat.service.smartevents.shard.operator.resources.BridgeExecutor) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) When(io.cucumber.java.en.When)

Example 5 with LabelsBuilder

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;
}
Also used : LabelsBuilder(com.redhat.service.smartevents.shard.operator.utils.LabelsBuilder) Service(io.fabric8.kubernetes.api.model.Service)

Aggregations

LabelsBuilder (com.redhat.service.smartevents.shard.operator.utils.LabelsBuilder)7 When (io.cucumber.java.en.When)2 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)2 EnvVarBuilder (io.fabric8.kubernetes.api.model.EnvVarBuilder)2 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)2 Secret (io.fabric8.kubernetes.api.model.Secret)2 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)2 Service (io.fabric8.kubernetes.api.model.Service)2 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 BridgeExecutor (com.redhat.service.smartevents.shard.operator.resources.BridgeExecutor)1 BridgeIngress (com.redhat.service.smartevents.shard.operator.resources.BridgeIngress)1