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

(bugfix) Issue-1464 issue resolved #1644

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

S-mishina
Copy link
Contributor

@S-mishina S-mishina commented May 15, 2024

summary

if delegation: true is set while a VirtualService has already been created by Flagger, there are no changes to the newSpec. Therefore, I suspect that the hosts and gateway are not removed.

flagger/pkg/router/istio.go

Lines 296 to 300 in 9a0c6e7

if canary.Spec.Service.Delegation {
// delegate VirtualService requires the hosts and gateway empty.
virtualService.Spec.Gateways = []string{}
virtualService.Spec.Hosts = []string{}
}

if specDiff != "" || labelsDiff != "" || annotationsDiff != "" {

[MEMO] Code of the relevant part

flagger/pkg/router/istio.go

Lines 325 to 364 in 9a0c6e7

if virtualService != nil {
specDiff := cmp.Diff(
newSpec,
virtualService.Spec,
ignoreCmpOptions...,
)
labelsDiff := cmp.Diff(newMetadata.Labels, virtualService.Labels, cmpopts.EquateEmpty())
annotationsDiff := cmp.Diff(newMetadata.Annotations, virtualService.Annotations, cmpopts.EquateEmpty())
if specDiff != "" || labelsDiff != "" || annotationsDiff != "" {
vtClone := virtualService.DeepCopy()
vtClone.Spec = newSpec
vtClone.ObjectMeta.Annotations = newMetadata.Annotations
vtClone.ObjectMeta.Labels = newMetadata.Labels
//If annotation kubectl.kubernetes.io/last-applied-configuration is present no need to duplicate
//serialization. If not present store the serialized object in annotation
//flagger.kubernetes.app/original-configuration
if _, ok := vtClone.Annotations[kubectlAnnotation]; !ok && specDiff != "" {
b, err := json.Marshal(virtualService.Spec)
if err != nil {
ir.logger.Warnf("Unable to marshal VS %s for orig-configuration annotation", virtualService.Name)
}
if vtClone.ObjectMeta.Annotations == nil {
vtClone.ObjectMeta.Annotations = make(map[string]string)
} else {
vtClone.ObjectMeta.Annotations = filterMetadata(vtClone.ObjectMeta.Annotations)
}
vtClone.ObjectMeta.Annotations[configAnnotation] = string(b)
}
_, err = ir.istioClient.NetworkingV1beta1().VirtualServices(canary.Namespace).Update(context.TODO(), vtClone, metav1.UpdateOptions{})
if err != nil {
return fmt.Errorf("VirtualService %s.%s update error: %w", apexName, canary.Namespace, err)
}
ir.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
Infof("VirtualService %s.%s updated", virtualService.GetName(), canary.Namespace)
}
}

※ This is just a suggestion for now, and there may be a better way to do it.

reference)
#1464

Signed-off-by: S-mishina <seiryu.mishina@zozo.com>
@S-mishina
Copy link
Contributor Author

S-mishina commented May 15, 2024

The current fix causes the changes to be periodically applied to Istio. It would be better to incorporate newSpec and detect the differences, so that only the changes are applied.

80cae71

@S-mishina S-mishina marked this pull request as draft May 15, 2024 17:59
Signed-off-by: S-mishina <seiryu.mishina@zozo.com>
@S-mishina
Copy link
Contributor Author

S-mishina commented May 15, 2024

flagger/pkg/router/istio.go

Lines 296 to 300 in 9a0c6e7

if canary.Spec.Service.Delegation {
// delegate VirtualService requires the hosts and gateway empty.
virtualService.Spec.Gateways = []string{}
virtualService.Spec.Hosts = []string{}
}

If we replace the above with newSpec and make a difference, it could be applied!

65867f7

@S-mishina
Copy link
Contributor Author

If virtualService.Spec.Gateways and virtualService.Spec.Hosts are empty, wouldn't it mean that no differences will be detected if nothing is added to newSpec?

Signed-off-by: S-mishina <seiryu.mishina@zozo.com>
Signed-off-by: S-mishina <seiryu.mishina@zozo.com>
@codecov-commenter
Copy link

codecov-commenter commented May 16, 2024

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 34.09%. Comparing base (e3a529e) to head (808f945).
Report is 18 commits behind head on main.

Files Patch % Lines
pkg/router/istio.go 0.00% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1644       +/-   ##
===========================================
- Coverage   56.51%   34.09%   -22.43%     
===========================================
  Files          85      282      +197     
  Lines        8571    20563    +11992     
===========================================
+ Hits         4844     7011     +2167     
- Misses       3053    12622     +9569     
- Partials      674      930      +256     

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

Signed-off-by: S-mishina <seiryu.mishina@zozo.com>
Signed-off-by: S-mishina <seiryu.mishina@zozo.com>
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.

2 participants