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

Hap Diff Test #1814

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ralikio
Copy link
Member

@ralikio ralikio commented Mar 4, 2025

Description

Changes proposed in this pull request:

  • Corrected HAP Migration test to guarantee that old and new implementations return the same results.

Related issue(s)

#1520

@ralikio ralikio added the kind/enhancement Categorizes issue or PR as related to modifying or improving an existing feature label Mar 4, 2025
@ralikio ralikio self-assigned this Mar 4, 2025
@ralikio ralikio requested a review from a team as a code owner March 4, 2025 14:49
@kyma-gopher-bot kyma-gopher-bot enabled auto-merge (squash) March 4, 2025 14:49
Copy link

github-actions bot commented Mar 4, 2025

Add one of following labels

- kind/feature -> Use it when you want to submit a new feature

- kind/enhancement -> Use it when you modify or improve an existing feature

- kind/bug -> Use it when you fix a bug

@kyma-bot kyma-bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Mar 4, 2025
@ralikio ralikio mentioned this pull request Mar 4, 2025
@jaroslaw-pieszka jaroslaw-pieszka self-requested a review March 4, 2025 14:56
"us-west1",
"us-east4",
"europe-west4",
}
Copy link
Contributor

@jaroslaw-pieszka jaroslaw-pieszka Mar 4, 2025

Choose a reason for hiding this comment

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

How come:

INPUT: PlanID: 4deee563-e5ec-4731-b9b1-53b42d855f0c, PlatformRegion: cf-ap21, ClusterRegion: centralus, Provider: AWS
!dirty,!euAccess,hyperscalerType=aws,tenantName=e8f7ec0a-0cd6-41f0-905d-5d1efa9fb6c4
INPUT: PlanID: 4deee563-e5ec-4731-b9b1-53b42d855f0c, PlatformRegion: cf-ap21, ClusterRegion: centralus, Provider: Azure
!dirty,!euAccess,hyperscalerType=azure,tenantName=e8f7ec0a-0cd6-41f0-905d-5d1efa9fb6c4
INPUT: PlanID: 4deee563-e5ec-4731-b9b1-53b42d855f0c, PlatformRegion: cf-ap21, ClusterRegion: centralus, Provider: GCP
!dirty,!euAccess,hyperscalerType=gcp,tenantName=e8f7ec0a-0cd6-41f0-905d-5d1efa9fb6c4

centralus is only valid for azure provider (and related plans).
So we test not allowed combinations of plan and cluster region.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is not issue but could be.
If we have difference for not allowed combinations, we report failure of comparison however it is not necessarily a problem.

Copy link
Contributor

@jaroslaw-pieszka jaroslaw-pieszka Mar 4, 2025

Choose a reason for hiding this comment

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

And here we generate over 50k cases instead of around 3k.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was easier for just to go through all combinations. Test will be removed with removal of old resolve_creds steps.

var newImplementationLog *bufio.Writer

if writeFiles {
oldLog, err := os.OpenFile("./hap-old-implementation.log", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
Copy link
Contributor

@jaroslaw-pieszka jaroslaw-pieszka Mar 4, 2025

Choose a reason for hiding this comment

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

executable? I think we need to reconsider permissions.

Copy link
Member Author

Choose a reason for hiding this comment

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


oldImplementationLog = bufio.NewWriter(oldLog)

newLog, err := os.OpenFile("./hap-new-implementation.log", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
Copy link
Contributor

Choose a reason for hiding this comment

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

executable? Is this really needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

require.Zero(t, when)

for label, count := range queriesCountMap {
require.NotZero(t, count, "first invocation produced wrong number of queries for label: %s, count: %d", label, count)
Copy link
Contributor

@jaroslaw-pieszka jaroslaw-pieszka Mar 4, 2025

Choose a reason for hiding this comment

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

If count > 0 regardless of the actual value we are fine?
What if count > 1?

Copy link
Contributor

Choose a reason for hiding this comment

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

What if implementation wrongly requests twice the same (or different) secret bindings?
Should we detect it?

)

// To generate output hap-old-implementation files (used to compare results by hand) switch writeFiles to true
func TestResolveCredentials_IntegrationAzure2(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you consider changing the name of function?

increase := true

gc.PrependReactor("list", gardener.SecretBindingResource.Resource, func(action k8sTesting.Action) (bool, runtime.Object, error) {
originalLabel := action.(k8sTesting.ListActionImpl).GetListRestrictions().Labels.String()
Copy link
Contributor

Choose a reason for hiding this comment

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

These are labels (as GetListRestrictions().Labels suggests).


// first run
increase = true
_, when, err := step.Run(op, fixLogger())
Copy link
Contributor

@jaroslaw-pieszka jaroslaw-pieszka Mar 4, 2025

Choose a reason for hiding this comment

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

So here we have reactor called and queriesCountMap filled.
Comparison is based on assumption that map key will be the same (GetListRestrictions().Labels.String()).
What if order is not stable?
What if there is irrelevant label added?
Shouldn't we compare explicitely shared, euaccess, hyperscalertype labels?
What if tenant change?

// for example !dirty selects a secret without dirty label
filteredSplit := []string{}
split := strings.Split(originalLabel, ",")
for _, label := range split {
Copy link
Contributor

Choose a reason for hiding this comment

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

This part is needed only to fix appropriate SecretBinding.
So could be extracted as it has different responsibility.

split := strings.Split(originalLabel, ",")
for _, label := range split {
label = strings.Trim(label, " ")
if label != "" && label != " " && label != "!dirty" && label != "!euAccess" && label != "shared!=true" && label != "!tenantName" {
Copy link
Contributor

Choose a reason for hiding this comment

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

So we omit "!euAccess".

split := strings.Split(originalLabel, ",")
for _, label := range split {
label = strings.Trim(label, " ")
if label != "" && label != " " && label != "!dirty" && label != "!euAccess" && label != "shared!=true" && label != "!tenantName" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could "shared!=true" actually happen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Categorizes issue or PR as related to modifying or improving an existing feature size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants