Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement AppMesh v1beta2 router #584

Merged
merged 13 commits into from
May 14, 2020
2 changes: 2 additions & 0 deletions artifacts/flagger/account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ rules:
resources:
- virtualnodes
- virtualnodes/finalizers
- virtualrouters
- virtualrouters/finalizers
- virtualservices
- virtualservices/finalizers
verbs:
Expand Down
2 changes: 2 additions & 0 deletions charts/flagger/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ rules:
resources:
- virtualnodes
- virtualnodes/finalizers
- virtualrouters
- virtualrouters/finalizers
- virtualservices
- virtualservices/finalizers
verbs:
Expand Down
92 changes: 63 additions & 29 deletions docs/gitbook/tutorials/crossover-progressive-delivery.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,6 @@ helm upgrade -i flagger flagger/flagger \
--set meshProvider=smi:crossover
```

Optionally you can enable Slack notifications:

```bash
helm upgrade -i flagger flagger/flagger \
--reuse-values \
--namespace test \
--set slack.url=https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK \
--set slack.channel=general \
--set slack.user=flagger
```

## Bootstrap

Flagger takes a Kubernetes deployment and optionally a horizontal pod autoscaler (HPA),
Expand All @@ -82,6 +71,59 @@ helm upgrade -i flagger-loadtester flagger/loadtester \
--namespace=test
```

Create a metric template to measure the HTTP requests error rate:

```yaml
apiVersion: flagger.app/v1beta1
kind: MetricTemplate
metadata:
name: error-rate
namespace: test
spec:
provider:
address: http://flagger-prometheus:9090
type: prometheus
query: |
100 - rate(
envoy_cluster_upstream_rq{
kubernetes_namespace="{{ namespace }}",
envoy_cluster_name="{{ target }}-canary",
envoy_response_code!~"5.*"
}[{{ interval }}])
/
rate(
envoy_cluster_upstream_rq{
kubernetes_namespace="{{ namespace }}",
envoy_cluster_name="{{ target }}-canary"
}[{{ interval }}]
) * 100
```

Create a metric template to measure the HTTP requests average duration:

```yaml
apiVersion: flagger.app/v1beta1
kind: MetricTemplate
metadata:
name: latency
namespace: test
spec:
provider:
address: http://flagger-prometheus:9090
type: prometheus
query: |
histogram_quantile(0.99,
sum(
rate(
envoy_cluster_upstream_rq_time_bucket{
kubernetes_namespace="{{ namespace }}",
envoy_cluster_name="{{ target }}-canary"
}[{{ interval }}]
)
) by (le)
)
```

Create a canary custom resource:

```yaml
Expand All @@ -91,26 +133,20 @@ metadata:
name: podinfo
namespace: test
spec:
# specify mesh provider if it isn't the default one
# provider: "smi:crossover"
provider: "smi:crossover"
# deployment reference
targetRef:
apiVersion: apps/v1
kind: Deployment
name: podinfo
# the maximum time in seconds for the canary deployment
# to make progress before it is rollback (default 600s)
progressDeadlineSeconds: 60
# HPA reference (optional)
autoscalerRef:
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
name: podinfo
service:
# ClusterIP port number
port: 9898
# container port number or name (optional)
targetPort: 9898
# define the canary analysis timing and KPIs
analysis:
# schedule interval (default 60s)
Expand All @@ -123,21 +159,19 @@ spec:
# canary increment step
# percentage (0-100)
stepWeight: 5
# App Mesh Prometheus checks
metrics:
- name: request-success-rate
# minimum req success rate (non 5xx responses)
# percentage (0-100)
- name: error-rate
templateRef:
name: error-rate
thresholdRange:
min: 99
interval: 1m
- name: request-duration
# maximum req duration P99
# milliseconds
max: 1
interval: 30s
- name: latency
templateRef:
name: latency
thresholdRange:
max: 500
max: 0.5
interval: 30s
# testing (optional)
webhooks:
- name: acceptance-test
type: pre-rollout
Expand Down
2 changes: 1 addition & 1 deletion docs/gitbook/tutorials/prometheus-operator.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ spec:
) * 100
```

Amd a metric template to measure the HTTP requests average duration:
Create a metric template to measure the HTTP requests average duration:

