caddy-ingess/internal/controller/action_ingress.go
Marc-Antoine e9c594cd55
feat(annotations): Add annotations to rewrite requests (#68)
* feat(annotations): Add annotations to rewrite requests

* Upgrade caddy, ingress API version and some other deps

* fix graceful shutdown

* Upgrade caddy to v2.4.6 and add OCSP Check interval to global config

* Add caddy duration parser
2022-03-26 23:19:04 -06:00

71 lines
2.0 KiB
Go

package controller
import (
"k8s.io/api/networking/v1"
)
// IngressAddedAction provides an implementation of the action interface.
type IngressAddedAction struct {
resource *v1.Ingress
}
// IngressUpdatedAction provides an implementation of the action interface.
type IngressUpdatedAction struct {
resource *v1.Ingress
oldResource *v1.Ingress
}
// IngressDeletedAction provides an implementation of the action interface.
type IngressDeletedAction struct {
resource *v1.Ingress
}
// onIngressAdded runs when an ingress resource is added to the cluster.
func (c *CaddyController) onIngressAdded(obj *v1.Ingress) {
c.syncQueue.Add(IngressAddedAction{
resource: obj,
})
}
// onIngressUpdated is run when an ingress resource is updated in the cluster.
func (c *CaddyController) onIngressUpdated(old *v1.Ingress, new *v1.Ingress) {
c.syncQueue.Add(IngressUpdatedAction{
resource: new,
oldResource: old,
})
}
// onIngressDeleted is run when an ingress resource is deleted from the cluster.
func (c *CaddyController) onIngressDeleted(obj *v1.Ingress) {
c.syncQueue.Add(IngressDeletedAction{
resource: obj,
})
}
func (r IngressAddedAction) handle(c *CaddyController) error {
c.logger.Infof("Ingress created (%s/%s)", r.resource.Namespace, r.resource.Name)
// add this ingress to the internal store
c.resourceStore.AddIngress(r.resource)
// Ingress may now have a TLS config
return c.watchTLSSecrets()
}
func (r IngressUpdatedAction) handle(c *CaddyController) error {
c.logger.Infof("Ingress updated (%s/%s)", r.resource.Namespace, r.resource.Name)
// add or update this ingress in the internal store
c.resourceStore.AddIngress(r.resource)
// Ingress may now have a TLS config
return c.watchTLSSecrets()
}
func (r IngressDeletedAction) handle(c *CaddyController) error {
c.logger.Infof("Ingress deleted (%s/%s)", r.resource.Namespace, r.resource.Name)
// delete all resources from caddy config that are associated with this resource
c.resourceStore.PluckIngress(r.resource)
return nil
}