Search in sources :

Example 36 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.Deployment in project fabric8 by jboss-fuse.

the class ContainerUpgradeAndRollbackTest method deployment.

@Deployment
@StartLevelAware(autostart = true)
public static Archive<?> deployment() {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "container-upgrade-rollback-test.jar");
    archive.addPackage(CommandSupport.class.getPackage());
    archive.setManifest(new Asset() {

        @Override
        public InputStream openStream() {
            OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
            builder.addBundleManifestVersion(2);
            builder.addBundleSymbolicName(archive.getName());
            builder.addBundleVersion("1.0.0");
            builder.addImportPackages(ServiceLocator.class, FabricService.class);
            builder.addImportPackages("io.fabric8.git");
            builder.addImportPackages(AbstractCommand.class, Action.class);
            builder.addImportPackage("org.apache.felix.service.command;status=provisional");
            builder.addImportPackages(ConfigurationAdmin.class, ServiceTracker.class, Logger.class);
            return builder.openStream();
        }
    });
    return archive;
}
Also used : Action(org.apache.felix.gogo.commands.Action) ServiceTracker(org.osgi.util.tracker.ServiceTracker) InputStream(java.io.InputStream) AbstractCommand(org.apache.felix.gogo.commands.basic.AbstractCommand) Logger(org.slf4j.Logger) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) ServiceLocator(io.fabric8.api.gravia.ServiceLocator) FabricService(io.fabric8.api.FabricService) OSGiManifestBuilder(org.jboss.osgi.metadata.OSGiManifestBuilder) Asset(org.jboss.shrinkwrap.api.asset.Asset) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) CommandSupport(io.fabric8.itests.support.CommandSupport) StartLevelAware(org.jboss.arquillian.osgi.StartLevelAware) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 37 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.Deployment in project fabric8 by jboss-fuse.

the class FabricTestSupport method containerSetProfile.

/**
 * Cleans a containers profile by switching to default profile and resetting the profile.
 */
private boolean containerSetProfile(FabricService fabricService, CuratorFramework curator, String containerName, String profileName, Boolean waitForProvision) throws Exception {
    System.out.println("Switching profile: " + profileName + " on container:" + containerName);
    Container container = fabricService.getContainer(containerName);
    Version version = container.getVersion();
    Profile[] profiles = new Profile[] { version.getRequiredProfile(profileName) };
    Profile[] currentProfiles = container.getProfiles();
    Arrays.sort(profiles);
    Arrays.sort(currentProfiles);
    boolean same = true;
    if (profiles.length != currentProfiles.length) {
        same = false;
    } else {
        for (int i = 0; i < currentProfiles.length; i++) {
            if (!currentProfiles[i].equals(profiles[i])) {
                same = false;
            }
        }
    }
    if (!same && waitForProvision) {
        // This is required so that waitForProvisionSuccess doesn't retrun before the deployment agent kicks in.
        ZooKeeperUtils.setData(curator, ZkPath.CONTAINER_PROVISION_RESULT.getPath(containerName), "switching profile");
        container.setProfiles(profiles);
        Provision.containersStatus(Arrays.asList(container), "success", PROVISION_TIMEOUT);
    }
    return same;
}
Also used : Container(io.fabric8.api.Container) Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile)

Example 38 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.Deployment in project keycloak by keycloak.

the class KeycloakController method prepareEventSources.

@Override
public List<EventSource> prepareEventSources(EventSourceContext<Keycloak> context) {
    SharedIndexInformer<Deployment> deploymentInformer = client.apps().deployments().inNamespace(context.getConfigurationService().getClientConfiguration().getNamespace()).withLabels(Constants.DEFAULT_LABELS).runnableInformer(0);
    EventSource deploymentEvent = new InformerEventSource<>(deploymentInformer, Mappers.fromOwnerReference());
    return List.of(deploymentEvent);
}
Also used : InformerEventSource(io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource) EventSource(io.javaoperatorsdk.operator.processing.event.source.EventSource) InformerEventSource(io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment)

Example 39 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.Deployment in project keycloak by keycloak.

the class ClusterOperatorTest method createRBACresourcesAndOperatorDeployment.

private static void createRBACresourcesAndOperatorDeployment() throws FileNotFoundException {
    Log.info("Creating RBAC into Namespace " + namespace);
    List<HasMetadata> hasMetadata = k8sclient.load(new FileInputStream(TARGET_KUBERNETES_GENERATED_YML_FOLDER + deploymentTarget + ".yml")).inNamespace(namespace).get();
    hasMetadata.stream().map(b -> {
        if ("Deployment".equalsIgnoreCase(b.getKind()) && b.getMetadata().getName().contains("operator")) {
            ((Deployment) b).getSpec().getTemplate().getSpec().getContainers().get(0).setImagePullPolicy("Never");
        }
        return b;
    }).forEach(c -> {
        Log.info("processing part : " + c.getKind() + "--" + c.getMetadata().getName() + " -- " + namespace);
        k8sclient.resource(c).inNamespace(namespace).createOrReplace();
    });
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AfterAll(org.junit.jupiter.api.AfterAll) OperatorProducer(io.quarkiverse.operatorsdk.runtime.OperatorProducer) Reconciler(io.javaoperatorsdk.operator.api.reconciler.Reconciler) Operator(io.javaoperatorsdk.operator.Operator) BeforeAll(org.junit.jupiter.api.BeforeAll) TypeLiteral(javax.enterprise.util.TypeLiteral) Duration(java.time.Duration) Log(io.quarkus.logging.Log) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Instance(javax.enterprise.inject.Instance) FileWriter(java.io.FileWriter) CDI(javax.enterprise.inject.spi.CDI) FileInputStream(java.io.FileInputStream) UUID(java.util.UUID) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Keycloak(org.keycloak.operator.v2alpha1.crds.Keycloak) TimeUnit(java.util.concurrent.TimeUnit) Config(io.fabric8.kubernetes.client.Config) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) ConfigProvider(org.eclipse.microprofile.config.ConfigProvider) NamespaceBuilder(io.fabric8.kubernetes.api.model.NamespaceBuilder) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) QuarkusConfigurationService(io.quarkiverse.operatorsdk.runtime.QuarkusConfigurationService) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Awaitility(org.awaitility.Awaitility) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) FileInputStream(java.io.FileInputStream)

