Skip to content

feat(envctx): refactor LazyLoad; use PartialCloneClusterRepo - #486

Open
GavinPJK wants to merge 6 commits into
jenkins-x-plugins:mainfrom
spring-financial-group:feat/init-sparseclone
Open

feat(envctx): refactor LazyLoad; use PartialCloneClusterRepo#486
GavinPJK wants to merge 6 commits into
jenkins-x-plugins:mainfrom
spring-financial-group:feat/init-sparseclone

Conversation

@GavinPJK

Copy link
Copy Markdown
Contributor

Changes

  • Refactor envctx.LazyLoad by breaking it up into smaller helpers (loadDevEnv, loadRequirements, overrideDevGitURL, loadVersionResolver)
  • Replace gitclient.CloneToDir with requirements.PartialCloneClusterRepo when loading the version resolver

Context

LazyLoad is overly-complex, so it's now split up into helpers - loadDevEnv, loadRequirements, overrideDevGitURLandloadVersionResolver`.

loadVersionResolver also uses new helpers - resolveGitCredentials, cloneDevEnvRepo and ensureVersionStreamDir.

The version resolver only requires versionStream from the dev env repo and doesn't require a detailed git history. The full repository clone (gitclient.CloneToDir, from jx-helpers) is replaced with a partial and shallow clone (requirements.PartialCloneClusterRepo, also from jx-helpers), that falls-back to a full clone if these features aren't supported by the upstream git server.

Done as part of jenkins-x/jx#8240. The clone setup in pkg/environments/gitops.go is more complex so should be dealt with separately.

@jenkins-x-bot

Copy link
Copy Markdown
Contributor

Hi @GavinPJK. Thanks for your PR.

I'm waiting for a jenkins-x-plugins member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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 jenkins-x/lighthouse repository.

@jenkins-x-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
The changes made require 1 more approval(s).
To complete the pull request process, please assign mentlak0
You can assign the PR to them by writing /assign @mentlak0 in a comment when ready.

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

@GavinPJK

Copy link
Copy Markdown
Contributor Author

/cc @Skisocks @msvticket @mentlak0

@msvticket

Copy link
Copy Markdown
Contributor

/ok-to-test

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors pkg/envctx.EnvironmentContext.LazyLoad into smaller helper methods to reduce complexity, and switches version-stream loading to use requirements.PartialCloneClusterRepo (sparse/shallow with fallback) instead of a full gitclient.CloneToDir.

Changes:

  • Split LazyLoad into focused helpers (loadDevEnv, loadRequirements, overrideDevGitURL, loadVersionResolver, plus supporting helpers).
  • Use requirements.PartialCloneClusterRepo to fetch only versionStream/ for the version resolver.
  • Add unit tests covering the new helper behaviors and orchestration no-op behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/envctx/load.go Refactors LazyLoad into helper methods and updates version resolver cloning to partial/sparse clone.
pkg/envctx/load_test.go Adds unit tests for the new helper methods and LazyLoad orchestration behavior.
Comments suppressed due to low confidence (1)

pkg/envctx/load.go:168

  • If PartialCloneClusterRepo returns an empty directory path, the current error message says "to dir %s" but prints an empty string, and also repeats gitCloneURL (which may contain credentials). Use a clearer message and avoid including the credentialed URL.
	if cloneDir == "" {
		return "", fmt.Errorf("failed to clone URL %s to dir %s", gitCloneURL, cloneDir)
	}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/envctx/load.go Outdated
Comment thread pkg/envctx/load.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

Comment thread pkg/envctx/load.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.

Comment thread Makefile
./hack/gofmt.sh
./hack/linter.sh
./hack/generate.sh
lint: fmt ## Fromat and lint the code
Comment thread Makefile
GO111MODULE=on golangci-lint run --verbose --build-tags build

.PHONY: all
all: fmt build lint test
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.

4 participants