From 80cae71986421f32a665f3f76cedb3438c1bf56a Mon Sep 17 00:00:00 2001 From: S-mishina Date: Thu, 16 May 2024 02:26:22 +0900 Subject: [PATCH 1/6] Issue-1464 issue resolved Signed-off-by: S-mishina --- pkg/router/istio.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/router/istio.go b/pkg/router/istio.go index 75b3701a7..9f5fbaecc 100644 --- a/pkg/router/istio.go +++ b/pkg/router/istio.go @@ -297,6 +297,8 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error { // delegate VirtualService requires the hosts and gateway empty. virtualService.Spec.Gateways = []string{} virtualService.Spec.Hosts = []string{} + newSpec.Hosts = []string{} + newSpec.Gateways = []string{} } ignoreCmpOptions := []cmp.Option{ @@ -330,16 +332,15 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error { ) labelsDiff := cmp.Diff(newMetadata.Labels, virtualService.Labels, cmpopts.EquateEmpty()) annotationsDiff := cmp.Diff(newMetadata.Annotations, virtualService.Annotations, cmpopts.EquateEmpty()) - if specDiff != "" || labelsDiff != "" || annotationsDiff != "" { + if specDiff != "" || labelsDiff != "" || annotationsDiff != "" || canary.Spec.Service.Delegation { 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 != "" { + if _, ok := vtClone.Annotations[kubectlAnnotation]; !ok && specDiff != "" || canary.Spec.Service.Delegation { b, err := json.Marshal(virtualService.Spec) if err != nil { ir.logger.Warnf("Unable to marshal VS %s for orig-configuration annotation", virtualService.Name) From 65867f7cbfae78f25dfb40e66b93f52fa76e7e82 Mon Sep 17 00:00:00 2001 From: S-mishina Date: Thu, 16 May 2024 03:06:49 +0900 Subject: [PATCH 2/6] fix Signed-off-by: S-mishina --- pkg/router/istio.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/router/istio.go b/pkg/router/istio.go index 9f5fbaecc..f35797157 100644 --- a/pkg/router/istio.go +++ b/pkg/router/istio.go @@ -295,8 +295,6 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error { if canary.Spec.Service.Delegation { // delegate VirtualService requires the hosts and gateway empty. - virtualService.Spec.Gateways = []string{} - virtualService.Spec.Hosts = []string{} newSpec.Hosts = []string{} newSpec.Gateways = []string{} } @@ -332,7 +330,7 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error { ) labelsDiff := cmp.Diff(newMetadata.Labels, virtualService.Labels, cmpopts.EquateEmpty()) annotationsDiff := cmp.Diff(newMetadata.Annotations, virtualService.Annotations, cmpopts.EquateEmpty()) - if specDiff != "" || labelsDiff != "" || annotationsDiff != "" || canary.Spec.Service.Delegation { + if specDiff != "" || labelsDiff != "" || annotationsDiff != "" { vtClone := virtualService.DeepCopy() vtClone.Spec = newSpec vtClone.ObjectMeta.Annotations = newMetadata.Annotations @@ -340,7 +338,7 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error { //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 != "" || canary.Spec.Service.Delegation { + 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) From 720277742915577aefaa5978c206fb1a93e7d474 Mon Sep 17 00:00:00 2001 From: S-mishina Date: Thu, 16 May 2024 20:51:04 +0900 Subject: [PATCH 3/6] fix Signed-off-by: S-mishina --- pkg/router/istio.go | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/pkg/router/istio.go b/pkg/router/istio.go index f35797157..6249c26fd 100644 --- a/pkg/router/istio.go +++ b/pkg/router/istio.go @@ -21,6 +21,7 @@ import ( "encoding/json" "fmt" "math/rand" + "reflect" "strings" "time" @@ -142,6 +143,7 @@ func canaryToL4Match(canary *flaggerv1.Canary) []istiov1beta1.L4MatchAttributes return match } +// TODO: aaa func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error { apexName, primaryName, canaryName := canary.GetServiceNames() @@ -292,13 +294,27 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error { } else if err != nil { return fmt.Errorf("VirtualService %s.%s get query error %v", apexName, canary.Namespace, err) } - - if canary.Spec.Service.Delegation { + fmt.Println("aaa_bbb") + fmt.Println(canary.Spec.Service.Delegation) + fmt.Println(reflect.DeepEqual(newSpec, istiov1beta1.VirtualServiceSpec{})) + fmt.Println(virtualService.Spec.Gateways) + fmt.Println(virtualService.Spec.Hosts) + if (canary.Spec.Service.Delegation && reflect.DeepEqual(newSpec, istiov1beta1.VirtualServiceSpec{}) == false) && + (virtualService.Spec.Gateways != nil || virtualService.Spec.Hosts != nil) { // delegate VirtualService requires the hosts and gateway empty. - newSpec.Hosts = []string{} - newSpec.Gateways = []string{} + virtualService.Spec.Gateways = []string{} + virtualService.Spec.Hosts = []string{} + _, err = ir.istioClient.NetworkingV1beta1().VirtualServices(canary.Namespace).Update(context.TODO(), virtualService, 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) + } else if canary.Spec.Service.Delegation { + // delegate VirtualService requires the hosts and gateway empty. + virtualService.Spec.Gateways = []string{} + virtualService.Spec.Hosts = []string{} } - ignoreCmpOptions := []cmp.Option{ cmpopts.IgnoreFields(istiov1beta1.HTTPRouteDestination{}, "Weight"), cmpopts.IgnoreFields(istiov1beta1.HTTPRoute{}, "Mirror", "MirrorPercentage"), @@ -338,7 +354,7 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error { //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 != ""{ + 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) From d79bfa77508b2ac0fe60ce5ca1cf12b77e40ac32 Mon Sep 17 00:00:00 2001 From: S-mishina Date: Thu, 16 May 2024 21:13:33 +0900 Subject: [PATCH 4/6] fix Signed-off-by: S-mishina --- pkg/router/istio.go | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/pkg/router/istio.go b/pkg/router/istio.go index 6249c26fd..93a55a525 100644 --- a/pkg/router/istio.go +++ b/pkg/router/istio.go @@ -143,7 +143,6 @@ func canaryToL4Match(canary *flaggerv1.Canary) []istiov1beta1.L4MatchAttributes return match } -// TODO: aaa func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error { apexName, primaryName, canaryName := canary.GetServiceNames() @@ -294,26 +293,17 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error { } else if err != nil { return fmt.Errorf("VirtualService %s.%s get query error %v", apexName, canary.Namespace, err) } - fmt.Println("aaa_bbb") - fmt.Println(canary.Spec.Service.Delegation) - fmt.Println(reflect.DeepEqual(newSpec, istiov1beta1.VirtualServiceSpec{})) - fmt.Println(virtualService.Spec.Gateways) - fmt.Println(virtualService.Spec.Hosts) - if (canary.Spec.Service.Delegation && reflect.DeepEqual(newSpec, istiov1beta1.VirtualServiceSpec{}) == false) && - (virtualService.Spec.Gateways != nil || virtualService.Spec.Hosts != nil) { - // delegate VirtualService requires the hosts and gateway empty. + if canary.Spec.Service.Delegation { virtualService.Spec.Gateways = []string{} virtualService.Spec.Hosts = []string{} - _, err = ir.istioClient.NetworkingV1beta1().VirtualServices(canary.Namespace).Update(context.TODO(), virtualService, metav1.UpdateOptions{}) - if err != nil { - return fmt.Errorf("VirtualService %s.%s update error: %w", apexName, canary.Namespace, err) + if !reflect.DeepEqual(newSpec, istiov1beta1.VirtualServiceSpec{}) { + _, err = ir.istioClient.NetworkingV1beta1().VirtualServices(canary.Namespace).Update(context.TODO(), virtualService, 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) } - ir.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)). - Infof("VirtualService %s.%s updated", virtualService.GetName(), canary.Namespace) - } else if canary.Spec.Service.Delegation { - // delegate VirtualService requires the hosts and gateway empty. - virtualService.Spec.Gateways = []string{} - virtualService.Spec.Hosts = []string{} } ignoreCmpOptions := []cmp.Option{ cmpopts.IgnoreFields(istiov1beta1.HTTPRouteDestination{}, "Weight"), From 948f6b04e28f79399825648ff3169b7afc4c7a4c Mon Sep 17 00:00:00 2001 From: S-mishina Date: Thu, 16 May 2024 21:15:57 +0900 Subject: [PATCH 5/6] fix Signed-off-by: S-mishina --- pkg/router/istio.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/router/istio.go b/pkg/router/istio.go index 93a55a525..8f5c65630 100644 --- a/pkg/router/istio.go +++ b/pkg/router/istio.go @@ -293,7 +293,9 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error { } else if err != nil { return fmt.Errorf("VirtualService %s.%s get query error %v", apexName, canary.Namespace, err) } + if canary.Spec.Service.Delegation { + // delegate VirtualService requires the hosts and gateway empty. virtualService.Spec.Gateways = []string{} virtualService.Spec.Hosts = []string{} if !reflect.DeepEqual(newSpec, istiov1beta1.VirtualServiceSpec{}) { @@ -341,6 +343,7 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error { 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 From 808f945891dcf7ebe5bee5a9a578d90a73022270 Mon Sep 17 00:00:00 2001 From: S-mishina Date: Thu, 16 May 2024 21:17:10 +0900 Subject: [PATCH 6/6] fix Signed-off-by: S-mishina --- pkg/router/istio.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/router/istio.go b/pkg/router/istio.go index 8f5c65630..0a8e65739 100644 --- a/pkg/router/istio.go +++ b/pkg/router/istio.go @@ -307,6 +307,7 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error { Infof("VirtualService %s.%s updated", virtualService.GetName(), canary.Namespace) } } + ignoreCmpOptions := []cmp.Option{ cmpopts.IgnoreFields(istiov1beta1.HTTPRouteDestination{}, "Weight"), cmpopts.IgnoreFields(istiov1beta1.HTTPRoute{}, "Mirror", "MirrorPercentage"),