-
Notifications
You must be signed in to change notification settings - Fork 0
Deduplication branch #22
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
base: main
Are you sure you want to change the base?
Conversation
…endpoint name formatting in VirtualService templates
… wildcard handling
…x for improved formatting consistency
… improved wildcard matching
…oyments, jobs, and statefulsets
Signed-off-by: Byran Carlock <[email protected]>
…updating sync options for ArgoCD to use Force instead of PruneLast. (#19) Signed-off-by: Byran Carlock <[email protected]>
…r various matching scenarios
Helm Unit Test Results - charts/mycarrier-helm162 tests 162 ✅ 1m 40s ⏱️ Results for commit a109fd1. ♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements deduplication logic for VirtualService endpoints to prevent validation errors caused by duplicate endpoint definitions. The changes ensure that language-specific defaults (e.g., /api
, /health
, /liveness
for C#) and user-defined endpoints are merged and deduplicated based on their normalized path and match type (exact/prefix/regex).
Key Changes:
- Introduced deduplication logic that creates unique endpoint keys using
kind:normalized_path
format - Centralized wildcard path processing in reusable helper functions
- Added schema validation for the
allowedEndpoints
array with support for both string and object formats
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
File | Description |
---|---|
values.schema.json | Added JSON schema validation for allowedEndpoints array, supporting both string paths and objects with kind/match fields |
allowed_endpoints_deduplication_test.yaml | Comprehensive test suite (10 tests) validating deduplication across exact/prefix/regex matches, wildcards, and case-sensitivity |
_spec_virtualservice.tpl | Refactored endpoint detection logic and cleaned up template formatting (removed redundant whitespace/conditions) |
_lang.tpl | Implemented core deduplication algorithm with path normalization, added helper functions for wildcard/prefix/name processing |
Chart.yaml | Added Bitnami common chart dependency |
…shes for consistent deduplication
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal of the ticket was as follows:
- add default endpoints /health, /liveness, /api for csharp apis
- allow adding endpoints along with default
- provide a way to disable default endpoints
- deduplicate endpoints to make sure render is clean ✅
The first three have not been achieved yet. I was able to confirm deduplication works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address the comments and ensure:
- /health is automatically added as an allowed endpoint when
eq $.Values.global.language "csharp"
- /liveness is automatically added as an allowed endpoint when
eq $.Values.global.language "csharp"
- /api is automatically added as an allowed endpoint when
and (eq $.Values.global.language "csharp") ($fullName | contains "api"
- Make sure these default endpoints work with manually configured endpoints ie, if I add "/fakeendpoint" to "my-api" I should end up with /health, /liveness, /api, and /fakeendpoint
- There needs to be a way to disable the default endpoints, but that disable should not prevent the use of manually configured allowed endpoints.
- Tests that prove each item above
…oints configuration
…ubernetes naming; update tests accordingly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
…rocessing; update VirtualService template for Istio configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my comments
{{- if contains "*" .match }} | ||
- name: {{ $fullName }}-allowed--{{ $endpointName }} | ||
{{- else }} | ||
- name: {{ $fullName }}-allowed-{{ $endpointName }} | ||
{{- end }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is no difference between the true and false case we should skip the if statement entirely.
{{- if contains "*" .match }} | |
- name: {{ $fullName }}-allowed--{{ $endpointName }} | |
{{- else }} | |
- name: {{ $fullName }}-allowed-{{ $endpointName }} | |
{{- end }} | |
- name: {{ $fullName }}-allowed-{{ $endpointName }} |
{{- if eq .kind "prefix" }} | ||
{{/* Use original match for name generation to preserve wildcards */}} | ||
{{- $endpointName := include "helm.processEndpointName" .match -}} | ||
{{/* Use double dash for wildcard patterns, single dash for simple prefixes */}} | ||
{{- if contains "*" .match }} | ||
- name: {{ $fullName }}-allowed--{{ $endpointName }} | ||
{{- else }} | ||
- name: {{ $fullName }}-allowed-{{ $endpointName }} | ||
{{- end }} | ||
match: | ||
- uri: | ||
{{- if contains "*" . }} | ||
prefix: {{ . | replace "*" "" }} | ||
{{- else }} | ||
exact: {{ . }} | ||
{{- end }} | ||
- uri: | ||
prefix: {{ include "helm.processPrefixPath" .match }} | ||
{{- else if eq .kind "exact" }} | ||
{{- $processedMatch := .match | replace "/" "-" | trimAll "-" }} | ||
{{- if $processedMatch }} | ||
- name: {{ $fullName }}-allowed--{{ $processedMatch }} | ||
{{- else }} | ||
{{/* New format with kind and match fields */}} | ||
- name: {{ $fullName }}-allowed-{{ .match | replace "/" "-" | replace "*" "wildcard" | replace "(" "" | replace ")" "" | replace "|" "-" | replace "." "-" | replace "?" "-" | replace "+" "-" | replace "^" "" | replace "$" "" | trimSuffix "-" }} | ||
- name: {{ $fullName }}-allowed- | ||
{{- end }} | ||
match: | ||
- uri: | ||
exact: {{ .match }} | ||
{{- else if eq .kind "regex" }} | ||
{{- $processedMatch := include "helm.processRegexEndpointName" .match }} | ||
- name: {{ $fullName }}-allowed--{{ $processedMatch }} | ||
match: | ||
- uri: | ||
{{- if eq .kind "exact" }} | ||
exact: {{ .match }} | ||
{{- else if eq .kind "prefix" }} | ||
prefix: {{ .match }} | ||
{{- else if eq .kind "regex" }} | ||
regex: {{ .match }} | ||
{{- else }} | ||
{{/* Default to exact if kind is not recognized */}} | ||
exact: {{ .match }} | ||
{{- end }} | ||
- uri: | ||
regex: {{ .match }} | ||
{{- end }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The body of the match rule is identical except for the key of the operation, which means we can better follow the DRY principle by condensing all 3 of these into this:
- name: {{ $fullName }}-allowed--{{ if eq .kind "prefix" }}{{ $endpointName }}{{ else }}{{ $processedMatch }}{{ end }}
match:
- uri:
{{- if eq .kind "prefix" }}
prefix: {{ include "helm.processPrefixPath" .match }}
{{- else if eq .kind "exact" }}
exact: {{ .match }}
{{- else if eq .kind "regex" }}
regex: {{ .match }}
{{ end }}
DRY Violations in Proposed Helm Template ChangesSummary of DRY Violations
Refactoring SuggestionsTo address these DRY violations, consider the following refactor: 1. Centralize Endpoint Name Generation
2. Centralize Endpoint Match Rendering
3. Centralize Endpoint Rule Block
4. DRY Rendering Loop for All Endpoint RulesAfter deduplication, simply loop and call the above centralized template:
5. Forbidden Rule Stays SeparateThe forbidden rule is unique and can remain a separate block. Net effect:
|
{{- $endpointName := include "helm.processEndpointName" .match -}} | ||
{{/* Use double dash for wildcard patterns, single dash for simple prefixes */}} | ||
{{- if contains "*" .match }} | ||
- name: {{ $fullName }}-allowed--{{ $endpointName }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the double hyphens and trailing hyphens.
Example:
- {{ $fullName }}-allowed--{{ $endpointName }} should be {{ $fullName }}-allowed-{{ $endpointName }}
- {{ $fullName }}-allowed- should be {{ $fullName }}-allowed
Please update the test cases as well since this change will break them.
Fix: Endpoint Deduplication in VirtualService
Problem
Language-specific endpoints (/api, /health) were duplicating user-defined endpoints, causing VirtualService validation errors.
Solution
Deduplication logic: Merge and deduplicate endpoints by normalized path (kind:path)
Refactored wildcard handling: Centralized in helm.processPrefixPath helper
Schema validation: Added allowedEndpoints to values.schema.json (validates kind enum, requires kind/match, allows metadata)
Conditional rendering: Forbidden rule only when endpoints exist.
Testing
Added 10 tests for deduplication logic.