Skip to content

Commit

Permalink
chore: deprecate KongIngress entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
czeslavo committed Oct 30, 2023
1 parent 513db87 commit 317459c
Show file tree
Hide file tree
Showing 33 changed files with 137 additions and 717 deletions.
11 changes: 10 additions & 1 deletion config/crd/bases/configuration.konghq.com_kongingresses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ spec:
- name: v1
schema:
openAPIV3Schema:
description: KongIngress is the Schema for the kongingresses API.
description: 'KongIngress is the Schema for the kongingresses API. Deprecated:
use Service''s annotations, Ingress''s annotations, or KongUpstreamPolicy
instead.'
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand Down Expand Up @@ -351,6 +353,13 @@ spec:
type: integer
type: object
type: object
x-kubernetes-validations:
- message: '''proxy'' field is no longer supported, use Service''s annotations
instead'
rule: '!has(self.proxy)'
- message: '''route'' field is no longer supported, use Ingress'' annotations
instead'
rule: '!has(self.route)'
served: true
storage: true
subresources:
Expand Down
4 changes: 2 additions & 2 deletions docs/api-reference.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion docs/cli-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
| `--enable-controller-kong-upstream-policy` | `bool` | Enable the KongUpstreamPolicy controller. | `true` |
| `--enable-controller-kongclusterplugin` | `bool` | Enable the KongClusterPlugin controller. | `true` |
| `--enable-controller-kongconsumer` | `bool` | Enable the KongConsumer controller. | `true` |
| `--enable-controller-kongingress` | `bool` | Enable the KongIngress controller. | `true` |
| `--enable-controller-kongplugin` | `bool` | Enable the KongPlugin controller. | `true` |
| `--enable-controller-service` | `bool` | Enable the Service controller. | `true` |
| `--enable-controller-tcpingress` | `bool` | Enable the TCPIngress controller. | `true` |
Expand Down
14 changes: 0 additions & 14 deletions hack/generators/controllers/networking/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,6 @@ var inputControllersNeeded = &typesNeeded{
AcceptsIngressClassNameSpec: false,
RBACVerbs: []string{"get", "list", "watch"},
},
typeNeeded{
Group: "configuration.konghq.com",
Version: "v1",
Kind: "KongIngress",
PackageImportAlias: "kongv1",
PackageAlias: "KongV1",
Package: kongv1,
Plural: "kongingresses",
CacheType: "KongIngress",
NeedsStatusPermissions: true,
AcceptsIngressClassNameAnnotation: false,
AcceptsIngressClassNameSpec: false,
RBACVerbs: []string{"get", "list", "watch"},
},
typeNeeded{
Group: "configuration.konghq.com",
Version: "v1beta1",
Expand Down
10 changes: 4 additions & 6 deletions internal/admission/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,14 @@ func (h RequestHandler) handleKongIngress(_ context.Context, request admissionv1
// KongIngress is always allowed.
responseBuilder = responseBuilder.Allowed(true)

if kongIngress.Proxy != nil {
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. It will have no effect. Use Ingress' annotations instead."
const warning = "'upstream' is DEPRECATED. It will have no effect. Use KongUpstreamPolicy instead."
responseBuilder = responseBuilder.WithWarning(warning)
}

// Both Service and Route are required to be absent on the API server CRD validations level so we don't need to
// check for them here.

return responseBuilder.Build(), nil
}

Expand Down
6 changes: 0 additions & 6 deletions internal/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,6 @@ func ExtractKongPluginsFromAnnotations(anns map[string]string) []string {
return kongPluginCRs
}

// ExtractConfigurationName extracts the name of the KongIngress object that holds
// information about the configuration to use in Routes, Services and Upstreams.
func ExtractConfigurationName(anns map[string]string) string {
return anns[AnnotationPrefix+ConfigurationKey]
}

// ExtractProtocolName extracts the protocol supplied in the annotation.
func ExtractProtocolName(anns map[string]string) string {
return anns[AnnotationPrefix+ProtocolKey]
Expand Down
28 changes: 0 additions & 28 deletions internal/annotations/annotations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,34 +157,6 @@ func TestExtractKongPluginsFromAnnotations(t *testing.T) {
}
}

func TestExtractConfigurationName(t *testing.T) {
type args struct {
anns map[string]string
}
tests := []struct {
name string
args args
want string
}{
{
name: "non-empty",
args: args{
anns: map[string]string{
"konghq.com/override": "foo",
},
},
want: "foo",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ExtractConfigurationName(tt.args.anns); got != tt.want {
t.Errorf("ExtractConfigurationName() = %v, want %v", got, tt.want)
}
})
}
}

