Skip to content

Commit fed27ee

Browse files
authored
Merge pull request kubernetes-sigs#10244 from fabriziopandini/allow-tilt-provider-without-building-images
🌱 Allow tilt provider with pre-build images
2 parents 21a52f9 + b0bbf9d commit fed27ee

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

Tiltfile

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -342,23 +342,24 @@ def enable_provider(name, debug):
342342

343343
port_forwards, links = get_port_forwards(debug)
344344

345-
build_go_binary(
346-
context = p.get("context"),
347-
reload_deps = p.get("live_reload_deps"),
348-
debug = debug,
349-
go_main = p.get("go_main", "main.go"),
350-
binary_name = "manager",
351-
label = label,
352-
)
345+
if p.get("image"):
346+
build_go_binary(
347+
context = p.get("context"),
348+
reload_deps = p.get("live_reload_deps"),
349+
debug = debug,
350+
go_main = p.get("go_main", "main.go"),
351+
binary_name = "manager",
352+
label = label,
353+
)
353354

354-
build_docker_image(
355-
image = p.get("image"),
356-
context = p.get("context"),
357-
binary_name = "manager",
358-
additional_docker_helper_commands = p.get("additional_docker_helper_commands", ""),
359-
additional_docker_build_commands = p.get("additional_docker_build_commands", ""),
360-
port_forwards = port_forwards,
361-
)
355+
build_docker_image(
356+
image = p.get("image"),
357+
context = p.get("context"),
358+
binary_name = "manager",
359+
additional_docker_helper_commands = p.get("additional_docker_helper_commands", ""),
360+
additional_docker_build_commands = p.get("additional_docker_build_commands", ""),
361+
port_forwards = port_forwards,
362+
)
362363

363364
additional_objs = []
364365
p_resources = p.get("additional_resources", [])