```yaml
apiVersion: flagger.app/v1beta1
Expand Down
2 changes: 1 addition & 1 deletion hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ chmod +x ${CODEGEN_PKG}/generate-groups.sh

${CODEGEN_PKG}/generate-groups.sh all \
github.com/weaveworks/flagger/pkg/client github.com/weaveworks/flagger/pkg/apis \
"flagger:v1beta1 appmesh:v1beta1 istio:v1alpha3 smi:v1alpha1 smi:v1alpha2 gloo:v1 projectcontour:v1" \
"flagger:v1beta1 appmesh:v1beta2 appmesh:v1beta1 istio:v1alpha3 smi:v1alpha1 smi:v1alpha2 gloo:v1 projectcontour:v1" \
--output-base "${TEMP_DIR}" \
--go-header-file ${SCRIPT_ROOT}/hack/boilerplate.go.txt

Expand Down
2 changes: 2 additions & 0 deletions kustomize/base/flagger/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ rules:
resources:
- virtualnodes
- virtualnodes/finalizers
- virtualrouters
- virtualrouters/finalizers
- virtualservices
- virtualservices/finalizers
verbs:
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/appmesh/v1beta2/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +k8s:deepcopy-gen=package

// Package v1beta2 is the v1beta2 version of the API.
// +groupName=appmesh.k8s.aws
package v1beta2
41 changes: 41 additions & 0 deletions pkg/apis/appmesh/v1beta2/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package v1beta2

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/weaveworks/flagger/pkg/apis/appmesh"
)

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: appmesh.GroupName, Version: "v1beta2"}

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

var (
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
AddToScheme = SchemeBuilder.AddToScheme
)

// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&VirtualService{},
&VirtualServiceList{},
&VirtualRouter{},
&VirtualRouterList{},
&VirtualNode{},
&VirtualNodeList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
91 changes: 91 additions & 0 deletions pkg/apis/appmesh/v1beta2/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package v1beta2

import "k8s.io/apimachinery/pkg/types"

// +kubebuilder:validation:Enum=s;ms
type DurationUnit string

const (
DurationUnitS DurationUnit = "s"
DurationUnitMS DurationUnit = "ms"
)

type Duration struct {
// A unit of time.
Unit DurationUnit `json:"unit"`
// A number of time units.
// +kubebuilder:validation:Minimum=0
Value int64 `json:"value"`
}

// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=65535
type PortNumber int64

// +kubebuilder:validation:Enum=grpc;http;http2;tcp
type PortProtocol string

const (
PortProtocolGRPC PortProtocol = "grpc"
PortProtocolHTTP PortProtocol = "http"
PortProtocolHTTP2 PortProtocol = "http2"
PortProtocolTCP PortProtocol = "tcp"
)

// PortMapping refers to https://docs.aws.amazon.com/app-mesh/latest/APIReference/API_PortMapping.html
type PortMapping struct {
// The port used for the port mapping.
Port PortNumber `json:"port"`
// The protocol used for the port mapping.
Protocol PortProtocol `json:"protocol"`
}

// VirtualNodeReference holds a reference to VirtualNode.appmesh.k8s.aws
type VirtualNodeReference struct {
// Namespace is the namespace of VirtualNode CR.
// If unspecified, defaults to the referencing object's namespace
// +optional
Namespace *string `json:"namespace,omitempty"`
// Name is the name of VirtualNode CR
Name string `json:"name"`
}

// VirtualServiceReference holds a reference to VirtualService.appmesh.k8s.aws
type VirtualServiceReference struct {
// Namespace is the namespace of VirtualService CR.
// If unspecified, defaults to the referencing object's namespace
// +optional
Namespace *string `json:"namespace,omitempty"`
// Name is the name of VirtualService CR
Name string `json:"name"`
}

// VirtualRouterReference holds a reference to VirtualRouter.appmesh.k8s.aws
type VirtualRouterReference struct {
// Namespace is the namespace of VirtualRouter CR.
// If unspecified, defaults to the referencing object's namespace
// +optional
Namespace *string `json:"namespace,omitempty"`
// Name is the name of VirtualRouter CR
Name string `json:"name"`
}

// MeshReference holds a reference to Mesh.appmesh.k8s.aws
type MeshReference struct {
// Name is the name of Mesh CR
Name string `json:"name"`
// UID is the UID of Mesh CR
UID types.UID `json:"uid"`
}

// VirtualGatewayReference holds a reference to VirtualGateway.appmesh.k8s.aws
type VirtualGatewayReference struct {
// Namespace is the namespace of VirtualGateway CR.
// If unspecified, defaults to the referencing object's namespace
// +optional
Namespace *string `json:"namespace,omitempty"`
// Name is the name of VirtualGateway CR
Name string `json:"name"`
// UID is the UID of VirtualGateway CR
UID types.UID `json:"uid"`
}
Loading