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

Verify non dirty or mismatched k/release checkouts #1284

Merged
merged 1 commit into from
May 13, 2020
Merged

Verify non dirty or mismatched k/release checkouts #1284

merged 1 commit into from
May 13, 2020

Conversation

saschagrunert
Copy link
Member

What type of PR is this?

/kind feature

What this PR does / why we need it:

We now verify that the worktree is neither dirty nor diverged from the
latest remote commit. This introduces a new API function
git.IsDirty() as well as updates all surrounding tests.

Which issue(s) this PR fixes:

Fixes #1278

Special notes for your reviewer:

Requires #1283
/hold

Does this PR introduce a user-facing change?

- Added `git.IsDirty()` method to verify the state of a local repository
- `krel gcbmgr` now verifies that the local copy of k/release is neither dirty nor diverged with the latest remote commit

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-priority size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 13, 2020
@k8s-ci-robot k8s-ci-robot requested review from cpanato and jeefy May 13, 2020 10:31
@k8s-ci-robot k8s-ci-robot added area/release-eng Issues or PRs related to the Release Engineering subproject sig/release Categorizes an issue or PR as relevant to SIG Release. labels May 13, 2020
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 13, 2020
Copy link
Member

@cpanato cpanato left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 13, 2020
@justaugustus
Copy link
Member

Hmmmm...
/hold

$ krel gcbmgr --stage
INFO Verifying repository state                   
INFO Repository is in clean state                 
FATA verifying repository state: branch "master" expected but got "verify-check" 

