Skip to content

Commit

Permalink
chore: remove deprecated KongIngress functionality (#4760)
Browse files Browse the repository at this point in the history
  • Loading branch information
czeslavo authored Oct 2, 2023
1 parent ace87d0 commit be62bf7
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 648 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ Adding a new version? You'll need three changes:
[#4749](https://github.com/Kong/kubernetes-ingress-controller/pull/4749)
- Removed Knative support.
[#4748](https://github.com/Kong/kubernetes-ingress-controller/pull/4748)
- Removed support for deprecated `KongIngress` fields: `Proxy` and `Route`. Respective
`Service` or `Ingress` annotations should be used instead. See [KIC Annotations reference].
[#4760](https://github.com/Kong/kubernetes-ingress-controller/pull/4760)

### Fixed

Expand All @@ -99,6 +102,8 @@ Adding a new version? You'll need three changes:
it'll be treated as any other label without a special meaning.
[#4737](https://github.com/Kong/kubernetes-ingress-controller/pull/4737)

[KIC Annotations reference]: https://docs.konghq.com/kubernetes-ingress-controller/latest/references/annotations/

## 2.12.0

> Release date: 2023-09-25
Expand Down
4 changes: 2 additions & 2 deletions internal/admission/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ func (h RequestHandler) handleKongIngress(_ context.Context, request admissionv1
responseBuilder = responseBuilder.Allowed(true)

if kongIngress.Proxy != nil {
const warning = "'proxy' is DEPRECATED. Use Service's annotations instead."
const warning = "'proxy' is DEPRECATED. It will have no effect. Use Service's annotations instead."
responseBuilder = responseBuilder.WithWarning(warning)
}

if kongIngress.Route != nil {
const warning = "'route' is DEPRECATED. Use Ingress' annotations instead."
const warning = "'route' is DEPRECATED. It will have no effect. Use Ingress' annotations instead."
responseBuilder = responseBuilder.WithWarning(warning)
}

Expand Down
23 changes: 2 additions & 21 deletions internal/dataplane/kongstate/kongstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,30 +196,11 @@ func (ks *KongState) FillConsumerGroups(_ logrus.FieldLogger, s store.Storer) {
func (ks *KongState) FillOverrides(log logrus.FieldLogger, s store.Storer) {
for i := 0; i < len(ks.Services); i++ {
// Services
kongIngress, err := getKongIngressForServices(s, ks.Services[i].K8sServices)
if err != nil {
log.WithError(err).
Errorf("failed to fetch KongIngress resource for Services %s",
PrettyPrintServiceList(ks.Services[i].K8sServices),
)
continue
}

for _, svc := range ks.Services[i].K8sServices {
ks.Services[i].override(log, kongIngress, svc)
}
ks.Services[i].override()

// Routes
for j := 0; j < len(ks.Services[i].Routes); j++ {
kongIngress, err := getKongIngressFromObjectMeta(s, ks.Services[i].Routes[j].Ingress)
if err != nil {
log.WithFields(logrus.Fields{
"resource_name": ks.Services[i].Routes[j].Ingress.Name,
"resource_namespace": ks.Services[i].Routes[j].Ingress.Namespace,
}).WithError(err).Errorf("failed to fetch KongIngress resource")
}

ks.Services[i].Routes[j].override(log, kongIngress)
ks.Services[i].Routes[j].override(log)
}
}

Expand Down
95 changes: 1 addition & 94 deletions internal/dataplane/kongstate/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import (

"github.com/kong/go-kong/kong"
"github.com/sirupsen/logrus"
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"

"github.com/kong/kubernetes-ingress-controller/v2/internal/annotations"
"github.com/kong/kubernetes-ingress-controller/v2/internal/util"
kongv1 "github.com/kong/kubernetes-ingress-controller/v2/pkg/apis/configuration/v1"
)

// Route represents a Kong Route and holds a reference to the Ingress
Expand Down Expand Up @@ -250,106 +248,15 @@ func (r *Route) overrideByAnnotation(log logrus.FieldLogger) {
}

// override sets Route fields by KongIngress first, then by annotation.
func (r *Route) override(log logrus.FieldLogger, kongIngress *kongv1.KongIngress) {
func (r *Route) override(log logrus.FieldLogger) {
if r == nil {
return
}

// Check if we're trying to get KongIngress configuration based on an annotation
// on Gateway API object (this would most likely happen for *Route objects but
// log a warning for all other Gateway API objects as well since that also should
// not happen) and if that's the case then skip it since those should not be
// affected by said annotation.
if gvk := r.Ingress.GroupVersionKind; gvk.Group == gatewayv1alpha2.GroupName && kongIngress != nil {
log.WithFields(logrus.Fields{
"resource_name": r.Ingress.Name,
"resource_namespace": r.Ingress.Namespace,
"resource_kind": gvk.Kind,
}).Warn("KongIngress annotation is not allowed on Gateway API objects.")
return
}

r.overrideByKongIngress(log, kongIngress)
r.overrideByAnnotation(log)
r.normalizeProtocols()
}

// overrideByKongIngress sets Route fields by KongIngress.
func (r *Route) overrideByKongIngress(log logrus.FieldLogger, kongIngress *kongv1.KongIngress) {
// disable overriding routes by KongIngress if expression routes is enabled.
if r.ExpressionRoutes {
return
}

if kongIngress == nil || kongIngress.Route == nil {
return
}

ir := kongIngress.Route
if len(ir.Methods) != 0 {
invalid := false
var methods []*string
for _, method := range ir.Methods {
sanitizedMethod := strings.TrimSpace(strings.ToUpper(*method))
if validMethods.MatchString(sanitizedMethod) {
methods = append(methods, kong.String(sanitizedMethod))
} else {
// if any method is invalid (not an uppercase alpha string),
// discard everything
log.WithFields(logrus.Fields{
"ingress_namespace": r.Ingress.Namespace,
"ingress_name": r.Ingress.Name,
}).Errorf("ingress contains invalid method: '%v'", *method)
invalid = true
}
}
if !invalid {
r.Methods = methods
}
}
if len(ir.Headers) != 0 {
r.Headers = ir.Headers
}
if len(ir.Protocols) != 0 {
r.Protocols = protocolPointersToStringPointers(ir.Protocols)
}
if ir.RegexPriority != nil {
r.RegexPriority = kong.Int(*ir.RegexPriority)
}
if ir.StripPath != nil {
r.StripPath = kong.Bool(*ir.StripPath)
}
if ir.PreserveHost != nil {
r.PreserveHost = kong.Bool(*ir.PreserveHost)
}
if ir.HTTPSRedirectStatusCode != nil {
r.HTTPSRedirectStatusCode = kong.Int(*ir.HTTPSRedirectStatusCode)
}
if ir.PathHandling != nil {
r.PathHandling = kong.String(*ir.PathHandling)
}
if len(ir.SNIs) != 0 {
var SNIs []*string
for _, unsanitizedSNI := range ir.SNIs {
SNI := strings.TrimSpace(*unsanitizedSNI)
if validSNIs.MatchString(SNI) {
SNIs = append(SNIs, kong.String(SNI))
} else {
// SNI is not a valid hostname
log.WithField("kongroute", r.Name).Errorf("invalid SNI: %v", unsanitizedSNI)
return
}
}
r.SNIs = SNIs
}
if ir.RequestBuffering != nil {
r.RequestBuffering = kong.Bool(*ir.RequestBuffering)
}
if ir.ResponseBuffering != nil {
r.ResponseBuffering = kong.Bool(*ir.ResponseBuffering)
}
}

// overrideRequestBuffering ensures defaults for the request_buffering option.
func (r *Route) overrideRequestBuffering(log logrus.FieldLogger, anns map[string]string) {
annotationValue, ok := annotations.ExtractRequestBuffering(anns)
Expand Down
Loading

0 comments on commit be62bf7

Please sign in to comment.