Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
battlebyte committed Sep 20, 2023
1 parent 1254c4a commit be60710
Showing 1 changed file with 58 additions and 28 deletions.
86 changes: 58 additions & 28 deletions file/kong2kic.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,38 @@ func newCustomResourceBuilder() *CustomResourceBuilder {
}

func (b *CustomResourceBuilder) buildServices(content *Content) {
populateKICServicesWithCustomResources(content, b.kicContent)
err := populateKICServicesWithCustomResources(content, b.kicContent)
if err != nil {
log.Fatal(err)
}
}

func (b *CustomResourceBuilder) buildRoutes(content *Content) {
populateKICIngressesWithCustomResources(content, b.kicContent)
err := populateKICIngressesWithCustomResources(content, b.kicContent)
if err != nil {
log.Fatal(err)
}
}

func (b *CustomResourceBuilder) buildGlobalPlugins(content *Content) {
populateKICKongClusterPlugins(content, b.kicContent)
err := populateKICKongClusterPlugins(content, b.kicContent)
if err != nil {
log.Fatal(err)
}
}

func (b *CustomResourceBuilder) buildConsumers(content *Content) {
populateKICConsumers(content, b.kicContent)
err := populateKICConsumers(content, b.kicContent)
if err != nil {
log.Fatal(err)
}
}

func (b *CustomResourceBuilder) buildConsumerGroups(content *Content) {
populateKICConsumerGroups(content, b.kicContent)
err := populateKICConsumerGroups(content, b.kicContent)
if err != nil {
log.Fatal(err)
}
}