func TestExtractProtocolName(t *testing.T) {
type args struct {
anns map[string]string
Expand Down
85 changes: 0 additions & 85 deletions internal/controllers/configuration/zz_generated_controllers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 2 additions & 9 deletions internal/dataplane/kongstate/kongstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (ks *KongState) FillConsumerGroups(_ logr.Logger, s store.Storer) {
}
}

func (ks *KongState) FillOverrides(logger logr.Logger, s store.Storer) {
func (ks *KongState) FillOverrides(logger logr.Logger) {
for i := 0; i < len(ks.Services); i++ {
// Services
ks.Services[i].override()
Expand All @@ -198,15 +198,8 @@ func (ks *KongState) FillOverrides(logger logr.Logger, s store.Storer) {

// Upstreams
for i := 0; i < len(ks.Upstreams); i++ {
kongIngress, err := getKongIngressForServices(s, ks.Upstreams[i].Service.K8sServices)
if err != nil {
logger.Error(err, "failed to fetch KongIngress resource for Services",
"names", PrettyPrintServiceList(ks.Upstreams[i].Service.K8sServices))
continue
}

for _, svc := range ks.Upstreams[i].Service.K8sServices {
ks.Upstreams[i].override(kongIngress, svc)
ks.Upstreams[i].override(svc)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/dataplane/kongstate/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (r *Route) overrideByAnnotation(logger logr.Logger) {
}
}

// override sets Route fields by KongIngress first, then by annotation.
// override sets Route fields using annotations.
func (r *Route) override(logger logr.Logger) {
if r == nil {
return
Expand Down
2 changes: 1 addition & 1 deletion internal/dataplane/kongstate/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func TestNormalizeProtocols(t *testing.T) {

assert.NotPanics(func() {
var nilUpstream *Upstream
nilUpstream.override(nil, nil)
nilUpstream.override(nil)
})
}

Expand Down
82 changes: 3 additions & 79 deletions internal/dataplane/kongstate/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package kongstate
import (
"github.com/kong/go-kong/kong"
corev1 "k8s.io/api/core/v1"
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"

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

// Upstream is a wrapper around Upstream object in Kong.
Expand Down Expand Up @@ -37,87 +35,13 @@ func (u *Upstream) overrideByAnnotation(anns map[string]string) {
u.overrideHostHeader(anns)
}

// overrideByKongIngress modifies the Kong upstream based on KongIngresses
// associated with the Kubernetes service.
func (u *Upstream) overrideByKongIngress(kongIngress *kongv1.KongIngress) {
if u == nil {
return
}

if kongIngress == nil || kongIngress.Upstream == nil {
return
}
k := kongIngress.Upstream
if k.HostHeader != nil {
u.HostHeader = kong.String(*k.HostHeader)
}
if k.Algorithm != nil {
u.Algorithm = kong.String(*k.Algorithm)
}
if k.Slots != nil {
u.Slots = kong.Int(*k.Slots)
}
if k.Healthchecks != nil {
u.Healthchecks = k.Healthchecks
}
if k.HashOn != nil {
u.HashOn = kong.String(*k.HashOn)
}
if k.HashFallback != nil {
u.HashFallback = kong.String(*k.HashFallback)
}
if k.HashOnHeader != nil {
u.HashOnHeader = kong.String(*k.HashOnHeader)
}
if k.HashFallbackHeader != nil {
u.HashFallbackHeader = kong.String(*k.HashFallbackHeader)
}
if k.HashOnCookie != nil {
u.HashOnCookie = kong.String(*k.HashOnCookie)
}
if k.HashOnCookiePath != nil {
u.HashOnCookiePath = kong.String(*k.HashOnCookiePath)
}
if k.HashOnQueryArg != nil {
u.HashOnQueryArg = kong.String(*k.HashOnQueryArg)
}
if k.HashFallbackQueryArg != nil {
u.HashFallbackQueryArg = kong.String(*k.HashFallbackQueryArg)
}
if k.HashOnURICapture != nil {
u.HashOnURICapture = kong.String(*k.HashOnURICapture)
}
if k.HashFallbackURICapture != nil {
u.HashFallbackURICapture = kong.String(*k.HashFallbackURICapture)
}
}

// override sets Upstream fields by KongIngress first, then by k8s Service's annotations.
// override sets Upstream using k8s Service's annotations.
func (u *Upstream) override(
kongIngress *kongv1.KongIngress,
svc *corev1.Service,
) {
if u == nil {
if u == nil || svc == nil {
return
}

if u.Service.Parent != nil && kongIngress != nil {
// If the parent object behind Kong Upstream's is a Gateway API object
// (probably *Route) then check if we're trying to override said Service
// configuration with a KongIngress object and if that's the case then
// skip it since those should not be affected.
gvk := u.Service.Parent.GetObjectKind().GroupVersionKind()
if gvk.Group == gatewayv1alpha2.GroupName {
// No log needed here as there will be one issued already from Kong's
// Service override. The reason for this is that there is no other
// object in Kubernetes that creates a Kong's Upstream and Kubernetes
// Service will already trigger Kong's Service creation and log issuance.
return
}
}

u.overrideByKongIngress(kongIngress)
if svc != nil {
u.overrideByAnnotation(svc.Annotations)
}
u.overrideByAnnotation(svc.Annotations)
}
Loading

0 comments on commit 317459c

Please sign in to comment.