mirror of
https://github.com/fluxcd/flagger.git
synced 2026-04-15 06:57:34 +00:00
Add ingress class support for Contour
Add `-ingress-class` command flag. When set, the specified class is used to annotate the generated HTTPProxy objects.
This commit is contained in:
@@ -76,7 +76,7 @@ func newDaemonSetFixture(c *flaggerv1.Canary) daemonSetFixture {
|
||||
}
|
||||
|
||||
// init router
|
||||
rf := router.NewFactory(nil, kubeClient, flaggerClient, "annotationsPrefix", logger, flaggerClient)
|
||||
rf := router.NewFactory(nil, kubeClient, flaggerClient, "annotationsPrefix", "", logger, flaggerClient)
|
||||
|
||||
// init observer
|
||||
observerFactory, _ := observers.NewFactory("fake")
|
||||
|
||||
@@ -104,7 +104,7 @@ func newDeploymentFixture(c *flaggerv1.Canary) fixture {
|
||||
}
|
||||
|
||||
// init router
|
||||
rf := router.NewFactory(nil, kubeClient, flaggerClient, "annotationsPrefix", logger, flaggerClient)
|
||||
rf := router.NewFactory(nil, kubeClient, flaggerClient, "annotationsPrefix", "", logger, flaggerClient)
|
||||
|
||||
// init observer
|
||||
observerFactory, _ := observers.NewFactory("fake")
|
||||
|
||||
@@ -23,10 +23,13 @@ type ContourRouter struct {
|
||||
contourClient clientset.Interface
|
||||
flaggerClient clientset.Interface
|
||||
logger *zap.SugaredLogger
|
||||
ingressClass string
|
||||
}
|
||||
|
||||
// Reconcile creates or updates the HTTP proxy
|
||||
func (cr *ContourRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
annotation := "projectcontour.io/ingress.class"
|
||||
|
||||
apexName, primaryName, canaryName := canary.GetServiceNames()
|
||||
|
||||
newSpec := contourv1.HTTPProxySpec{
|
||||
@@ -151,6 +154,12 @@ func (cr *ContourRouter) Reconcile(canary *flaggerv1.Canary) error {
|
||||
},
|
||||
}
|
||||
|
||||
if cr.ingressClass != "" {
|
||||
proxy.Annotations = map[string]string{
|
||||
annotation: cr.ingressClass,
|
||||
}
|
||||
}
|
||||
|
||||
_, err = cr.contourClient.ProjectcontourV1().HTTPProxies(canary.Namespace).Create(context.TODO(), proxy, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("HTTPProxy %s.%s create error: %w", apexName, canary.Namespace, err)
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestContourRouter_Reconcile(t *testing.T) {
|
||||
flaggerClient: mocks.flaggerClient,
|
||||
contourClient: mocks.meshClient,
|
||||
kubeClient: mocks.kubeClient,
|
||||
ingressClass: "contour",
|
||||
}
|
||||
|
||||
// init
|
||||
@@ -31,6 +32,7 @@ func TestContourRouter_Reconcile(t *testing.T) {
|
||||
require.Len(t, services, 2)
|
||||
assert.Equal(t, uint32(100), services[0].Weight)
|
||||
assert.Equal(t, uint32(0), services[1].Weight)
|
||||
assert.Equal(t, "contour", proxy.Annotations["projectcontour.io/ingress.class"])
|
||||
|
||||
// test update
|
||||
cd, err := mocks.flaggerClient.FlaggerV1beta1().Canaries("default").Get(context.TODO(), "podinfo", metav1.GetOptions{})
|
||||
|
||||
@@ -17,12 +17,14 @@ type Factory struct {
|
||||
meshClient clientset.Interface
|
||||
flaggerClient clientset.Interface
|
||||
ingressAnnotationsPrefix string
|
||||
ingressClass string
|
||||
logger *zap.SugaredLogger
|
||||
}
|
||||
|
||||
func NewFactory(kubeConfig *restclient.Config, kubeClient kubernetes.Interface,
|
||||
flaggerClient clientset.Interface,
|
||||
ingressAnnotationsPrefix string,
|
||||
ingressClass string,
|
||||
logger *zap.SugaredLogger,
|
||||
meshClient clientset.Interface) *Factory {
|
||||
return &Factory{
|
||||
@@ -31,6 +33,7 @@ func NewFactory(kubeConfig *restclient.Config, kubeClient kubernetes.Interface,
|
||||
kubeClient: kubeClient,
|
||||
flaggerClient: flaggerClient,
|
||||
ingressAnnotationsPrefix: ingressAnnotationsPrefix,
|
||||
ingressClass: ingressClass,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user