Skip to content

Commit

Permalink
tilt: ensure in-tree providers always use start.sh to allow restarts
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Jun 28, 2024
1 parent 8c55a6e commit 9aa60a6
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions hack/tools/internal/tilt-prepare/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,28 @@ var (
// which is containing "hard-coded" tilt-provider.yaml files for the providers managed in the Cluster API repository.
providers = map[string]tiltProviderConfig{
"core": {
Context: ptr.To("."),
Context: ptr.To("."),
hardCodedProvider: true,
},
"kubeadm-bootstrap": {
Context: ptr.To("bootstrap/kubeadm"),
Context: ptr.To("bootstrap/kubeadm"),
hardCodedProvider: true,
},
"kubeadm-control-plane": {
Context: ptr.To("controlplane/kubeadm"),
Context: ptr.To("controlplane/kubeadm"),
hardCodedProvider: true,
},
"docker": {
Context: ptr.To("test/infrastructure/docker"),
Context: ptr.To("test/infrastructure/docker"),
hardCodedProvider: true,
},
"in-memory": {
Context: ptr.To("test/infrastructure/inmemory"),
Context: ptr.To("test/infrastructure/inmemory"),
hardCodedProvider: true,
},
"test-extension": {
Context: ptr.To("test/extension"),
Context: ptr.To("test/extension"),
hardCodedProvider: true,
},
}

Expand Down Expand Up @@ -137,6 +143,9 @@ type tiltProviderConfig struct {
ApplyProviderYaml *bool `json:"apply_provider_yaml,omitempty"`
KustomizeFolder *string `json:"kustomize_folder,omitempty"`
KustomizeOptions []string `json:"kustomize_options,omitempty"`

// hardCodedProvider is used for providers hardc-oded in the Tiltfile to always set cmd for them to start.sh to allow restarts.
hardCodedProvider bool
}

func init() {
Expand Down Expand Up @@ -354,7 +363,7 @@ func tiltResources(ctx context.Context, ts *tiltSettings) error {
debugConfig = &d
}
extraArgs := ts.ExtraArgs[providerName]
tasks[providerName] = workloadTask(providerName, "provider", "manager", "manager", liveReloadDeps, debugConfig, extraArgs, kustomizeFolder, kustomizeOptions, getProviderObj(config.Version))
tasks[providerName] = workloadTask(providerName, "provider", "manager", "manager", liveReloadDeps, debugConfig, extraArgs, config.hardCodedProvider, kustomizeFolder, kustomizeOptions, getProviderObj(config.Version))
}
}

Expand Down Expand Up @@ -693,7 +702,7 @@ func kustomizeTask(path, out string) taskFunction {
// workloadTask generates a task for creating the component yaml for a workload and saving the output on a file.
// NOTE: This task has several sub steps including running kustomize, envsubst, fixing components for debugging,
// and adding the workload resource mimicking what clusterctl init does.
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 {
func workloadTask(name, workloadType, binaryName, containerName string, liveReloadDeps []string, debugConfig *tiltSettingsDebugConfig, extraArgs tiltSettingsExtraArgs, hardCodedProvider bool, path string, options []string, getAdditionalObject func(string, []unstructured.Unstructured) (*unstructured.Unstructured, error)) taskFunction {
return func(ctx context.Context, prefix string, errCh chan error) {
args := []string{"build"}
args = append(args, options...)
Expand Down Expand Up @@ -725,7 +734,7 @@ func workloadTask(name, workloadType, binaryName, containerName string, liveRelo
return
}

if err := prepareWorkload(prefix, binaryName, containerName, objs, liveReloadDeps, debugConfig, extraArgs); err != nil {
if err := prepareWorkload(prefix, binaryName, containerName, objs, liveReloadDeps, debugConfig, extraArgs, hardCodedProvider); err != nil {
errCh <- err
return
}
Expand Down Expand Up @@ -794,7 +803,7 @@ func writeIfChanged(prefix string, path string, yaml []byte) error {
// If there are extra_args given for the workload, we append those to the ones that already exist in the deployment.
// This has the affect that the appended ones will take precedence, as those are read last.
// Finally, we modify the deployment to enable prometheus metrics scraping.
func prepareWorkload(prefix, binaryName, containerName string, objs []unstructured.Unstructured, liveReloadDeps []string, debugConfig *tiltSettingsDebugConfig, extraArgs tiltSettingsExtraArgs) error {
func prepareWorkload(prefix, binaryName, containerName string, objs []unstructured.Unstructured, liveReloadDeps []string, debugConfig *tiltSettingsDebugConfig, extraArgs tiltSettingsExtraArgs, hardcodedProvider bool) error {
// Update provider namespaces to have the pod security standard enforce label set to privileged.
// This is required because we remove the SecurityContext from provider deployments below to make tilt work.
updateNamespacePodSecurityStandard(objs)
Expand All @@ -805,7 +814,7 @@ func prepareWorkload(prefix, binaryName, containerName string, objs []unstructur
}

cmd := []string{"/" + binaryName}
if len(liveReloadDeps) > 0 || debugConfig != nil {
if len(liveReloadDeps) > 0 || debugConfig != nil || hardcodedProvider {
cmd = []string{"sh", "/start.sh", "/" + binaryName}
}
args := append(container.Args, []string(extraArgs)...)
Expand Down

0 comments on commit 9aa60a6

Please sign in to comment.