Skip to content

[feature] CRW-11940: Add CLI Activity Tracker configuration to CheCluster CRD - #2170

Open
vrubezhny wants to merge 1 commit into
eclipse-che:mainfrom
vrubezhny:feature/cli-watcher-checluster-cr
Open

[feature] CRW-11940: Add CLI Activity Tracker configuration to CheCluster CRD#2170
vrubezhny wants to merge 1 commit into
eclipse-che:mainfrom
vrubezhny:feature/cli-watcher-checluster-cr

Conversation

@vrubezhny

@vrubezhny vrubezhny commented Jul 29, 2026

Copy link
Copy Markdown

This PR adds spec.devEnvironments.cliActivityTracker section to the CheCluster CRD, allowing administrators to enable and configure CLI Activity Tracker settings cluster-wide. When enabled, the operator writes CLI_ACTIVITY_TRACKER_* environment variables to the che-user-settings ConfigMap, which is auto-mounted to all workspace containers via DevWorkspace Operator. che-machine-exec reads these env vars and uses them as admin-level configuration for monitoring active CLI processes and preventing workspace idling.

What does this PR do?

Adds spec.devEnvironments.cliActivityTracker section to the CheCluster CRD, allowing administrators to enable and configure CLI Activity Tracker settings cluster-wide.

New CRD fields under spec.devEnvironments.cliActivityTracker:

Field Type Description
enabled *bool Enables CLI Activity Tracker to monitor running CLI processes and prevent workspace idling. When omitted, che-machine-exec determines the default behavior.
secondsOfCheckPeriod *int32 How often (in seconds) to scan for active CLI processes.
secondsOfActivityWindow *int32 How long (in seconds) to wait for input from interactive processes before considering them idle.
secondsOfGracePeriod *int32 All processes unconditionally prevent idling when younger than this (in seconds).
secondsOfMaxProcessAge *int32 Safety limit (in seconds). Processes older than this stop preventing idling.

All timing fields are optional. When omitted, set to -1, or set to 0, che-machine-exec calculates defaults dynamically based on the workspace idle timeout. Minimum validation is set to -1 for all timing fields.

How it works:

  • The operator reads spec.devEnvironments.cliActivityTracker from the CheCluster CR
  • When enabled is explicitly true, it writes CLI_ACTIVITY_TRACKER_* env vars to the che-user-settings ConfigMap
  • The ConfigMap is auto-mounted to all workspace containers via DevWorkspace Operator
  • che-machine-exec reads these env vars and applies them as admin-level configuration
  • When enabled is false, nil, or the entire section is omitted, no env vars are written

Env var mapping:

CRD field ConfigMap env var
enabled CLI_ACTIVITY_TRACKER_ENABLED
secondsOfCheckPeriod CLI_ACTIVITY_TRACKER_CHECK_PERIOD
secondsOfActivityWindow CLI_ACTIVITY_TRACKER_ACTIVITY_WINDOW
secondsOfGracePeriod CLI_ACTIVITY_TRACKER_GRACE_PERIOD
secondsOfMaxProcessAge CLI_ACTIVITY_TRACKER_MAX_PROCESS_AGE

Screenshot/screencast of this PR

N/A — no UI changes. This is a CRD and controller change.

What issues does this PR fix or reference?

How to test this PR?

Tests added:

  • Existing TestCreatesDataInNamespace extended with CLI Activity Tracker assertions including -1 and nil field handling
  • New TestOptionalFeaturesOmitEnvVars verifies no env vars are written when the feature is disabled (nil, false, or nil-enabled with timing fields set)

Manual testing:

  1. Deploy the operator from sources (see below)
  2. Patch the CheCluster CR to enable CLI Activity Tracker:
    kubectl patch checluster/eclipse-che -n eclipse-che --type=merge \
      -p '{"spec":{"devEnvironments":{"cliActivityTracker":{"enabled":true,"secondsOfCheckPeriod":30,"secondsOfActivityWindow":900}}}}'
  3. Start a workspace and verify the che-user-settings ConfigMap in the user namespace contains CLI_ACTIVITY_TRACKER_ENABLED=true, CLI_ACTIVITY_TRACKER_CHECK_PERIOD=30, CLI_ACTIVITY_TRACKER_ACTIVITY_WINDOW=900
  4. Verify that omitted fields (e.g. secondsOfGracePeriod) do not appear in the ConfigMap
  5. Set enabled: false or remove the cliActivityTracker section — verify no CLI_ACTIVITY_TRACKER_* env vars in the ConfigMap

OpenShift

./build/scripts/olm/test-catalog-from-sources.sh

or

build/scripts/docker-run.sh /bin/bash -c "
  oc login \
    --token=<...> \
    --server=<...> \
    --insecure-skip-tls-verify=true && \
  build/scripts/olm/test-catalog-from-sources.sh
"

on Minikube

./build/scripts/minikube-tests/test-operator-from-sources.sh

Common Test Scenarios

  • Deploy Eclipse Che
  • Start an empty workspace
  • Open terminal and build/run an image
  • Stop a workspace
  • Check operator logs for reconciliation errors or infinite reconciliation loops

PR Checklist

As the author of this Pull Request I made sure that:

Reviewers

Reviewers, please comment how you tested the PR when approving it.

@openshift-ci-robot

openshift-ci-robot commented Jul 29, 2026

Copy link
Copy Markdown

