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

Add test for executing K8S_SYNC stage at the kubernetes plugin #5431

Merged
merged 8 commits into from
Dec 20, 2024

Conversation

Warashi
Copy link
Contributor

@Warashi Warashi commented Dec 17, 2024

What this PR does:

Implement the test in the same way as #5399 at the Kubernetes plugin, then fix the failure about the resource key.

Why we need it:

To ensure compatibility between the current Kubernetes platform provider and the Kubernetes plugin.

Which issue(s) this PR fixes:

Part of #4980

Does this PR introduce a user-facing change?: No

  • How are users affected by this change:
  • Is this breaking change:
  • How to migrate (if breaking change):

Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
Comment on lines 207 to 214
assert.Equal(t, "simple", deployment.GetName())
assert.Equal(t, "simple", deployment.GetLabels()["app"])
assert.Equal(t, "piped", deployment.GetAnnotations()["pipecd.dev/managed-by"])
assert.Equal(t, "piped-id", deployment.GetAnnotations()["pipecd.dev/piped"])
assert.Equal(t, "app-id", deployment.GetAnnotations()["pipecd.dev/application"])
assert.Equal(t, "apps/v1", deployment.GetAnnotations()["pipecd.dev/original-api-version"])
assert.Equal(t, "apps/v1:Deployment:default:simple", deployment.GetAnnotations()["pipecd.dev/resource-key"])
assert.Equal(t, "0123456789", deployment.GetAnnotations()["pipecd.dev/commit-hash"])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these assertions are copied from #5399

@Warashi Warashi marked this pull request as ready for review December 17, 2024 08:38
Copy link

codecov bot commented Dec 17, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 12 lines in your changes missing coverage. Please review.

Project coverage is 26.24%. Comparing base (7cf95df) to head (8fe9dad).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
...ugin/logpersister/logpersistertest/logpersister.go 47.82% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5431      +/-   ##
==========================================
+ Coverage   26.11%   26.24%   +0.13%     
==========================================
  Files         451      452       +1     
  Lines       48823    48860      +37     
==========================================
+ Hits        12749    12825      +76     
+ Misses      35057    35011      -46     
- Partials     1017     1024       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 90 to 92
if k.Namespace == "" {
k.Namespace = DefaultNamespace
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was an incompatibility between the current Kubernetes platform provider and the Kubernetes plugin, so I fixed this.

Copy link
Member

Choose a reason for hiding this comment

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

This quite tricky and could lead to some issues because logic which depends on resource key need the ns be set carefully. Say, if the resource is cluster resource, we should not force setting ns value to it cc @ffjlabo

Copy link
Member

Choose a reason for hiding this comment

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

IMO: it is quite tricky as @khanhtc1202 said. So at first, we might be good to implement the same as pipedv0. And later fix the resource key problem.

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 for commenting. I reverted this change and fixed the assertion.
We can write the e2e test now, so I want to write tests to prevent bugs.

057b9f5
e030be1


// newTestLogPersister creates a new testLogPersister for testing.
//
// TODO: move to a common package
Copy link
Member

Choose a reason for hiding this comment

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

it's good to move this to logpersister package itself. Just like git package provides gittest for testing

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. I moved these to pkg/plugin/logpersister/logpersistertest.
3c0a57d

}
}

// TODO: move to a common package
Copy link
Member

Choose a reason for hiding this comment

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

this is okay to be here since it's kubernetes specific

Copy link
Contributor Author

@Warashi Warashi Dec 18, 2024

Choose a reason for hiding this comment

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

Thank you. I removed the TODO comment.
8fe9dad

Comment on lines 90 to 92
if k.Namespace == "" {
k.Namespace = DefaultNamespace
}
Copy link
Member

Choose a reason for hiding this comment

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

This quite tricky and could lead to some issues because logic which depends on resource key need the ns be set carefully. Say, if the resource is cluster resource, we should not force setting ns value to it cc @ffjlabo

Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>

This reverts commit 098d1da.
Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
@Warashi Warashi requested a review from khanhtc1202 December 18, 2024 08:52
@@ -189,7 +189,7 @@ func (a *DeploymentService) loadManifests(ctx context.Context, deploy *model.Dep
manifests, err := a.loader.LoadManifests(ctx, provider.LoaderInput{
PipedID: deploy.GetPipedId(),
AppID: deploy.GetApplicationId(),
CommitHash: deploy.GetTrigger().GetCommit().GetHash(),
CommitHash: deploymentSource.GetRevision(),
Copy link
Member

Choose a reason for hiding this comment

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

This could be the same but I like the previous version more. How about to rename GetRevision to GetCommitHash 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

First, I also like commit hash more than revision.

However, this is not the same because the deploymentSource can be the running deploy source, not the target deploy source.

The naming GetRevision comes from proto definition, so how about renaming this field as commit_hash?

// The git commit revision of the source code.
string revision = 2;

Copy link
Member

Choose a reason for hiding this comment

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

I got your point. Also, it's a commit hash, so it should be named directly as a commit hash to reduce confusion. Let's address it by another PR (change proto and update this)

Copy link
Member

@khanhtc1202 khanhtc1202 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Member

@ffjlabo ffjlabo left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@Warashi Warashi merged commit b98a963 into master Dec 20, 2024
18 checks passed
@Warashi Warashi deleted the k8s-plugin-sync-test branch December 20, 2024 04:27
@github-actions github-actions bot mentioned this pull request Jan 21, 2025
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.

3 participants