Skip to content

Commit b8f95a8

Browse files
team-k8s-botpmalek
andauthored
Revert "fix: fix generating SNIs in dbless (#7853)" (#7872) (#7873)
This reverts commit 18c1423. (cherry picked from commit a5878ae) Co-authored-by: Patryk Małek <pmalek@users.noreply.github.com>
1 parent f6eaa97 commit b8f95a8

11 files changed

Lines changed: 42 additions & 120 deletions

File tree

internal/dataplane/deckgen/deckgen.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func GenerateSHA(targetContent *file.Content, customEntities map[string][]custom
3232
}
3333

3434
// GetFCertificateFromKongCert converts a kong.Certificate to a file.FCertificate.
35-
func GetFCertificateFromKongCert(inmemory bool, kongCert kong.Certificate) file.FCertificate {
35+
func GetFCertificateFromKongCert(kongCert kong.Certificate) file.FCertificate {
3636
var res file.FCertificate
3737
if kongCert.ID != nil {
3838
res.ID = kong.String(*kongCert.ID)
@@ -43,17 +43,17 @@ func GetFCertificateFromKongCert(inmemory bool, kongCert kong.Certificate) file.
4343
if kongCert.Cert != nil {
4444
res.Cert = kong.String(*kongCert.Cert)
4545
}
46-
res.SNIs = getCertsSNIs(inmemory, kongCert)
46+
res.SNIs = getCertsSNIs(kongCert)
4747
return res
4848
}
4949

50-
func getCertsSNIs(inmemory bool, kongCert kong.Certificate) []kong.SNI {
50+
func getCertsSNIs(kongCert kong.Certificate) []kong.SNI {
5151
snis := make([]kong.SNI, 0, len(kongCert.SNIs))
5252
for _, sni := range kongCert.SNIs {
5353
kongSNI := kong.SNI{
5454
Name: sni,
5555
}
56-
if !inmemory && kongCert.ID != nil {
56+
if kongCert.ID != nil {
5757
kongSNI.Certificate = &kong.Certificate{
5858
ID: kongCert.ID,
5959
}

internal/dataplane/deckgen/deckgen_test.go

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -10,102 +10,6 @@ import (
1010
"github.com/kong/kubernetes-ingress-controller/v3/internal/dataplane/deckgen"
1111
)
1212

13-
func TestGetFCertificateFromKongCert(t *testing.T) {
14-
testCases := []struct {
15-
name string
16-
inmemory bool
17-
cert kong.Certificate
18-
want file.FCertificate
19-
}{
20-
{
21-
name: "empty certificate",
22-
inmemory: false,
23-
cert: kong.Certificate{},
24-
want: file.FCertificate{
25-
SNIs: []kong.SNI{},
26-
},
27-
},
28-
{
29-
name: "all fields set, inmemory=true, SNIs have no certificate ref",
30-
inmemory: true,
31-
cert: kong.Certificate{
32-
ID: kong.String("cert-id"),
33-
Key: kong.String("cert-key"),
34-
Cert: kong.String("cert-pem"),
35-
SNIs: []*string{kong.String("example.com"), kong.String("other.com")},
36-
},
37-
want: file.FCertificate{
38-
ID: kong.String("cert-id"),
39-
Key: kong.String("cert-key"),
40-
Cert: kong.String("cert-pem"),
41-
SNIs: []kong.SNI{
42-
{Name: kong.String("example.com")},
43-
{Name: kong.String("other.com")},
44-
},
45-
},
46-
},
47-
{
48-
name: "all fields set, inmemory=false, SNIs have certificate ref",
49-
inmemory: false,
50-
cert: kong.Certificate{
51-
ID: kong.String("cert-id"),
52-
Key: kong.String("cert-key"),
53-
Cert: kong.String("cert-pem"),
54-
SNIs: []*string{kong.String("example.com")},
55-
},
56-
want: file.FCertificate{
57-
ID: kong.String("cert-id"),
58-
Key: kong.String("cert-key"),
59-
Cert: kong.String("cert-pem"),
60-
SNIs: []kong.SNI{
61-
{
62-
Name: kong.String("example.com"),
63-
Certificate: &kong.Certificate{ID: kong.String("cert-id")},
64-
},
65-
},
66-
},
67-
},
68-
{
69-
name: "nil ID, inmemory=false, SNIs have no certificate ref",
70-
inmemory: false,
71-
cert: kong.Certificate{
72-
Key: kong.String("cert-key"),
73-
Cert: kong.String("cert-pem"),
74-
SNIs: []*string{kong.String("example.com")},
75-
},
76-
want: file.FCertificate{
77-
Key: kong.String("cert-key"),
78-
Cert: kong.String("cert-pem"),
79-
SNIs: []kong.SNI{
80-
{Name: kong.String("example.com")},
81-
},
82-
},
83-
},
84-
{
85-
name: "no SNIs",
86-
inmemory: false,
87-
cert: kong.Certificate{
88-
ID: kong.String("cert-id"),
89-
Key: kong.String("cert-key"),
90-
Cert: kong.String("cert-pem"),
91-
},
92-
want: file.FCertificate{
93-
ID: kong.String("cert-id"),
94-
Key: kong.String("cert-key"),
95-
Cert: kong.String("cert-pem"),
96-
SNIs: []kong.SNI{},
97-
},
98-
},
99-
}
100-
101-
for _, tc := range testCases {
102-
t.Run(tc.name, func(t *testing.T) {
103-
got := deckgen.GetFCertificateFromKongCert(tc.inmemory, tc.cert)
104-
require.Equal(t, tc.want, got)
105-
})
106-
}
107-
}
108-
10913
func TestIsContentEmpty(t *testing.T) {
11014
testCases := []struct {
11115
name string

internal/dataplane/deckgen/generate.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ type GenerateDeckContentParams struct {
3232
// the configuration is empty. It is used to workaround behavior in Kong where sending an empty configuration
3333
// does not make its `GET /status/ready` endpoint return 200s.
3434
AppendStubEntityWhenConfigEmpty bool
35-
36-
// InMemory indicates whether the generated deck content is intended to be used in-memory.
37-
// This is used to determine whether to include certain fields in the generated content
38-
// that are not relevant for in-memory use but are required for db based / konnect configurations.
39-
InMemory bool
4035
}
4136

4237
// ToDeckContent generates a decK configuration from `k8sState` and auxiliary parameters.
@@ -130,7 +125,7 @@ func ToDeckContent(
130125
})
131126

132127
for _, c := range k8sState.Certificates {
133-
cert := GetFCertificateFromKongCert(params.InMemory, c.Certificate)
128+
cert := GetFCertificateFromKongCert(c.Certificate)
134129
content.Certificates = append(content.Certificates, cert)
135130
}
136131
sort.SliceStable(content.Certificates, func(i, j int) bool {

internal/dataplane/kong_client.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,6 @@ func (c *KongClient) sendToClient(
794794
ExpressionRoutes: config.ExpressionRoutes,
795795
PluginSchemas: client.PluginSchemaStore(),
796796
AppendStubEntityWhenConfigEmpty: config.InMemory,
797-
InMemory: config.InMemory,
798797
}
799798
targetContent := deckgen.ToDeckContent(ctx, logger, s, deckGenParams)
800799
customEntities := make(sendconfig.CustomEntitiesByType)

internal/dataplane/kong_client_golden_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func runKongClientGoldenTest(t *testing.T, tc kongClientGoldenTestCase) {
262262
// Create the translator.
263263
logger := zapr.NewLogger(zap.NewNop())
264264
s := store.New(cacheStores, "kong", logger)
265-
p, err := translator.NewTranslator(logger, s, "", semver.MustParse("3.12.0"), tc.featureFlags, fakeSchemaServiceProvier{},
265+
p, err := translator.NewTranslator(logger, s, "", semver.MustParse("3.9.1"), tc.featureFlags, fakeSchemaServiceProvier{},
266266
translator.Config{
267267
ClusterDomain: consts.DefaultClusterDomain,
268268
EnableDrainSupport: consts.DefaultEnableDrainSupport,

internal/dataplane/testdata/golden/ingress-v1-rule-with-tls-and-consumer-ee/default_golden.yaml renamed to internal/dataplane/testdata/golden/ingress-v1-rule-with-tls-and-consumer/default_golden.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ certificates:
3131
5GTyl7XJmyY/
3232
-----END PRIVATE KEY-----
3333
snis:
34-
- name: 1.example.com
35-
- name: 2.example.com
34+
- certificate:
35+
id: c6ac927c-4f5a-4e88-8b5d-c7b01d0f43af
36+
name: 1.example.com
37+
- certificate:
38+
id: c6ac927c-4f5a-4e88-8b5d-c7b01d0f43af
39+
name: 2.example.com
3640
consumers:
3741
- basicauth_credentials:
3842
- password: consumer-1-password

internal/dataplane/testdata/golden/ingress-v1-rule-with-tls-and-consumer-ee/expression-routes-on_golden.yaml renamed to internal/dataplane/testdata/golden/ingress-v1-rule-with-tls-and-consumer/expression-routes-on_golden.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ certificates:
3131
5GTyl7XJmyY/
3232
-----END PRIVATE KEY-----
3333
snis:
34-
- name: 1.example.com
35-
- name: 2.example.com
34+
- certificate:
35+
id: c6ac927c-4f5a-4e88-8b5d-c7b01d0f43af
36+
name: 1.example.com
37+
- certificate:
38+
id: c6ac927c-4f5a-4e88-8b5d-c7b01d0f43af
39+
name: 2.example.com
3640
consumers:
3741
- basicauth_credentials:
3842
- password: consumer-1-password

internal/dataplane/testdata/golden/ingress-v1-rule-with-tls-and-consumer-ee/expression-routes-on_settings.yaml renamed to internal/dataplane/testdata/golden/ingress-v1-rule-with-tls-and-consumer/expression-routes-on_settings.yaml

File renamed without changes.

internal/dataplane/testdata/golden/ingress-v1-rule-with-tls-and-consumer-ee/in.yaml renamed to internal/dataplane/testdata/golden/ingress-v1-rule-with-tls-and-consumer/in.yaml

File renamed without changes.

internal/dataplane/testdata/golden/ingress-v1-rule-with-tls/default_golden.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ certificates:
3131
7InkkRoDnTrU3Ro=
3232
-----END PRIVATE KEY-----
3333
snis:
34-
- name: 3.example.com
35-
- name: 4.example.com
34+
- certificate:
35+
id: 8aade13c-1470-46bd-9849-9a74e349214f
36+
name: 3.example.com
37+
- certificate:
38+
id: 8aade13c-1470-46bd-9849-9a74e349214f
39+
name: 4.example.com
3640
- cert: |-
3741
-----BEGIN CERTIFICATE-----
3842
MIIBoTCCAQoCCQC/V5OfTXu7xDANBgkqhkiG9w0BAQsFADAVMRMwEQYDVQQDDApr
@@ -64,8 +68,12 @@ certificates:
6468
5GTyl7XJmyY/
6569
-----END PRIVATE KEY-----
6670
snis:
67-
- name: 1.example.com
68-
- name: 2.example.com
71+
- certificate:
72+
id: c6ac927c-4f5a-4e88-8b5d-c7b01d0f43af
73+
name: 1.example.com
74+
- certificate:
75+
id: c6ac927c-4f5a-4e88-8b5d-c7b01d0f43af
76+
name: 2.example.com
6977
services:
7078
- connect_timeout: 60000
7179
host: foo-svc.bar-namespace.80.svc

0 commit comments

Comments
 (0)