Skip to content

Commit

Permalink
Cut rallyhealth v1.3.1 (#7)
Browse files Browse the repository at this point in the history
* feat: add support for influxdb as a metrics provider (argoproj#1839)

* feat: add InfluxDB metric provider implementation

Signed-off-by: Jayme Bird <[email protected]>

* feat: add influx to metric provider util count, add missing graphite

Signed-off-by: Jayme Bird <[email protected]>

* feat: add protobuf definitions for InfluxdbMetric

Signed-off-by: Jayme Bird <[email protected]>

* feat: add docs for the Influxdb metrics provider

Signed-off-by: Jayme Bird <[email protected]>

* feat: add tests for influxdb metrics provider

Signed-off-by: Jayme Bird <[email protected]>

* feat: add go mod replace for version of moq due to security issue

Signed-off-by: Jayme Bird <[email protected]>

* feat: update error message to distinguish failed cases - review feedback

Signed-off-by: Jayme Bird <[email protected]>

* feat: update tests to simplify mocking of QueryTableResult

An upstream change to the influx go client makes it easier to mock
QueryTableResult in tests. This removes a lot of boilerplate duplication
in the tests.

Signed-off-by: Jayme Bird <[email protected]>

* feat: re-run codegen

Signed-off-by: Jayme Bird <[email protected]>

* feat: Adds support for Istio traffic mirroring (argoproj#2074)

* feat: Add support for istio traffic mirroring steps

Signed-off-by: zachaller <[email protected]>

* bump e2e timeout

Signed-off-by: zachaller <[email protected]>

* Remove unintended change

Signed-off-by: zachaller <[email protected]>

* Cleaner events

Signed-off-by: zachaller <[email protected]>

* Add docs for mirror and fix up header routing

Signed-off-by: zachaller <[email protected]>

* small doc changes

Signed-off-by: zachaller <[email protected]>

* Add example

Signed-off-by: zachaller <[email protected]>

* Fix types and change example

Signed-off-by: zachaller <[email protected]>

* Remove unused type

Signed-off-by: zachaller <[email protected]>

* Docs change

Signed-off-by: zachaller <[email protected]>

* Fix PR comments

Signed-off-by: zachaller <[email protected]>

* Check for >=

Signed-off-by: zachaller <[email protected]>

* Remove unused function

Signed-off-by: zachaller <[email protected]>

* codegen

Signed-off-by: zachaller <[email protected]>

* Add better error logging

Signed-off-by: zachaller <[email protected]>

* a few more error msgs

Signed-off-by: zachaller <[email protected]>

* fix comments

Signed-off-by: zachaller <[email protected]>

* typo

Signed-off-by: zachaller <[email protected]>

* fix logic error

Signed-off-by: zachaller <[email protected]>

* redo header logic

Signed-off-by: zachaller <[email protected]>

* cleanup

Signed-off-by: zachaller <[email protected]>

* Fix issue with keeping route weight updated when no routes
are defined in spec.strategy.canary.trafficRouting.istio.virtualService.routes
requiring only a single route

Signed-off-by: zachaller <[email protected]>

* cleanup routes when promiting with last step being a pause

Signed-off-by: zachaller <[email protected]>

* fix bug with promote and last step is a pause

Signed-off-by: zachaller <[email protected]>

* Fix tests

Signed-off-by: zachaller <[email protected]>

* fix typo

Signed-off-by: zachaller <[email protected]>

* chore: improve openapi schema (argoproj#2081)

* feat: include all CRDs to the OpenAPI schema

Signed-off-by: Mário Bezerra <[email protected]>

* feat: use kube-openapi naming convention in the OpenAPI schema

Signed-off-by: Mário Bezerra <[email protected]>

* chore: generate OpenAPI schema

Signed-off-by: Mário Bezerra <[email protected]>

* feat(grafana): Allow selecting datasource for grafana dashboard (argoproj#1988)

Signed-off-by: Jesse Antoszyk <[email protected]>

* feat: support /rollouts/:namespace?q=... and /rollout/:namespace/:name (argoproj#1902)

Signed-off-by: Simon Ninon <[email protected]>

* chore: Add e2e and unit test comment reports (argoproj#2123)

Signed-off-by: zachaller <[email protected]>

* chore: upgrade deps (argoproj#2136)

Signed-off-by: zachaller <[email protected]>

* fixes argoproj#2141 Added list and watch to clusterrole (argoproj#2145)

Signed-off-by: Martin Adler <[email protected]>

* fix: Update ro.Status.ALB when first creating rollout object (argoproj#1986)

* fix: make sure we update rollout.Status.ALB when first create Rollout object

This fixes the case when we first create a rollout the status.ALB field does not
get updated with valid information form the elb.

Signed-off-by: zachaller <[email protected]>

* Refactor check for if we should verify alb.

This creates a new rolloututil function ShouldVerifyWeight that verifies
that we should call aws because the rollout is in the middle of some update.

The reason I feel this should move into the ingress implmentation function VerifyWeight
is becuase in the future other ingresses might also need to verify weights and adding
ingress specific status checks in trafficrouting.go like a leak details where it should be
up to the ingress provider to determin if it should be careful of rate limiting do to say it
being a cloud provider call.

Signed-off-by: zachaller <[email protected]>

* lint

Signed-off-by: zachaller <[email protected]>

* Fix tests

Signed-off-by: zachaller <[email protected]>

* Add new test for ShouldVerifyWeight

Signed-off-by: zachaller <[email protected]>

* Fix logic

Signed-off-by: zachaller <[email protected]>

* Add test for where we do not need to verify weight and its already set

Signed-off-by: zachaller <[email protected]>

* fix up review comments

Signed-off-by: zachaller <[email protected]>

* fix tests

Signed-off-by: zachaller <[email protected]>

* fix bad merge

Signed-off-by: zachaller <[email protected]>

* Fix test

Signed-off-by: zachaller <[email protected]>

* Fix test

Signed-off-by: zachaller <[email protected]>

* Clearer function name

Signed-off-by: zachaller <[email protected]>

* Clean up if logic

Signed-off-by: zachaller <[email protected]>

* fix: remove metrics when objects are removed from cluster to prevent build up (argoproj#2115)

* fix: remove metrics on resource removal

Signed-off-by: zachaller <[email protected]>

* Add test

Signed-off-by: zachaller <[email protected]>

* More tests

Signed-off-by: zachaller <[email protected]>

* back off deps updates

Signed-off-by: zachaller <[email protected]>

* Fix dep change

Signed-off-by: zachaller <[email protected]>

* upgrade prom deps for new features

Signed-off-by: zachaller <[email protected]>

* fix deps

Signed-off-by: zachaller <[email protected]>

* chore: use controler-gen for cluster analysis template scope (argoproj#2148)

Signed-off-by: zachaller <[email protected]>

* fix(analysis): Fix Analysis Terminal Decision For Dry-Run Metrics (argoproj#2131)

Signed-off-by: Rohit Agrawal <[email protected]>

* docs: update release doc with brew formula details (argoproj#2165)

Signed-off-by: Leonardo Luz Almeida <[email protected]>

* fix(docs) Graphite metrics provider linked in docs sidebar. Fixes argoproj#2102. (argoproj#2094)

* Graphite metrics provider linked in docs sidebar

This fixes an issue wherein the Graphite metrics
provider has no sidebar link in the docs hosted
at https://argoproj.github.io/argo-rollouts/.

As a bonus, this also removes various trailing
whitespace from analysis docs.

Signed-off-by: Mike Ball <[email protected]>

* build trigger

Signed-off-by: Mike Ball <[email protected]>

* feat: emit rollout delete event (argoproj#1893)

Signed-off-by: Hui Kang <[email protected]>

Co-authored-by: Hui Kang <[email protected]>

* chore: Upgrade golang (argoproj#2160)

* Upgrade golang

Signed-off-by: zachaller <[email protected]>

* upgrade golang to 1.18 for e2e

Signed-off-by: zachaller <[email protected]>

* Fix deps

Signed-off-by: zachaller <[email protected]>

* Update build action

Signed-off-by: zachaller <[email protected]>

* Upgrade push action

Signed-off-by: zachaller <[email protected]>

* Update docker file

Signed-off-by: zachaller <[email protected]>

* Bump golang lint to match

Signed-off-by: zachaller <[email protected]>

* fix go.mod

Signed-off-by: zachaller <[email protected]>

* fix: Failed to process: Object 'Kind' is missing in Errors with rollouts notification (argoproj#2150)

* fix: update rolloutobject with gvk before writing to rollout informer

Signed-off-by: Ravi Hari <[email protected]>

* fix: controller schema linting

Signed-off-by: Ravi Hari <[email protected]>

* docs: comment the details on the change

Signed-off-by: Ravi Hari <[email protected]>

* docs: comment the details on the change

Signed-off-by: Ravi Hari <[email protected]>

* fix: rootPath support so that it uses the embedded files system (argoproj#2198)

* fix: rootPath support so that it uses the embeded files system

Signed-off-by: zachaller <[email protected]>

* Catch edge cases and make sure we always server index.html on not found

Signed-off-by: zachaller <[email protected]>

* turn path.Clean into var

Signed-off-by: zachaller <[email protected]>

Signed-off-by: zachaller <[email protected]>

* fix: change completed condition so it only triggers on pod hash changes also adds an event for when it  does changes. (argoproj#2203)

* feat: add healthy event/condition and fix completed event/condition

Signed-off-by: zachaller <[email protected]>

* fix unit tests

Signed-off-by: zachaller <[email protected]>

* rename vars to make more sense and remove healthy event becase it will never be consistent

Signed-off-by: zachaller <[email protected]>

* fix unit tests

Signed-off-by: zachaller <[email protected]>

* possible fix for e2e

Signed-off-by: zachaller <[email protected]>

* fix e2e

Signed-off-by: zachaller <[email protected]>

* unit test for complete function

Signed-off-by: zachaller <[email protected]>

* small cleanup and changes to not check generation

Signed-off-by: zachaller <[email protected]>

* fix unit test and proper behavior

Signed-off-by: zachaller <[email protected]>

* Fix e2e

Signed-off-by: zachaller <[email protected]>

* rename and fix one unit test

Signed-off-by: zachaller <[email protected]>

* fix unit tests

Signed-off-by: zachaller <[email protected]>

* fix unit test

Signed-off-by: zachaller <[email protected]>

* add seperate test for TestRolloutComplete

Signed-off-by: zachaller <[email protected]>

* renames

Signed-off-by: zachaller <[email protected]>

* fix e2e

Signed-off-by: zachaller <[email protected]>

* Set Completed to false

Signed-off-by: zachaller <[email protected]>

* Add event

Signed-off-by: zachaller <[email protected]>

* fix e2e

Signed-off-by: zachaller <[email protected]>

* refactor

Signed-off-by: zachaller <[email protected]>

* Fix all but one unit test

Signed-off-by: zachaller <[email protected]>

* fix last unit test

Signed-off-by: zachaller <[email protected]>

* lint

Signed-off-by: zachaller <[email protected]>

* cleanup

Signed-off-by: zachaller <[email protected]>

* Rename

Signed-off-by: zachaller <[email protected]>

* More renames

Signed-off-by: zachaller <[email protected]>

* small comment change

Signed-off-by: zachaller <[email protected]>

Signed-off-by: zachaller <[email protected]>

* feat: Add support for spec.ingressClassName (argoproj#2178)

This change adds support for `spec.ingressClassName` while still supporting
`kubernetes.io/ingress.class` annotation for backwards compatibility.

Fixes argoproj#1277

Signed-off-by: Siavash Safi <[email protected]>

Signed-off-by: Siavash Safi <[email protected]>

* fix: enable notifications without when condition (argoproj#2231)

* fix: enable notifications without when condition

Signed-off-by: Ravi Hari <[email protected]>

* fix: use trigger action item from the list

Signed-off-by: Ravi Hari <[email protected]>

* fix: add emptycondition logic to make notifications work with/without conditions

Signed-off-by: Ravi Hari <[email protected]>

* fix: linting

Signed-off-by: Ravi Hari <[email protected]>

Signed-off-by: Ravi Hari <[email protected]>

* Use standard cli format for dashboard root path (argoproj#2244)

Signed-off-by: zachaller <[email protected]>

Signed-off-by: zachaller <[email protected]>

* fix: UI not redirecting on / (argoproj#2252)

Signed-off-by: zachaller <[email protected]>

Signed-off-by: zachaller <[email protected]>

* fix: nil pointer while linting with basic canary and ingresses (argoproj#2256)

* fix: nil pointer while linting basic canary with Ingress resources

Signed-off-by: zachaller <[email protected]>

* Add test case

Signed-off-by: zachaller <[email protected]>

Signed-off-by: zachaller <[email protected]>

* fix(controller):  Fix k8s clientset controller metrics. Fixes argoproj#2139 (argoproj#2261)

* Add roundtripper to kubeconfig before creating kubeclient

Signed-off-by: Nikhil <[email protected]>

* Check if k8sRequestsCount is nil before attempting increase

Signed-off-by: Nikhil <[email protected]>

* Added Flipkart to Users.md

Signed-off-by: Nikhil <[email protected]>

* gofmt controller/metrics/client.go

Signed-off-by: Nikhil <[email protected]>

Signed-off-by: Nikhil <[email protected]>

* fixes(controller): istio dropping fields not defined in type (argoproj#2268)

* fixes argoproj#2266

Signed-off-by: zachaller <[email protected]>

* typo

Signed-off-by: zachaller <[email protected]>

* test after calling set mirror

Signed-off-by: zachaller <[email protected]>

* Keep port on user defined service by adding to internal types

Signed-off-by: zachaller <[email protected]>

* github trigger re-run

Signed-off-by: zachaller <[email protected]>

* Drop port on virtual service to be consistent with added routes

Drop the port on the virtual service with the statment that rollouts only supports
one port services.

Signed-off-by: zachaller <[email protected]>

* cleanup test to just test extra fields and add a port check on destination as well

Signed-off-by: zachaller <[email protected]>

* keep port for both mirroring and header routes

Signed-off-by: zachaller <[email protected]>

* github trigger re-run

Signed-off-by: zachaller <[email protected]>

* github trigger re-run

Signed-off-by: zachaller <[email protected]>

* add function comment

Signed-off-by: zachaller <[email protected]>

Signed-off-by: zachaller <[email protected]>

Signed-off-by: Jayme Bird <[email protected]>
Signed-off-by: zachaller <[email protected]>
Signed-off-by: Mário Bezerra <[email protected]>
Signed-off-by: Jesse Antoszyk <[email protected]>
Signed-off-by: Simon Ninon <[email protected]>
Signed-off-by: Martin Adler <[email protected]>
Signed-off-by: Rohit Agrawal <[email protected]>
Signed-off-by: Leonardo Luz Almeida <[email protected]>
Signed-off-by: Mike Ball <[email protected]>
Signed-off-by: Ravi Hari <[email protected]>
Signed-off-by: Siavash Safi <[email protected]>
Signed-off-by: Nikhil <[email protected]>
Signed-off-by: zachaller <[email protected]>
Signed-off-by: Travis Perdue <[email protected]>
Co-authored-by: jaymebrd <[email protected]>
Co-authored-by: Zach Aller <[email protected]>
Co-authored-by: Mário Bezerra <[email protected]>
Co-authored-by: Jesse Antoszyk <[email protected]>
Co-authored-by: Simon Ninon <[email protected]>
Co-authored-by: Martin Adler <[email protected]>
Co-authored-by: Rohit Agrawal <[email protected]>
Co-authored-by: Leonardo Luz Almeida <[email protected]>
Co-authored-by: Mike Ball <[email protected]>
Co-authored-by: cskh <[email protected]>
Co-authored-by: Hui Kang <[email protected]>
Co-authored-by: RaviHari <[email protected]>
Co-authored-by: Siavash Safi <[email protected]>
Co-authored-by: nikhil1raghav <[email protected]>
  • Loading branch information
15 people authored Oct 31, 2022
1 parent a1af660 commit 00e39cd
Show file tree
Hide file tree
Showing 11 changed files with 332 additions and 26 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ env:
# Golang version to use across CI steps
GOLANG_VERSION: '1.18'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
event_file:
name: "Event File"
Expand Down
1 change: 1 addition & 0 deletions USERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Organizations below are **officially** using Argo Rollouts. Please send a PR wit
1. [Databricks](https://github.com/databricks)
1. [Devtron Labs](https://github.com/devtron-labs/devtron)
1. [Farfetch](https://www.farfetch.com/)
1. [Flipkart](https://flipkart.com)
1. [Gllue](https://gllue.com)
1. [Ibotta](https://home.ibotta.com/)
1. [Intuit](https://www.intuit.com/)
Expand Down
5 changes: 3 additions & 2 deletions cmd/rollouts-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func newCommand() *cobra.Command {
log.Infof("Using namespace %s", namespace)
}

k8sRequestProvider := &metrics.K8sRequestsCountProvider{}
kubeclientmetrics.AddMetricsTransportWrapper(config, k8sRequestProvider.IncKubernetesRequest)

kubeClient, err := kubernetes.NewForConfig(config)
checkError(err)
argoprojClient, err := clientset.NewForConfig(config)
Expand Down Expand Up @@ -154,8 +157,6 @@ func newCommand() *cobra.Command {
configMapInformer := controllerNamespaceInformerFactory.Core().V1().ConfigMaps()
secretInformer := controllerNamespaceInformerFactory.Core().V1().Secrets()

k8sRequestProvider := &metrics.K8sRequestsCountProvider{}
kubeclientmetrics.AddMetricsTransportWrapper(config, k8sRequestProvider.IncKubernetesRequest)
mode, err := ingressutil.DetermineIngressMode(ingressVersion, kubeClient.DiscoveryClient)
checkError(err)
ingressWrapper, err := ingressutil.NewIngressWrapper(mode, kubeClient, kubeInformerFactory)
Expand Down
5 changes: 3 additions & 2 deletions controller/metrics/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func (m *K8sRequestsCountProvider) IncKubernetesRequest(resourceInfo kubeclientm
name = "Unknown"
kind = "Unknown"
}

m.k8sRequestsCount.WithLabelValues(kind, namespace, name, string(resourceInfo.Verb), statusCode).Inc()
if m.k8sRequestsCount != nil {
m.k8sRequestsCount.WithLabelValues(kind, namespace, name, string(resourceInfo.Verb), statusCode).Inc()
}
return nil
}
5 changes: 5 additions & 0 deletions pkg/kubectl-argo-rollouts/cmd/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ func setIngressManagedAnnotation(rollouts []v1alpha1.Rollout, refResource valida
for _, rollout := range rollouts {
for i := range refResource.Ingresses {
var serviceName string

// Basic Canary so ingress is only pointing a single service and so no linting is needed for this case.
if rollout.Spec.Strategy.Canary == nil || rollout.Spec.Strategy.Canary.TrafficRouting == nil {
return
}
if rollout.Spec.Strategy.Canary.TrafficRouting.Nginx != nil {
serviceName = rollout.Spec.Strategy.Canary.StableService
} else if rollout.Spec.Strategy.Canary.TrafficRouting.ALB != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/kubectl-argo-rollouts/cmd/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestLintValidRollout(t *testing.T) {
"testdata/valid-ingress-smi-multi.yml",
"testdata/valid-alb-canary.yml",
"testdata/valid-nginx-canary.yml",
"testdata/valid-nginx-basic-canary.yml",
"testdata/valid-istio-v1beta1-mulitiple-virtualsvcs.yml",
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
apiVersion: v1
kind: Service
metadata:
name: nginx-rollout-stable
spec:
type: NodePort
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app: nginx-rollout
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: nginx-rollout-ingress
spec:
rules:
- http:
paths:
- path: /*
backend:
serviceName: nginx-rollout-root
servicePort: use-annotation
---
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: nginx-rollout
spec:
selector:
matchLabels:
app: nginx-rollout
template:
metadata:
labels:
app: nginx-rollout
spec:
containers:
- name: nginx-rollout
image: argoproj/rollouts-demo:blue
ports:
- name: http
containerPort: 80
protocol: TCP
resources:
requests:
memory: 16Mi
cpu: 5m
strategy:
canary:
steps:
- setWeight: 10
- pause: {}
- setWeight: 50
- pause: {}
87 changes: 65 additions & 22 deletions rollout/trafficrouting/istio/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ func (r *Reconciler) getVirtualService(namespace string, vsvcName string, client
return vsvc, err
}

func (r *Reconciler) reconcileVirtualServiceHeaderRoutes(obj *unstructured.Unstructured, headerRouting *v1alpha1.SetHeaderRoute) error {
func (r *Reconciler) reconcileVirtualServiceHeaderRoutes(virtualService v1alpha1.IstioVirtualService, obj *unstructured.Unstructured, headerRouting *v1alpha1.SetHeaderRoute) error {
// HTTP Routes
httpRoutesI, err := GetHttpRoutesI(obj)
if err != nil {
Expand Down Expand Up @@ -687,7 +687,7 @@ func (r *Reconciler) reconcileVirtualServiceHeaderRoutes(obj *unstructured.Unstr
return fmt.Errorf("[reconcileVirtualServiceHeaderRoutes] failed to remove http route from virtual service: %w", err)
}

httpRoutesI = append(httpRoutesI, createHeaderRoute(headerRouting, canarySvc, canarySubset))
httpRoutesI = append(httpRoutesI, createHeaderRoute(virtualService, obj, headerRouting, canarySvc, canarySubset))

err = unstructured.SetNestedSlice(obj.Object, httpRoutesI, "spec", Http)
if err != nil {
Expand All @@ -712,7 +712,7 @@ func (r *Reconciler) SetHeaderRoute(headerRouting *v1alpha1.SetHeaderRoute) erro
return fmt.Errorf("[SetHeaderRoute] failed to get istio virtual service: %w", err)
}

err = r.reconcileVirtualServiceHeaderRoutes(vsvc, headerRouting)
err = r.reconcileVirtualServiceHeaderRoutes(virtualService, vsvc, headerRouting)
if err != nil {
return fmt.Errorf("[SetHeaderRoute] failed to reconcile header routes: %w", err)
}
Expand Down Expand Up @@ -765,12 +765,19 @@ func (r *Reconciler) getDestinationRule(dRuleSpec *v1alpha1.IstioDestinationRule
return origBytes, dRule, dRuleNew, nil
}

func createHeaderRoute(headerRouting *v1alpha1.SetHeaderRoute, host string, subset string) map[string]interface{} {
func createHeaderRoute(virtualService v1alpha1.IstioVirtualService, unVsvc *unstructured.Unstructured, headerRouting *v1alpha1.SetHeaderRoute, host string, subset string) map[string]interface{} {
var routeMatches []interface{}
for _, hrm := range headerRouting.Match {
routeMatches = append(routeMatches, createHeaderRouteMatch(hrm))
}
canaryDestination := routeDestination(host, subset, 100)

port, err := getVirtualServiceCanaryPort(unVsvc, virtualService)
if err != nil {
port = Port{Number: 0}
}

canaryDestination := routeDestination(host, port.Number, subset, 100)

return map[string]interface{}{
"name": headerRouting.Name,
"match": routeMatches,
Expand All @@ -795,10 +802,13 @@ func setMapValueIfNotEmpty(m map[string]interface{}, key string, value string) {
}
}

func routeDestination(host, subset string, weight int64) map[string]interface{} {
func routeDestination(host string, port uint32, subset string, weight int64) map[string]interface{} {
dest := map[string]interface{}{
"host": host,
}
if port > 0 {
dest["port"] = map[string]interface{}{"number": int64(port)}
}
if subset != "" {
dest["subset"] = subset
}
Expand Down Expand Up @@ -1141,14 +1151,20 @@ func createMirrorRoute(virtualService v1alpha1.IstioVirtualService, httpRoutes [
})
}

mirrorDestinations := VirtualServiceDestination{
Host: canarySvc,
Subset: subset,
}
if len(route) >= 0 && route[0].Destination.Port != nil {
// We try to pull the port from any of the routes destinations that are supposed to be updated via SetWeight
mirrorDestinations.Port = &Port{Number: route[0].Destination.Port.Number}
}

mirrorRoute := map[string]interface{}{
"name": mirrorRouting.Name,
"match": istioMatch,
"route": route,
"mirror": VirtualServiceDestination{
Host: canarySvc,
Subset: subset,
},
"name": mirrorRouting.Name,
"match": istioMatch,
"route": route,
"mirror": mirrorDestinations,
"mirrorPercentage": map[string]interface{}{"value": float64(percent)},
}

Expand Down Expand Up @@ -1232,7 +1248,7 @@ func (r *Reconciler) orderRoutes(istioVirtualService *unstructured.Unstructured)
return fmt.Errorf("[orderRoutes] could not split routes between managed and non managed: %w", err)
}

finalRoutes, err := getOrderedVirtualServiceRoutes(managedRoutes, httpRoutesWithinManagedRoutes, httpRoutesNotWithinManagedRoutes)
finalRoutes, err := getOrderedVirtualServiceRoutes(httpRouteI, managedRoutes, httpRoutesWithinManagedRoutes, httpRoutesNotWithinManagedRoutes)
if err != nil {
return fmt.Errorf("[orderRoutes] could not get ordered virtual service routes: %w", err)
}
Expand Down Expand Up @@ -1279,7 +1295,7 @@ func splitManagedRoutesAndNonManagedRoutes(managedRoutes []v1alpha1.MangedRoutes
// getOrderedVirtualServiceRoutes This returns an []interface{} of istio virtual routes where the routes are ordered based
// on the rollouts managedRoutes field. We take the routes from the rollouts managedRoutes field order them and place them on top
// of routes that are manually defined within the virtual service (aka. routes that users have defined manually)
func getOrderedVirtualServiceRoutes(managedRoutes []v1alpha1.MangedRoutes, httpRoutesWithinManagedRoutes []VirtualServiceHTTPRoute, httpRoutesNotWithinManagedRoutes []VirtualServiceHTTPRoute) ([]interface{}, error) {
func getOrderedVirtualServiceRoutes(httpRouteI []interface{}, managedRoutes []v1alpha1.MangedRoutes, httpRoutesWithinManagedRoutes []VirtualServiceHTTPRoute, httpRoutesNotWithinManagedRoutes []VirtualServiceHTTPRoute) ([]interface{}, error) {
var orderedManagedRoutes []VirtualServiceHTTPRoute
for _, route := range managedRoutes {
for _, managedRoute := range httpRoutesWithinManagedRoutes {
Expand All @@ -1289,18 +1305,45 @@ func getOrderedVirtualServiceRoutes(managedRoutes []v1alpha1.MangedRoutes, httpR
}
}

allIstioRoutes := append(orderedManagedRoutes, httpRoutesNotWithinManagedRoutes...)
orderedVirtualServiceHTTPRoutes := append(orderedManagedRoutes, httpRoutesNotWithinManagedRoutes...)

jsonAllIstioRoutes, err := json.Marshal(allIstioRoutes)
var orderedInterfaceVSVCHTTPRoutes []interface{}
for _, routeTyped := range orderedVirtualServiceHTTPRoutes {
for _, route := range httpRouteI {
r := route.(map[string]interface{})

// No need to check if exist because the empty string returned on cast failure is good for this check
name, _ := r["name"].(string)
if name == routeTyped.Name {
orderedInterfaceVSVCHTTPRoutes = append(orderedInterfaceVSVCHTTPRoutes, route)
}
}
}

return orderedInterfaceVSVCHTTPRoutes, nil
}

// getVirtualServiceCanaryPort This function returns the port that the canary service is running on. It does this by looking at the
// istio Virtual Service and finding any port from a destination that is suppose to be update via SetWeight.
func getVirtualServiceCanaryPort(unVsvc *unstructured.Unstructured, virtualService v1alpha1.IstioVirtualService) (Port, error) {
httpRoutes, _, err := getVirtualServiceHttpRoutes(unVsvc)
if err != nil {
return nil, fmt.Errorf("[getOrderedVirtualServiceRoutes] failed to marsharl istio routes: %w", err)
return Port{}, fmt.Errorf("[getVirtualServiceCanaryPort] failed to get virtual service http routes: %w", err)
}
var orderedRoutes []interface{}
if err := json.Unmarshal(jsonAllIstioRoutes, &orderedRoutes); err != nil {
return nil, fmt.Errorf("[getOrderedVirtualServiceRoutes] failed to unmarsharl istio routes: %w", err)

route, err := getVirtualServiceSetWeightRoute(virtualService.Routes, httpRoutes)
if err != nil {
return Port{}, fmt.Errorf("[getVirtualServiceCanaryPort] failed to get virtual service set weight route: %w", err)
}

var port uint32 = 0
if len(route) > 0 && route[0].Destination.Port != nil {
port = route[0].Destination.Port.Number
}

return orderedRoutes, nil
return Port{
Number: port,
}, nil
}

// RemoveManagedRoutes this removes all the routes in all the istio virtual services rollouts is managing by getting two slices
Expand Down
Loading

0 comments on commit 00e39cd

Please sign in to comment.