func (b *CustomResourceBuilder) getContent() *KICContent {
Expand All @@ -93,23 +108,38 @@ func newAnnotationsBuilder() *AnnotationsBuilder {
}

func (b *AnnotationsBuilder) buildServices(content *Content) {
populateKICServicesWithAnnotations(content, b.kicContent)
err := populateKICServicesWithAnnotations(content, b.kicContent)
if err != nil {
log.Fatal(err)
}
}

func (b *AnnotationsBuilder) buildRoutes(content *Content) {
populateKICIngressesWithAnnotations(content, b.kicContent)
err := populateKICIngressesWithAnnotations(content, b.kicContent)
if err != nil {
log.Fatal(err)
}
}

func (b *AnnotationsBuilder) buildGlobalPlugins(content *Content) {
populateKICKongClusterPlugins(content, b.kicContent)
err := populateKICKongClusterPlugins(content, b.kicContent)
if err != nil {
log.Fatal(err)
}
}

func (b *AnnotationsBuilder) buildConsumers(content *Content) {
populateKICConsumers(content, b.kicContent)
err := populateKICConsumers(content, b.kicContent)
if err != nil {
log.Fatal(err)
}
}

func (b *AnnotationsBuilder) buildConsumerGroups(content *Content) {
populateKICConsumerGroups(content, b.kicContent)
err := populateKICConsumerGroups(content, b.kicContent)
if err != nil {
log.Fatal(err)
}
}

func (b *AnnotationsBuilder) getContent() *KICContent {
Expand Down Expand Up @@ -140,20 +170,20 @@ func (d *Director) buildManifests(content *Content) *KICContent {
////////////////////

func MarshalKongToKICYaml(content *Content, builderType string) ([]byte, error) {
kicContent, _ := convertKongToKIC(content, builderType)
kicContent := convertKongToKIC(content, builderType)
return kicContent.marshalKICContentToYaml()
}

func MarshalKongToKICJson(content *Content, builderType string) ([]byte, error) {
kicContent, _ := convertKongToKIC(content, builderType)
kicContent := convertKongToKIC(content, builderType)
return kicContent.marshalKICContentToJson()

Check failure on line 180 in file/kong2kic.go

View workflow job for this annotation

GitHub Actions / test

File is not `gofumpt`-ed (gofumpt)
}

func convertKongToKIC(content *Content, builderType string) (*KICContent, error) {
func convertKongToKIC(content *Content, builderType string) (*KICContent) {

Check failure on line 183 in file/kong2kic.go

View workflow job for this annotation

GitHub Actions / test

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
builder := getBuilder(builderType)
director := newDirector(builder)
return director.buildManifests(content), nil
return director.buildManifests(content)
}

/////
Expand Down Expand Up @@ -491,7 +521,7 @@ func populateKICUpstream(content *Content, service *FService, k8sservice *k8scor
}
}

func addPluginsToService(service FService, k8sService k8scorev1.Service, kicContent *KICContent) (bool, error) {
func addPluginsToService(service FService, k8sService k8scorev1.Service, kicContent *KICContent) error {

Check failure on line 524 in file/kong2kic.go

View workflow job for this annotation

GitHub Actions / test

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
for _, plugin := range service.Plugins {
var kongPlugin kicv1.KongPlugin
kongPlugin.APIVersion = "configuration.konghq.com/v1"
Expand All @@ -506,18 +536,18 @@ func addPluginsToService(service FService, k8sService k8scorev1.Service, kicCont
var err error
configJSON.Raw, err = json.Marshal(plugin.Config)
if err != nil {
return true, err
return err
}
kongPlugin.Config = configJSON

k8sService.ObjectMeta.Annotations["konghq.com/plugins"] = kongPlugin.ObjectMeta.Name

kicContent.KongPlugins = append(kicContent.KongPlugins, kongPlugin)
}
return false, nil
return nil
}

func addPluginsToRoute(route *FRoute, routeIngresses []k8snetv1.Ingress, kicContent *KICContent) (bool, error) {
func addPluginsToRoute(route *FRoute, routeIngresses []k8snetv1.Ingress, kicContent *KICContent) error {
for _, plugin := range route.Plugins {
var kongPlugin kicv1.KongPlugin
kongPlugin.APIVersion = "configuration.konghq.com/v1"
Expand All @@ -532,7 +562,7 @@ func addPluginsToRoute(route *FRoute, routeIngresses []k8snetv1.Ingress, kicCont
var err error
configJSON.Raw, err = json.Marshal(plugin.Config)
if err != nil {
return true, err
return err
}
kongPlugin.Config = configJSON

Expand All @@ -546,7 +576,7 @@ func addPluginsToRoute(route *FRoute, routeIngresses []k8snetv1.Ingress, kicCont

kicContent.KongPlugins = append(kicContent.KongPlugins, kongPlugin)
}
return false, nil
return nil
}

func fillIngressHostAndPortSection(host *string, service FService, k8sIngress *k8snetv1.Ingress, path *string, pathTypeImplSpecific k8snetv1.PathType) {
Expand Down Expand Up @@ -785,8 +815,8 @@ func populateKICServicesWithCustomResources(content *Content, kicContent *KICCon
// iterate over the plugins for this service, create a KongPlugin for each one and add an annotation to the service
// transform the plugin config from map[string]interface{} to apiextensionsv1.JSON
// create a plugins annotation in the k8sservice to link the plugin to it
shouldReturn, error := addPluginsToService(service, k8sService, kicContent)
if shouldReturn {
error := addPluginsToService(service, k8sService, kicContent)

Check warning on line 818 in file/kong2kic.go

View workflow job for this annotation

GitHub Actions / test

redefines-builtin-id: redefinition of the built-in type error (revive)
if error != nil {
return error
}
kicContent.Services = append(kicContent.Services, k8sService)
Expand Down Expand Up @@ -821,8 +851,8 @@ func populateKICIngressesWithCustomResources(content *Content, kicContent *KICCo
// transform the plugin config from map[string]interface{} to apiextensionsv1.JSON
// create a plugins annotation in the routeIngresses to link them to this plugin.
// separate plugins with commas
shouldReturn, error := addPluginsToRoute(route, routeIngresses, kicContent)
if shouldReturn {
error := addPluginsToRoute(route, routeIngresses, kicContent)

Check warning on line 854 in file/kong2kic.go

View workflow job for this annotation

GitHub Actions / test

redefines-builtin-id: redefinition of the built-in type error (revive)
if error != nil {
return error
}
}
Expand Down Expand Up @@ -963,8 +993,8 @@ func populateKICServicesWithAnnotations(content *Content, kicContent *KICContent
// iterate over the plugins for this service, create a KongPlugin for each one and add an annotation to the service
// transform the plugin config from map[string]interface{} to apiextensionsv1.JSON
// create a plugins annotation in the k8sservice to link the plugin to it
shouldReturn, error := addPluginsToService(service, k8sService, kicContent)
if shouldReturn {
error := addPluginsToService(service, k8sService, kicContent)

Check warning on line 996 in file/kong2kic.go

View workflow job for this annotation

GitHub Actions / test

redefines-builtin-id: redefinition of the built-in type error (revive)
if error != nil {
return error
}

Expand Down Expand Up @@ -1000,8 +1030,8 @@ func populateKICIngressesWithAnnotations(content *Content, kicContent *KICConten
// transform the plugin config from map[string]interface{} to apiextensionsv1.JSON
// create a plugins annotation in the routeIngresses to link them to this plugin.
// separate plugins with commas
shouldReturn, error := addPluginsToRoute(route, routeIngresses, kicContent)
if shouldReturn {
error := addPluginsToRoute(route, routeIngresses, kicContent)
if error != nil {
return error
}
}
Expand Down

0 comments on commit be60710

Please sign in to comment.