mirror of
https://github.com/fluxcd/flagger.git
synced 2026-04-15 06:57:34 +00:00
pkg/router: improve error handling messages
This commit is contained in:
+22
-34
@@ -42,35 +42,35 @@ func (ar *AppMeshRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
// DNS app.namespace
|
||||
err := ar.reconcileVirtualNode(canary, apexName, primaryHost)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("reconcileVirtualNode failed: %w", err)
|
||||
}
|
||||
|
||||
// sync virtual node e.g. app-primary-namespace
|
||||
// DNS app-primary.namespace
|
||||
err = ar.reconcileVirtualNode(canary, primaryName, primaryHost)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("reconcileVirtualNode failed: %w", err)
|
||||
}
|
||||
|
||||
// sync virtual node e.g. app-canary-namespace
|
||||
// DNS app-canary.namespace
|
||||
err = ar.reconcileVirtualNode(canary, canaryName, canaryHost)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("reconcileVirtualNode failed: %w", err)
|
||||
}
|
||||
|
||||
// sync main virtual service
|
||||
// DNS app.namespace
|
||||
err = ar.reconcileVirtualService(canary, targetHost, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("reconcileVirtualService failed: %w", err)
|
||||
}
|
||||
|
||||
// sync canary virtual service
|
||||
// DNS app-canary.namespace
|
||||
err = ar.reconcileVirtualService(canary, fmt.Sprintf("%s.%s", canaryName, canary.Namespace), 100)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("reconcileVirtualService failed: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -97,15 +97,15 @@ func (ar *AppMeshRouter) reconcileVirtualNode(canary *flaggerv1.Canary, name str
|
||||
},
|
||||
}
|
||||
|
||||
backends := []appmeshv1.Backend{}
|
||||
for _, b := range canary.Spec.Service.Backends {
|
||||
backend := appmeshv1.Backend{
|
||||
backends := make([]appmeshv1.Backend, len(canary.Spec.Service.Backends))
|
||||
for i, b := range canary.Spec.Service.Backends {
|
||||
backends[i] = appmeshv1.Backend{
|
||||
VirtualService: appmeshv1.VirtualServiceBackend{
|
||||
VirtualServiceName: b,
|
||||
},
|
||||
}
|
||||
backends = append(backends, backend)
|
||||
}
|
||||
|
||||
if len(backends) > 0 {
|
||||
vnSpec.Backends = backends
|
||||
}
|
||||
@@ -130,15 +130,13 @@ func (ar *AppMeshRouter) reconcileVirtualNode(canary *flaggerv1.Canary, name str
|
||||
}
|
||||
_, err = ar.appmeshClient.AppmeshV1beta1().VirtualNodes(canary.Namespace).Create(virtualnode)
|
||||
if err != nil {
|
||||
return fmt.Errorf("VirtualNode %s.%s create error %v", name, canary.Namespace, err)
|
||||
return fmt.Errorf("VirtualNode %s.%s create error %w", name, canary.Namespace, err)
|
||||
}
|
||||
ar.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
Infof("VirtualNode %s.%s created", virtualnode.GetName(), canary.Namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("VirtualNode %s query error %v", name, err)
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("VirtualNode %s get query error %w", name, err)
|
||||
}
|
||||
|
||||
// update virtual node
|
||||
@@ -148,7 +146,7 @@ func (ar *AppMeshRouter) reconcileVirtualNode(canary *flaggerv1.Canary, name str
|
||||
vnClone.Spec = vnSpec
|
||||
_, err = ar.appmeshClient.AppmeshV1beta1().VirtualNodes(canary.Namespace).Update(vnClone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("VirtualNode %s update error %v", name, err)
|
||||
return fmt.Errorf("VirtualNode %s update error %w", name, err)
|
||||
}
|
||||
ar.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
Infof("VirtualNode %s updated", virtualnode.GetName())
|
||||
@@ -294,15 +292,13 @@ func (ar *AppMeshRouter) reconcileVirtualService(canary *flaggerv1.Canary, name
|
||||
|
||||
_, err = ar.appmeshClient.AppmeshV1beta1().VirtualServices(canary.Namespace).Create(virtualService)
|
||||
if err != nil {
|
||||
return fmt.Errorf("VirtualService %s create error %v", name, err)
|
||||
return fmt.Errorf("VirtualService %s create error %w", name, err)
|
||||
}
|
||||
ar.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
Infof("VirtualService %s created", virtualService.GetName())
|
||||
return nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("VirtualService %s query error %v", name, err)
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("VirtualService %s get query error: %w", name, err)
|
||||
}
|
||||
|
||||
// update virtual service but keep the original target weights
|
||||
@@ -322,7 +318,7 @@ func (ar *AppMeshRouter) reconcileVirtualService(canary *flaggerv1.Canary, name
|
||||
|
||||
_, err = ar.appmeshClient.AppmeshV1beta1().VirtualServices(canary.Namespace).Update(vsClone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("VirtualService %s update error %v", name, err)
|
||||
return fmt.Errorf("VirtualService %s update error: %w", name, err)
|
||||
}
|
||||
ar.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
Infof("VirtualService %s updated", virtualService.GetName())
|
||||
@@ -343,11 +339,7 @@ func (ar *AppMeshRouter) GetRoutes(canary *flaggerv1.Canary) (
|
||||
vsName := fmt.Sprintf("%s.%s", apexName, canary.Namespace)
|
||||
vs, err := ar.appmeshClient.AppmeshV1beta1().VirtualServices(canary.Namespace).Get(vsName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
err = fmt.Errorf("VirtualService %s not found", vsName)
|
||||
return
|
||||
}
|
||||
err = fmt.Errorf("VirtualService %s query error %v", vsName, err)
|
||||
err = fmt.Errorf("VirtualService %s get query error: %w", vsName, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -381,16 +373,13 @@ func (ar *AppMeshRouter) SetRoutes(
|
||||
canary *flaggerv1.Canary,
|
||||
primaryWeight int,
|
||||
canaryWeight int,
|
||||
mirrored bool,
|
||||
_ bool,
|
||||
) error {
|
||||
apexName, _, _ := canary.GetServiceNames()
|
||||
vsName := fmt.Sprintf("%s.%s", apexName, canary.Namespace)
|
||||
vs, err := ar.appmeshClient.AppmeshV1beta1().VirtualServices(canary.Namespace).Get(vsName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
return fmt.Errorf("VirtualService %s not found", vsName)
|
||||
}
|
||||
return fmt.Errorf("VirtualService %s query error %v", vsName, err)
|
||||
return fmt.Errorf("VirtualService %s get query error: %w", vsName, err)
|
||||
}
|
||||
|
||||
vsClone := vs.DeepCopy()
|
||||
@@ -409,9 +398,8 @@ func (ar *AppMeshRouter) SetRoutes(
|
||||
|
||||
_, err = ar.appmeshClient.AppmeshV1beta1().VirtualServices(canary.Namespace).Update(vsClone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("VirtualService %s update error %v", vsName, err)
|
||||
return fmt.Errorf("VirtualService %s update error: %w", vsName, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -449,8 +437,8 @@ func makeRetryPolicy(canary *flaggerv1.Canary) *appmeshv1.HttpRetryPolicy {
|
||||
|
||||
// makeRetryPolicy creates an App Mesh HttpRouteHeader from the Canary.CanaryAnalysis.Match
|
||||
func (ar *AppMeshRouter) makeHeaders(canary *flaggerv1.Canary) []appmeshv1.HttpRouteHeader {
|
||||
headers := []appmeshv1.HttpRouteHeader{}
|
||||
|
||||
var headers []appmeshv1.HttpRouteHeader
|
||||
for _, m := range canary.GetAnalysis().Match {
|
||||
for key, value := range m.Headers {
|
||||
header := appmeshv1.HttpRouteHeader{
|
||||
|
||||
+8
-18
@@ -152,15 +152,13 @@ func (cr *ContourRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
|
||||
_, err = cr.contourClient.ProjectcontourV1().HTTPProxies(canary.Namespace).Create(proxy)
|
||||
if err != nil {
|
||||
return fmt.Errorf("HTTPProxy %s.%s create error %v", apexName, canary.Namespace, err)
|
||||
return fmt.Errorf("HTTPProxy %s.%s create error: %w", apexName, canary.Namespace, err)
|
||||
}
|
||||
cr.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
Infof("HTTPProxy %s.%s created", proxy.GetName(), canary.Namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("HTTPProxy %s.%s query error %v", apexName, canary.Namespace, err)
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("HTTPProxy %s.%s get query error: %w", apexName, canary.Namespace, err)
|
||||
}
|
||||
|
||||
// update HTTPProxy but keep the original destination weights
|
||||
@@ -175,7 +173,7 @@ func (cr *ContourRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
|
||||
_, err = cr.contourClient.ProjectcontourV1().HTTPProxies(canary.Namespace).Update(clone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("HTTPProxy %s.%s update error %v", apexName, canary.Namespace, err)
|
||||
return fmt.Errorf("HTTPProxy %s.%s update error: %w", apexName, canary.Namespace, err)
|
||||
}
|
||||
cr.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
Infof("HTTPProxy %s.%s updated", proxy.GetName(), canary.Namespace)
|
||||
@@ -196,11 +194,7 @@ func (cr *ContourRouter) GetRoutes(canary *flaggerv1.Canary) (
|
||||
|
||||
proxy, err := cr.contourClient.ProjectcontourV1().HTTPProxies(canary.Namespace).Get(apexName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
err = fmt.Errorf("HTTPProxy %s.%s not found", apexName, canary.Namespace)
|
||||
return
|
||||
}
|
||||
err = fmt.Errorf("HTTPProxy %s.%s query error %v", apexName, canary.Namespace, err)
|
||||
err = fmt.Errorf("HTTPProxy %s.%s get query error %w", apexName, canary.Namespace, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -225,7 +219,7 @@ func (cr *ContourRouter) SetRoutes(
|
||||
canary *flaggerv1.Canary,
|
||||
primaryWeight int,
|
||||
canaryWeight int,
|
||||
mirrored bool,
|
||||
_ bool,
|
||||
) error {
|
||||
apexName, primaryName, canaryName := canary.GetServiceNames()
|
||||
|
||||
@@ -235,11 +229,7 @@ func (cr *ContourRouter) SetRoutes(
|
||||
|
||||
proxy, err := cr.contourClient.ProjectcontourV1().HTTPProxies(canary.Namespace).Get(apexName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
return fmt.Errorf("HTTPProxy %s.%s not found", apexName, canary.Namespace)
|
||||
|
||||
}
|
||||
return fmt.Errorf("HTTPProxy %s.%s query error %v", apexName, canary.Namespace, err)
|
||||
return fmt.Errorf("HTTPProxy %s.%s query error: %w", apexName, canary.Namespace, err)
|
||||
}
|
||||
|
||||
proxy.Spec = contourv1.HTTPProxySpec{
|
||||
@@ -344,7 +334,7 @@ func (cr *ContourRouter) SetRoutes(
|
||||
|
||||
_, err = cr.contourClient.ProjectcontourV1().HTTPProxies(canary.Namespace).Update(proxy)
|
||||
if err != nil {
|
||||
return fmt.Errorf("HTTPProxy %s.%s update error %v", apexName, canary.Namespace, err)
|
||||
return fmt.Errorf("HTTPProxy %s.%s update error: %w", apexName, canary.Namespace, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
+8
-18
@@ -73,15 +73,13 @@ func (gr *GlooRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
|
||||
_, err = gr.glooClient.GlooV1().UpstreamGroups(canary.Namespace).Create(upstreamGroup)
|
||||
if err != nil {
|
||||
return fmt.Errorf("UpstreamGroup %s.%s create error %v", apexName, canary.Namespace, err)
|
||||
return fmt.Errorf("UpstreamGroup %s.%s create error: %w", apexName, canary.Namespace, err)
|
||||
}
|
||||
gr.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
Infof("UpstreamGroup %s.%s created", upstreamGroup.GetName(), canary.Namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("UpstreamGroup %s.%s query error %v", apexName, canary.Namespace, err)
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("UpstreamGroup %s.%s get query error: %w", apexName, canary.Namespace, err)
|
||||
}
|
||||
|
||||
// update upstreamGroup but keep the original destination weights
|
||||
@@ -96,7 +94,7 @@ func (gr *GlooRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
|
||||
_, err = gr.glooClient.GlooV1().UpstreamGroups(canary.Namespace).Update(clone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("UpstreamGroup %s.%s update error %v", apexName, canary.Namespace, err)
|
||||
return fmt.Errorf("UpstreamGroup %s.%s update error: %w", apexName, canary.Namespace, err)
|
||||
}
|
||||
gr.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
Infof("UpstreamGroup %s.%s updated", upstreamGroup.GetName(), canary.Namespace)
|
||||
@@ -118,11 +116,7 @@ func (gr *GlooRouter) GetRoutes(canary *flaggerv1.Canary) (
|
||||
|
||||
upstreamGroup, err := gr.glooClient.GlooV1().UpstreamGroups(canary.Namespace).Get(apexName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
err = fmt.Errorf("UpstreamGroup %s.%s not found", apexName, canary.Namespace)
|
||||
return
|
||||
}
|
||||
err = fmt.Errorf("UpstreamGroup %s.%s query error %v", apexName, canary.Namespace, err)
|
||||
err = fmt.Errorf("UpstreamGroup %s.%s get query error: %w", apexName, canary.Namespace, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -147,7 +141,7 @@ func (gr *GlooRouter) SetRoutes(
|
||||
canary *flaggerv1.Canary,
|
||||
primaryWeight int,
|
||||
canaryWeight int,
|
||||
mirrored bool,
|
||||
_ bool,
|
||||
) error {
|
||||
apexName, _, _ := canary.GetServiceNames()
|
||||
canaryName := fmt.Sprintf("%s-%s-canary-%v", canary.Namespace, apexName, canary.Spec.Service.Port)
|
||||
@@ -159,11 +153,7 @@ func (gr *GlooRouter) SetRoutes(
|
||||
|
||||
upstreamGroup, err := gr.glooClient.GlooV1().UpstreamGroups(canary.Namespace).Get(apexName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
return fmt.Errorf("UpstreamGroup %s.%s not found", apexName, canary.Namespace)
|
||||
|
||||
}
|
||||
return fmt.Errorf("UpstreamGroup %s.%s query error %v", apexName, canary.Namespace, err)
|
||||
return fmt.Errorf("UpstreamGroup %s.%s query error: %w", apexName, canary.Namespace, err)
|
||||
}
|
||||
|
||||
upstreamGroup.Spec = gloov1.UpstreamGroupSpec{
|
||||
@@ -191,7 +181,7 @@ func (gr *GlooRouter) SetRoutes(
|
||||
|
||||
_, err = gr.glooClient.GlooV1().UpstreamGroups(canary.Namespace).Update(upstreamGroup)
|
||||
if err != nil {
|
||||
return fmt.Errorf("UpstreamGroup %s.%s update error %v", apexName, canary.Namespace, err)
|
||||
return fmt.Errorf("UpstreamGroup %s.%s update error: %w", apexName, canary.Namespace, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
+16
-18
@@ -33,7 +33,7 @@ func (i *IngressRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
|
||||
ingress, err := i.kubeClient.ExtensionsV1beta1().Ingresses(canary.Namespace).Get(canary.Spec.IngressRef.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("ingress %s.%s get query error: %w", canary.Spec.IngressRef.Name, canary.Namespace, err)
|
||||
}
|
||||
|
||||
ingressClone := ingress.DeepCopy()
|
||||
@@ -76,16 +76,14 @@ func (i *IngressRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
|
||||
_, err := i.kubeClient.ExtensionsV1beta1().Ingresses(canary.Namespace).Create(ing)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("ingress %s.%s create error: %w", ing.Name, ing.Namespace, err)
|
||||
}
|
||||
|
||||
i.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
Infof("Ingress %s.%s created", ing.GetName(), canary.Namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("ingress %s query error %v", canaryIngressName, err)
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("ingress %s.%s query error: %w", canaryIngressName, canary.Namespace, err)
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(ingressClone.Spec, canaryIngress.Spec); diff != "" {
|
||||
@@ -94,7 +92,7 @@ func (i *IngressRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
|
||||
_, err := i.kubeClient.ExtensionsV1beta1().Ingresses(canary.Namespace).Update(iClone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ingress %s update error %v", canaryIngressName, err)
|
||||
return fmt.Errorf("ingress %s.%s update error: %w", canaryIngressName, iClone.Namespace, err)
|
||||
}
|
||||
|
||||
i.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
@@ -113,7 +111,8 @@ func (i *IngressRouter) GetRoutes(canary *flaggerv1.Canary) (
|
||||
canaryIngressName := fmt.Sprintf("%s-canary", canary.Spec.IngressRef.Name)
|
||||
canaryIngress, err := i.kubeClient.ExtensionsV1beta1().Ingresses(canary.Namespace).Get(canaryIngressName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return 0, 0, false, err
|
||||
err = fmt.Errorf("ingress %s.%s get query error: %w", canaryIngressName, canary.Namespace, err)
|
||||
return
|
||||
}
|
||||
|
||||
// A/B testing
|
||||
@@ -128,9 +127,10 @@ func (i *IngressRouter) GetRoutes(canary *flaggerv1.Canary) (
|
||||
// Canary
|
||||
for k, v := range canaryIngress.Annotations {
|
||||
if k == i.GetAnnotationWithPrefix("canary-weight") {
|
||||
val, err := strconv.Atoi(v)
|
||||
if err != nil {
|
||||
return 0, 0, false, err
|
||||
val, errAtoi := strconv.Atoi(v)
|
||||
if errAtoi != nil {
|
||||
err = fmt.Errorf("failed to convert %s to int: %w", v, errAtoi)
|
||||
return
|
||||
}
|
||||
|
||||
canaryWeight = val
|
||||
@@ -145,23 +145,21 @@ func (i *IngressRouter) GetRoutes(canary *flaggerv1.Canary) (
|
||||
|
||||
func (i *IngressRouter) SetRoutes(
|
||||
canary *flaggerv1.Canary,
|
||||
primaryWeight int,
|
||||
_ int,
|
||||
canaryWeight int,
|
||||
mirrored bool,
|
||||
_ bool,
|
||||
) error {
|
||||
canaryIngressName := fmt.Sprintf("%s-canary", canary.Spec.IngressRef.Name)
|
||||
canaryIngress, err := i.kubeClient.ExtensionsV1beta1().Ingresses(canary.Namespace).Get(canaryIngressName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("ingress %s.%s get query error: %w", canaryIngressName, canary.Namespace, err)
|
||||
}
|
||||
|
||||
iClone := canaryIngress.DeepCopy()
|
||||
|
||||
// A/B testing
|
||||
if len(canary.GetAnalysis().Match) > 0 {
|
||||
cookie := ""
|
||||
header := ""
|
||||
headerValue := ""
|
||||
var cookie, header, headerValue string
|
||||
for _, m := range canary.GetAnalysis().Match {
|
||||
for k, v := range m.Headers {
|
||||
if k == "cookie" {
|
||||
@@ -188,7 +186,7 @@ func (i *IngressRouter) SetRoutes(
|
||||
|
||||
_, err = i.kubeClient.ExtensionsV1beta1().Ingresses(canary.Namespace).Update(iClone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ingress %s update error %v", canaryIngressName, err)
|
||||
return fmt.Errorf("ingress %s.%s update error %v", iClone.Name, iClone.Namespace, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
+17
-34
@@ -28,21 +28,17 @@ type IstioRouter struct {
|
||||
func (ir *IstioRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
_, primaryName, canaryName := canary.GetServiceNames()
|
||||
|
||||
err := ir.reconcileDestinationRule(canary, canaryName)
|
||||
if err != nil {
|
||||
return err
|
||||
if err := ir.reconcileDestinationRule(canary, canaryName); err != nil {
|
||||
return fmt.Errorf("reconcileDestinationRule failed: %w", err)
|
||||
}
|
||||
|
||||
err = ir.reconcileDestinationRule(canary, primaryName)
|
||||
if err != nil {
|
||||
return err
|
||||
if err := ir.reconcileDestinationRule(canary, primaryName); err != nil {
|
||||
return fmt.Errorf("reconcileDestinationRule failed: %w", err)
|
||||
}
|
||||
|
||||
err = ir.reconcileVirtualService(canary)
|
||||
if err != nil {
|
||||
return err
|
||||
if err := ir.reconcileVirtualService(canary); err != nil {
|
||||
return fmt.Errorf("reconcileVirtualService failed: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -71,15 +67,13 @@ func (ir *IstioRouter) reconcileDestinationRule(canary *flaggerv1.Canary, name s
|
||||
}
|
||||
_, err = ir.istioClient.NetworkingV1alpha3().DestinationRules(canary.Namespace).Create(destinationRule)
|
||||
if err != nil {
|
||||
return fmt.Errorf("DestinationRule %s.%s create error %v", name, canary.Namespace, err)
|
||||
return fmt.Errorf("DestinationRule %s.%s create error: %w", name, canary.Namespace, err)
|
||||
}
|
||||
ir.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
Infof("DestinationRule %s.%s created", destinationRule.GetName(), canary.Namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("DestinationRule %s.%s query error %v", name, canary.Namespace, err)
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("DestinationRule %s.%s get query error: %w", name, canary.Namespace, err)
|
||||
}
|
||||
|
||||
// update
|
||||
@@ -89,7 +83,7 @@ func (ir *IstioRouter) reconcileDestinationRule(canary *flaggerv1.Canary, name s
|
||||
clone.Spec = newSpec
|
||||
_, err = ir.istioClient.NetworkingV1alpha3().DestinationRules(canary.Namespace).Update(clone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("DestinationRule %s.%s update error %v", name, canary.Namespace, err)
|
||||
return fmt.Errorf("DestinationRule %s.%s update error: %w", name, canary.Namespace, err)
|
||||
}
|
||||
ir.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
Infof("DestinationRule %s.%s updated", destinationRule.GetName(), canary.Namespace)
|
||||
@@ -197,15 +191,13 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error {
|
||||
}
|
||||
_, err = ir.istioClient.NetworkingV1alpha3().VirtualServices(canary.Namespace).Create(virtualService)
|
||||
if err != nil {
|
||||
return fmt.Errorf("VirtualService %s.%s create error %v", apexName, canary.Namespace, err)
|
||||
return fmt.Errorf("VirtualService %s.%s create error: %w", apexName, canary.Namespace, err)
|
||||
}
|
||||
ir.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
Infof("VirtualService %s.%s created", virtualService.GetName(), canary.Namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("VirtualService %s.%s query error %v", apexName, canary.Namespace, err)
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("VirtualService %s.%s get query error %v", apexName, canary.Namespace, err)
|
||||
}
|
||||
|
||||
// update service but keep the original destination weights and mirror
|
||||
@@ -221,7 +213,7 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error {
|
||||
|
||||
_, err = ir.istioClient.NetworkingV1alpha3().VirtualServices(canary.Namespace).Update(vtClone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("VirtualService %s.%s update error %v", apexName, canary.Namespace, err)
|
||||
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)
|
||||
@@ -242,11 +234,7 @@ func (ir *IstioRouter) GetRoutes(canary *flaggerv1.Canary) (
|
||||
vs := &istiov1alpha3.VirtualService{}
|
||||
vs, err = ir.istioClient.NetworkingV1alpha3().VirtualServices(canary.Namespace).Get(apexName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
err = fmt.Errorf("VirtualService %s.%s not found", apexName, canary.Namespace)
|
||||
return
|
||||
}
|
||||
err = fmt.Errorf("VirtualService %s.%s query error %v", apexName, canary.Namespace, err)
|
||||
err = fmt.Errorf("VirtualService %s.%s get query error %v", apexName, canary.Namespace, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -291,11 +279,7 @@ func (ir *IstioRouter) SetRoutes(
|
||||
|
||||
vs, err := ir.istioClient.NetworkingV1alpha3().VirtualServices(canary.Namespace).Get(apexName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
return fmt.Errorf("VirtualService %s.%s not found", apexName, canary.Namespace)
|
||||
|
||||
}
|
||||
return fmt.Errorf("VirtualService %s.%s query error %v", apexName, canary.Namespace, err)
|
||||
return fmt.Errorf("VirtualService %s.%s get query error %v", apexName, canary.Namespace, err)
|
||||
}
|
||||
|
||||
vsCopy := vs.DeepCopy()
|
||||
@@ -355,8 +339,7 @@ func (ir *IstioRouter) SetRoutes(
|
||||
|
||||
vs, err = ir.istioClient.NetworkingV1alpha3().VirtualServices(canary.Namespace).Update(vsCopy)
|
||||
if err != nil {
|
||||
return fmt.Errorf("VirtualService %s.%s update failed: %v", apexName, canary.Namespace, err)
|
||||
|
||||
return fmt.Errorf("VirtualService %s.%s update failed: %w", apexName, canary.Namespace, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -34,13 +34,13 @@ func (c *KubernetesDeploymentRouter) Initialize(canary *flaggerv1.Canary) error
|
||||
// canary svc
|
||||
err := c.reconcileService(canary, canaryName, canary.Spec.TargetRef.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("reconcileService failed: %w", err)
|
||||
}
|
||||
|
||||
// primary svc
|
||||
err = c.reconcileService(canary, primaryName, fmt.Sprintf("%s-primary", canary.Spec.TargetRef.Name))
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("reconcileService failed: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -53,17 +53,17 @@ func (c *KubernetesDeploymentRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
// main svc
|
||||
err := c.reconcileService(canary, apexName, fmt.Sprintf("%s-primary", canary.Spec.TargetRef.Name))
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("reconcileService failed: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *KubernetesDeploymentRouter) SetRoutes(canary *flaggerv1.Canary, primaryRoute int, canaryRoute int) error {
|
||||
func (c *KubernetesDeploymentRouter) SetRoutes(_ *flaggerv1.Canary, _ int, _ int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *KubernetesDeploymentRouter) GetRoutes(canary *flaggerv1.Canary) (primaryRoute int, canaryRoute int, err error) {
|
||||
func (c *KubernetesDeploymentRouter) GetRoutes(_ *flaggerv1.Canary) (primaryRoute int, canaryRoute int, err error) {
|
||||
return 0, 0, nil
|
||||
}
|
||||
|
||||
@@ -128,18 +128,16 @@ func (c *KubernetesDeploymentRouter) reconcileService(canary *flaggerv1.Canary,
|
||||
Spec: svcSpec,
|
||||
}
|
||||
|
||||
_, err = c.kubeClient.CoreV1().Services(canary.Namespace).Create(svc)
|
||||
_, err := c.kubeClient.CoreV1().Services(canary.Namespace).Create(svc)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("service %s.%s create error: %w", svc.Name, canary.Namespace, err)
|
||||
}
|
||||
|
||||
c.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
Infof("Service %s.%s created", svc.GetName(), canary.Namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("service %s query error %v", name, err)
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("service %s get query error: %w", name, err)
|
||||
}
|
||||
|
||||
if svc != nil {
|
||||
@@ -155,7 +153,7 @@ func (c *KubernetesDeploymentRouter) reconcileService(canary *flaggerv1.Canary,
|
||||
svcClone.Spec.Selector = svcSpec.Selector
|
||||
_, err = c.kubeClient.CoreV1().Services(canary.Namespace).Update(svcClone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("service %s update error %v", name, err)
|
||||
return fmt.Errorf("service %s update error: %w", name, err)
|
||||
}
|
||||
c.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
Infof("Service %s updated", svc.GetName())
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
type KubernetesNoopRouter struct {
|
||||
}
|
||||
|
||||
func (c *KubernetesNoopRouter) Initialize(canary *flaggerv1.Canary) error {
|
||||
func (c *KubernetesNoopRouter) Initialize(_ *flaggerv1.Canary) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *KubernetesNoopRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
func (c *KubernetesNoopRouter) Reconcile(_ *flaggerv1.Canary) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
+2
-2
@@ -8,11 +8,11 @@ import (
|
||||
type NopRouter struct {
|
||||
}
|
||||
|
||||
func (*NopRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
func (*NopRouter) Reconcile(_ *flaggerv1.Canary) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (*NopRouter) SetRoutes(canary *flaggerv1.Canary, primaryWeight int, canaryWeight int, mirror bool) error {
|
||||
func (*NopRouter) SetRoutes(_ *flaggerv1.Canary, _ int, _ int, _ bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+12
-20
@@ -73,16 +73,14 @@ func (sr *SmiRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
|
||||
_, err := sr.smiClient.SplitV1alpha1().TrafficSplits(canary.Namespace).Create(t)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("TrafficSplit %s.%s create error: %w", apexName, canary.Namespace, err)
|
||||
}
|
||||
|
||||
sr.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
Infof("TrafficSplit %s.%s created", t.GetName(), canary.Namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("traffic split %s query error %v", apexName, err)
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("TrafficSplit %s.%s get query error: %w", apexName, canary.Namespace, err)
|
||||
}
|
||||
|
||||
// update traffic split
|
||||
@@ -92,7 +90,7 @@ func (sr *SmiRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
|
||||
_, err := sr.smiClient.SplitV1alpha1().TrafficSplits(canary.Namespace).Update(tsClone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("TrafficSplit %s update error %v", apexName, err)
|
||||
return fmt.Errorf("TrafficSplit %s.%s update error: %w", apexName, canary.Namespace, err)
|
||||
}
|
||||
|
||||
sr.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
@@ -113,11 +111,7 @@ func (sr *SmiRouter) GetRoutes(canary *flaggerv1.Canary) (
|
||||
apexName, primaryName, canaryName := canary.GetServiceNames()
|
||||
ts, err := sr.smiClient.SplitV1alpha1().TrafficSplits(canary.Namespace).Get(apexName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
err = fmt.Errorf("TrafficSplit %s.%s not found", apexName, canary.Namespace)
|
||||
return
|
||||
}
|
||||
err = fmt.Errorf("TrafficSplit %s.%s query error %v", apexName, canary.Namespace, err)
|
||||
err = fmt.Errorf("TrafficSplit %s.%s get query error %v", apexName, canary.Namespace, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -146,16 +140,12 @@ func (sr *SmiRouter) SetRoutes(
|
||||
canary *flaggerv1.Canary,
|
||||
primaryWeight int,
|
||||
canaryWeight int,
|
||||
mirrored bool,
|
||||
_ bool,
|
||||
) error {
|
||||
apexName, primaryName, canaryName := canary.GetServiceNames()
|
||||
ts, err := sr.smiClient.SplitV1alpha1().TrafficSplits(canary.Namespace).Get(apexName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
return fmt.Errorf("TrafficSplit %s.%s not found", apexName, canary.Namespace)
|
||||
|
||||
}
|
||||
return fmt.Errorf("TrafficSplit %s.%s query error %v", apexName, canary.Namespace, err)
|
||||
return fmt.Errorf("TrafficSplit %s.%s get query error %v", apexName, canary.Namespace, err)
|
||||
}
|
||||
|
||||
backends := []smiv1alpha1.TrafficSplitBackend{
|
||||
@@ -174,7 +164,7 @@ func (sr *SmiRouter) SetRoutes(
|
||||
|
||||
_, err = sr.smiClient.SplitV1alpha1().TrafficSplits(canary.Namespace).Update(tsClone)
|
||||
if err != nil {
|
||||
return fmt.Errorf("TrafficSplit %s update error %v", apexName, err)
|
||||
return fmt.Errorf("TrafficSplit %s.%s update error %v", apexName, canary.Namespace, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -224,11 +214,13 @@ func (sr *SmiRouter) getWithConvert(canary *flaggerv1.Canary, host string) (*smi
|
||||
|
||||
_, err := sr.smiClient.SplitV1alpha2().TrafficSplits(canary.Namespace).Update(t)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("TrafficSplit %s.%s update error: %w", apexName, canary.Namespace, err)
|
||||
}
|
||||
|
||||
sr.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
Infof("TrafficSplit %s.%s converted", t.GetName(), canary.Namespace)
|
||||
} else if err != nil {
|
||||
return nil, fmt.Errorf("TrafficSplit %s.%s get query error %v", apexName, canary.Namespace, err)
|
||||
}
|
||||
return ts, err
|
||||
return ts, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user