@vrubezhny: This pull request references CRW-11940 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the feature to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Add spec.devEnvironments.cliWatcher section to expose CLI Watcher settings at the CheCluster CR level. The operator propagates these as CLI_WATCHER_* env vars via the che-user-settings ConfigMap to all workspace containers.

Issue: https://issues.redhat.com/browse/CRW-11940

Assisted-By: Claude Opus 4.6 noreply@anthropic.com

What does this PR do?

Screenshot/screencast of this PR

What issues does this PR fix or reference?

How to test this PR?

  1. Deploy the operator:

OpenShift

./build/scripts/olm/test-catalog-from-sources.sh

or

build/scripts/docker-run.sh /bin/bash -c "
 oc login \
   --token=<...> \
   --server=<...> \
   --insecure-skip-tls-verify=true && \
 build/scripts/olm/test-catalog-from-sources.sh
"

on Minikube

./build/scripts/minikube-tests/test-operator-from-sources.sh

Common Test Scenarios

  • Deploy Eclipse Che
  • Start an empty workspace
  • Open terminal and build/run an image
  • Stop a workspace
  • Check operator logs for reconciliation errors or infinite reconciliation loops

PR Checklist

As the author of this Pull Request I made sure that:

Reviewers

Reviewers, please comment how you tested the PR when approving it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci

openshift-ci Bot commented Jul 29, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: vrubezhny

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@vrubezhny

Copy link
Copy Markdown
Author

/retest-required

@vrubezhny
vrubezhny force-pushed the feature/cli-watcher-checluster-cr branch from db8b71d to c1c3c1e Compare July 29, 2026 22:54
Comment thread api/v2/checluster_types.go Outdated

// CLI Watcher configuration for preventing workspace idling during active CLI processes.
// +optional
CliWatcher *CliWatcherConfig `json:"cliWatcher,omitempty"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have some better naming?
activityMonitor ?

cc @ibuziuk

@vrubezhny vrubezhny Jul 30, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that's it's actually not for the whole 'activityMonitor`-thing, but only a part of what we have for Activity Tracking related to only user CLI processes running in Terminal.

So, maybe still something like cliActivityMonitor?

@tolusha tolusha Jul 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cliActivityTracker ?

@vrubezhny vrubezhny Jul 30, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with both names if they keep mentioning that's these properties are for CLI processes that need to be tracked/monitored.
And I'd changed the env. variable names that are to be generated in ConfigMaps accordingly - like CLI_ACTIVITY_MONITOR_* or CLI_ACTIVITY_TRACKER_*.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the latest version I've changed it to use cliActivityTracker and CLI_ACTIVITY_TRACKER_*.

We can change this later at any time before we merge it, if any objections.

@tolusha

tolusha commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

/che-ai-assistant ok-pr-review

Task completed.

@tolusha tolusha left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider omitting cliWatcher from the top-level DevEnvironments default annotation

The +kubebuilder:default:= annotation on the DevEnvironments field now includes cliWatcher: {enabled: false}. This means every existing CheCluster CR will get cliWatcher: {enabled: false} injected by the API server's defaulting webhook on CRD upgrade, which shows up as a noisy diff in CR audits. The CliWatcher field is already a pointer with omitempty, and the controller already guards it with if checluster.Spec.DevEnvironments.CliWatcher != nil, so the feature stays off without the struct-level default. The +kubebuilder:default:=false on Enabled still applies when a user explicitly creates a cliWatcher: section.


Document actual defaults that che-machine-exec applies when numeric fields are absent

The CRD field comments say "Set to -1 to use the default value calculated by che-machine-exec" but do not state what those values actually are. Would it be possible to add a brief note (e.g., "defaults to 30s") so admins can reason about resource consumption without having to read che-machine-exec source?

Comment thread api/v2/checluster_types.go
Comment thread controllers/usernamespace/usernamespace_controller.go Outdated
Comment thread controllers/usernamespace/usernamespace_controller_test.go Outdated
Comment thread controllers/usernamespace/usernamespace_controller_test.go Outdated
@vrubezhny

Copy link
Copy Markdown
Author

Consider omitting cliWatcher from the top-level DevEnvironments default annotation

The default values are removed from the spec, it's up to che-machine-exec to dynamically calculate them in function of the secondsOfInactivityBeforeIdling property

Document actual defaults that che-machine-exec applies when numeric fields are absent

Each field is described and possible (but not guaranteed defaults has given as examples), also the consequence of omitting a property or setting it to -1 or 0 is described.

@vrubezhny
vrubezhny force-pushed the feature/cli-watcher-checluster-cr branch from c1c3c1e to e9cdae0 Compare July 30, 2026 19:24
@vrubezhny vrubezhny changed the title [feature] CRW-11940: Add CLI Watcher configuration to CheCluster CRD [feature] CRW-11940: Add CLI Activity Tracker configuration to CheCluster CRD Jul 30, 2026
@vrubezhny
vrubezhny requested a review from tolusha July 30, 2026 21:55
…ster CRD

Add spec.devEnvironments.cliActivityTracker section to expose CLI Activity
Tracker settings at the CheCluster CR level. The operator propagates these
as CLI_ACTIVITY_TRACKER_* env vars via the che-user-settings ConfigMap to
all workspace containers.

Issue: https://issues.redhat.com/browse/CRW-11940

Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
Assisted-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants