use of io.fabric8.knative.serving.v1.Service in project strimzi by strimzi.
the class KafkaConnectS2IAssemblyOperatorTest method testUpdateCluster.
@Test
public void testUpdateCluster(TestContext context) {
ConfigMapOperator mockCmOps = mock(ConfigMapOperator.class);
ServiceOperator mockServiceOps = mock(ServiceOperator.class);
DeploymentConfigOperator mockDcOps = mock(DeploymentConfigOperator.class);
BuildConfigOperator mockBcOps = mock(BuildConfigOperator.class);
ImageStreamOperator mockIsOps = mock(ImageStreamOperator.class);
String clusterCmName = "foo";
String clusterCmNamespace = "test";
ConfigMap clusterCm = ResourceUtils.createEmptyKafkaConnectS2IClusterConfigMap(clusterCmNamespace, clusterCmName);
KafkaConnectS2ICluster connect = KafkaConnectS2ICluster.fromConfigMap(clusterCm);
// Change the image to generate some diff
clusterCm.getData().put("image", "some/different:image");
when(mockCmOps.get(clusterCmNamespace, clusterCmName)).thenReturn(clusterCm);
when(mockServiceOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateService());
when(mockDcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateDeploymentConfig());
when(mockIsOps.get(clusterCmNamespace, connect.getSourceImageStreamName())).thenReturn(connect.generateSourceImageStream());
when(mockIsOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateTargetImageStream());
when(mockBcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateBuildConfig());
ArgumentCaptor<String> serviceNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> serviceNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Service> serviceCaptor = ArgumentCaptor.forClass(Service.class);
when(mockServiceOps.reconcile(serviceNamespaceCaptor.capture(), serviceNameCaptor.capture(), serviceCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> dcNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> dcNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<DeploymentConfig> dcCaptor = ArgumentCaptor.forClass(DeploymentConfig.class);
when(mockDcOps.reconcile(dcNamespaceCaptor.capture(), dcNameCaptor.capture(), dcCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> dcScaleUpNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> dcScaleUpNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Integer> dcScaleUpReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
when(mockDcOps.scaleUp(dcScaleUpNamespaceCaptor.capture(), dcScaleUpNameCaptor.capture(), dcScaleUpReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> dcScaleDownNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> dcScaleDownNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Integer> dcScaleDownReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
when(mockDcOps.scaleDown(dcScaleDownNamespaceCaptor.capture(), dcScaleDownNameCaptor.capture(), dcScaleDownReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> isNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> isNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<ImageStream> isCaptor = ArgumentCaptor.forClass(ImageStream.class);
when(mockIsOps.reconcile(isNamespaceCaptor.capture(), isNameCaptor.capture(), isCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> bcNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> bcNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<BuildConfig> bcCaptor = ArgumentCaptor.forClass(BuildConfig.class);
when(mockBcOps.reconcile(bcNamespaceCaptor.capture(), bcNameCaptor.capture(), bcCaptor.capture())).thenReturn(Future.succeededFuture());
KafkaConnectS2IAssemblyOperator ops = new KafkaConnectS2IAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps, mockIsOps, mockBcOps);
Async async = context.async();
ops.createOrUpdate(new Reconciliation("test-trigger", AssemblyType.CONNECT_S2I, clusterCmNamespace, clusterCmName), clusterCm, createResult -> {
context.assertTrue(createResult.succeeded());
KafkaConnectS2ICluster compareTo = KafkaConnectS2ICluster.fromConfigMap(clusterCm);
// Vertify service
List<Service> capturedServices = serviceCaptor.getAllValues();
context.assertEquals(1, capturedServices.size());
Service service = capturedServices.get(0);
context.assertEquals(compareTo.getName(), service.getMetadata().getName());
context.assertEquals(compareTo.generateService(), service, "Services are not equal");
// Verify Deployment Config
List<DeploymentConfig> capturedDc = dcCaptor.getAllValues();
context.assertEquals(1, capturedDc.size());
DeploymentConfig dc = capturedDc.get(0);
context.assertEquals(compareTo.getName(), dc.getMetadata().getName());
context.assertEquals(compareTo.generateDeploymentConfig(), dc, "Deployment Configs are not equal");
// Verify Build Config
List<BuildConfig> capturedBc = bcCaptor.getAllValues();
context.assertEquals(1, capturedBc.size());
BuildConfig bc = capturedBc.get(0);
context.assertEquals(compareTo.getName(), dc.getMetadata().getName());
context.assertEquals(compareTo.generateBuildConfig(), bc, "Build Configs are not equal");
// Verify Image Streams
List<ImageStream> capturedIs = isCaptor.getAllValues();
context.assertEquals(2, capturedIs.size());
int sisIndex = (compareTo.getSourceImageStreamName()).equals(capturedIs.get(0).getMetadata().getName()) ? 0 : 1;
int tisIndex = (compareTo.getName()).equals(capturedIs.get(0).getMetadata().getName()) ? 0 : 1;
ImageStream sis = capturedIs.get(sisIndex);
context.assertEquals(compareTo.getSourceImageStreamName(), sis.getMetadata().getName());
context.assertEquals(compareTo.generateSourceImageStream(), sis, "Source Image Streams are not equal");
ImageStream tis = capturedIs.get(tisIndex);
context.assertEquals(compareTo.getName(), tis.getMetadata().getName());
context.assertEquals(compareTo.generateTargetImageStream(), tis, "Target Image Streams are not equal");
async.complete();
});
}
use of io.fabric8.knative.serving.v1.Service in project strimzi by strimzi.
the class KafkaConnectS2IAssemblyOperatorTest method testUpdateClusterFailure.
@Test
public void testUpdateClusterFailure(TestContext context) {
ConfigMapOperator mockCmOps = mock(ConfigMapOperator.class);
ServiceOperator mockServiceOps = mock(ServiceOperator.class);
DeploymentConfigOperator mockDcOps = mock(DeploymentConfigOperator.class);
BuildConfigOperator mockBcOps = mock(BuildConfigOperator.class);
ImageStreamOperator mockIsOps = mock(ImageStreamOperator.class);
String clusterCmName = "foo";
String clusterCmNamespace = "test";
ConfigMap clusterCm = ResourceUtils.createEmptyKafkaConnectS2IClusterConfigMap(clusterCmNamespace, clusterCmName);
KafkaConnectS2ICluster connect = KafkaConnectS2ICluster.fromConfigMap(clusterCm);
// Change the image to generate some diff
clusterCm.getData().put("image", "some/different:image");
when(mockCmOps.get(clusterCmNamespace, clusterCmName)).thenReturn(clusterCm);
when(mockServiceOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateService());
when(mockDcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateDeploymentConfig());
when(mockIsOps.get(clusterCmNamespace, connect.getSourceImageStreamName())).thenReturn(connect.generateSourceImageStream());
when(mockIsOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateTargetImageStream());
when(mockBcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateBuildConfig());
ArgumentCaptor<String> serviceNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> serviceNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Service> serviceCaptor = ArgumentCaptor.forClass(Service.class);
when(mockServiceOps.reconcile(serviceNamespaceCaptor.capture(), serviceNameCaptor.capture(), serviceCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> dcNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> dcNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<DeploymentConfig> dcCaptor = ArgumentCaptor.forClass(DeploymentConfig.class);
when(mockDcOps.reconcile(dcNamespaceCaptor.capture(), dcNameCaptor.capture(), dcCaptor.capture())).thenReturn(Future.failedFuture("Failed"));
ArgumentCaptor<String> dcScaleUpNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> dcScaleUpNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Integer> dcScaleUpReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
when(mockDcOps.scaleUp(dcScaleUpNamespaceCaptor.capture(), dcScaleUpNameCaptor.capture(), dcScaleUpReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> dcScaleDownNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> dcScaleDownNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Integer> dcScaleDownReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
when(mockDcOps.scaleDown(dcScaleDownNamespaceCaptor.capture(), dcScaleDownNameCaptor.capture(), dcScaleDownReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> isNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> isNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<ImageStream> isCaptor = ArgumentCaptor.forClass(ImageStream.class);
when(mockIsOps.reconcile(isNamespaceCaptor.capture(), isNameCaptor.capture(), isCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> bcNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> bcNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<BuildConfig> bcCaptor = ArgumentCaptor.forClass(BuildConfig.class);
when(mockBcOps.reconcile(bcNamespaceCaptor.capture(), bcNameCaptor.capture(), bcCaptor.capture())).thenReturn(Future.succeededFuture());
KafkaConnectS2IAssemblyOperator ops = new KafkaConnectS2IAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps, mockIsOps, mockBcOps);
Async async = context.async();
ops.createOrUpdate(new Reconciliation("test-trigger", AssemblyType.CONNECT_S2I, clusterCmNamespace, clusterCmName), clusterCm, createResult -> {
context.assertFalse(createResult.succeeded());
async.complete();
});
}
use of io.fabric8.knative.serving.v1.Service in project strimzi by strimzi.
the class AbstractModel method createHeadlessService.
protected Service createHeadlessService(String name, List<ServicePort> ports, Map<String, String> annotations) {
Service service = new ServiceBuilder().withNewMetadata().withName(name).withLabels(getLabelsWithName(name)).withNamespace(namespace).withAnnotations(annotations).endMetadata().withNewSpec().withType("ClusterIP").withClusterIP("None").withSelector(getLabelsWithName()).withPorts(ports).endSpec().build();
log.trace("Created headless service {}", service);
return service;
}
use of io.fabric8.knative.serving.v1.Service in project strimzi by strimzi.
the class KafkaAssemblyOperator method createOrUpdateKafka.
private final Future<Void> createOrUpdateKafka(Reconciliation reconciliation, ConfigMap assemblyCm) {
String namespace = assemblyCm.getMetadata().getNamespace();
String name = assemblyCm.getMetadata().getName();
log.info("{}: create/update kafka {}", reconciliation, name);
KafkaCluster kafka = KafkaCluster.fromConfigMap(assemblyCm);
Service service = kafka.generateService();
Service headlessService = kafka.generateHeadlessService();
ConfigMap metricsConfigMap = kafka.generateMetricsConfigMap();
StatefulSet statefulSet = kafka.generateStatefulSet(isOpenShift);
Future<Void> chainFuture = Future.future();
kafkaSetOperations.scaleDown(namespace, kafka.getName(), kafka.getReplicas()).compose(scale -> serviceOperations.reconcile(namespace, kafka.getName(), service)).compose(i -> serviceOperations.reconcile(namespace, kafka.getHeadlessName(), headlessService)).compose(i -> configMapOperations.reconcile(namespace, kafka.getMetricsConfigName(), metricsConfigMap)).compose(i -> kafkaSetOperations.reconcile(namespace, kafka.getName(), statefulSet)).compose(diffs -> {
if (diffs instanceof ReconcileResult.Patched && ((ReconcileResult.Patched<Boolean>) diffs).differences()) {
return kafkaSetOperations.rollingUpdate(namespace, kafka.getName());
} else {
return Future.succeededFuture();
}
}).compose(i -> kafkaSetOperations.scaleUp(namespace, kafka.getName(), kafka.getReplicas())).compose(scale -> serviceOperations.endpointReadiness(namespace, service, 1_000, operationTimeoutMs)).compose(i -> serviceOperations.endpointReadiness(namespace, headlessService, 1_000, operationTimeoutMs)).compose(chainFuture::complete, chainFuture);
return chainFuture;
}
use of io.fabric8.knative.serving.v1.Service in project syndesis by syndesisio.
the class OpenShiftServiceImplTest method testDeploy.
@SuppressWarnings({ "PMD.ExcessiveMethodLength", "PMD.JUnitTestsShouldIncludeAssert" })
@Test
public void testDeploy() {
String name = "test-deployment";
OpenShiftConfigurationProperties config = new OpenShiftConfigurationProperties();
OpenShiftServiceImpl service = new OpenShiftServiceImpl(client, config);
DeploymentData deploymentData = new DeploymentData.Builder().addAnnotation("testName", testName.getMethodName()).addLabel("type", "test").addSecretEntry("secret-key", "secret-val").withImage("testimage").build();
ImageStream expectedImageStream = new ImageStreamBuilder().withNewMetadata().withName(name).endMetadata().build();
Secret expectedSecret = new SecretBuilder().withNewMetadata().withName(name).addToAnnotations(deploymentData.getAnnotations()).addToLabels(deploymentData.getLabels()).endMetadata().withStringData(deploymentData.getSecret()).build();
DeploymentConfig expectedDeploymentConfig = new DeploymentConfigBuilder().withNewMetadata().withName(OpenShiftServiceImpl.openshiftName(name)).addToAnnotations(deploymentData.getAnnotations()).addToLabels(deploymentData.getLabels()).endMetadata().withNewSpec().withReplicas(1).addToSelector("integration", name).withNewStrategy().withType("Recreate").withNewResources().addToLimits("memory", new Quantity(config.getDeploymentMemoryLimitMi() + "Mi")).addToRequests("memory", new Quantity(config.getDeploymentMemoryRequestMi() + "Mi")).endResources().endStrategy().withRevisionHistoryLimit(0).withNewTemplate().withNewMetadata().addToLabels("integration", name).addToLabels(OpenShiftServiceImpl.COMPONENT_LABEL, "integration").addToLabels(deploymentData.getLabels()).addToAnnotations(deploymentData.getAnnotations()).addToAnnotations("prometheus.io/scrape", "true").addToAnnotations("prometheus.io/port", "9779").endMetadata().withNewSpec().addNewContainer().withImage(deploymentData.getImage()).withImagePullPolicy("Always").withName(name).addToEnv(new EnvVarBuilder().withName("LOADER_HOME").withValue(config.getIntegrationDataPath()).build()).addToEnv(new EnvVarBuilder().withName("AB_JMX_EXPORTER_CONFIG").withValue("/tmp/src/prometheus-config.yml").build()).addNewPort().withName("jolokia").withContainerPort(8778).endPort().addNewVolumeMount().withName("secret-volume").withMountPath("/deployments/config").withReadOnly(false).endVolumeMount().endContainer().addNewVolume().withName("secret-volume").withNewSecret().withSecretName(expectedSecret.getMetadata().getName()).endSecret().endVolume().endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().withNewStatus().withLatestVersion(1L).endStatus().build();
server.expect().withPath("/oapi/v1/namespaces/test/imagestreams").andReturn(200, expectedImageStream).always();
server.expect().withPath("/api/v1/namespaces/test/secrets").andReturn(200, expectedSecret).always();
server.expect().withPath("/oapi/v1/namespaces/test/deploymentconfigs").andReturn(200, expectedDeploymentConfig).always();
server.expect().withPath("/oapi/v1/namespaces/test/deploymentconfigs/i-test-deployment").andReturn(200, expectedDeploymentConfig).always();
server.expect().withPath("/oapi/v1/namespaces/test/deploymentconfigs/test-deployment").andReturn(200, expectedDeploymentConfig).always();
service.deploy(name, deploymentData);
}
Aggregations