Skip to content

Commit

Permalink
Merge pull request #411 from weaveworks/contour-up
Browse files Browse the repository at this point in the history
Update Contour to v1.1 and add Linkerd header
  • Loading branch information
stefanprodan committed Jan 16, 2020
2 parents 6eaf421 + 558a1fc commit 3083519
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 11 deletions.
52 changes: 44 additions & 8 deletions pkg/apis/projectcontour/v1/httpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// source: https://github.com/projectcontour/contour/blob/master/apis/projectcontour/v1/httpproxy.go
package v1

import (
Expand Down Expand Up @@ -151,15 +150,20 @@ type Route struct {
// The policy for rewriting the path of the request URL
// after the request has been routed to a Service.
//
// +kubebuilder:validation:Optional
PathRewrite *PathRewritePolicy `json:"pathRewritePolicy,omitempty"`
// +optional
PathRewritePolicy *PathRewritePolicy `json:"pathRewritePolicy,omitempty"`
// The policy for managing request headers during proxying
// +optional
RequestHeadersPolicy *HeadersPolicy `json:"requestHeadersPolicy,omitempty"`
// The policy for managing response headers during proxying
// +optional
ResponseHeadersPolicy *HeadersPolicy `json:"responseHeadersPolicy,omitempty"`
}

func (r *Route) GetPrefixReplacements() []ReplacePrefix {
if r.PathRewrite != nil {
return r.PathRewrite.ReplacePrefix
if r.PathRewritePolicy != nil {
return r.PathRewritePolicy.ReplacePrefix
}

return nil
}

Expand Down Expand Up @@ -192,6 +196,10 @@ type Service struct {
Name string `json:"name"`
// Port (defined as Integer) to proxy traffic to since a service can have multiple defined.
Port int `json:"port"`
// Protocol may be used to specify (or override) the protocol used to reach this Service.
// Values may be tls, h2, h2c. It ommitted protocol-selection falls back on Service annotations.
// +optional
Protocol *string `json:"protocol,omitempty"`
// Weight defines percentage of traffic to balance traffic
// +optional
Weight uint32 `json:"weight,omitempty"`
Expand All @@ -200,6 +208,12 @@ type Service struct {
UpstreamValidation *UpstreamValidation `json:"validation,omitempty"`
// If Mirror is true the Service will receive a read only mirror of the traffic for this route.
Mirror bool `json:"mirror,omitempty"`
// The policy for managing request headers during proxying
// +optional
RequestHeadersPolicy *HeadersPolicy `json:"requestHeadersPolicy,omitempty"`
// The policy for managing response headers during proxying
// +optional
ResponseHeadersPolicy *HeadersPolicy `json:"responseHeadersPolicy,omitempty"`
}

// HTTPHealthCheckPolicy defines health checks on the upstream service.
Expand Down Expand Up @@ -266,7 +280,7 @@ type ReplacePrefix struct {
// If Prefix is not specified, all routing prefixes rendered
// by the include chain will be replaced.
//
// +kubebuilder:validation:Optional
// +optional
// +kubebuilder:validation:MinLength=1
Prefix string `json:"prefix,omitempty"`

Expand All @@ -286,7 +300,7 @@ type ReplacePrefix struct {
// Exactly one field in this struct may be specified.
type PathRewritePolicy struct {
// ReplacePrefix describes how the path prefix should be replaced.
// +kubebuilder:validation:Optional
// +optional
ReplacePrefix []ReplacePrefix `json:"replacePrefix,omitempty"`
}

Expand All @@ -295,6 +309,28 @@ type LoadBalancerPolicy struct {
Strategy string `json:"strategy,omitempty"`
}

// HeadersPolicy defines how headers are managed during forwarding
type HeadersPolicy struct {
// Set specifies a list of HTTP header values that will be set in the HTTP header
// +optional
Set []HeaderValue `json:"set,omitempty"`
// Remove specifies a list of HTTP header names to remove
// +optional
Remove []string `json:"remove,omitempty"`
}

// HeaderValue represents a header name/value pair
type HeaderValue struct {
// Name represents a key of a header
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinLength=1
Name string `json:"name"`
// Value represents the value of a header specified by a key
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinLength=1
Value string `json:"value"`
}

// UpstreamValidation defines how to verify the backend service's certificate
type UpstreamValidation struct {
// Name of the Kubernetes secret be used to validate the certificate presented by the backend
Expand Down
71 changes: 69 additions & 2 deletions pkg/apis/projectcontour/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions pkg/router/contour.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,21 @@ func (cr *ContourRouter) Reconcile(canary *flaggerv1.Canary) error {
Name: primaryName,
Port: int(canary.Spec.Service.Port),
Weight: uint32(100),
RequestHeadersPolicy: &contourv1.HeadersPolicy{
Set: []contourv1.HeaderValue{
cr.makeLinkerdHeaderValue(canary, primaryName),
},
},
},
{
Name: canaryName,
Port: int(canary.Spec.Service.Port),
Weight: uint32(0),
RequestHeadersPolicy: &contourv1.HeadersPolicy{
Set: []contourv1.HeaderValue{
cr.makeLinkerdHeaderValue(canary, canaryName),
},
},
},
},
},
Expand All @@ -68,11 +78,21 @@ func (cr *ContourRouter) Reconcile(canary *flaggerv1.Canary) error {
Name: primaryName,
Port: int(canary.Spec.Service.Port),
Weight: uint32(100),
RequestHeadersPolicy: &contourv1.HeadersPolicy{
Set: []contourv1.HeaderValue{
cr.makeLinkerdHeaderValue(canary, primaryName),
},
},
},
{
Name: canaryName,
Port: int(canary.Spec.Service.Port),
Weight: uint32(0),
RequestHeadersPolicy: &contourv1.HeadersPolicy{
Set: []contourv1.HeaderValue{
cr.makeLinkerdHeaderValue(canary, canaryName),
},
},
},
},
},
Expand All @@ -89,11 +109,21 @@ func (cr *ContourRouter) Reconcile(canary *flaggerv1.Canary) error {
Name: primaryName,
Port: int(canary.Spec.Service.Port),
Weight: uint32(100),
RequestHeadersPolicy: &contourv1.HeadersPolicy{
Set: []contourv1.HeaderValue{
cr.makeLinkerdHeaderValue(canary, primaryName),
},
},
},
{
Name: canaryName,
Port: int(canary.Spec.Service.Port),
Weight: uint32(0),
RequestHeadersPolicy: &contourv1.HeadersPolicy{
Set: []contourv1.HeaderValue{
cr.makeLinkerdHeaderValue(canary, canaryName),
},
},
},
},
},
Expand Down Expand Up @@ -232,11 +262,21 @@ func (cr *ContourRouter) SetRoutes(
Name: primaryName,
Port: int(canary.Spec.Service.Port),
Weight: uint32(primaryWeight),
RequestHeadersPolicy: &contourv1.HeadersPolicy{
Set: []contourv1.HeaderValue{
cr.makeLinkerdHeaderValue(canary, primaryName),
},
},
},
{
Name: canaryName,
Port: int(canary.Spec.Service.Port),
Weight: uint32(canaryWeight),
RequestHeadersPolicy: &contourv1.HeadersPolicy{
Set: []contourv1.HeaderValue{
cr.makeLinkerdHeaderValue(canary, canaryName),
},
},
},
}},
},
Expand All @@ -254,11 +294,21 @@ func (cr *ContourRouter) SetRoutes(
Name: primaryName,
Port: int(canary.Spec.Service.Port),
Weight: uint32(primaryWeight),
RequestHeadersPolicy: &contourv1.HeadersPolicy{
Set: []contourv1.HeaderValue{
cr.makeLinkerdHeaderValue(canary, primaryName),
},
},
},
{
Name: canaryName,
Port: int(canary.Spec.Service.Port),
Weight: uint32(canaryWeight),
RequestHeadersPolicy: &contourv1.HeadersPolicy{
Set: []contourv1.HeaderValue{
cr.makeLinkerdHeaderValue(canary, canaryName),
},
},
},
},
},
Expand All @@ -275,11 +325,21 @@ func (cr *ContourRouter) SetRoutes(
Name: primaryName,
Port: int(canary.Spec.Service.Port),
Weight: uint32(100),
RequestHeadersPolicy: &contourv1.HeadersPolicy{
Set: []contourv1.HeaderValue{
cr.makeLinkerdHeaderValue(canary, primaryName),
},
},
},
{
Name: canaryName,
Port: int(canary.Spec.Service.Port),
Weight: uint32(0),
RequestHeadersPolicy: &contourv1.HeadersPolicy{
Set: []contourv1.HeaderValue{
cr.makeLinkerdHeaderValue(canary, canaryName),
},
},
},
},
},
Expand Down Expand Up @@ -364,3 +424,11 @@ func (cr *ContourRouter) makeRetryPolicy(canary *flaggerv1.Canary) *contourv1.Re
}
return nil
}

func (cr *ContourRouter) makeLinkerdHeaderValue(canary *flaggerv1.Canary, serviceName string) contourv1.HeaderValue {
return contourv1.HeaderValue{
Name: "l5d-dst-override",
Value: fmt.Sprintf("%s.%.s.svc.cluster.local:%v", serviceName, canary.Namespace, canary.Spec.Service.Port),
}

}
4 changes: 3 additions & 1 deletion test/e2e-contour.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ set -o errexit

REPO_ROOT=$(git rev-parse --show-toplevel)

CONTOUR_VER="release-1.1"

echo '>>> Installing Contour'
kubectl apply -f https://projectcontour.io/quickstart/contour.yaml
kubectl apply -f https://raw.githubusercontent.com/projectcontour/contour/${CONTOUR_VER}/examples/render/contour.yaml

kubectl -n projectcontour rollout status deployment/contour
kubectl -n projectcontour get all
Expand Down

0 comments on commit 3083519

Please sign in to comment.