mirror of
https://github.com/fluxcd/flagger.git
synced 2026-04-15 06:57:34 +00:00
Enable updates for labels and annotations
Fix #1386 Signed-off-by: jonny.langefeld <jonnylangefeld@gmail.com> Signed-off-by: Jonny Langefeld <jonnylangefeld@gmail.com> Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
This commit is contained in:
+20
-14
@@ -143,25 +143,26 @@ func (ar *AppMeshRouter) reconcileVirtualNode(canary *flaggerv1.Canary, name str
|
||||
|
||||
virtualnode, err := ar.appmeshClient.AppmeshV1beta1().VirtualNodes(canary.Namespace).Get(context.TODO(), name, metav1.GetOptions{})
|
||||
|
||||
newMetadata := canary.Spec.Service.Apex
|
||||
if newMetadata == nil {
|
||||
newMetadata = &flaggerv1.CustomMetadata{}
|
||||
}
|
||||
if newMetadata.Labels == nil {
|
||||
newMetadata.Labels = make(map[string]string)
|
||||
}
|
||||
if newMetadata.Annotations == nil {
|
||||
newMetadata.Annotations = make(map[string]string)
|
||||
}
|
||||
newMetadata.Annotations = filterMetadata(newMetadata.Annotations)
|
||||
|
||||
// create virtual node
|
||||
if errors.IsNotFound(err) {
|
||||
metadata := canary.Spec.Service.Apex
|
||||
if metadata == nil {
|
||||
metadata = &flaggerv1.CustomMetadata{}
|
||||
}
|
||||
if metadata.Labels == nil {
|
||||
metadata.Labels = make(map[string]string)
|
||||
}
|
||||
if metadata.Annotations == nil {
|
||||
metadata.Annotations = make(map[string]string)
|
||||
}
|
||||
|
||||
virtualnode = &appmeshv1.VirtualNode{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: canary.Namespace,
|
||||
Labels: metadata.Labels,
|
||||
Annotations: filterMetadata(metadata.Annotations),
|
||||
Labels: newMetadata.Labels,
|
||||
Annotations: newMetadata.Annotations,
|
||||
},
|
||||
Spec: vnSpec,
|
||||
}
|
||||
@@ -187,9 +188,14 @@ func (ar *AppMeshRouter) reconcileVirtualNode(canary *flaggerv1.Canary, name str
|
||||
|
||||
// update virtual node
|
||||
if virtualnode != nil {
|
||||
if diff := cmp.Diff(vnSpec, virtualnode.Spec); diff != "" {
|
||||
specDiff := cmp.Diff(vnSpec, virtualnode.Spec)
|
||||
labelsDiff := cmp.Diff(newMetadata.Labels, virtualnode.Labels, cmpopts.EquateEmpty())
|
||||
annotationsDiff := cmp.Diff(newMetadata.Labels, virtualnode.Annotations, cmpopts.EquateEmpty())
|
||||
if specDiff != "" || labelsDiff != "" || annotationsDiff != "" {
|
||||
vnClone := virtualnode.DeepCopy()
|
||||
vnClone.Spec = vnSpec
|
||||
vnClone.ObjectMeta.Annotations = newMetadata.Annotations
|
||||
vnClone.ObjectMeta.Labels = newMetadata.Labels
|
||||
_, err = ar.appmeshClient.AppmeshV1beta1().VirtualNodes(canary.Namespace).Update(context.TODO(), vnClone, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("VirtualNode %s update error %w", name, err)
|
||||
|
||||
@@ -157,25 +157,26 @@ func (ar *AppMeshv1beta2Router) reconcileVirtualNode(canary *flaggerv1.Canary, n
|
||||
|
||||
virtualnode, err := ar.appmeshClient.AppmeshV1beta2().VirtualNodes(canary.Namespace).Get(context.TODO(), name, metav1.GetOptions{})
|
||||
|
||||
newMetadata := canary.Spec.Service.Apex
|
||||
if newMetadata == nil {
|
||||
newMetadata = &flaggerv1.CustomMetadata{}
|
||||
}
|
||||
if newMetadata.Labels == nil {
|
||||
newMetadata.Labels = make(map[string]string)
|
||||
}
|
||||
if newMetadata.Annotations == nil {
|
||||
newMetadata.Annotations = make(map[string]string)
|
||||
}
|
||||
newMetadata.Annotations = filterMetadata(newMetadata.Annotations)
|
||||
|
||||
// create virtual node
|
||||
if errors.IsNotFound(err) {
|
||||
metadata := canary.Spec.Service.Apex
|
||||
if metadata == nil {
|
||||
metadata = &flaggerv1.CustomMetadata{}
|
||||
}
|
||||
if metadata.Labels == nil {
|
||||
metadata.Labels = make(map[string]string)
|
||||
}
|
||||
if metadata.Annotations == nil {
|
||||
metadata.Annotations = make(map[string]string)
|
||||
}
|
||||
|
||||
virtualnode = &appmeshv1.VirtualNode{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: canary.Namespace,
|
||||
Labels: metadata.Labels,
|
||||
Annotations: filterMetadata(metadata.Annotations),
|
||||
Labels: newMetadata.Labels,
|
||||
Annotations: newMetadata.Annotations,
|
||||
},
|
||||
Spec: vnSpec,
|
||||
}
|
||||
@@ -201,12 +202,16 @@ func (ar *AppMeshv1beta2Router) reconcileVirtualNode(canary *flaggerv1.Canary, n
|
||||
|
||||
// update virtual node
|
||||
if virtualnode != nil {
|
||||
if diff := cmp.Diff(vnSpec, virtualnode.Spec,
|
||||
cmpopts.IgnoreFields(appmeshv1.VirtualNodeSpec{}, "AWSName", "MeshRef")); diff != "" {
|
||||
specDiff := cmp.Diff(vnSpec, virtualnode.Spec, cmpopts.IgnoreFields(appmeshv1.VirtualNodeSpec{}, "AWSName", "MeshRef"))
|
||||
labelsDiff := cmp.Diff(newMetadata.Labels, virtualnode.Labels, cmpopts.EquateEmpty())
|
||||
annotationsDiff := cmp.Diff(newMetadata.Annotations, virtualnode.Annotations, cmpopts.EquateEmpty())
|
||||
if specDiff != "" || labelsDiff != "" || annotationsDiff != "" {
|
||||
vnClone := virtualnode.DeepCopy()
|
||||
vnClone.Spec = vnSpec
|
||||
vnClone.Spec.AWSName = virtualnode.Spec.AWSName
|
||||
vnClone.Spec.MeshRef = virtualnode.Spec.MeshRef
|
||||
vnClone.ObjectMeta.Annotations = newMetadata.Annotations
|
||||
vnClone.ObjectMeta.Labels = newMetadata.Labels
|
||||
_, err = ar.appmeshClient.AppmeshV1beta2().VirtualNodes(canary.Namespace).Update(context.TODO(), vnClone, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("VirtualNode %s update error %w", name, err)
|
||||
|
||||
+21
-15
@@ -151,25 +151,26 @@ func (cr *ContourRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
}
|
||||
}
|
||||
|
||||
newMetadata := canary.Spec.Service.Apex
|
||||
if newMetadata == nil {
|
||||
newMetadata = &flaggerv1.CustomMetadata{}
|
||||
}
|
||||
if newMetadata.Labels == nil {
|
||||
newMetadata.Labels = make(map[string]string)
|
||||
}
|
||||
if newMetadata.Annotations == nil {
|
||||
newMetadata.Annotations = make(map[string]string)
|
||||
}
|
||||
newMetadata.Annotations = filterMetadata(newMetadata.Annotations)
|
||||
|
||||
proxy, err := cr.contourClient.ProjectcontourV1().HTTPProxies(canary.Namespace).Get(context.TODO(), apexName, metav1.GetOptions{})
|
||||
if errors.IsNotFound(err) {
|
||||
metadata := canary.Spec.Service.Apex
|
||||
if metadata == nil {
|
||||
metadata = &flaggerv1.CustomMetadata{}
|
||||
}
|
||||
if metadata.Labels == nil {
|
||||
metadata.Labels = make(map[string]string)
|
||||
}
|
||||
if metadata.Annotations == nil {
|
||||
metadata.Annotations = make(map[string]string)
|
||||
}
|
||||
|
||||
proxy = &contourv1.HTTPProxy{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: apexName,
|
||||
Namespace: canary.Namespace,
|
||||
Labels: metadata.Labels,
|
||||
Annotations: filterMetadata(metadata.Annotations),
|
||||
Labels: newMetadata.Labels,
|
||||
Annotations: newMetadata.Annotations,
|
||||
},
|
||||
Spec: newSpec,
|
||||
Status: contourv1.HTTPProxyStatus{
|
||||
@@ -207,13 +208,18 @@ func (cr *ContourRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
|
||||
// update HTTPProxy but keep the original destination weights
|
||||
if proxy != nil {
|
||||
if diff := cmp.Diff(
|
||||
specDiff := cmp.Diff(
|
||||
newSpec,
|
||||
proxy.Spec,
|
||||
cmpopts.IgnoreFields(contourv1.Service{}, "Weight"),
|
||||
); diff != "" {
|
||||
)
|
||||
labelsDiff := cmp.Diff(newMetadata.Labels, proxy.Labels, cmpopts.EquateEmpty())
|
||||
annotationsDiff := cmp.Diff(newMetadata.Annotations, proxy.Annotations, cmpopts.EquateEmpty())
|
||||
if specDiff != "" || labelsDiff != "" || annotationsDiff != "" {
|
||||
clone := proxy.DeepCopy()
|
||||
clone.Spec = newSpec
|
||||
clone.ObjectMeta.Annotations = newMetadata.Annotations
|
||||
clone.ObjectMeta.Labels = newMetadata.Labels
|
||||
|
||||
_, err = cr.contourClient.ProjectcontourV1().HTTPProxies(canary.Namespace).Update(context.TODO(), clone, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
|
||||
+20
-14
@@ -123,23 +123,25 @@ func (gwr *GatewayAPIRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
context.TODO(), apexSvcName, metav1.GetOptions{},
|
||||
)
|
||||
|
||||
newMetadata := canary.Spec.Service.Apex
|
||||
if newMetadata == nil {
|
||||
newMetadata = &flaggerv1.CustomMetadata{}
|
||||
}
|
||||
if newMetadata.Labels == nil {
|
||||
newMetadata.Labels = make(map[string]string)
|
||||
}
|
||||
if newMetadata.Annotations == nil {
|
||||
newMetadata.Annotations = make(map[string]string)
|
||||
}
|
||||
newMetadata.Annotations = filterMetadata(newMetadata.Annotations)
|
||||
|
||||
if errors.IsNotFound(err) {
|
||||
metadata := canary.Spec.Service.Apex
|
||||
if metadata == nil {
|
||||
metadata = &flaggerv1.CustomMetadata{}
|
||||
}
|
||||
if metadata.Labels == nil {
|
||||
metadata.Labels = make(map[string]string)
|
||||
}
|
||||
if metadata.Annotations == nil {
|
||||
metadata.Annotations = make(map[string]string)
|
||||
}
|
||||
route := &v1alpha2.HTTPRoute{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: apexSvcName,
|
||||
Namespace: hrNamespace,
|
||||
Labels: metadata.Labels,
|
||||
Annotations: filterMetadata(metadata.Annotations),
|
||||
Labels: newMetadata.Labels,
|
||||
Annotations: newMetadata.Annotations,
|
||||
},
|
||||
Spec: httpRouteSpec,
|
||||
}
|
||||
@@ -167,13 +169,17 @@ func (gwr *GatewayAPIRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
}
|
||||
|
||||
if httpRoute != nil {
|
||||
diff := cmp.Diff(
|
||||
specDiff := cmp.Diff(
|
||||
httpRoute.Spec, httpRouteSpec,
|
||||
cmpopts.IgnoreFields(v1alpha2.BackendRef{}, "Weight"),
|
||||
)
|
||||
if diff != "" && httpRoute.Name != "" {
|
||||
labelsDiff := cmp.Diff(newMetadata.Labels, httpRoute.Labels, cmpopts.EquateEmpty())
|
||||
annotationsDiff := cmp.Diff(newMetadata.Annotations, httpRoute.Annotations, cmpopts.EquateEmpty())
|
||||
if (specDiff != "" && httpRoute.Name != "") || labelsDiff != "" || annotationsDiff != "" {
|
||||
hrClone := httpRoute.DeepCopy()
|
||||
hrClone.Spec = httpRouteSpec
|
||||
hrClone.ObjectMeta.Annotations = newMetadata.Annotations
|
||||
hrClone.ObjectMeta.Labels = newMetadata.Labels
|
||||
_, err := gwr.gatewayAPIClient.GatewayapiV1alpha2().HTTPRoutes(hrNamespace).
|
||||
Update(context.TODO(), hrClone, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
|
||||
@@ -117,23 +117,25 @@ func (gwr *GatewayAPIV1Beta1Router) Reconcile(canary *flaggerv1.Canary) error {
|
||||
context.TODO(), apexSvcName, metav1.GetOptions{},
|
||||
)
|
||||
|
||||
newMetadata := canary.Spec.Service.Apex
|
||||
if newMetadata == nil {
|
||||
newMetadata = &flaggerv1.CustomMetadata{}
|
||||
}
|
||||
if newMetadata.Labels == nil {
|
||||
newMetadata.Labels = make(map[string]string)
|
||||
}
|
||||
if newMetadata.Annotations == nil {
|
||||
newMetadata.Annotations = make(map[string]string)
|
||||
}
|
||||
newMetadata.Annotations = filterMetadata(newMetadata.Annotations)
|
||||
|
||||
if errors.IsNotFound(err) {
|
||||
metadata := canary.Spec.Service.Apex
|
||||
if metadata == nil {
|
||||
metadata = &flaggerv1.CustomMetadata{}
|
||||
}
|
||||
if metadata.Labels == nil {
|
||||
metadata.Labels = make(map[string]string)
|
||||
}
|
||||
if metadata.Annotations == nil {
|
||||
metadata.Annotations = make(map[string]string)
|
||||
}
|
||||
route := &v1beta1.HTTPRoute{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: apexSvcName,
|
||||
Namespace: hrNamespace,
|
||||
Labels: metadata.Labels,
|
||||
Annotations: filterMetadata(metadata.Annotations),
|
||||
Labels: newMetadata.Labels,
|
||||
Annotations: newMetadata.Annotations,
|
||||
},
|
||||
Spec: httpRouteSpec,
|
||||
}
|
||||
@@ -161,13 +163,17 @@ func (gwr *GatewayAPIV1Beta1Router) Reconcile(canary *flaggerv1.Canary) error {
|
||||
}
|
||||
|
||||
if httpRoute != nil {
|
||||
diff := cmp.Diff(
|
||||
specDiff := cmp.Diff(
|
||||
httpRoute.Spec, httpRouteSpec,
|
||||
cmpopts.IgnoreFields(v1beta1.BackendRef{}, "Weight"),
|
||||
)
|
||||
if diff != "" && httpRoute.Name != "" {
|
||||
labelsDiff := cmp.Diff(newMetadata.Labels, httpRoute.Labels, cmpopts.EquateEmpty())
|
||||
annotationsDiff := cmp.Diff(newMetadata.Annotations, httpRoute.Annotations, cmpopts.EquateEmpty())
|
||||
if (specDiff != "" && httpRoute.Name != "") || labelsDiff != "" || annotationsDiff != "" {
|
||||
hrClone := httpRoute.DeepCopy()
|
||||
hrClone.Spec = httpRouteSpec
|
||||
hrClone.ObjectMeta.Annotations = newMetadata.Annotations
|
||||
hrClone.ObjectMeta.Labels = newMetadata.Labels
|
||||
_, err := gwr.gatewayAPIClient.GatewayapiV1beta1().HTTPRoutes(hrNamespace).
|
||||
Update(context.TODO(), hrClone, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
|
||||
+21
-15
@@ -98,25 +98,26 @@ func (gr *GlooRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
},
|
||||
}
|
||||
|
||||
newMetadata := canary.Spec.Service.Apex
|
||||
if newMetadata == nil {
|
||||
newMetadata = &flaggerv1.CustomMetadata{}
|
||||
}
|
||||
if newMetadata.Labels == nil {
|
||||
newMetadata.Labels = make(map[string]string)
|
||||
}
|
||||
if newMetadata.Annotations == nil {
|
||||
newMetadata.Annotations = make(map[string]string)
|
||||
}
|
||||
newMetadata.Annotations = filterMetadata(newMetadata.Annotations)
|
||||
|
||||
routeTable, err := gr.glooClient.GatewayV1().RouteTables(canary.Namespace).Get(context.TODO(), apexName, metav1.GetOptions{})
|
||||
if errors.IsNotFound(err) {
|
||||
metadata := canary.Spec.Service.Apex
|
||||
if metadata == nil {
|
||||
metadata = &flaggerv1.CustomMetadata{}
|
||||
}
|
||||
if metadata.Labels == nil {
|
||||
metadata.Labels = make(map[string]string)
|
||||
}
|
||||
if metadata.Annotations == nil {
|
||||
metadata.Annotations = make(map[string]string)
|
||||
}
|
||||
|
||||
routeTable = &gatewayv1.RouteTable{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: apexName,
|
||||
Namespace: canary.Namespace,
|
||||
Labels: metadata.Labels,
|
||||
Annotations: filterMetadata(metadata.Annotations),
|
||||
Labels: newMetadata.Labels,
|
||||
Annotations: newMetadata.Annotations,
|
||||
},
|
||||
Spec: newSpec,
|
||||
}
|
||||
@@ -143,13 +144,18 @@ func (gr *GlooRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
|
||||
// update routeTable but keep the original destination weights
|
||||
if routeTable != nil {
|
||||
if diff := cmp.Diff(
|
||||
specDiff := cmp.Diff(
|
||||
newSpec,
|
||||
routeTable.Spec,
|
||||
cmpopts.IgnoreFields(gatewayv1.WeightedDestination{}, "Weight"),
|
||||
); diff != "" {
|
||||
)
|
||||
labelsDiff := cmp.Diff(newMetadata.Labels, routeTable.Labels, cmpopts.EquateEmpty())
|
||||
annotationsDiff := cmp.Diff(newMetadata.Annotations, routeTable.Annotations, cmpopts.EquateEmpty())
|
||||
if specDiff != "" || labelsDiff != "" || annotationsDiff != "" {
|
||||
clone := routeTable.DeepCopy()
|
||||
clone.Spec = newSpec
|
||||
clone.ObjectMeta.Annotations = newMetadata.Annotations
|
||||
clone.ObjectMeta.Labels = newMetadata.Labels
|
||||
|
||||
_, err = gr.glooClient.GatewayV1().RouteTables(canary.Namespace).Update(context.TODO(), clone, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
|
||||
+28
-16
@@ -191,6 +191,18 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error {
|
||||
},
|
||||
}
|
||||
|
||||
newMetadata := canary.Spec.Service.Apex
|
||||
if newMetadata == nil {
|
||||
newMetadata = &flaggerv1.CustomMetadata{}
|
||||
}
|
||||
if newMetadata.Labels == nil {
|
||||
newMetadata.Labels = make(map[string]string)
|
||||
}
|
||||
if newMetadata.Annotations == nil {
|
||||
newMetadata.Annotations = make(map[string]string)
|
||||
}
|
||||
newMetadata.Annotations = filterMetadata(newMetadata.Annotations)
|
||||
|
||||
if len(canary.GetAnalysis().Match) > 0 {
|
||||
canaryMatch := mergeMatchConditions(canary.GetAnalysis().Match, canary.Spec.Service.Match)
|
||||
newSpec.Http = []istiov1alpha3.HTTPRoute{
|
||||
@@ -220,23 +232,12 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error {
|
||||
virtualService, err := ir.istioClient.NetworkingV1alpha3().VirtualServices(canary.Namespace).Get(context.TODO(), apexName, metav1.GetOptions{})
|
||||
// insert
|
||||
if errors.IsNotFound(err) {
|
||||
metadata := canary.Spec.Service.Apex
|
||||
if metadata == nil {
|
||||
metadata = &flaggerv1.CustomMetadata{}
|
||||
}
|
||||
if metadata.Labels == nil {
|
||||
metadata.Labels = make(map[string]string)
|
||||
}
|
||||
if metadata.Annotations == nil {
|
||||
metadata.Annotations = make(map[string]string)
|
||||
}
|
||||
|
||||
virtualService = &istiov1alpha3.VirtualService{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: apexName,
|
||||
Namespace: canary.Namespace,
|
||||
Labels: metadata.Labels,
|
||||
Annotations: filterMetadata(metadata.Annotations),
|
||||
Labels: newMetadata.Labels,
|
||||
Annotations: newMetadata.Annotations,
|
||||
},
|
||||
Spec: newSpec,
|
||||
}
|
||||
@@ -282,20 +283,31 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error {
|
||||
ignoreCmpOptions = append(ignoreCmpOptions, ignoreSlice)
|
||||
ignoreCmpOptions = append(ignoreCmpOptions, cmpopts.IgnoreFields(istiov1alpha3.HTTPRouteDestination{}, "Headers"))
|
||||
}
|
||||
if v, ok := virtualService.Annotations[kubectlAnnotation]; ok {
|
||||
newMetadata.Annotations[kubectlAnnotation] = v
|
||||
}
|
||||
if v, ok := virtualService.Annotations[configAnnotation]; ok {
|
||||
newMetadata.Annotations[configAnnotation] = v
|
||||
}
|
||||
// update service but keep the original destination weights and mirror
|
||||
if virtualService != nil {
|
||||
if diff := cmp.Diff(
|
||||
specDiff := cmp.Diff(
|
||||
newSpec,
|
||||
virtualService.Spec,
|
||||
ignoreCmpOptions...,
|
||||
); diff != "" {
|
||||
)
|
||||
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 {
|
||||
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)
|
||||
|
||||
+31
-23
@@ -63,22 +63,22 @@ func (kr *KumaRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
},
|
||||
}
|
||||
|
||||
newMetadata := canary.Spec.Service.Apex
|
||||
if newMetadata == nil {
|
||||
newMetadata = &flaggerv1.CustomMetadata{}
|
||||
}
|
||||
if newMetadata.Labels == nil {
|
||||
newMetadata.Labels = make(map[string]string)
|
||||
}
|
||||
if newMetadata.Annotations == nil {
|
||||
newMetadata.Annotations = make(map[string]string)
|
||||
}
|
||||
newMetadata.Annotations = filterMetadata(newMetadata.Annotations)
|
||||
|
||||
tr, err := kr.kumaClient.KumaV1alpha1().TrafficRoutes().Get(context.TODO(), apexName, metav1.GetOptions{})
|
||||
|
||||
// create TrafficRoute
|
||||
if errors.IsNotFound(err) {
|
||||
metadata := canary.Spec.Service.Apex
|
||||
if metadata == nil {
|
||||
metadata = &flaggerv1.CustomMetadata{}
|
||||
}
|
||||
if metadata.Labels == nil {
|
||||
metadata.Labels = make(map[string]string)
|
||||
}
|
||||
if metadata.Annotations == nil {
|
||||
metadata.Annotations = make(map[string]string)
|
||||
metadata.Annotations[fmt.Sprintf("%d.service.kuma.io", canary.Spec.Service.Port)] = "http"
|
||||
}
|
||||
|
||||
meshName, ok := canary.Annotations["kuma.io/mesh"]
|
||||
if !ok {
|
||||
meshName = "default"
|
||||
@@ -88,7 +88,8 @@ func (kr *KumaRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
t := &kumav1alpha1.TrafficRoute{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: apexName,
|
||||
Annotations: filterMetadata(metadata.Annotations),
|
||||
Labels: newMetadata.Labels,
|
||||
Annotations: newMetadata.Annotations,
|
||||
},
|
||||
Spec: trSpec,
|
||||
Mesh: meshName,
|
||||
@@ -108,19 +109,26 @@ func (kr *KumaRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
}
|
||||
|
||||
// update TrafficRoute
|
||||
if diff := cmp.Diff(trSpec, tr.Spec, cmpopts.IgnoreFields(kumav1alpha1.TrafficRouteSplit{}, "Weight")); diff != "" {
|
||||
trClone := tr.DeepCopy()
|
||||
trClone.Spec = trSpec
|
||||
if tr != nil {
|
||||
specDiff := cmp.Diff(trSpec, tr.Spec, cmpopts.IgnoreFields(kumav1alpha1.TrafficRouteSplit{}, "Weight"))
|
||||
labelsDiff := cmp.Diff(newMetadata.Labels, tr.Labels, cmpopts.EquateEmpty())
|
||||
annotationsDiff := cmp.Diff(newMetadata.Annotations, tr.Annotations, cmpopts.EquateEmpty())
|
||||
if specDiff != "" || labelsDiff != "" || annotationsDiff != "" {
|
||||
trClone := tr.DeepCopy()
|
||||
trClone.Spec = trSpec
|
||||
trClone.ObjectMeta.Annotations = newMetadata.Annotations
|
||||
trClone.ObjectMeta.Labels = newMetadata.Labels
|
||||
|
||||
_, err := kr.kumaClient.KumaV1alpha1().TrafficRoutes().Update(context.TODO(), trClone, metav1.UpdateOptions{})
|
||||
_, err := kr.kumaClient.KumaV1alpha1().TrafficRoutes().Update(context.TODO(), trClone, metav1.UpdateOptions{})
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("TrafficRoute %s update error: %w", apexName, err)
|
||||
if err != nil {
|
||||
return fmt.Errorf("TrafficRoute %s update error: %w", apexName, err)
|
||||
}
|
||||
|
||||
kr.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
Infof("TrafficRoute %s.%s updated", apexName, canary.Namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
kr.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).
|
||||
Infof("TrafficRoute %s.%s updated", apexName, canary.Namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
+21
-16
@@ -55,25 +55,26 @@ func (tr *TraefikRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
},
|
||||
}
|
||||
|
||||
newMetadata := canary.Spec.Service.Apex
|
||||
if newMetadata == nil {
|
||||
newMetadata = &flaggerv1.CustomMetadata{}
|
||||
}
|
||||
if newMetadata.Labels == nil {
|
||||
newMetadata.Labels = make(map[string]string)
|
||||
}
|
||||
if newMetadata.Annotations == nil {
|
||||
newMetadata.Annotations = make(map[string]string)
|
||||
}
|
||||
newMetadata.Annotations = filterMetadata(newMetadata.Annotations)
|
||||
|
||||
traefikService, err := tr.traefikClient.TraefikV1alpha1().TraefikServices(canary.Namespace).Get(context.TODO(), apexName, metav1.GetOptions{})
|
||||
if errors.IsNotFound(err) {
|
||||
tsMetadata := canary.Spec.Service.Apex
|
||||
if tsMetadata == nil {
|
||||
tsMetadata = &flaggerv1.CustomMetadata{}
|
||||
}
|
||||
if tsMetadata.Labels == nil {
|
||||
tsMetadata.Labels = make(map[string]string)
|
||||
}
|
||||
if tsMetadata.Annotations == nil {
|
||||
tsMetadata.Annotations = make(map[string]string)
|
||||
}
|
||||
|
||||
traefikService = &traefikv1alpha1.TraefikService{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: apexName,
|
||||
Namespace: canary.Namespace,
|
||||
Labels: tsMetadata.Labels,
|
||||
Annotations: filterMetadata(tsMetadata.Annotations),
|
||||
Labels: newMetadata.Labels,
|
||||
Annotations: newMetadata.Annotations,
|
||||
},
|
||||
Spec: newSpec,
|
||||
}
|
||||
@@ -112,14 +113,18 @@ func (tr *TraefikRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
)
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(
|
||||
specDiff := cmp.Diff(
|
||||
newSpec,
|
||||
traefikService.Spec,
|
||||
cmpopts.IgnoreFields(traefikv1alpha1.Service{}, "Weight"),
|
||||
); diff != "" {
|
||||
|
||||
)
|
||||
labelsDiff := cmp.Diff(newMetadata.Labels, traefikService.Labels, cmpopts.EquateEmpty())
|
||||
annotationsDiff := cmp.Diff(newMetadata.Annotations, traefikService.Annotations, cmpopts.EquateEmpty())
|
||||
if specDiff != "" || labelsDiff != "" || annotationsDiff != "" {
|
||||
clone := traefikService.DeepCopy()
|
||||
clone.Spec = newSpec
|
||||
clone.ObjectMeta.Annotations = newMetadata.Annotations
|
||||
clone.ObjectMeta.Labels = newMetadata.Labels
|
||||
|
||||
_, err = tr.traefikClient.TraefikV1alpha1().TraefikServices(canary.Namespace).Update(context.TODO(), clone, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
|
||||
@@ -52,7 +52,7 @@ func TestTraefikRouter_Reconcile(t *testing.T) {
|
||||
assert.Equal(t, uint(100), services[0].Weight)
|
||||
|
||||
assert.Equal(t, ts.ObjectMeta.Labels, mocks.canary.Spec.Service.Apex.Labels)
|
||||
assert.Equal(t, ts.ObjectMeta.Annotations, filterMetadata(mocks.canary.Spec.Service.Apex.Annotations))
|
||||
assert.Equal(t, filterMetadata(ts.ObjectMeta.Annotations), filterMetadata(mocks.canary.Spec.Service.Apex.Annotations))
|
||||
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user