Skip to content

Commit

Permalink
Merge pull request #16 from ssttehrani/main
Browse files Browse the repository at this point in the history
refactor: enhance HttpVersion translation
  • Loading branch information
ssttehrani authored Dec 11, 2023
2 parents c687dcf + 0f8e7b3 commit 53ea71e
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
4 changes: 2 additions & 2 deletions deploy/charts/route-to-contour-httpproxy/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.5
version: 0.1.6
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.3.6"
appVersion: "1.3.7"
44 changes: 44 additions & 0 deletions internal/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,5 +685,49 @@ var _ = Describe("Testing Route to HTTPProxy Controller", func() {

cleanUpRoute(route)
})

It("Should set http versions to [http/1.1] for routes that do not use tls", func() {
route := getSampleRoute()
route.Spec.TLS = nil

Expect(k8sClient.Create(context.Background(), route)).To(Succeed())

admitRoute(route)

Eventually(func(g Gomega) {
httpProxyList := contourv1.HTTPProxyList{}
g.Expect(k8sClient.List(context.Background(), &httpProxyList, client.InNamespace(DefaultNamespace))).To(Succeed())
g.Expect(len(httpProxyList.Items)).To(Equal(1))
g.Expect(len(httpProxyList.Items[0].Spec.HttpVersions)).To(Equal(1))
g.Expect(httpProxyList.Items[0].Spec.HttpVersions[0]).To(Equal(contourv1.HttpVersion("http/1.1")))
}).Should(Succeed())

cleanUpRoute(route)
})

It("Should set http versions to [http/1.1] for routes that enforce http/1.1", func() {
route := getSampleRoute()
route.Annotations = map[string]string{
consts.AnnotationKeyHttp1Enforced: "",
}
// Routes labeled as 'inter-dc' will use h2 in addition to http/1.1, independent of the certificate wildcard status.
route.Labels[consts.RouteShardLabel] = consts.IngressClassInterDc
route.Spec.TLS = &routev1.TLSConfig{
Termination: routev1.TLSTerminationEdge,
}
Expect(k8sClient.Create(context.Background(), route)).To(Succeed())

admitRoute(route)

Eventually(func(g Gomega) {
httpProxyList := contourv1.HTTPProxyList{}
g.Expect(k8sClient.List(context.Background(), &httpProxyList, client.InNamespace(DefaultNamespace))).To(Succeed())
g.Expect(len(httpProxyList.Items)).To(Equal(1))
g.Expect(len(httpProxyList.Items[0].Spec.HttpVersions)).To(Equal(1))
g.Expect(httpProxyList.Items[0].Spec.HttpVersions[0]).To(Equal(contourv1.HttpVersion("http/1.1")))
}).Should(Succeed())

cleanUpRoute(route)
})
})
})
8 changes: 7 additions & 1 deletion internal/controller/route/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (r *Reconciler) assembleHttpproxy(ctx context.Context, owner *routev1.Route
httpproxy.Spec.IngressClassName = utils.GetIngressClass(owner)

// Enable h2 and http/1.1 by default.
// Later we disable h2 for a specific set of routes
// Later we disable h2 for a specific set of routes.
httpproxy.Spec.HttpVersions = []contourv1.HttpVersion{"h2", "http/1.1"}

if owner.Spec.TLS != nil {
Expand Down Expand Up @@ -342,6 +342,12 @@ func (r *Reconciler) assembleHttpproxy(ctx context.Context, owner *routev1.Route
default:
return nil, fmt.Errorf("invalid termination mode specified on route")
}
} else {
httpproxy.Spec.HttpVersions = []contourv1.HttpVersion{"http/1.1"}
}

if utils.IsHttp1Enforced(r.route) {
httpproxy.Spec.HttpVersions = []contourv1.HttpVersion{"http/1.1"}
}

// use `tcpproxy` for passthrough mode and `routes` for other termination modes
Expand Down
1 change: 1 addition & 0 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (

AnnotationKeyPrefix = "snappcloud.io/"
AnnotationKeyReconciliationPaused = AnnotationKeyPrefix + "paused"
AnnotationKeyHttp1Enforced = AnnotationKeyPrefix + "force-h1"

TLSSecretNS = "openshift-ingress"
TLSSecretName = "letsencrypt"
Expand Down
10 changes: 10 additions & 0 deletions pkg/utils/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ func IsDeleted(obj metav1.Object) bool {
return !obj.GetDeletionTimestamp().IsZero()
}

// IsHttp1Enforced returns true if the object has the AnnotationKeyHttp1Enforced
func IsHttp1Enforced(obj metav1.Object) bool {
annotations := obj.GetAnnotations()
if annotations == nil {
return false
}
_, ok := annotations[consts.AnnotationKeyHttp1Enforced]
return ok
}

// IsPaused returns true if the object has the AnnotationKeyReconciliationPaused
func IsPaused(obj metav1.Object) bool {
annotations := obj.GetAnnotations()
Expand Down

0 comments on commit 53ea71e

Please sign in to comment.