Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ layout:
projectName: uptime-operator
repo: github.com/PDOK/uptime-operator
resources:
- controller: true
domain: pdok.nl
group: traefik.containo.us
kind: IngressRoute
version: v1alpha1
- controller: true
domain: pdok.nl
group: traefik.io
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Submit a PR when you wish to add another provider!
Traefik `IngressRoute` resources should be annotated in order to successfully register an uptime check. For example:

```yaml
apiVersion: traefik.containo.us/v1alpha1
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: my-sweet-route
Expand All @@ -36,7 +36,7 @@ metadata:

The `id`, `name` and `url` annotations are mandatory, the rest is optional.

Both `traefik.containo.us/v1alpha1` as well as `traefik.io/v1alpha1` resources are supported.
Only `traefik.io/v1alpha1` resources are supported (not the legacy `traefik.containo.us`).

### Ignoring routes

Expand Down
2 changes: 0 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook"

"github.com/PDOK/uptime-operator/internal/controller"
traefikcontainous "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikcontainous/v1alpha1"
traefikio "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
//+kubebuilder:scaffold:imports
)
Expand All @@ -55,7 +54,6 @@ var (
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

utilruntime.Must(traefikcontainous.AddToScheme(scheme))
utilruntime.Must(traefikio.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}
Expand Down
14 changes: 0 additions & 14 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@ kind: ClusterRole
metadata:
name: manager-role
rules:
- apiGroups:
- traefik.containo.us
resources:
- ingressroutes
verbs:
- get
- list
- watch
- apiGroups:
- traefik.containo.us
resources:
- ingressroutes/finalizers
verbs:
- update
- apiGroups:
- traefik.io
resources:
Expand Down
34 changes: 11 additions & 23 deletions internal/controller/ingressroute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (

m "github.com/PDOK/uptime-operator/internal/model"
"github.com/PDOK/uptime-operator/internal/service"
traefikcontainous "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikcontainous/v1alpha1"
traefikio "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -49,8 +48,6 @@ type IngressRouteReconciler struct {
UptimeCheckService *service.UptimeCheckService
}

//+kubebuilder:rbac:groups=traefik.containo.us,resources=ingressroutes,verbs=get;list;watch
//+kubebuilder:rbac:groups=traefik.containo.us,resources=ingressroutes/finalizers,verbs=update
//+kubebuilder:rbac:groups=traefik.io,resources=ingressroutes,verbs=get;list;watch
//+kubebuilder:rbac:groups=traefik.io,resources=ingressroutes/finalizers,verbs=update

Expand All @@ -76,24 +73,19 @@ func (r *IngressRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request
}

func (r *IngressRouteReconciler) getIngressRoute(ctx context.Context, req ctrl.Request) (client.Object, error) {
// first try getting "traefik.containo.us/v1alpha1" ingress
ingressContainous := &traefikcontainous.IngressRoute{}
if err := r.Get(ctx, req.NamespacedName, ingressContainous); err != nil {
// not found, now try getting "traefik.io/v1alpha1" ingress
ingressIo := &traefikio.IngressRoute{}
if err = r.Get(ctx, req.NamespacedName, ingressIo); err != nil {
// still not found, handle error
logger := log.FromContext(ctx)
if apierrors.IsNotFound(err) {
logger.Info("IngressRoute resource not found", "name", req.NamespacedName)
} else {
logger.Error(err, "unable to fetch IngressRoute resource", "error", err)
}
return nil, err
// try getting "traefik.io/v1alpha1" ingress
ingressIo := &traefikio.IngressRoute{}
if err := r.Get(ctx, req.NamespacedName, ingressIo); err != nil {
// still not found, handle error
logger := log.FromContext(ctx)
if apierrors.IsNotFound(err) {
logger.Info("IngressRoute resource not found", "name", req.NamespacedName)
} else {
logger.Error(err, "unable to fetch IngressRoute resource", "error", err)
}
return ingressIo, nil
return nil, err
}
return ingressContainous, nil
return ingressIo, nil
}

func finalizeIfNecessary(ctx context.Context, c client.Client, obj client.Object, finalizerName string, finalizer func() error) (shouldContinue bool, err error) {
Expand Down Expand Up @@ -127,10 +119,6 @@ func (r *IngressRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {

return ctrl.NewControllerManagedBy(mgr).
Named(m.OperatorName).
Watches(
&traefikcontainous.IngressRoute{}, // watch "traefik.containo.us/v1alpha1" ingresses
&handler.EnqueueRequestForObject{},
builder.WithPredicates(preCondition)).
Watches(
&traefikio.IngressRoute{}, // watch "traefik.io/v1alpha1" ingresses
&handler.EnqueueRequestForObject{},
Expand Down
18 changes: 9 additions & 9 deletions internal/controller/ingressroute_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/PDOK/uptime-operator/internal/service"
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo bdd
. "github.com/onsi/gomega" //nolint:revive // gingko bdd
traefikcontainous "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikcontainous/v1alpha1"
traefikio "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -64,7 +64,7 @@ func (m *testUptimeProvider) DeleteCheck(_ context.Context, check m.UptimeCheck)
return nil
}

var ingressRouteWithUptimeCheck = &traefikcontainous.IngressRoute{
var ingressRouteWithUptimeCheck = &traefikio.IngressRoute{
TypeMeta: v1.TypeMeta{},
ObjectMeta: v1.ObjectMeta{
Name: testIngress,
Expand All @@ -76,14 +76,14 @@ var ingressRouteWithUptimeCheck = &traefikcontainous.IngressRoute{
m.AnnotationName: "Test uptime check",
},
},
Spec: traefikcontainous.IngressRouteSpec{
Routes: []traefikcontainous.Route{
Spec: traefikio.IngressRouteSpec{
Routes: []traefikio.Route{
{
Kind: "Rule",
Match: "Host(`localhost`)",
Services: []traefikcontainous.Service{
Services: []traefikio.Service{
{
LoadBalancerSpec: traefikcontainous.LoadBalancerSpec{
LoadBalancerSpec: traefikio.LoadBalancerSpec{
Name: "test",
},
},
Expand Down Expand Up @@ -111,7 +111,7 @@ var _ = Describe("IngressRoute Controller", func() {
}

By("Creating an IngressRoute")
newIngressRoute := &traefikcontainous.IngressRoute{}
newIngressRoute := &traefikio.IngressRoute{}
err := k8sClient.Get(ctx, typeNamespacedName, newIngressRoute)
if err != nil {
if k8serrors.IsNotFound(err) {
Expand All @@ -135,7 +135,7 @@ var _ = Describe("IngressRoute Controller", func() {
}))

By("Fetching and updating IngressRoute (adding extra uptime annotation)")
fetchedIngressRoute := &traefikcontainous.IngressRoute{}
fetchedIngressRoute := &traefikio.IngressRoute{}
Eventually(func() bool {
err := k8sClient.Get(ctx, typeNamespacedName, fetchedIngressRoute)
return err == nil
Expand Down Expand Up @@ -182,7 +182,7 @@ var _ = Describe("IngressRoute Controller", func() {
}))

By("Delete IngressRoute")
fetchedIngressRoute := &traefikcontainous.IngressRoute{}
fetchedIngressRoute := &traefikio.IngressRoute{}
Eventually(func() bool {
err := k8sClient.Get(ctx, typeNamespacedName, fetchedIngressRoute)
return err == nil
Expand Down
4 changes: 0 additions & 4 deletions internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (

. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo bdd
. "github.com/onsi/gomega" //nolint:revive // ginkgo bdd
traefikcontainous "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikcontainous/v1alpha1"
traefikio "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"

"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -91,9 +90,6 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())
Expect(cfg).NotTo(BeNil())

err = traefikcontainous.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())

err = traefikio.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())

Expand Down