Skip to content

Commit

Permalink
feat: add init task support to kind / minikube
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Sep 22, 2023
1 parent 844beec commit 8498d2c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.ApplicationInfoBuildItem;
import io.quarkus.deployment.builditem.InitTaskBuildItem;
import io.quarkus.deployment.metrics.MetricsCapabilityBuildItem;
import io.quarkus.deployment.pkg.PackageConfig;
import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem;
Expand All @@ -26,6 +27,7 @@
import io.quarkus.kubernetes.client.spi.KubernetesClientCapabilityBuildItem;
import io.quarkus.kubernetes.deployment.AddPortToKubernetesConfig;
import io.quarkus.kubernetes.deployment.DevClusterHelper;
import io.quarkus.kubernetes.deployment.InitTaskProcessor;
import io.quarkus.kubernetes.deployment.KubernetesCommonHelper;
import io.quarkus.kubernetes.deployment.KubernetesConfig;
import io.quarkus.kubernetes.deployment.ResourceNameUtil;
Expand Down Expand Up @@ -135,4 +137,25 @@ public void postBuild(ContainerImageInfoBuildItem image, List<ContainerImageBuil
//So, we now always perform this step
ExecUtil.exec("kind", "load", "docker-image", image.getImage());
}
}

@BuildStep
void externalizeInitTasks(
ApplicationInfoBuildItem applicationInfo,
KubernetesConfig config,
ContainerImageInfoBuildItem image,
List<InitTaskBuildItem> initTasks,
BuildProducer<KubernetesJobBuildItem> jobs,
BuildProducer<KubernetesInitContainerBuildItem> initContainers,
BuildProducer<KubernetesEnvBuildItem> env,
BuildProducer<KubernetesRoleBuildItem> roles,
BuildProducer<KubernetesRoleBindingBuildItem> roleBindings,
BuildProducer<KubernetesServiceAccountBuildItem> serviceAccount,

BuildProducer<DecoratorBuildItem> decorators) {
final String name = ResourceNameUtil.getResourceName(config, applicationInfo);
if (config.isExternalizeInit()) {
InitTaskProcessor.process(KIND, name, image, initTasks, config.getInitTaskDefaults(), config.getInitTasks(),
jobs, initContainers, env, roles, roleBindings, serviceAccount, decorators);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.ApplicationInfoBuildItem;
import io.quarkus.deployment.builditem.InitTaskBuildItem;
import io.quarkus.deployment.metrics.MetricsCapabilityBuildItem;
import io.quarkus.deployment.pkg.PackageConfig;
import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem;
import io.quarkus.kubernetes.client.spi.KubernetesClientCapabilityBuildItem;
import io.quarkus.kubernetes.deployment.AddPortToKubernetesConfig;
import io.quarkus.kubernetes.deployment.DevClusterHelper;
import io.quarkus.kubernetes.deployment.InitTaskProcessor;
import io.quarkus.kubernetes.deployment.KubernetesCommonHelper;
import io.quarkus.kubernetes.deployment.KubernetesConfig;
import io.quarkus.kubernetes.deployment.ResourceNameUtil;
Expand Down Expand Up @@ -122,4 +124,25 @@ public List<DecoratorBuildItem> createDecorators(ApplicationInfoBuildItem applic
livenessPath, readinessPath, startupPath,
roles, clusterRoles, serviceAccounts, roleBindings, customProjectRoot);
}
}

@BuildStep
void externalizeInitTasks(
ApplicationInfoBuildItem applicationInfo,
KubernetesConfig config,
ContainerImageInfoBuildItem image,
List<InitTaskBuildItem> initTasks,
BuildProducer<KubernetesJobBuildItem> jobs,
BuildProducer<KubernetesInitContainerBuildItem> initContainers,
BuildProducer<KubernetesEnvBuildItem> env,
BuildProducer<KubernetesRoleBuildItem> roles,
BuildProducer<KubernetesRoleBindingBuildItem> roleBindings,
BuildProducer<KubernetesServiceAccountBuildItem> serviceAccount,

BuildProducer<DecoratorBuildItem> decorators) {
final String name = ResourceNameUtil.getResourceName(config, applicationInfo);
if (config.isExternalizeInit()) {
InitTaskProcessor.process(MINIKUBE, name, image, initTasks, config.getInitTaskDefaults(), config.getInitTasks(),
jobs, initContainers, env, roles, roleBindings, serviceAccount, decorators);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class InitTaskProcessor {

private static final String INIT_CONTAINER_WAITER_NAME = "wait-for-";

static void process(
public static void process(
String target, // kubernetes, openshift, etc.
String name,
ContainerImageInfoBuildItem image,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,4 +634,16 @@ public KubernetesConfig.DeploymentResourceKind getDeploymentResourceKind(Capabil

return DeploymentResourceKind.Deployment;
}

public boolean isExternalizeInit() {
return externalizeInit;
}

public Map<String, InitTaskConfig> getInitTasks() {
return initTasks;
}

public InitTaskConfig getInitTaskDefaults() {
return initTaskDefaults;
}
}

0 comments on commit 8498d2c

Please sign in to comment.