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

chore: Validate before adding Xds resource #1662

Merged
merged 30 commits into from
Aug 3, 2023

Conversation

Ronnie-personal
Copy link
Contributor

What type of PR is this? Chore: Validate before adding Xds resource

What this PR does / why we need it: This PR calls Validate() before adding the resource to Xds resource table.

Which issue(s) this PR fixes: #1647

Fixes #

Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
@Ronnie-personal Ronnie-personal requested a review from a team as a code owner July 16, 2023 20:30
@codecov
Copy link

codecov bot commented Jul 16, 2023

Codecov Report

Merging #1662 (d886fe3) into main (ea18f8f) will increase coverage by 0.08%.
Report is 6 commits behind head on main.
The diff coverage is 67.91%.

@@            Coverage Diff             @@
##             main    #1662      +/-   ##
==========================================
+ Coverage   64.77%   64.86%   +0.08%     
==========================================
  Files          83       84       +1     
  Lines       11925    12081     +156     
==========================================
+ Hits         7725     7836     +111     
- Misses       3715     3744      +29     
- Partials      485      501      +16     
Files Changed Coverage Δ
internal/xds/translator/jsonpatch.go 30.10% <0.00%> (+0.10%) ⬆️
internal/xds/translator/authentication.go 65.10% <25.00%> (-0.78%) ⬇️
internal/xds/translator/extension.go 72.38% <25.00%> (-1.66%) ⬇️
internal/xds/translator/ratelimit.go 87.94% <25.00%> (-0.91%) ⬇️
internal/xds/translator/translator.go 72.58% <51.02%> (-5.87%) ⬇️
internal/xds/types/resourceversiontable.go 84.31% <89.09%> (+2.83%) ⬆️
internal/xds/translator/accesslog.go 98.20% <100.00%> (+0.02%) ⬆️
internal/xds/translator/tracing.go 95.09% <100.00%> (+0.09%) ⬆️

... and 7 files with indirect coverage changes

Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
@arkodg
Copy link
Contributor

arkodg commented Jul 18, 2023

thanks for raising this PR @Ronnie-personal .
Imo attaching a ValidateAll() right before inserting the resource into tCtx.AddXdsResource is something the developer might forget to do, instead should we add ValidateAll() inside the tCtx.AddXdsResource and change the signature of it to return a error code instead ?

Xunzhuo and others added 3 commits July 19, 2023 11:03
@Ronnie-personal
Copy link
Contributor Author

Ronnie-personal commented Jul 21, 2023

thanks for raising this PR @Ronnie-personal . Imo attaching a ValidateAll() right before inserting the resource into tCtx.AddXdsResource is something the developer might forget to do, instead should we add ValidateAll() inside the tCtx.AddXdsResource and change the signature of it to return a error code instead ?

How about this code change?

`func (t *ResourceVersionTable) AddXdsResource(rType resourcev3.Type, xdsResource types.Resource) error {

// Perform type switch to handle different types of xdsResource
switch r := xdsResource.(type) {

case *listenerv3.Listener:
	// Handle Type specific operations
	if resourceOfType, ok := xdsResource.(*listenerv3.Listener); ok {
		if err := resourceOfType.ValidateAll(); err != nil {
			return fmt.Errorf("validation failed for xds resource %+v, err:%v", r, err)
		}
	} else {
		return fmt.Errorf("failed to cast xds resource %+v to Listener type", r)
	}

case *routev3.RouteConfiguration:
	// Handle Type specific operations
	if resourceOfType, ok := xdsResource.(*routev3.RouteConfiguration); ok {
		if err := resourceOfType.ValidateAll(); err != nil {
			return fmt.Errorf("validation failed for xds resource %+v, err:%v", r, err)
		}
	} else {
		return fmt.Errorf("failed to cast xds resource %+v to RouteConfiguration type", r)
	}

case *Type3:
	// Handle Type3 specific operations

// Add more cases for other types as needed
default:
	// Handle the case when the type is not recognized or supported
	return fmt.Errorf("Unsupported resource type: %v", rType)
}

if t.XdsResources == nil {
	t.XdsResources = make(XdsResources)
}
if t.XdsResources[rType] == nil {
	t.XdsResources[rType] = make([]types.Resource, 0, 1)
}

t.XdsResources[rType] = append(t.XdsResources[rType], xdsResource)
return nil

}`

@arkodg
Copy link
Contributor

arkodg commented Jul 21, 2023

yeah @Ronnie-personal something similar to above logic is needed, you can probably use rType resourcev3.Type as in input to switch and then typecast from resource to the specific type before running ValidateAll

Ronnie-personal and others added 15 commits July 21, 2023 22:01
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
Signed-off-by: Ronnie-personal <76408835+Ronnie-personal@users.noreply.github.com>
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
Co-authored-by: tony-2023 <138949958+tony-2023@users.noreply.github.com>
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
@Ronnie-personal
Copy link
Contributor Author

@arkodg
The e2e ratelimit test failed. Please find detailed error at https://github.com/envoyproxy/gateway/actions/runs/5633849037/job/15263275737?pr=1662#step:6:1913.

This PR does not change e2e test code. Do you think the error is caused by any code change in this pull request?

Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
@Ronnie-personal Ronnie-personal marked this pull request as draft July 27, 2023 03:00
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
}

case resourcev3.EndpointType:
// TBD - ValidateAll() breaks existing test internal/cmd/egctl/translate_test
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for catching this, lets raise a issue to track this

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, I have opened #1742. Here is the PR to fix the issue #1758

@arkodg
Copy link
Contributor

arkodg commented Aug 1, 2023

LGTM @Ronnie-personal, this PR looks good, just added some minor comments, thanks again !

@arkodg arkodg added this to the 0.6.0-rc1 milestone Aug 1, 2023
arkodg
arkodg previously approved these changes Aug 1, 2023
@arkodg arkodg requested review from a team, zhaohuabing, qicz and chauhanshubham and removed request for a team August 1, 2023 21:20
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
@Ronnie-personal
Copy link
Contributor Author

@arkodg
Sorry, I pushed a minor change to fix the typo.
Here are the changes Ronnie-personal@d886fe3

@arkodg arkodg requested review from a team August 3, 2023 01:08
@Xunzhuo Xunzhuo merged commit d768a67 into envoyproxy:main Aug 3, 2023
5 of 6 checks passed
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.

5 participants