Skip to content

Commit

Permalink
feat: exec support for worker jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrox committed Oct 23, 2024
1 parent 6dbeafc commit 5cabe64
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions exec/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ type remoteCommandParameters struct {

type applicationCmd struct {
resourceCmd
Stdin bool `name:"stdin" short:"i" help:"Pass stdin to the application" default:"true"`
Tty bool `name:"tty" short:"t" help:"Stdin is a TTY" default:"true"`
Command []string `arg:"" help:"command to execute" optional:""`
Stdin bool `name:"stdin" short:"i" help:"Pass stdin to the application" default:"true"`
Tty bool `name:"tty" short:"t" help:"Stdin is a TTY" default:"true"`
WorkerJob string `name:"worker-job" short:"w" help:"Exec into worker job by name"`
Command []string `arg:"" help:"command to execute" optional:""`
}

// Help displays examples for the application exec command
Expand Down Expand Up @@ -102,10 +103,25 @@ func (cmd *applicationCmd) getReplica(ctx context.Context, client *api.Client) (
if release.Spec.ForProvider.DockerfileBuild {
buildType = appBuildTypeDockerfile
}
if len(release.Status.AtProvider.ReplicaObservation) == 0 {
replicaObs := release.Status.AtProvider.ReplicaObservation

if cmd.WorkerJob != "" {
found := false
for _, wj := range release.Status.AtProvider.WorkerJobStatus {
if wj.Name == cmd.WorkerJob {
found = true
replicaObs = wj.ReplicaObservation
}
}
if !found {
return "", buildType, fmt.Errorf("worker job %q not found", cmd.WorkerJob)
}
}

if len(replicaObs) == 0 {
return "", buildType, fmt.Errorf("no replica information found for release %s", release.Name)
}
if replica := readyReplica(release.Status.AtProvider.ReplicaObservation); replica != "" {
if replica := readyReplica(replicaObs); replica != "" {
return replica, buildType, nil
}
return "", buildType, fmt.Errorf("no ready replica found for release %s", release.Name)
Expand Down

0 comments on commit 5cabe64

Please sign in to comment.