hack/tools/internal/tilt-prepare/main.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ type tiltProvider struct {
133133
type tiltProviderConfig struct {
134134
Context *string `json:"context,omitempty"`
135135
Version *string `json:"version,omitempty"`
136+
LiveReloadDeps []string `json:"live_reload_deps,omitempty"`
136137
ApplyProviderYaml *bool `json:"apply_provider_yaml,omitempty"`
137138
KustomizeFolder *string `json:"kustomize_folder,omitempty"`
138139
KustomizeOptions []string `json:"kustomize_options,omitempty"`
@@ -347,7 +348,13 @@ func tiltResources(ctx context.Context, ts *tiltSettings) error {
347348
if ptr.Deref(config.ApplyProviderYaml, true) {
348349
kustomizeFolder := path.Join(*config.Context, ptr.Deref(config.KustomizeFolder, "config/default"))
349350
kustomizeOptions := config.KustomizeOptions
350-
tasks[providerName] = workloadTask(providerName, "provider", "manager", "manager", ts, kustomizeFolder, kustomizeOptions, getProviderObj(config.Version))
351+
liveReloadDeps := config.LiveReloadDeps
352+
var debugConfig *tiltSettingsDebugConfig
353+
if d, ok := ts.Debug[providerName]; ok {
354+
debugConfig = &d
355+
}
356+
extraArgs := ts.ExtraArgs[providerName]
357+
tasks[providerName] = workloadTask(providerName, "provider", "manager", "manager", liveReloadDeps, debugConfig, extraArgs, kustomizeFolder, kustomizeOptions, getProviderObj(config.Version))
351358
}
352359
}
353360

@@ -686,7 +693,7 @@ func kustomizeTask(path, out string) taskFunction {
686693
// workloadTask generates a task for creating the component yaml for a workload and saving the output on a file.
687694
// NOTE: This task has several sub steps including running kustomize, envsubst, fixing components for debugging,
688695
// and adding the workload resource mimicking what clusterctl init does.
689-
func workloadTask(name, workloadType, binaryName, containerName string, ts *tiltSettings, path string, options []string, getAdditionalObject func(string, []unstructured.Unstructured) (*unstructured.Unstructured, error)) taskFunction {
696+
func workloadTask(name, workloadType, binaryName, containerName string, liveReloadDeps []string, debugConfig *tiltSettingsDebugConfig, extraArgs tiltSettingsExtraArgs, path string, options []string, getAdditionalObject func(string, []unstructured.Unstructured) (*unstructured.Unstructured, error)) taskFunction {
690697
return func(ctx context.Context, prefix string, errCh chan error) {
691698
args := []string{"build"}
692699
args = append(args, options...)
@@ -718,7 +725,7 @@ func workloadTask(name, workloadType, binaryName, containerName string, ts *tilt
718725
return
719726
}
720727

721-
if err := prepareWorkload(name, prefix, binaryName, containerName, objs, ts); err != nil {
728+
if err := prepareWorkload(prefix, binaryName, containerName, objs, liveReloadDeps, debugConfig, extraArgs); err != nil {
722729
errCh <- err
723730
return
724731
}
@@ -787,14 +794,18 @@ func writeIfChanged(prefix string, path string, yaml []byte) error {
787794
// If there are extra_args given for the workload, we append those to the ones that already exist in the deployment.
788795
// This has the affect that the appended ones will take precedence, as those are read last.
789796
// Finally, we modify the deployment to enable prometheus metrics scraping.
790-
func prepareWorkload(name, prefix, binaryName, containerName string, objs []unstructured.Unstructured, ts *tiltSettings) error {
797+
func prepareWorkload(prefix, binaryName, containerName string, objs []unstructured.Unstructured, liveReloadDeps []string, debugConfig *tiltSettingsDebugConfig, extraArgs tiltSettingsExtraArgs) error {
791798
return updateDeployment(prefix, objs, func(deployment *appsv1.Deployment) {
792799
for j, container := range deployment.Spec.Template.Spec.Containers {
793800
if container.Name != containerName {
794801
continue
795802
}
796-
cmd := []string{"sh", "/start.sh", "/" + binaryName}
797-
args := append(container.Args, []string(ts.ExtraArgs[name])...)
803+
804+
cmd := []string{"/" + binaryName}
805+
if len(liveReloadDeps) > 0 || debugConfig != nil {
806+
cmd = []string{"sh", "/start.sh", "/" + binaryName}
807+
}
808+
args := append(container.Args, []string(extraArgs)...)
798809

799810
// remove securityContext for tilt live_update, see https://github.com/tilt-dev/tilt/issues/3060
800811
container.SecurityContext = nil
@@ -805,19 +816,19 @@ func prepareWorkload(name, prefix, binaryName, containerName string, objs []unst
805816
// alter deployment for working nicely with delve debugger;
806817
// most specifically, configuring delve, starting the manager with profiling enabled, dropping liveness and
807818
// readiness probes and disabling leader election.
808-
if d, ok := ts.Debug[name]; ok {
819+
if debugConfig != nil {
809820
cmd = []string{"sh", "/start.sh", "/dlv", "--accept-multiclient", "--api-version=2", "--headless=true", "exec"}
810821

811-
if d.Port != nil && *d.Port > 0 {
822+
if debugConfig.Port != nil && *debugConfig.Port > 0 {
812823
cmd = append(cmd, "--listen=:30000")
813824
}
814-
if d.Continue != nil && *d.Continue {
825+
if debugConfig.Continue != nil && *debugConfig.Continue {
815826
cmd = append(cmd, "--continue")
816827
}
817828

818829
cmd = append(cmd, []string{"--", "/" + binaryName}...)
819830

820-
if d.ProfilerPort != nil && *d.ProfilerPort > 0 {
831+
if debugConfig.ProfilerPort != nil && *debugConfig.ProfilerPort > 0 {
821832
args = append(args, []string{"--profiler-address=:6060"}...)
822833
}
823834

0 commit comments

Comments
 (0)