Example 40 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.Deployment in project fabric8-maven-plugin by fabric8io.

the class DefaultControllerEnricher method addMissingResources.

@Override
public void addMissingResources(KubernetesListBuilder builder) {
    final String name = getConfig(Config.name, MavenUtil.createDefaultResourceName(getProject()));
    final ResourceConfig config = new ResourceConfig.Builder().controllerName(name).imagePullPolicy(getConfig(Config.pullPolicy)).withReplicas(Configs.asInt(getConfig(Config.replicaCount))).build();
    final List<ImageConfiguration> images = getImages();
    // Check if at least a replica set is added. If not add a default one
    if (!KubernetesResourceUtil.checkForKind(builder, POD_CONTROLLER_KINDS)) {
        // At least one image must be present, otherwise the resulting config will be invalid
        if (!Lists.isNullOrEmpty(images)) {
            String type = getConfig(Config.type);
            if ("deployment".equalsIgnoreCase(type)) {
                log.info("Adding a default Deployment");
                builder.addToDeploymentItems(deployHandler.getDeployment(config, images));
            } else if ("statefulSet".equalsIgnoreCase(type)) {
                log.info("Adding a default StatefulSet");
                builder.addToStatefulSetItems(statefulSetHandler.getStatefulSet(config, images));
            } else if ("daemonSet".equalsIgnoreCase(type)) {
                log.info("Adding a default DaemonSet");
                builder.addToDaemonSetItems(daemonSetHandler.getDaemonSet(config, images));
            } else if ("replicaSet".equalsIgnoreCase(type)) {
                log.info("Adding a default ReplicaSet");
                builder.addToReplicaSetItems(rsHandler.getReplicaSet(config, images));
            } else if ("replicationController".equalsIgnoreCase(type)) {
                log.info("Adding a default ReplicationController");
                builder.addToReplicationControllerItems(rcHandler.getReplicationController(config, images));
            } else if ("job".equalsIgnoreCase(type)) {
                log.info("Adding a default Job");
                builder.addToJobItems(jobHandler.getJob(config, images));
            }
        }
    } else if (KubernetesResourceUtil.checkForKind(builder, "StatefulSet")) {
        final StatefulSetSpec spec = statefulSetHandler.getStatefulSet(config, images).getSpec();
        if (spec != null) {
            builder.accept(new TypedVisitor<StatefulSetBuilder>() {

                @Override
                public void visit(StatefulSetBuilder statefulSetBuilder) {
                    statefulSetBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
                    mergeStatefulSetSpec(statefulSetBuilder, spec);
                }
            });
            if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
                final PodSpec podSpec = spec.getTemplate().getSpec();
                builder.accept(new TypedVisitor<PodSpecBuilder>() {

                    @Override
                    public void visit(PodSpecBuilder builder) {
                        KubernetesResourceUtil.mergePodSpec(builder, podSpec, name);
                    }
                });
            }
        }
    } else {
        final DeploymentSpec spec = deployHandler.getDeployment(config, images).getSpec();
        if (spec != null) {
            builder.accept(new TypedVisitor<DeploymentBuilder>() {

                @Override
                public void visit(DeploymentBuilder deploymentBuilder) {
                    deploymentBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
                    mergeDeploymentSpec(deploymentBuilder, spec);
                }
            });
            if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
                final PodSpec podSpec = spec.getTemplate().getSpec();
                builder.accept(new TypedVisitor<PodSpecBuilder>() {

                    @Override
                    public void visit(PodSpecBuilder builder) {
                        KubernetesResourceUtil.mergePodSpec(builder, podSpec, name);
                    }
                });
            }
        }
    }
}
Also used : TypedVisitor(io.fabric8.kubernetes.api.builder.TypedVisitor) PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) StatefulSetSpec(io.fabric8.kubernetes.api.model.extensions.StatefulSetSpec) DeploymentSpec(io.fabric8.kubernetes.api.model.extensions.DeploymentSpec) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) StatefulSetBuilder(io.fabric8.kubernetes.api.model.extensions.StatefulSetBuilder) PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder) ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) StatefulSetBuilder(io.fabric8.kubernetes.api.model.extensions.StatefulSetBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)

Aggregations

Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)52 Test (org.junit.Test)28 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)27 InputStream (java.io.InputStream)26 Service (io.fabric8.kubernetes.api.model.Service)24 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)22 Deployment (org.jboss.arquillian.container.test.api.Deployment)21 OSGiManifestBuilder (org.jboss.osgi.metadata.OSGiManifestBuilder)21 Asset (org.jboss.shrinkwrap.api.asset.Asset)21 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)21 ServiceTracker (org.osgi.util.tracker.ServiceTracker)20 CommandSupport (io.fabric8.itests.support.CommandSupport)18 Logger (org.slf4j.Logger)18 Pod (io.fabric8.kubernetes.api.model.Pod)17 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)17 IOException (java.io.IOException)17 FabricService (io.fabric8.api.FabricService)16 ServiceLocator (io.fabric8.api.gravia.ServiceLocator)16 ArrayList (java.util.ArrayList)16 StartLevelAware (org.jboss.arquillian.osgi.StartLevelAware)16