Skip to content

Commit

Permalink
fix: restore Gateway API generation (issue #1427). (#1431)
Browse files Browse the repository at this point in the history
* fix: restore Gateway API generation (issue #1427).
Separate integration tests in kong2kic_integration_test.go and must be explicitly invoked with -tags=integration.
Fix tests to evaluate all yaml objects.

* refactor: replace hardcoded strings with constants in KIC components

* fix: remove nolint directive for service port assignment in createIngressPaths

---------

Co-authored-by: Prashansa Kulshrestha <[email protected]>
  • Loading branch information
battlebyte and Prashansa-K committed Dec 17, 2024
1 parent 2cc9261 commit 36a676f
Show file tree
Hide file tree
Showing 18 changed files with 784 additions and 404 deletions.
2 changes: 1 addition & 1 deletion kong2kic/builder_v2_gw_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (b *KICv2GatewayAPIBuilder) buildServices(content *file.Content) {
}

func (b *KICv2GatewayAPIBuilder) buildRoutes(content *file.Content) {
err := populateKICIngressesWithAnnotations(content, b.kicContent)
err := populateKICIngressesWithGatewayAPI(content, b.kicContent)
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion kong2kic/builder_v3_gw_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (b *KICv3GatewayAPIBuider) buildServices(content *file.Content) {
}

func (b *KICv3GatewayAPIBuider) buildRoutes(content *file.Content) {
err := populateKICIngressesWithAnnotations(content, b.kicContent)
err := populateKICIngressesWithGatewayAPI(content, b.kicContent)
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions kong2kic/ca_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func populateKICCACertificate(content *file.Content, file *KICContent) {
continue
}
if caCert.CertDigest != nil {
secret.StringData["ca.digest"] = *caCert.CertDigest
secret.StringData[SecretCADigest] = *caCert.CertDigest
}

// add konghq.com/tags annotation if cacert.Tags is not nil
Expand All @@ -43,7 +43,7 @@ func populateKICCACertificate(content *file.Content, file *KICContent) {
tags = append(tags, *tag)
}
}
secret.ObjectMeta.Annotations["konghq.com/tags"] = strings.Join(tags, ",")
secret.ObjectMeta.Annotations[KongHQTags] = strings.Join(tags, ",")
}

file.Secrets = append(file.Secrets, secret)
Expand Down
2 changes: 1 addition & 1 deletion kong2kic/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func populateKICCertificates(content *file.Content, file *KICContent) {
tags = append(tags, *tag)
}
}
secret.ObjectMeta.Annotations["konghq.com/tags"] = strings.Join(tags, ",")
secret.ObjectMeta.Annotations[KongHQTags] = strings.Join(tags, ",")
}

file.Secrets = append(file.Secrets, secret)
Expand Down
4 changes: 2 additions & 2 deletions kong2kic/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func populateKICConsumers(content *file.Content, file *KICContent) error {
username := *consumer.Username
kongConsumer := configurationv1.KongConsumer{
TypeMeta: metav1.TypeMeta{
APIVersion: KICAPIVersion,
Kind: "KongConsumer",
APIVersion: ConfigurationKongHQv1,
Kind: KongConsumerKind,
},
ObjectMeta: metav1.ObjectMeta{
Name: calculateSlug(username),
Expand Down
4 changes: 2 additions & 2 deletions kong2kic/consumer_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ func createCredentialSecret(consumerUsername, credentialType string, dataFields
stringData := make(map[string]string)
labels := map[string]string{}
if targetKICVersionAPI == KICV3GATEWAY || targetKICVersionAPI == KICV3INGRESS {
labels["konghq.com/credential"] = credentialType
labels[KongHQCredential] = credentialType
} else {
stringData["kongCredType"] = credentialType
stringData[KongCredType] = credentialType
}

// Add the data fields to stringData
Expand Down
8 changes: 4 additions & 4 deletions kong2kic/consumer_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func createConsumerGroupKongPlugin(
pluginName := *plugin.Name
kongPlugin := &configurationv1.KongPlugin{
TypeMeta: metav1.TypeMeta{
APIVersion: "configuration.konghq.com/v1",
Kind: "KongPlugin",
APIVersion: ConfigurationKongHQv1,
Kind: KongPluginKind,
},
ObjectMeta: metav1.ObjectMeta{
Name: calculateSlug(ownerName + "-" + pluginName),
Expand Down Expand Up @@ -55,8 +55,8 @@ func populateKICConsumerGroups(content *file.Content, kicContent *KICContent) er

kongConsumerGroup := configurationv1beta1.KongConsumerGroup{
TypeMeta: metav1.TypeMeta{
APIVersion: "configuration.konghq.com/v1beta1",
Kind: "KongConsumerGroup",
APIVersion: ConfigurationKongHQv1beta1,
Kind: KongConsumerGroupKind,
},
ObjectMeta: metav1.ObjectMeta{
Name: calculateSlug(groupName),
Expand Down
6 changes: 3 additions & 3 deletions kong2kic/global_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func populateKICKongClusterPlugins(content *file.Content, file *KICContent) erro
continue
}
var kongClusterPlugin configurationv1.KongClusterPlugin
kongClusterPlugin.APIVersion = KICAPIVersion
kongClusterPlugin.Kind = "KongClusterPlugin"
kongClusterPlugin.APIVersion = ConfigurationKongHQv1
kongClusterPlugin.Kind = KongClusterPluginKind
kongClusterPlugin.ObjectMeta.Annotations = map[string]string{IngressClass: ClassName}
if plugin.Name != nil {
kongClusterPlugin.PluginName = *plugin.Name
Expand Down Expand Up @@ -65,7 +65,7 @@ func populateKICKongClusterPlugins(content *file.Content, file *KICContent) erro
tags = append(tags, *tag)
}
}
kongClusterPlugin.ObjectMeta.Annotations["konghq.com/tags"] = strings.Join(tags, ",")
kongClusterPlugin.ObjectMeta.Annotations[KongHQTags] = strings.Join(tags, ",")
}

// transform the plugin config from map[string]interface{} to apiextensionsv1.JSON
Expand Down
16 changes: 0 additions & 16 deletions kong2kic/kong2kic.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,6 @@ import (
"github.com/kong/go-database-reconciler/pkg/file"
)

const (
KICV3GATEWAY = "KICV3_GATEWAY"
KICV3INGRESS = "KICV3_INGRESS"
KICV2GATEWAY = "KICV2_GATEWAY"
KICV2INGRESS = "KICV2_INGRESS"
KICAPIVersion = "configuration.konghq.com/v1"
KICAPIVersionV1Beta1 = "configuration.konghq.com/v1beta1"
GatewayAPIVersionV1Beta1 = "gateway.networking.k8s.io/v1beta1"
GatewayAPIVersionV1 = "gateway.networking.k8s.io/v1"
KongPluginKind = "KongPlugin"
SecretKind = "Secret"
IngressKind = "KongIngress"
UpstreamPolicyKind = "KongUpstreamPolicy"
IngressClass = "kubernetes.io/ingress.class"
)

// ClassName is set by the CLI flag --class-name
var ClassName = "kong"

Expand Down
Loading

0 comments on commit 36a676f

Please sign in to comment.