Skip to content

SRVOCF-1081: List functions only from the current cluster - #185

Open
pmeida wants to merge 1 commit into
openshift:masterfrom
pmeida:SRVOCF-1081-single-cluster-list
Open

SRVOCF-1081: List functions only from the current cluster#185
pmeida wants to merge 1 commit into
openshift:masterfrom
pmeida:SRVOCF-1081-single-cluster-list

Conversation

@pmeida

@pmeida pmeida commented Sep 9, 2026

Copy link
Copy Markdown

Summary

The list merges two sources: GitHub repos tagged as serverless functions (fetched via the SCM API) and Knative Services deployed in the cluster (fetched via the Knative func lister). A repo's KUBECONFIG secret may target a different cluster from the one updating it, resulting in a failure, so we filter out any repo whose CLUSTER_API_URL variable does not match the current cluster's API server URL.

  • Store CLUSTER_API_URL as a GitHub repo variable when a function repo is created, alongside the existing KUBECONFIG secret
  • Filter the function list so only repos whose CLUSTER_API_URL var matches the current cluster are shown - repos created from a different cluster are excluded
    • Repos which don't contain this var are also excluded
  • Unit tests for StoreVariable/GetVariable error paths, rollback on failure, and all filtering scenarios
  • E2e test (cluster-filter.test.ts) verifying cross-cluster repos are hidden. Same-cluster repos are visible test is covered by existing ones.

Fixes SRVOCF-1081

Checklist

  • Updated docs/ARCHITECTURE.md (if there are relevant changes to our layered architecture)
  • Updated docs/TESTING.md (if there are relevant changes to our testing framework or setup)

@openshift-merge-bot

Copy link
Copy Markdown

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci

openshift-ci Bot commented Sep 9, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign cragsmann for approval. For more information see the Code Review Process.

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

@pmeida pmeida changed the title feat: filter function list to show only functions from the current cluster SRVOCF-1081: filter function list to show only functions from the current cluster Sep 9, 2026
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Sep 9, 2026
@openshift-ci-robot

openshift-ci-robot commented Sep 9, 2026

Copy link
Copy Markdown

@pmeida: This pull request references SRVOCF-1081 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 bug to target the "5.1.0" version, but no target version was set.

Details

In response to this:

Summary

  • Store CLUSTER_API_URL as a GitHub Actions repo variable when a function repo is created, alongside the existing KUBECONFIG secret
  • Filter the function list so only repos whose CLUSTER_API_URL matches the current cluster are shown - repos created from a different cluster are excluded
  • Unit tests for StoreVariable/GetVariable error paths, rollback on failure, and all filtering scenarios
  • E2e test (cluster-filter.test.ts) verifying cross-cluster repos are hidden and same-cluster repos are visible

Fixes SRVOCF-1081

Checklist

  • Updated docs/ARCHITECTURE.md (if there are relevant changes to our layered architecture)
  • Updated docs/TESTING.md (if there are relevant changes to our testing framework or setup)

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.

@pmeida
pmeida force-pushed the SRVOCF-1081-single-cluster-list branch from 43e9b22 to 651b1c4 Compare September 9, 2026 09:42
@pmeida pmeida changed the title SRVOCF-1081: filter function list to show only functions from the current cluster SRVOCF-1081: List functions only from the current cluster Sep 9, 2026
@pmeida

pmeida commented Sep 9, 2026

Copy link
Copy Markdown
Author

/test e2e-aws

Comment thread backend/handler/list.go Outdated
}
filtered := items[:0]
for i, item := range items {
url := repoClusterURLs[i]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you add Url normalization here? there might be mismatch with exact string equality check

@pmeida pmeida Sep 10, 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.

The value is stored from clusterAPIURL at creation time, so both sides share the same format/origin by construction. Normalization would therefore only be relevant if the value came from an external or user-controlled source. In this case, although the variable is named url, it should effectively be treated as a string identifier that the backend knows deterministically:

Users should not be modifying this value manually in GitHub either way.

Comment thread backend/handler/list.go
g.SetLimit(10)
for i, repo := range repos {
g.Go(func() error {
repoClusterURL, err := client.GetVariable(gctx, repo.Owner, repo.Name, repoVarClusterAPIURL)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you reorder the goroutine to fetch func.yaml first, and only call GetVariable for repos that will survive filtering by namespace

@pmeida pmeida Sep 10, 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.

Although the current approach always does both calls for every repo. There are downside to each suggestion:

  1. Cluster filtering is always active (unlike namespace filtering, which is optional). Deferring GetVariable past func.yaml means we pay the cost of fetching and parsing func.yaml for every repo before we can apply the primary filter of this PR. The cost of GetVariable should be lower then GetFileContent + parseFuncYaml.
  2. There's a correctness edge case: if func.yaml fails or is invalid, skipping GetVariable means cluster filtering can't run for that repo - a repo from a different cluster with a broken func.yaml would slip through instead of being excluded.
  3. The namespace early-return optimization only pays off when a namespace is provided and is selective. When no namespace is given (which is a common case), both orderings are equivalent in terms of API calls.

Anyway I evaluated the eficiency concerns and came up with the best solution.

Efficiency gains:
Repos from other clusters only pay for one API call (GetVariable) instead of two. In a mixed-cluster environment that can cut GitHub API usage by up to 50% per excluded repo.
On the CPU side: 2 fewer sequential loops over the repo list, and all filtering decisions are made inline during the goroutine pass so the data is touched once instead of three times.

@Cragsmann Cragsmann Sep 11, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe we can do this in one loop only with Mutex? second loop in listRepoFunctions seems redundant. What about sorting by name at HandleListFunctions?

@pmeida pmeida Sep 11, 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.

Switching to Mutex+append would lose the original repo order (goroutines append in completion order), add lock contention with SetLimit(10), and save nothing measurable - the compaction loop is O(n) in-memory, so it is negligible.

Happy to add a name sort. Though the better UX would be by creation date so newly created functions surface at the top rather than appearing mid-list - but that needs CreatedAt exposed on the SCM client and FE changes to append on top of the list at creation time. So I think this is out of scope for this PR.

…uster

Store CLUSTER_API_URL as a GitHub Actions repo variable when a function
repo is created. When listing functions, read that variable for every
repo and exclude repos that point to a different cluster, so each
console instance only shows functions it owns.

Fixes SRVOCF-1081

Signed-off-by: Pedro Almeida <pealmeid@redhat.com>
@pmeida
pmeida force-pushed the SRVOCF-1081-single-cluster-list branch from 651b1c4 to 3bb1fab Compare September 10, 2026 10:19
@openshift-ci

openshift-ci Bot commented Sep 10, 2026

Copy link
Copy Markdown

@pmeida: all tests passed!

Full PR test history. Your PR dashboard.

Details

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 kubernetes-sigs/prow repository. I understand the commands that are listed here.

@pmeida

pmeida commented Sep 10, 2026

Copy link
Copy Markdown
Author

/assign @Cragsmann

@pmeida

pmeida commented Sep 11, 2026

Copy link
Copy Markdown
Author

/retest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants