Skip to content

Commit 04cdfa6

Browse files
🌱 Small improvements to tilt (kubernetes-sigs#9936)
* small improvements to tilt * fix linter issues * address comments
1 parent 6d1cd8d commit 04cdfa6

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

Tiltfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def enable_provider(name, debug):
366366
k8s_yaml(p.get("context") + "/" + resource)
367367
additional_objs = additional_objs + decode_yaml_stream(read_file(p.get("context") + "/" + resource))
368368

369-
if p.get("kustomize_config", True):
369+
if p.get("apply_provider_yaml", True):
370370
yaml = read_file("./.tiltbuild/yaml/{}.provider.yaml".format(name))
371371
k8s_yaml(yaml, allow_duplicates = True)
372372
objs = decode_yaml_stream(yaml)

docs/book/src/developer/tilt.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,13 @@ COPY --from=tilt-helper /usr/bin/docker /usr/bin/docker
429429
COPY --from=tilt-helper /go/kubernetes/client/bin/kubectl /usr/bin/kubectl
430430
```
431431

432-
**kustomize_config** (Bool, default=true): Whether or not running kustomize on the ./config folder of the provider.
432+
**kustomize_folder** (String, default=config/default): The folder where the kustomize file for a provider
433+
is defined; the path is relative to the provider root folder.
434+
435+
**kustomize_options** ([]String, default=[]): Options to be applied when running kustomize for generating the
436+
yaml manifest for a provider. e.g. `"kustomize_options": [ "--load-restrictor=LoadRestrictionsNone" ]`
437+
438+
**apply_provider_yaml** (Bool, default=true): Whether to apply the provider yaml.
433439
Set to `false` if your provider does not have a ./config folder or you do not want it to be applied in the cluster.
434440

435441
**go_main** (String, default="main.go"): The go main file if not located at the root of the folder

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"io/fs"
2929
"os"
3030
"os/exec"
31+
"path"
3132
"path/filepath"
3233
"strings"
3334
"sync"
@@ -36,6 +37,7 @@ import (
3637
"github.com/pkg/errors"
3738
"github.com/spf13/pflag"
3839
appsv1 "k8s.io/api/apps/v1"
40+
corev1 "k8s.io/api/core/v1"
3941
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4042
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
4143
kerrors "k8s.io/apimachinery/pkg/util/errors"
@@ -129,8 +131,11 @@ type tiltProvider struct {
129131
}
130132

131133
type tiltProviderConfig struct {
132-
Context *string `json:"context,omitempty"`
133-
Version *string `json:"version,omitempty"`
134+
Context *string `json:"context,omitempty"`
135+
Version *string `json:"version,omitempty"`
136+
ApplyProviderYaml *bool `json:"apply_provider_yaml,omitempty"`
137+
KustomizeFolder *string `json:"kustomize_folder,omitempty"`
138+
KustomizeOptions []string `json:"kustomize_options,omitempty"`
134139
}
135140

136141
func init() {
@@ -339,7 +344,11 @@ func tiltResources(ctx context.Context, ts *tiltSettings) error {
339344
if !ok {
340345
return errors.Errorf("failed to obtain config for the provider %s, please add the providers path to the provider_repos list in tilt-settings.yaml/json file", providerName)
341346
}
342-
tasks[providerName] = workloadTask(providerName, "provider", "manager", "manager", ts, fmt.Sprintf("%s/config/default", *config.Context), getProviderObj(config.Version))
347+
if ptr.Deref(config.ApplyProviderYaml, true) {
348+
kustomizeFolder := path.Join(*config.Context, ptr.Deref(config.KustomizeFolder, "config/default"))
349+
kustomizeOptions := config.KustomizeOptions
350+
tasks[providerName] = workloadTask(providerName, "provider", "manager", "manager", ts, kustomizeFolder, kustomizeOptions, getProviderObj(config.Version))
351+
}
343352
}
344353

345354
return runTaskGroup(ctx, "resources", tasks)
@@ -361,8 +370,11 @@ func loadTiltProvider(providerRepository string) (map[string]tiltProviderConfig,
361370
contextPath := filepath.Join(providerRepository, ptr.Deref(p.Config.Context, "."))
362371

363372
ret[p.Name] = tiltProviderConfig{
364-
Context: &contextPath,
365-
Version: p.Config.Version,
373+
Context: &contextPath,
374+
Version: p.Config.Version,
375+
ApplyProviderYaml: p.Config.ApplyProviderYaml,
376+
KustomizeFolder: p.Config.KustomizeFolder,
377+
KustomizeOptions: p.Config.KustomizeOptions,
366378
}
367379
}
368380
return ret, nil
@@ -674,9 +686,12 @@ func kustomizeTask(path, out string) taskFunction {
674686
// workloadTask generates a task for creating the component yaml for a workload and saving the output on a file.
675687
// NOTE: This task has several sub steps including running kustomize, envsubst, fixing components for debugging,
676688
// and adding the workload resource mimicking what clusterctl init does.
677-
func workloadTask(name, workloadType, binaryName, containerName string, ts *tiltSettings, path string, getAdditionalObject func(string, []unstructured.Unstructured) (*unstructured.Unstructured, error)) taskFunction {
689+
func workloadTask(name, workloadType, binaryName, containerName string, ts *tiltSettings, path string, options []string, getAdditionalObject func(string, []unstructured.Unstructured) (*unstructured.Unstructured, error)) taskFunction {
678690
return func(ctx context.Context, prefix string, errCh chan error) {
679-
kustomizeCmd := exec.CommandContext(ctx, kustomizePath, "build", path)
691+
args := []string{"build"}
692+
args = append(args, options...)
693+
args = append(args, path)
694+
kustomizeCmd := exec.CommandContext(ctx, kustomizePath, args...)
680695
var stdout1, stderr1 bytes.Buffer
681696
kustomizeCmd.Dir = rootPath
682697
kustomizeCmd.Stdout = &stdout1
@@ -823,11 +838,14 @@ func prepareWorkload(name, prefix, binaryName, containerName string, objs []unst
823838

824839
container.LivenessProbe = nil
825840
container.ReadinessProbe = nil
841+
842+
container.Resources = corev1.ResourceRequirements{}
826843
}
827844

828845
container.Command = cmd
829846
container.Args = args
830847
deployment.Spec.Template.Spec.Containers[j] = container
848+
deployment.Spec.Replicas = ptr.To[int32](1)
831849
}
832850
})
833851
}

0 commit comments

Comments
 (0)