use of io.fabric8.kubernetes.api.model.extensions.ReplicaSet in project fabric8-maven-plugin by fabric8io.
the class DockerImageWatcher method updateImageName.
private void updateImageName(KubernetesClient kubernetes, String namespace, HasMetadata entity, String imagePrefix, String imageName) {
String name = KubernetesHelper.getName(entity);
if (entity instanceof Deployment) {
Deployment resource = (Deployment) entity;
DeploymentSpec spec = resource.getSpec();
if (spec != null) {
if (updateImageName(entity, spec.getTemplate(), imagePrefix, imageName)) {
kubernetes.extensions().deployments().inNamespace(namespace).withName(name).replace(resource);
}
}
} else if (entity instanceof ReplicaSet) {
ReplicaSet resource = (ReplicaSet) entity;
ReplicaSetSpec spec = resource.getSpec();
if (spec != null) {
if (updateImageName(entity, spec.getTemplate(), imagePrefix, imageName)) {
kubernetes.extensions().replicaSets().inNamespace(namespace).withName(name).replace(resource);
}
}
} else if (entity instanceof ReplicationController) {
ReplicationController resource = (ReplicationController) entity;
ReplicationControllerSpec spec = resource.getSpec();
if (spec != null) {
if (updateImageName(entity, spec.getTemplate(), imagePrefix, imageName)) {
kubernetes.replicationControllers().inNamespace(namespace).withName(name).replace(resource);
}
}
} else if (entity instanceof DeploymentConfig) {
DeploymentConfig resource = (DeploymentConfig) entity;
DeploymentConfigSpec spec = resource.getSpec();
if (spec != null) {
if (updateImageName(entity, spec.getTemplate(), imagePrefix, imageName)) {
OpenShiftClient openshiftClient = new Controller(kubernetes).getOpenShiftClientOrNull();
if (openshiftClient == null) {
log.warn("Ignoring DeploymentConfig %s as not connected to an OpenShift cluster", name);
}
openshiftClient.deploymentConfigs().inNamespace(namespace).withName(name).replace(resource);
}
}
}
}
use of io.fabric8.kubernetes.api.model.extensions.ReplicaSet in project fabric8-maven-plugin by fabric8io.
the class EnricherManagerTest method enrichSimple.
@Test
public void enrichSimple() {
new Expectations() {
{
context.getConfig();
result = new ProcessorConfig(Arrays.asList("fmp-project"), null, new HashMap<String, TreeMap>());
}
};
EnricherManager manager = new EnricherManager(null, context);
KubernetesListBuilder builder = new KubernetesListBuilder();
builder.addNewReplicaSetItem().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().withName("test").withImage("busybox").endContainer().endSpec().endTemplate().endSpec().endReplicaSetItem();
manager.enrich(builder);
KubernetesList list = builder.build();
assertEquals(1, list.getItems().size());
ReplicaSet pod = (ReplicaSet) list.getItems().get(0);
ObjectMeta metadata = pod.getMetadata();
assertNotNull(metadata);
Map<String, String> labels = metadata.getLabels();
assertNotNull(labels);
assertEquals("fabric8", labels.get("provider"));
}
use of io.fabric8.kubernetes.api.model.extensions.ReplicaSet in project fabric8 by fabric8io.
the class KubernetesAssert method deployments.
/**
* Finds all the resources that create pod selections (Deployment, DeploymentConfig, ReplicaSet, ReplicationController)
* and create a {@link HasPodSelectionAssert} to make assertions on their pods that they startup etc.
*
* @return the assertion object for the deployment
*/
public HasPodSelectionAssert deployments() {
List<HasPodSelectionAssert> asserters = new ArrayList<>();
List<HasMetadata> resources = new ArrayList<>();
try {
resources = KubernetesHelper.findKubernetesResourcesOnClasspath(new Controller(client));
} catch (IOException e) {
fail("Failed to load kubernetes resources on the classpath: " + e, e);
}
for (HasMetadata resource : resources) {
HasPodSelectionAssert asserter = createPodSelectionAssert(resource);
if (asserter != null) {
asserters.add(asserter);
}
}
String message = "No pod selection kinds found on the classpath such as Deployment, DeploymentConfig, ReplicaSet, ReplicationController";
// TODO we don't yet support size > 1
assertThat(asserters).describedAs(message).isNotEmpty();
if (asserters.size() == 1) {
return asserters.get(0);
}
return new MultiHasPodSelectionAssert(asserters);
}
use of io.fabric8.kubernetes.api.model.extensions.ReplicaSet in project fabric8 by fabric8io.
the class Controller method applyEntity.
/**
* Applies the given DTOs onto the Kubernetes master
*/
public void applyEntity(Object dto, String sourceName) throws Exception {
if (dto instanceof Pod) {
applyPod((Pod) dto, sourceName);
} else if (dto instanceof ReplicationController) {
applyReplicationController((ReplicationController) dto, sourceName);
} else if (dto instanceof Service) {
applyService((Service) dto, sourceName);
} else if (dto instanceof Namespace) {
applyNamespace((Namespace) dto);
} else if (dto instanceof Route) {
applyRoute((Route) dto, sourceName);
} else if (dto instanceof BuildConfig) {
applyBuildConfig((BuildConfig) dto, sourceName);
} else if (dto instanceof DeploymentConfig) {
DeploymentConfig resource = (DeploymentConfig) dto;
OpenShiftClient openShiftClient = getOpenShiftClientOrNull();
if (openShiftClient != null && openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.APPS)) {
applyResource(resource, sourceName, openShiftClient.deploymentConfigs());
} else {
LOG.warn("Not connected to OpenShift cluster so cannot apply entity " + dto);
}
} else if (dto instanceof PolicyBinding) {
applyPolicyBinding((PolicyBinding) dto, sourceName);
} else if (dto instanceof RoleBinding) {
applyRoleBinding((RoleBinding) dto, sourceName);
} else if (dto instanceof Role) {
Role resource = (Role) dto;
OpenShiftClient openShiftClient = getOpenShiftClientOrNull();
if (openShiftClient != null && openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.AUTHORIZATION)) {
applyResource(resource, sourceName, openShiftClient.roles());
} else {
LOG.warn("Not connected to OpenShift cluster so cannot apply entity " + dto);
}
} else if (dto instanceof ImageStream) {
applyImageStream((ImageStream) dto, sourceName);
} else if (dto instanceof OAuthClient) {
applyOAuthClient((OAuthClient) dto, sourceName);
} else if (dto instanceof Template) {
applyTemplate((Template) dto, sourceName);
} else if (dto instanceof ServiceAccount) {
applyServiceAccount((ServiceAccount) dto, sourceName);
} else if (dto instanceof Secret) {
applySecret((Secret) dto, sourceName);
} else if (dto instanceof ConfigMap) {
applyResource((ConfigMap) dto, sourceName, kubernetesClient.configMaps());
} else if (dto instanceof DaemonSet) {
applyResource((DaemonSet) dto, sourceName, kubernetesClient.extensions().daemonSets());
} else if (dto instanceof Deployment) {
applyResource((Deployment) dto, sourceName, kubernetesClient.extensions().deployments());
} else if (dto instanceof ReplicaSet) {
applyResource((ReplicaSet) dto, sourceName, kubernetesClient.extensions().replicaSets());
} else if (dto instanceof StatefulSet) {
applyResource((StatefulSet) dto, sourceName, kubernetesClient.apps().statefulSets());
} else if (dto instanceof Ingress) {
applyResource((Ingress) dto, sourceName, kubernetesClient.extensions().ingresses());
} else if (dto instanceof PersistentVolumeClaim) {
applyPersistentVolumeClaim((PersistentVolumeClaim) dto, sourceName);
} else if (dto instanceof HasMetadata) {
HasMetadata entity = (HasMetadata) dto;
try {
String namespace = getNamespace();
String resourceNamespace = getNamespace(entity);
if (Strings.isNotBlank(namespace) && Strings.isNullOrBlank(resourceNamespace)) {
getOrCreateMetadata(entity).setNamespace(namespace);
}
LOG.info("Applying " + getKind(entity) + " " + getName(entity) + " from " + sourceName);
kubernetesClient.resource(entity).inNamespace(namespace).createOrReplace();
} catch (Exception e) {
onApplyError("Failed to create " + getKind(entity) + " from " + sourceName + ". " + e, e);
}
} else {
throw new IllegalArgumentException("Unknown entity type " + dto);
}
}
use of io.fabric8.kubernetes.api.model.extensions.ReplicaSet in project fabric8-maven-plugin by fabric8io.
the class ResourceMojo method lateInit.
private void lateInit() throws MojoExecutionException {
if (goalFinder.runningWithGoal(project, session, "fabric8:watch") || goalFinder.runningWithGoal(project, session, "fabric8:watch")) {
Properties properties = project.getProperties();
properties.setProperty("fabric8.watch", "true");
}
platformMode = clusterAccess.resolvePlatformMode(mode, log);
log.info("Running in [[B]]%s[[B]] mode", platformMode.getLabel());
if (isOpenShiftMode()) {
Properties properties = project.getProperties();
if (!properties.contains(DOCKER_IMAGE_USER)) {
String namespace = clusterAccess.getNamespace();
log.info("Using docker image name of namespace: " + namespace);
properties.setProperty(DOCKER_IMAGE_USER, namespace);
}
if (!properties.contains(PlatformMode.FABRIC8_EFFECTIVE_PLATFORM_MODE)) {
properties.setProperty(PlatformMode.FABRIC8_EFFECTIVE_PLATFORM_MODE, platformMode.toString());
}
}
openShiftConverters = new HashMap<>();
openShiftConverters.put("ReplicaSet", new ReplicSetOpenShiftConverter());
openShiftConverters.put("Deployment", new DeploymentOpenShiftConverter(platformMode, getOpenshiftDeployTimeoutSeconds()));
// TODO : This converter shouldn't be here. See its javadoc.
openShiftConverters.put("DeploymentConfig", new DeploymentConfigOpenShiftConverter(getOpenshiftDeployTimeoutSeconds()));
openShiftConverters.put("Namespace", new NamespaceOpenShiftConverter());
handlerHub = new HandlerHub(project);
}
Aggregations