Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hydrator): add commit-server component #19537

Draft
wants to merge 1 commit into
base: source-hydrator-types
Choose a base branch
from

Conversation

crenshaw-dev
Copy link
Member

I'm breaking the hydrator into separate PRs. This is party to make them easier to review, partly because the commit history on the original PR is pretty messy at this point.

This PR is just for the new commit-server component. In this code, the commit server isn't invoked by anything besides tests, and the k8s manifests are not included in the rendered install manifests.

I've added everyone who helped as a co-author on this PR.

@crenshaw-dev
Copy link
Member Author

@CodiumAI-Agent /review

@CodiumAI-Agent
Copy link

PR Reviewer Guide 🔍

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Key issues to review

API Change
The method signature of Checkout has been changed to return a string and an error. Ensure that all invocations of this method handle the new return type correctly.

Error Handling
The new methods SetAuthor, CheckoutOrOrphan, CheckoutOrNew, RemoveContents, and CommitAndPush in nativeGitClient need to ensure proper error handling and propagation. Review if the error messages provide enough context and if errors are handled consistently.

Method Implementation
The implementation of CheckoutOrOrphan and CheckoutOrNew might lead to unexpected behavior if the branch exists but an error occurs that is not related to the branch's existence. The error handling logic could be refined to specifically check for the branch existence error rather than relying on string matching in error messages.

Co-authored-by: Alexandre Gaudreault <[email protected]>
Co-authored-by: Omer Azmon <[email protected]>
Co-authored-by: daengdaengLee <[email protected]>
Co-authored-by: Juwon Hwang (Kevin) <[email protected]>
Co-authored-by: thisishwan2 <[email protected]>
Co-authored-by: mirageoasis <[email protected]>
Co-authored-by: Robin Lieb <[email protected]>
Co-authored-by: miiiinju1 <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>

go mod tidy

Signed-off-by: Michael Crenshaw <[email protected]>

one test file for both implementations

Signed-off-by: Michael Crenshaw <[email protected]>

simplify

Signed-off-by: Michael Crenshaw <[email protected]>

fix test for linux

Signed-off-by: Michael Crenshaw <[email protected]>

fix git client mock

Signed-off-by: Michael Crenshaw <[email protected]>

fix git client mock

Signed-off-by: Michael Crenshaw <[email protected]>

address comments

Signed-off-by: Michael Crenshaw <[email protected]>

unit tests

Signed-off-by: Michael Crenshaw <[email protected]>

lint

Signed-off-by: Michael Crenshaw <[email protected]>

fix image, fix health checks, fix merge issue

Signed-off-by: Michael Crenshaw <[email protected]>

fix lint issues

Signed-off-by: Michael Crenshaw <[email protected]>
Copy link
Member

@agaudreault agaudreault left a comment

Choose a reason for hiding this comment

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

LGTM. Minor changes.

Maybe a bigger concern will be if the remote branch is modified between the moment it is pulled and when it is pushed. I expect push failures and maybe some "git merge" best effort attempt to be done in the future.

@@ -43,6 +43,7 @@ require (
github.com/golang/protobuf v1.5.4
github.com/google/btree v1.1.3
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v62 v62.0.0
Copy link
Member

Choose a reason for hiding this comment

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

v63 already imported below

Suggested change
github.com/google/go-github/v62 v62.0.0
github.com/google/go-github/v62 v62.0.0

Comment on lines +90 to +93
- mountPath: /helm-working-dir
name: helm-working-dir
- mountPath: /home/argocd/cmp-server/plugins
name: plugins
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be stuff copied from the repo-server that should be removed if commit-server is not doing helm/cmp operations

Comment on lines +14 to +15
// CommitServerSocketPath is the path to the socket used by the commit server to communicate with the askpass server
CommitServerSocketPath = "/tmp/commit-server-ask-pass.sock"
Copy link
Member

Choose a reason for hiding this comment

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

Move file to util/askpass/common.go instead. Current location is reposerver/askpass/common.go and it now contains information related to commit-server

}
return nil
return "", nil
Copy link
Member

Choose a reason for hiding this comment

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

Why adding the "out" parameter if the function always returns "" on success?

func (m *nativeGitClient) CheckoutOrNew(branch, base string, submoduleEnabled bool) (string, error) {
out, err := m.Checkout(branch, submoduleEnabled)
if err != nil {
if strings.Contains(err.Error(), "did not match any file(s) known to git") {
Copy link
Member

Choose a reason for hiding this comment

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

Can we do a call to validate if the branch exist or check the error code instead of the error message? I wouldn't trust the consistency of git client error string for such a critical functionality.

@@ -245,6 +266,13 @@ func NewSSHCreds(sshPrivateKey string, caPath string, insecureIgnoreHostKey bool
return SSHCreds{sshPrivateKey, caPath, insecureIgnoreHostKey, store, proxy, noProxy}
}

// GetUserInfo returns empty strings for user info.
// TODO: Implement this method to return the username and email address for the credentials, if they're available.
Copy link
Member

Choose a reason for hiding this comment

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

Create issues if this is still TODO and it could be implemented in another PR

Comment on lines +56 to +57
s.metricsServer.IncCommitRequest(repoURL, metrics.CommitResponseTypeFailure)
s.metricsServer.ObserveCommitRequestDuration(repoURL, metrics.CommitResponseTypeFailure, time.Since(startTime))
Copy link
Member

Choose a reason for hiding this comment

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

you can wrap that in a defer function that checks if the return error is not nil. This way you are sure to execute in in the future

func example() (err error) {
        startTime := time.Now()
	defer func() {
		if err != nil {
			s.metricsServer.IncCommitRequest(repoURL, metrics.CommitResponseTypeFailure)
		}
		s.metricsServer.IncCommitRequest(repoURL, metrics.CommitResponseTypeSuccess)
		s.metricsServer.ObserveCommitRequestDuration(repoURL, metrics.CommitResponseTypeFailure, time.Since(startTime))
	}
        return nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants