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
8 changes: 4 additions & 4 deletions internal/dataplane/deckgen/deckgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func GenerateSHA(targetContent *file.Content, customEntities map[string][]custom
}

// GetFCertificateFromKongCert converts a kong.Certificate to a file.FCertificate.
func GetFCertificateFromKongCert(inmemory bool, kongCert kong.Certificate) file.FCertificate {
func GetFCertificateFromKongCert(kongCert kong.Certificate) file.FCertificate {
var res file.FCertificate
if kongCert.ID != nil {
res.ID = kong.String(*kongCert.ID)
Expand All @@ -43,17 +43,17 @@ func GetFCertificateFromKongCert(inmemory bool, kongCert kong.Certificate) file.
if kongCert.Cert != nil {
res.Cert = kong.String(*kongCert.Cert)
}
res.SNIs = getCertsSNIs(inmemory, kongCert)
res.SNIs = getCertsSNIs(kongCert)
return res
}

func getCertsSNIs(inmemory bool, kongCert kong.Certificate) []kong.SNI {
func getCertsSNIs(kongCert kong.Certificate) []kong.SNI {
snis := make([]kong.SNI, 0, len(kongCert.SNIs))
for _, sni := range kongCert.SNIs {
kongSNI := kong.SNI{
Name: sni,
}
if !inmemory && kongCert.ID != nil {
if kongCert.ID != nil {
kongSNI.Certificate = &kong.Certificate{
ID: kongCert.ID,
}
Expand Down
96 changes: 0 additions & 96 deletions internal/dataplane/deckgen/deckgen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,102 +10,6 @@ import (
"github.com/kong/kubernetes-ingress-controller/v3/internal/dataplane/deckgen"
)

func TestGetFCertificateFromKongCert(t *testing.T) {
testCases := []struct {
name string
inmemory bool
cert kong.Certificate
want file.FCertificate
}{
{
name: "empty certificate",
inmemory: false,
cert: kong.Certificate{},
want: file.FCertificate{
SNIs: []kong.SNI{},
},
},
{
name: "all fields set, inmemory=true, SNIs have no certificate ref",
inmemory: true,
cert: kong.Certificate{
ID: kong.String("cert-id"),
Key: kong.String("cert-key"),
Cert: kong.String("cert-pem"),
SNIs: []*string{kong.String("example.com"), kong.String("other.com")},
},
want: file.FCertificate{
ID: kong.String("cert-id"),
Key: kong.String("cert-key"),
Cert: kong.String("cert-pem"),
SNIs: []kong.SNI{
{Name: kong.String("example.com")},
{Name: kong.String("other.com")},
},
},
},
{
name: "all fields set, inmemory=false, SNIs have certificate ref",
inmemory: false,
cert: kong.Certificate{
ID: kong.String("cert-id"),
Key: kong.String("cert-key"),
Cert: kong.String("cert-pem"),
SNIs: []*string{kong.String("example.com")},
},
want: file.FCertificate{
ID: kong.String("cert-id"),
Key: kong.String("cert-key"),
Cert: kong.String("cert-pem"),
SNIs: []kong.SNI{
{
Name: kong.String("example.com"),
Certificate: &kong.Certificate{ID: kong.String("cert-id")},
},
},
},
},
{
name: "nil ID, inmemory=false, SNIs have no certificate ref",
inmemory: false,
cert: kong.Certificate{
Key: kong.String("cert-key"),
Cert: kong.String("cert-pem"),
SNIs: []*string{kong.String("example.com")},
},
want: file.FCertificate{
Key: kong.String("cert-key"),
Cert: kong.String("cert-pem"),
SNIs: []kong.SNI{
{Name: kong.String("example.com")},
},
},
},
{
name: "no SNIs",
inmemory: false,
cert: kong.Certificate{
ID: kong.String("cert-id"),
Key: kong.String("cert-key"),
Cert: kong.String("cert-pem"),
},
want: file.FCertificate{
ID: kong.String("cert-id"),
Key: kong.String("cert-key"),
Cert: kong.String("cert-pem"),
SNIs: []kong.SNI{},
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := deckgen.GetFCertificateFromKongCert(tc.inmemory, tc.cert)
require.Equal(t, tc.want, got)
})
}
}

func TestIsContentEmpty(t *testing.T) {
testCases := []struct {
name string
Expand Down
7 changes: 1 addition & 6 deletions internal/dataplane/deckgen/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ type GenerateDeckContentParams struct {
// the configuration is empty. It is used to workaround behavior in Kong where sending an empty configuration
// does not make its `GET /status/ready` endpoint return 200s.
AppendStubEntityWhenConfigEmpty bool

// InMemory indicates whether the generated deck content is intended to be used in-memory.
// This is used to determine whether to include certain fields in the generated content
// that are not relevant for in-memory use but are required for db based / konnect configurations.
InMemory bool
}

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

for _, c := range k8sState.Certificates {
cert := GetFCertificateFromKongCert(params.InMemory, c.Certificate)
cert := GetFCertificateFromKongCert(c.Certificate)
content.Certificates = append(content.Certificates, cert)
}
sort.SliceStable(content.Certificates, func(i, j int) bool {
Expand Down
1 change: 0 additions & 1 deletion internal/dataplane/kong_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,6 @@ func (c *KongClient) sendToClient(
ExpressionRoutes: config.ExpressionRoutes,
PluginSchemas: client.PluginSchemaStore(),
AppendStubEntityWhenConfigEmpty: config.InMemory,
InMemory: config.InMemory,
}
targetContent := deckgen.ToDeckContent(ctx, logger, s, deckGenParams)
customEntities := make(sendconfig.CustomEntitiesByType)
Expand Down
2 changes: 1 addition & 1 deletion internal/dataplane/kong_client_golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func runKongClientGoldenTest(t *testing.T, tc kongClientGoldenTestCase) {
// Create the translator.
logger := zapr.NewLogger(zap.NewNop())
s := store.New(cacheStores, "kong", logger)
p, err := translator.NewTranslator(logger, s, "", semver.MustParse("3.12.0"), tc.featureFlags, fakeSchemaServiceProvier{},
p, err := translator.NewTranslator(logger, s, "", semver.MustParse("3.9.1"), tc.featureFlags, fakeSchemaServiceProvier{},
translator.Config{
ClusterDomain: consts.DefaultClusterDomain,
EnableDrainSupport: consts.DefaultEnableDrainSupport,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ certificates:
5GTyl7XJmyY/
-----END PRIVATE KEY-----
snis:
- name: 1.example.com
- name: 2.example.com
- certificate:
id: c6ac927c-4f5a-4e88-8b5d-c7b01d0f43af
name: 1.example.com
- certificate:
id: c6ac927c-4f5a-4e88-8b5d-c7b01d0f43af
name: 2.example.com
consumers:
- basicauth_credentials:
- password: consumer-1-password
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ certificates:
5GTyl7XJmyY/
-----END PRIVATE KEY-----
snis:
- name: 1.example.com
- name: 2.example.com
- certificate:
id: c6ac927c-4f5a-4e88-8b5d-c7b01d0f43af
name: 1.example.com
- certificate:
id: c6ac927c-4f5a-4e88-8b5d-c7b01d0f43af
name: 2.example.com
consumers:
- basicauth_credentials:
- password: consumer-1-password
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ certificates:
7InkkRoDnTrU3Ro=
-----END PRIVATE KEY-----
snis:
- name: 3.example.com
- name: 4.example.com
- certificate:
id: 8aade13c-1470-46bd-9849-9a74e349214f
name: 3.example.com
- certificate:
id: 8aade13c-1470-46bd-9849-9a74e349214f
name: 4.example.com
- cert: |-
-----BEGIN CERTIFICATE-----
MIIBoTCCAQoCCQC/V5OfTXu7xDANBgkqhkiG9w0BAQsFADAVMRMwEQYDVQQDDApr
Expand Down Expand Up @@ -64,8 +68,12 @@ certificates:
5GTyl7XJmyY/
-----END PRIVATE KEY-----
snis:
- name: 1.example.com
- name: 2.example.com
- certificate:
id: c6ac927c-4f5a-4e88-8b5d-c7b01d0f43af
name: 1.example.com
- certificate:
id: c6ac927c-4f5a-4e88-8b5d-c7b01d0f43af
name: 2.example.com
services:
- connect_timeout: 60000
host: foo-svc.bar-namespace.80.svc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ certificates:
7InkkRoDnTrU3Ro=
-----END PRIVATE KEY-----
snis:
- name: 3.example.com
- name: 4.example.com
- certificate:
id: 8aade13c-1470-46bd-9849-9a74e349214f
name: 3.example.com
- certificate:
id: 8aade13c-1470-46bd-9849-9a74e349214f
name: 4.example.com
- cert: |-
-----BEGIN CERTIFICATE-----
MIIBoTCCAQoCCQC/V5OfTXu7xDANBgkqhkiG9w0BAQsFADAVMRMwEQYDVQQDDApr
Expand Down Expand Up @@ -64,8 +68,12 @@ certificates:
5GTyl7XJmyY/
-----END PRIVATE KEY-----
snis:
- name: 1.example.com
- name: 2.example.com
- certificate:
id: c6ac927c-4f5a-4e88-8b5d-c7b01d0f43af
name: 1.example.com
- certificate:
id: c6ac927c-4f5a-4e88-8b5d-c7b01d0f43af
name: 2.example.com
services:
- connect_timeout: 60000
host: foo-svc.bar-namespace.80.svc
Expand Down
Loading