Skip to content

Conversation

@rsoaresd
Copy link
Contributor

@rsoaresd rsoaresd commented Feb 26, 2025

Description

This PR adds a pairing script to reduce pairing complexity and pairing duplication

Check codeready-toolchain/toolchain-e2e#1113

Note

For host-operator, member-operator, and registration-service, the changes are local for now until this PR and codeready-toolchain/toolchain-e2e#1113 are merged

Issue ticket number and link

KUBESAW-230

Copy link
Contributor

@alexeykazakov alexeykazakov left a comment

Choose a reason for hiding this comment

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

So less bach scripts and more go code! Nice :)

@rsoaresd rsoaresd force-pushed the add_pairing_go_script branch from 9401970 to 42de922 Compare February 27, 2025 17:15
Copy link
Collaborator

@MatousJobanek MatousJobanek left a comment

Choose a reason for hiding this comment

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

Thanks a lot for transforming the script into the go code.
Apart from the comments, I would also move the go project out of the scripts folder - just add a folder "pairing" in the root of the project.

// the pairing can be triggered by CI job or GH action
func getCurrentPRInfo() (*PullRequestMetadata, error) {
pr := &PullRequestMetadata{}
jobSpecEnvVarData := os.Getenv("JOB_SPEC")
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add a comment what the JOB_SPEC variable contains? Is it something similar to CLONEREFS_OPTIONS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! The info that we need can also be got from JOB_SPEC:

{
    "type": "presubmit",
    "job": "pull-ci-codeready-toolchain-toolchain-e2e-master-e2e",
    "buildid": "1889023022812106752",
    "prowjobid": "9ccb229f-aebf-45d6-90e2-2388663e8b9a",
    "refs": {
        "org": "codeready-toolchain",
        "repo": "toolchain-e2e",
        "repo_link": "https://github.com/codeready-toolchain/toolchain-e2e",
        "base_ref": "master",
        "base_sha": "47ac08434063871caf78c8f3d6dbab6df61ecb63",
        "base_link": "https://github.com/codeready-toolchain/toolchain-e2e/commit/47ac08434063871caf78c8f3d6dbab6df61ecb63",
        "pulls": [
            {
                "number": 1113,
                "author": "rsoaresd",
                "sha": "67ece9d9716bcc8556f91c0c909ecea4b7c17bff",
                "head_ref": "test-pairing",
                "link": "https://github.com/codeready-toolchain/toolchain-e2e/pull/1113",
                "commit_link": "https://github.com/codeready-toolchain/toolchain-e2e/pull/1113/commits/67ece9d9716bcc8556f91c0c909ecea4b7c17bff",
                "author_link": "https://github.com/rsoaresd"
            }
        ]
    },
    "decoration_config": {
        "timeout": "2h0m0s",
        "grace_period": "15s",
        "utility_images": {
            "clonerefs": "us-docker.pkg.dev/k8s-infra-prow/images/clonerefs:v20250205-e871edfd1",
            "initupload": "us-docker.pkg.dev/k8s-infra-prow/images/initupload:v20250205-e871edfd1",
            "entrypoint": "us-docker.pkg.dev/k8s-infra-prow/images/entrypoint:v20250205-e871edfd1",
            "sidecar": "us-docker.pkg.dev/k8s-infra-prow/images/sidecar:v20250205-e871edfd1"
        },
        "resources": {
            "clonerefs": {
                "limits": {
                    "memory": "3Gi"
                },
                "requests": {
                    "cpu": "100m",
                    "memory": "500Mi"
                }
            },
            "initupload": {
                "limits": {
                    "memory": "200Mi"
                },
                "requests": {
                    "cpu": "100m",
                    "memory": "50Mi"
                }
            },
            "place_entrypoint": {
                "limits": {
                    "memory": "100Mi"
                },
                "requests": {
                    "cpu": "100m",
                    "memory": "25Mi"
                }
            },
            "sidecar": {
                "limits": {
                    "memory": "2Gi"
                },
                "requests": {
                    "cpu": "100m",
                    "memory": "250Mi"
                }
            }
        },
        "gcs_configuration": {
            "bucket": "test-platform-results",
            "path_strategy": "single",
            "default_org": "openshift",
            "default_repo": "origin",
            "mediaTypes": {
                "log": "text/plain"
            },
            "compress_file_types": [
                "txt",
                "log",
                "json",
                "tar",
                "html",
                "yaml"
            ]
        },
        "gcs_credentials_secret": "gce-sa-credentials-gcs-publisher",
        "skip_cloning": true,
        "censor_secrets": true
    }
}

Comment on lines 117 to 118
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

if neither OpenShift-CI nor GH actions are recognized, then we should return an error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot the detail that when neither OpenShift-CI nor GH actions, we need to clone the parent repo

@rsoaresd rsoaresd force-pushed the add_pairing_go_script branch from 4b1909d to ed0a81e Compare March 6, 2025 13:47
@rsoaresd rsoaresd requested a review from MatousJobanek March 6, 2025 13:50
improve

improvements

improve

improve

clean

improve

clean

improve

improve

improve

improve
@rsoaresd rsoaresd force-pushed the add_pairing_go_script branch from 8a583d8 to b8323b9 Compare March 6, 2025 15:26
Copy link
Collaborator

@MatousJobanek MatousJobanek left a comment

Choose a reason for hiding this comment

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

Looks really nice 👍

Comment on lines 53 to 54
t.Setenv("AUTHOR", "rsoaresd")
t.Setenv("GITHUB_HEAD_REF", "clean_only_when_test_passed")
Copy link
Collaborator

Choose a reason for hiding this comment

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

the success of this unit-test relies on the presence of your fork and the branch with this name there.
Let's use more reliable approach - you can mock the call to .../info/refs?service=git-upload-pack - you can use Gock (that we use at other places too) or any other library

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, thanks! Addressed d27187d

Comment on lines +1 to +2
.PHONY: build-pairing
build-pairing:
Copy link
Collaborator

Choose a reason for hiding this comment

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

this looks like a duplicate of the build target in build.mk makefile

@MatousJobanek
Copy link
Collaborator

I also noticed that the PR contains some workload-analyzer submodule - probably added by accident https://github.com/codeready-toolchain/toolchain-cicd/pull/135/files#diff-98b7ead5e589543bf9211348ee50cd62c0bedf50539dd66c3d048a4e1af44ec0

"github.com/spf13/cobra"
)

type PairingServiceInterface interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we replaced this interface with a simple func we could get rid of both MockPairingService and PairingService and just replace them with their respective shouldPair impls.

Additionally, if you could mock out the actual HTTP call in shouldPair func, we could also no longer require passing in the pairing func (or interface) to Pair() altogether and just use the actual impl also in the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you so much! Adressed d27187d

@rsoaresd rsoaresd changed the title KUBESAW-230: add pairing script KUBESAW-230: add pairing mechanism May 27, 2025
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.

4 participants