forked from tilt-dev/tilt
-
Notifications
You must be signed in to change notification settings - Fork 0
[tilt]: add tilt attach command for blind pod attachment
#5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
devin-ai-integration
wants to merge
2
commits into
master
Choose a base branch
from
devin/1771393540-tilt-attach
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "context" | ||
| "log" | ||
| "os" | ||
| "strconv" | ||
| "time" | ||
|
|
||
| "github.com/mattn/go-isatty" | ||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/tilt-dev/tilt/internal/analytics" | ||
| engineanalytics "github.com/tilt-dev/tilt/internal/engine/analytics" | ||
| "github.com/tilt-dev/tilt/internal/hud/prompt" | ||
| "github.com/tilt-dev/tilt/internal/store" | ||
| "github.com/tilt-dev/tilt/pkg/logger" | ||
| "github.com/tilt-dev/tilt/pkg/model" | ||
| ) | ||
|
|
||
| type attachCmd struct { | ||
| fileName string | ||
| outputSnapshotOnExit string | ||
|
|
||
| legacy bool | ||
| stream bool | ||
| } | ||
|
|
||
| func (c *attachCmd) name() model.TiltSubcommand { return "attach" } | ||
|
|
||
| func (c *attachCmd) register() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "attach [<tilt flags>] [-- <Tiltfile args>]", | ||
| DisableFlagsInUseLine: true, | ||
| Short: "Attach to existing resources without rebuilding", | ||
| Long: ` | ||
| Starts Tilt and attaches to any resources that already exist on remote | ||
| without verifying the image hash. Resources that are missing are built | ||
| and deployed normally (identical to tilt up). | ||
|
|
||
| Accepts the same flags and Tiltfile args as tilt up. | ||
| `, | ||
| } | ||
|
|
||
| cmd.Flags().BoolVar(&c.legacy, "legacy", false, "If true, tilt will open in legacy terminal mode.") | ||
| cmd.Flags().BoolVar(&c.stream, "stream", false, "If true, tilt will stream logs in the terminal.") | ||
| cmd.Flags().BoolVar(&logActionsFlag, "logactions", false, "log all actions and state changes") | ||
| addStartServerFlags(cmd) | ||
| addDevServerFlags(cmd) | ||
| addTiltfileFlag(cmd, &c.fileName) | ||
| addKubeContextFlag(cmd) | ||
| addNamespaceFlag(cmd) | ||
| addLogFilterFlags(cmd, "log-") | ||
| addLogFilterResourcesFlag(cmd) | ||
| cmd.Flags().Lookup("logactions").Hidden = true | ||
| cmd.Flags().StringVar(&c.outputSnapshotOnExit, "output-snapshot-on-exit", "", "If specified, Tilt will dump a snapshot of its state to the specified path when it exits") | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *attachCmd) initialTermMode(isTerminal bool) store.TerminalMode { | ||
| if !isTerminal { | ||
| return store.TerminalModeStream | ||
| } | ||
| if c.legacy { | ||
| return store.TerminalModeHUD | ||
| } | ||
| if c.stream { | ||
| return store.TerminalModeStream | ||
| } | ||
| return store.TerminalModePrompt | ||
| } | ||
|
|
||
| func (c *attachCmd) run(ctx context.Context, args []string) error { | ||
| ctx, cancel := context.WithCancel(ctx) | ||
| defer cancel() | ||
|
|
||
| a := analytics.Get(ctx) | ||
| defer a.Flush(time.Second) | ||
|
|
||
| log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime)) | ||
| isTTY := isatty.IsTerminal(os.Stdout.Fd()) | ||
| termMode := c.initialTermMode(isTTY) | ||
|
|
||
| cmdTags := engineanalytics.CmdTags(map[string]string{ | ||
| "term_mode": strconv.Itoa(int(termMode)), | ||
| }) | ||
| a.Incr("cmd.attach", cmdTags.AsMap()) | ||
|
|
||
| deferred := logger.NewDeferredLogger(ctx) | ||
| ctx = redirectLogs(ctx, deferred) | ||
|
|
||
| webHost := provideWebHost() | ||
| webURL, _ := provideWebURL(webHost, provideWebPort()) | ||
| startLine := prompt.StartStatusLine(webURL, webHost) | ||
| log.Print(startLine) | ||
| log.Print(buildStamp()) | ||
|
|
||
| if ok, reason := analytics.IsAnalyticsDisabledFromEnv(); ok { | ||
| log.Printf("Tilt analytics disabled: %s", reason) | ||
| } | ||
|
|
||
| cmdUpDeps, err := wireCmdUp(ctx, a, cmdTags, "attach") | ||
| if err != nil { | ||
| deferred.SetOutput(deferred.Original()) | ||
| return err | ||
| } | ||
|
|
||
| upper := cmdUpDeps.Upper | ||
| if termMode == store.TerminalModePrompt { | ||
| cmdUpDeps.Prompt.SetInitOutput(deferred.CopyBuffered(logger.InfoLvl)) | ||
| } | ||
|
|
||
| l := store.NewLogActionLogger(ctx, upper.Dispatch) | ||
| deferred.SetOutput(l) | ||
| ctx = redirectLogs(ctx, l) | ||
| if c.outputSnapshotOnExit != "" { | ||
| defer cmdUpDeps.Snapshotter.WriteSnapshot(ctx, c.outputSnapshotOnExit) | ||
| } | ||
|
|
||
| err = upper.Start(ctx, args, cmdUpDeps.TiltBuild, | ||
| c.fileName, termMode, a.UserOpt(), cmdUpDeps.Token, string(cmdUpDeps.CloudAddress), true) | ||
| if err != context.Canceled { | ||
| return err | ||
| } | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Attach mode never sets HasEverDeployedSuccessfully, leaving K8s resources permanently stuck in Pending status
The synthetic build injected by
maybeInjectAttachBuildadds aBuildRecordto mark the manifest as "already built," but it never setsHasEverDeployedSuccessfully = trueon theK8sRuntimeState. This is critical becauseK8sRuntimeState.RuntimeStatus()(internal/store/runtime_state.go:124-127) short-circuits toRuntimeStatusPendingwheneverHasEverDeployedSuccessfullyis false.Root Cause and Impact
In the normal build path,
HasEverDeployedSuccessfullyis set totrueinHandleBuildCompletedatinternal/store/buildcontrols/reducers.go:233. But in attach mode, the real build is skipped entirely — only a syntheticBuildRecordis injected atinternal/store/kubernetesdiscoverys/reducers.go:118-123.Without
HasEverDeployedSuccessfully = true, the following cascade of failures occurs:krs.RuntimeStatus()always returnsRuntimeStatusPending(seeinternal/store/runtime_state.go:125-127)internal/store/kubernetesdiscoverys/reducers.go:92(if krs.RuntimeStatus() == v1alpha1.RuntimeStatusOK) never passes, soLastReadyOrSucceededTimeis never setHasEverBeenReadyOrSucceeded()(internal/store/runtime_state.go:164-166) also returns falseThis effectively makes the entire
tilt attachcommand non-functional for Kubernetes resources — the exact resources it is designed to handle.Was this helpful? React with 👍 or 👎 to provide feedback.