$ TOOL_ORG=saschagrunert TOOL_BRANCH=verify-check krel gcbmgr --stage
INFO Verifying repository state                   
INFO Repository is in clean state                 
INFO Found matching branch "verify-check"         
INFO Found matching organization "saschagrunert" and repository "release" in remote: sascha (https://github.com/saschagrunert/release.git) 
INFO Verifying remote HEAD commit                 
INFO Got remote commit: c111a6cb7ce15c9573dfcd8ac038bc70d23e1acf 
INFO Verifying that remote commit is equal to the local one 
FATA verifying repository state: Local HEAD (5b7c84a83c10e8827b58bbf783ef884d7aed36a3) is not equal to latest remote commit (c111a6cb7ce15c9573dfcd8ac038bc70d23e1acf) 

We now verify that the worktree is neither dirty nor diverged from the
latest remote commit. This introduces a new API function
`git.IsDirty()` as well as updates all surrounding tests.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 13, 2020
@saschagrunert
Copy link
Member Author

Hmmmm...
/hold

$ krel gcbmgr --stage
INFO Verifying repository state                   
INFO Repository is in clean state                 
FATA verifying repository state: branch "master" expected but got "verify-check" 

$ TOOL_ORG=saschagrunert TOOL_BRANCH=verify-check krel gcbmgr --stage
INFO Verifying repository state                   
INFO Repository is in clean state                 
INFO Found matching branch "verify-check"         
INFO Found matching organization "saschagrunert" and repository "release" in remote: sascha (https://github.com/saschagrunert/release.git) 
INFO Verifying remote HEAD commit                 
INFO Got remote commit: c111a6cb7ce15c9573dfcd8ac038bc70d23e1acf 
INFO Verifying that remote commit is equal to the local one 
FATA verifying repository state: Local HEAD (5b7c84a83c10e8827b58bbf783ef884d7aed36a3) is not equal to latest remote commit (c111a6cb7ce15c9573dfcd8ac038bc70d23e1acf) 

That's a good catch, if the branch is not master, then we have to run

git ls-remote --heads origin refs/heads/<BRANCH>

and not always refs/heads/master. Now it should work.

@@ -131,7 +143,7 @@ func (r *Repo) CheckState(expOrg, expRepo, expBranch string) error {

logrus.Info("Verifying remote HEAD commit")
lsRemoteOut, err := r.repo.LsRemote(
"--heads", foundRemote.Name(), "refs/heads/master",
"--heads", foundRemote.Name(), "refs/heads/"+expBranch,
Copy link
Member Author

Choose a reason for hiding this comment

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

That was the issue.

@justaugustus
Copy link
Member

Looks better!

Wrong branch:

$ krel gcbmgr --stage
INFO Verifying repository state                   
INFO Repository is in clean state                 
FATA verifying repository state: branch "master" expected but got "verify-check" 

Correct branch / org:

$ TOOL_ORG=saschagrunert TOOL_BRANCH=verify-check krel gcbmgr --stage
INFO Verifying repository state                   
INFO Repository is in clean state                 
INFO Found matching branch "verify-check"         
INFO Found matching organization "saschagrunert" and repository "release" in remote: sascha (https://github.com/saschagrunert/release.git) 
INFO Verifying remote HEAD commit                 
INFO Got remote commit: 595dfec1803e960adf29430123bf94dbf3d673cf 
INFO Verifying that remote commit is equal to the local one 
INFO Repository is up-to-date                     
INFO Running gcbmgr with the following options: &{Stage:true Release:false Stream:false Branch:master ReleaseType:prerelease BuildVersion: GcpUser: LastJobs:5 Repo:0xc000405920 Version:0xc000405930} 
INFO Build options: {  cloudbuild.yaml   kubernetes-release-test false false false   } 
INFO Retrieving Kubernetes release version for ci/latest on branch master 
INFO Retrieving Kubernetes build version from https://dl.k8s.io/ci/latest.txt... 
INFO Retrieved Kubernetes version: v1.19.0-alpha.3.208+3b024339bd67b8 
INFO Trying to get the kube-cross version for master... 
INFO Found the following kube-cross version: v1.13.9-5 
INFO Listing GCB substitutions prior to build submission... 
INFO RC:                                          
INFO RELEASE_BRANCH: master                       
INFO BUILD_AT_HEAD:                               
INFO TOOL_REPO: release                           
INFO NOMOCK:                                      
INFO RC_TAG:                                      
INFO OFFICIAL:                                    
INFO BUILDVERSION: --buildversion=v1.19.0-alpha.3.208+3b024339bd67b8 
INFO KUBE_CROSS_VERSION: v1.13.9-5                
INFO NOMOCK_TAG:                                  
INFO TOOL_ORG: saschagrunert                      
INFO GCP_USER_TAG: stephen-k8s-at-agst-us         
INFO OFFICIAL_TAG:                                
INFO BUILD_POINT: v1.19.0-alpha.3.208-3b024339bd67b8 
INFO TOOL_BRANCH: verify-check                    
INFO Build directory: /home/augustus/go/src/k8s.io/release/gcb/stage 
INFO Config directory: /home/augustus/go/src/k8s.io/release/gcb/stage 
INFO cd-ing to build directory: /home/augustus/go/src/k8s.io/release/gcb/stage 
ID                                    CREATE_TIME                DURATION  SOURCE  IMAGES  STATUS
6ec7fe0d-e0f7-41e6-b204-e938731bc3be  2020-05-13T14:47:49+00:00  -         -       -       QUEUED
INFO: Refreshing access_token
Created [https://cloudbuild.googleapis.com/v1/projects/kubernetes-release-test/builds/6ec7fe0d-e0f7-41e6-b204-e938731bc3be].
Logs are available at [https://console.cloud.google.com/cloud-build/builds/6ec7fe0d-e0f7-41e6-b204-e938731bc3be?project=648026197307].
INFO: Display format: "
        table(
          id,
          createTime.date('%Y-%m-%dT%H:%M:%S%Oz', undefined='-'),
          duration(start=startTime,end=finishTime,precision=0,calendar=false,undefined="  -").slice(2:).join(""):label=DURATION,
          build_source(undefined="-"):label=SOURCE,
          build_images(undefined="-"):label=IMAGES,
          status
        )
      "

Local ahead of remote tip:

$ TOOL_ORG=saschagrunert TOOL_BRANCH=verify-check krel gcbmgr --stage
INFO Verifying repository state                   
INFO Repository is in clean state                 
INFO Found matching branch "verify-check"         
INFO Found matching organization "saschagrunert" and repository "release" in remote: sascha (https://github.com/saschagrunert/release.git) 
INFO Verifying remote HEAD commit                 
INFO Got remote commit: 595dfec1803e960adf29430123bf94dbf3d673cf 
INFO Verifying that remote commit is equal to the local one 
FATA verifying repository state: Local HEAD (bab3c4933ef5be249bd00efe05bb6f3ef7107500) is not equal to latest remote commit (595dfec1803e960adf29430123bf94dbf3d673cf) 

/lgtm
/approve
/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 13, 2020
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 13, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cpanato, justaugustus, saschagrunert

The full list of commands accepted by this bot can be found here.

The pull request process is described here

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

@k8s-ci-robot k8s-ci-robot merged commit 043cf20 into kubernetes:master May 13, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.19 milestone May 13, 2020
@saschagrunert saschagrunert deleted the verify-check branch May 13, 2020 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/release-eng Issues or PRs related to the Release Engineering subproject cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/release Categorizes an issue or PR as relevant to SIG Release. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mismatched or dirty local k/release copy does not block krel gcbmgr runs
4 participants