Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/v1alpha1/taskspawner_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,15 @@ type TaskSpawnerStatus struct {
Phase TaskSpawnerPhase `json:"phase,omitempty"`

// DeploymentName is the name of the Deployment running the spawner.
// Set for polling-based sources (GitHub Issues, Jira).
// +optional
DeploymentName string `json:"deploymentName,omitempty"`

// CronJobName is the name of the CronJob running the spawner.
// Set for cron-based sources.
// +optional
CronJobName string `json:"cronJobName,omitempty"`

// TotalDiscovered is the total number of work items discovered.
// +optional
TotalDiscovered int `json:"totalDiscovered,omitempty"`
Expand Down
18 changes: 14 additions & 4 deletions cmd/kelos-spawner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func main() {
var jiraBaseURL string
var jiraProject string
var jiraJQL string
var oneShot bool

flag.StringVar(&name, "taskspawner-name", "", "Name of the TaskSpawner to manage")
flag.StringVar(&namespace, "taskspawner-namespace", "", "Namespace of the TaskSpawner")
Expand All @@ -51,6 +52,7 @@ func main() {
flag.StringVar(&jiraBaseURL, "jira-base-url", "", "Jira instance base URL (e.g. https://mycompany.atlassian.net)")
flag.StringVar(&jiraProject, "jira-project", "", "Jira project key")
flag.StringVar(&jiraJQL, "jira-jql", "", "Optional JQL filter for Jira issues")
flag.BoolVar(&oneShot, "one-shot", false, "Run a single discovery cycle and exit (used by CronJob)")

opts := zap.Options{Development: true}
opts.BindFlags(flag.CommandLine)
Expand Down Expand Up @@ -80,23 +82,31 @@ func main() {
ctx := ctrl.SetupSignalHandler()
key := types.NamespacedName{Name: name, Namespace: namespace}

log.Info("starting spawner", "taskspawner", key)
log.Info("Starting spawner", "taskspawner", key, "oneShot", oneShot)

if oneShot {
if err := runCycle(ctx, cl, key, githubOwner, githubRepo, githubAPIBaseURL, githubTokenFile, jiraBaseURL, jiraProject, jiraJQL); err != nil {
log.Error(err, "Discovery cycle failed")
os.Exit(1)
}
return
}

for {
if err := runCycle(ctx, cl, key, githubOwner, githubRepo, githubAPIBaseURL, githubTokenFile, jiraBaseURL, jiraProject, jiraJQL); err != nil {
log.Error(err, "discovery cycle failed")
log.Error(err, "Discovery cycle failed")
}

// Re-read the TaskSpawner to get the current poll interval
var ts kelosv1alpha1.TaskSpawner
if err := cl.Get(ctx, key, &ts); err != nil {
log.Error(err, "unable to fetch TaskSpawner for poll interval")
log.Error(err, "Unable to fetch TaskSpawner for poll interval")
sleepOrDone(ctx, 5*time.Minute)
continue
}

interval := parsePollInterval(ts.Spec.PollInterval)
log.Info("sleeping until next cycle", "interval", interval)
log.Info("Sleeping until next cycle", "interval", interval)
if done := sleepOrDone(ctx, interval); done {
return
}
Expand Down
3 changes: 2 additions & 1 deletion docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ The `promptTemplate` field uses Go `text/template` syntax. Available variables d
| Field | Description |
|-------|-------------|
| `status.phase` | Current phase: `Pending`, `Running`, `Suspended`, or `Failed` |
| `status.deploymentName` | Name of the Deployment running the spawner |
| `status.deploymentName` | Name of the Deployment running the spawner (polling-based sources) |
| `status.cronJobName` | Name of the CronJob running the spawner (cron-based sources) |
| `status.totalDiscovered` | Total number of items discovered from the source |
| `status.totalTasksCreated` | Total number of Tasks created by this spawner |
| `status.activeTasks` | Number of currently active (non-terminal) Tasks |
Expand Down
10 changes: 8 additions & 2 deletions install-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1233,9 +1233,15 @@ spec:
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
cronJobName:
description: |-
CronJobName is the name of the CronJob running the spawner.
Set for cron-based sources.
type: string
deploymentName:
description: DeploymentName is the name of the Deployment running
the spawner.
description: |-
DeploymentName is the name of the Deployment running the spawner.
Set for polling-based sources (GitHub Issues, Jira).
type: string
lastDiscoveryTime:
description: LastDiscoveryTime is the last time the source was polled.
Expand Down
1 change: 1 addition & 0 deletions install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ rules:
- apiGroups:
- batch
resources:
- cronjobs
- jobs
verbs:
- create
Expand Down
Loading