Skip to content
This repository was archived by the owner on Jun 26, 2026. It is now read-only.

Set KUBECONFIG GitHub secret during function creation - #18

Merged
twoGiants merged 5 commits into
masterfrom
018-feat-create-secret
May 5, 2026
Merged

twoGiants merged 5 commits into
masterfrom
018-feat-create-secret

Conversation

@matejvasek

@matejvasek matejvasek commented Apr 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Create a dedicated func-github ServiceAccount with RBAC permissions
    (pods, services, deployments, imagestreams, Knative serving resources)
    and a system:image-builder ClusterRole binding so CI can build and
    deploy functions
  • Generate a kubeconfig from a TokenRequest (1-year expiry) and cluster
    CA/API server info, then encrypt and store it as a GitHub Actions
    KUBECONFIG secret using libsodium sealed-box encryption
  • Reorder the create flow so the secret is set before the initial push,
    ensuring the workflow has cluster credentials on its first run
  • Handle 409 Conflict for idempotent resource creation (both K8s Status
    objects and standard HTTP error shapes)

New files

  • ClusterCredentialService interface + OcpClusterCredentialService implementation
  • useClusterCredentialService hook
  • ClusterCredentialService.test.ts (4 tests: happy path, two 409 shapes, error propagation)

Changed files

  • GithubService -- createSecret + encryptForGithub (libsodium sealed box)
  • SourceControlService interface -- added createSecret
  • FunctionCreatePage -- wired getKubeconfig + createSecret before push
  • SourceControlService.test.ts -- createSecret tests (encrypt + error)
  • FunctionCreatePage.test.ts -- updated to verify ordering (secret before push)
  • package.json / yarn.lock -- added libsodium-wrappers + @types/libsodium-wrappers

Test plan

  • Unit tests pass (yarn test)
  • Lint passes (yarn lint)
  • Create a function from the UI on an OCP cluster with a GitHub PAT
    that has repo and admin:repo_hook scopes
  • Verify the KUBECONFIG secret appears under the repo's
    Settings > Secrets and variables > Actions
  • Verify the GitHub Actions workflow succeeds and deploys the
    function to the cluster
  • Re-create in the same namespace to confirm 409 handling
    (SA/Role/RoleBinding already exist)

🤖 Generated with Claude Code

@matejvasek
matejvasek force-pushed the 018-feat-create-secret branch 2 times, most recently from d53a8f5 to a5e431c Compare April 30, 2026 14:44
@matejvasek
matejvasek requested a review from twoGiants April 30, 2026 14:56
@matejvasek
matejvasek marked this pull request as ready for review April 30, 2026 14:56
@matejvasek
matejvasek force-pushed the 018-feat-create-secret branch from 3dafaa5 to 0afd410 Compare April 30, 2026 17:03
Create a dedicated service account with RBAC permissions and store its
kubeconfig as a GitHub Actions secret so the generated CI workflow can
authenticate to the cluster and deploy functions.

- Add ClusterCredentialService that creates a ServiceAccount, Role,
  RoleBinding, and image-builder binding, then generates a kubeconfig
  from a TokenRequest and cluster info
- Add createSecret to SourceControlService/GithubService using
  libsodium sealed box encryption
- Wire getKubeconfig and createSecret into the create flow, running
  before push so the secret is available when the workflow triggers
- Handle 409 Conflict (resource already exists) for both K8s Status
  objects and standard HTTP error formats

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Matej Vašek <matejvasek@gmail.com>
@twoGiants
twoGiants force-pushed the 018-feat-create-secret branch from 0afd410 to 31768a2 Compare May 3, 2026 12:46
Created OcpClusterService with generateKubeconfig and exposed it
through useClusterService.

The create flow called createSecret before the repo existed,
which GitHub rejects. Added createRepoWithSecret to GithubService
so the repo is created first, then the secret is set before the
file push triggers the workflow.

Also converted all private members in GithubService and
OcpClusterService to native # private fields, and updated
README PAT permissions to include secret scope.

Signed-off-by: Stanislav Jakuschevskij <sjakusch@redhat.com>
Address PR review feedback and simplify TLS handling:

- Extract RepoSecret type for the secret parameter
- Remove duplicate createRepo, keep only createRepoWithSecret
- Make createSecret private (#createSecret)
- Use insecure-skip-tls-verify in kubeconfig instead of embedding
  the cluster CA certificate, removing the need to fetch
  kube-root-ca.crt configmap
- Merge createSecret tests into createRepoWithSecret describe block

Signed-off-by: Matej Vašek <matejvasek@gmail.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Matej Vašek <matejvasek@gmail.com>
@matejvasek
matejvasek requested a review from twoGiants May 4, 2026 18:31
@matejvasek

Copy link
Copy Markdown
Collaborator Author

PTAL @twoGiants

matejvasek and others added 2 commits May 4, 2026 20:37
Signed-off-by: Matej Vašek <matejvasek@gmail.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Matej Vašek <matejvasek@gmail.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@twoGiants
twoGiants merged commit b214a70 into master May 5, 2026
4 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants