Skip to content

Commit

Permalink
kc -> configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
programmer04 committed Nov 26, 2024
1 parent 2b95712 commit 96990b8
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 161 deletions.
199 changes: 99 additions & 100 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,120 +1,119 @@
run:
timeout: 10m
build-tags:
- integration
- integration
linters:
enable:
- asciicheck
- dogsled
- durationcheck
- exhaustive
- copyloopvar
- gci
- goconst
- gofmt
- gofumpt
- goimports
- gomodguard
- gosec
- govet
- importas
- lll
- gosimple
- staticcheck
- unused
- misspell
- nakedret
- nilerr
- nolintlint
- predeclared
- prealloc
- revive
- stylecheck
- unconvert
- unparam
- wastedassign
- errorlint
issues:
max-same-issues: 0
exclude-rules:
- linters:
- gosec
text: "weak cryptographic primitive"
path: "state/indexers/md5Indexer.*"
- linters:
- gosec
text: "TLS MinVersion too low"
path: "tests/integration/"
- linters:
- gosec
text: "weak random number generator"
path: _test\.go
- linters:
- errcheck
text: "Error return value" # ignore err not checked in test files
path: _test\.go
- linters:
- asciicheck
- dogsled
- durationcheck
- exhaustive
- copyloopvar
- gci
- goconst
- gofmt
- gofumpt
- goimports
- gomodguard
- gosec
text: "Expect WriteFile permissions to be 0600 or less"
path: file/codegen/main.go
# ignore unused warnings in test utils files
- linters:
- govet
- importas
- lll
- gosimple
- staticcheck
- unused
- misspell
- nakedret
- nilerr
- nolintlint
- predeclared
- prealloc
- revive
- stylecheck
- unconvert
- unparam
path: test_.*
# ignore SA1019 deprecation warning
- linters:
- staticcheck
text: "SA1019: rand..*"
# ignore formatting warnings in cmd/root.go due to nolint statements
- linters:
- gofumpt
text: "File is not `gofumpt`-ed"
path: cmd/root.go
- linters:
- gofmt
text: "File is not `gofmt`-ed with `-s`"
path: cmd/root.go
- linters:
- goimports
text: "File is not `goimports`-ed"
path: cmd/root.go
- wastedassign
- errorlint
issues:
max-same-issues: 0
exclude-rules:
- linters:
- gosec
text: "weak cryptographic primitive"
path: "state/indexers/md5Indexer.*"
- linters:
- gosec
text: "TLS MinVersion too low"
path: "tests/integration/"
- linters:
- gosec
text: "weak random number generator"
path: _test\.go
- linters:
- errcheck
text: "Error return value" # ignore err not checked in test files
path: _test\.go
- linters:
- gosec
text: "Expect WriteFile permissions to be 0600 or less"
path: file/codegen/main.go
# ignore unused warnings in test utils files
- linters:
- unused
- unparam
path: test_.*
# ignore SA1019 deprecation warning
- linters:
- staticcheck
text: "SA1019: rand..*"
# ignore formatting warnings in cmd/root.go due to nolint statements
- linters:
- gofumpt
text: "File is not `gofumpt`-ed"
path: cmd/root.go
- linters:
- gofmt
text: "File is not `gofmt`-ed with `-s`"
path: cmd/root.go
- linters:
- goimports
text: "File is not `goimports`-ed"
path: cmd/root.go

linters-settings:
gci:
sections:
- standard
- default
- standard
- default
goconst:
min-occurrences: 10
gomodguard:
blocked:
modules:
- github.com/ghodss/yaml:
recommendations:
- sigs.k8s.io/yaml
- gopkg.in/yaml.v2:
recommendations:
- sigs.k8s.io/yaml
- gopkg.in/yaml.v3:
recommendations:
- sigs.k8s.io/yaml
- github.com/pkg/errors:
recommendations:
- fmt
- errors
- golang.org/x/net/context:
recommendations:
- context
- github.com/kong/kubernetes-ingress-controller/v3:
recommendations:
- github.com/kong/kubernetes-configuration
- github.com/kong/gateway-operator:
recommendations:
- github.com/kong/kubernetes-configuration
- github.com/ghodss/yaml:
recommendations:
- sigs.k8s.io/yaml
- gopkg.in/yaml.v2:
recommendations:
- sigs.k8s.io/yaml
- gopkg.in/yaml.v3:
recommendations:
- sigs.k8s.io/yaml
- github.com/pkg/errors:
recommendations:
- fmt
- errors
- golang.org/x/net/context:
recommendations:
- context
- github.com/kong/kubernetes-ingress-controller/v3:
recommendations:
- github.com/kong/kubernetes-configuration
- github.com/kong/gateway-operator:
recommendations:
- github.com/kong/kubernetes-configuration
importas:
no-unaliased: true
alias:
- pkg: github.com/kong/kubernetes-configuration/api/configuration/(v[\w\d]+)
alias: kc${1}

- pkg: github.com/kong/kubernetes-configuration/api/configuration/(v[\w\d]+)
alias: configuration${1}
4 changes: 2 additions & 2 deletions kong2kic/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"log"

"github.com/kong/go-database-reconciler/pkg/file"
kcv1 "github.com/kong/kubernetes-configuration/api/configuration/v1"
configurationv1 "github.com/kong/kubernetes-configuration/api/configuration/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -16,7 +16,7 @@ func populateKICConsumers(content *file.Content, file *KICContent) error {
continue
}
username := *consumer.Username
kongConsumer := kcv1.KongConsumer{
kongConsumer := configurationv1.KongConsumer{
TypeMeta: metav1.TypeMeta{
APIVersion: KICAPIVersion,
Kind: "KongConsumer",
Expand Down
24 changes: 16 additions & 8 deletions kong2kic/consumer_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strconv"

"github.com/kong/go-database-reconciler/pkg/file"
kcv1 "github.com/kong/kubernetes-configuration/api/configuration/v1"
configurationv1 "github.com/kong/kubernetes-configuration/api/configuration/v1"
k8scorev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -43,7 +43,7 @@ func createCredentialSecret(consumerUsername, credentialType string, dataFields
}

// Functions to populate different credential types
func populateKICKeyAuthSecrets(consumer *file.FConsumer, kongConsumer *kcv1.KongConsumer, file *KICContent) {
func populateKICKeyAuthSecrets(consumer *file.FConsumer, kongConsumer *configurationv1.KongConsumer, file *KICContent) {
for _, keyAuth := range consumer.KeyAuths {
dataFields := map[string]*string{
"key": keyAuth.Key,
Expand All @@ -54,7 +54,7 @@ func populateKICKeyAuthSecrets(consumer *file.FConsumer, kongConsumer *kcv1.Kong
}
}

func populateKICHMACSecrets(consumer *file.FConsumer, kongConsumer *kcv1.KongConsumer, file *KICContent) {
func populateKICHMACSecrets(consumer *file.FConsumer, kongConsumer *configurationv1.KongConsumer, file *KICContent) {
for _, hmacAuth := range consumer.HMACAuths {
dataFields := map[string]*string{
"username": hmacAuth.Username,
Expand All @@ -66,7 +66,7 @@ func populateKICHMACSecrets(consumer *file.FConsumer, kongConsumer *kcv1.KongCon
}
}

func populateKICJWTAuthSecrets(consumer *file.FConsumer, kongConsumer *kcv1.KongConsumer, file *KICContent) {
func populateKICJWTAuthSecrets(consumer *file.FConsumer, kongConsumer *configurationv1.KongConsumer, file *KICContent) {
for _, jwtAuth := range consumer.JWTAuths {
dataFields := map[string]*string{
"key": jwtAuth.Key,
Expand All @@ -80,7 +80,9 @@ func populateKICJWTAuthSecrets(consumer *file.FConsumer, kongConsumer *kcv1.Kong
}
}

func populateKICBasicAuthSecrets(consumer *file.FConsumer, kongConsumer *kcv1.KongConsumer, file *KICContent) {
func populateKICBasicAuthSecrets(
consumer *file.FConsumer, kongConsumer *configurationv1.KongConsumer, file *KICContent,
) {
for _, basicAuth := range consumer.BasicAuths {
dataFields := map[string]*string{
"username": basicAuth.Username,
Expand All @@ -92,7 +94,9 @@ func populateKICBasicAuthSecrets(consumer *file.FConsumer, kongConsumer *kcv1.Ko
}
}

func populateKICOAuth2CredSecrets(consumer *file.FConsumer, kongConsumer *kcv1.KongConsumer, file *KICContent) {
func populateKICOAuth2CredSecrets(
consumer *file.FConsumer, kongConsumer *configurationv1.KongConsumer, file *KICContent,
) {
for _, oauth2Cred := range consumer.Oauth2Creds {
dataFields := map[string]*string{
"name": oauth2Cred.Name,
Expand All @@ -110,7 +114,9 @@ func populateKICOAuth2CredSecrets(consumer *file.FConsumer, kongConsumer *kcv1.K
}
}

func populateKICACLGroupSecrets(consumer *file.FConsumer, kongConsumer *kcv1.KongConsumer, file *KICContent) {
func populateKICACLGroupSecrets(
consumer *file.FConsumer, kongConsumer *configurationv1.KongConsumer, file *KICContent,
) {
for _, aclGroup := range consumer.ACLGroups {
dataFields := map[string]*string{
"group": aclGroup.Group,
Expand All @@ -121,7 +127,9 @@ func populateKICACLGroupSecrets(consumer *file.FConsumer, kongConsumer *kcv1.Kon
}
}

func populateKICMTLSAuthSecrets(consumer *file.FConsumer, kongConsumer *kcv1.KongConsumer, file *KICContent) {
func populateKICMTLSAuthSecrets(
consumer *file.FConsumer, kongConsumer *configurationv1.KongConsumer, file *KICContent,
) {
for _, mtlsAuth := range consumer.MTLSAuths {
dataFields := map[string]*string{
"subject_name": mtlsAuth.SubjectName,
Expand Down
12 changes: 7 additions & 5 deletions kong2kic/consumer_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ import (

"github.com/kong/go-database-reconciler/pkg/file"
"github.com/kong/go-kong/kong"
kcv1 "github.com/kong/kubernetes-configuration/api/configuration/v1"
kcv1beta1 "github.com/kong/kubernetes-configuration/api/configuration/v1beta1"
configurationv1 "github.com/kong/kubernetes-configuration/api/configuration/v1"
configurationv1beta1 "github.com/kong/kubernetes-configuration/api/configuration/v1beta1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Helper function to populate consumer group plugins
func createConsumerGroupKongPlugin(plugin *kong.ConsumerGroupPlugin, ownerName string) (*kcv1.KongPlugin, error) {
func createConsumerGroupKongPlugin(
plugin *kong.ConsumerGroupPlugin, ownerName string,
) (*configurationv1.KongPlugin, error) {
if plugin.Name == nil {
log.Println("Plugin name is empty. Please provide a name for the plugin.")
return nil, nil
}
pluginName := *plugin.Name
kongPlugin := &kcv1.KongPlugin{
kongPlugin := &configurationv1.KongPlugin{
TypeMeta: metav1.TypeMeta{
APIVersion: "configuration.konghq.com/v1",
Kind: "KongPlugin",
Expand Down Expand Up @@ -51,7 +53,7 @@ func populateKICConsumerGroups(content *file.Content, kicContent *KICContent) er
}
groupName := *consumerGroup.Name

kongConsumerGroup := kcv1beta1.KongConsumerGroup{
kongConsumerGroup := configurationv1beta1.KongConsumerGroup{
TypeMeta: metav1.TypeMeta{
APIVersion: "configuration.konghq.com/v1beta1",
Kind: "KongConsumerGroup",
Expand Down
10 changes: 5 additions & 5 deletions kong2kic/global_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import (

"github.com/kong/go-database-reconciler/pkg/file"
"github.com/kong/go-kong/kong"
kcv1 "github.com/kong/kubernetes-configuration/api/configuration/v1"
configurationv1 "github.com/kong/kubernetes-configuration/api/configuration/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
)

func populateKICKongClusterPlugins(content *file.Content, file *KICContent) error {
// Global Plugins map to KongClusterPlugins
// iterate content.Plugins and copy them into kcv1.KongPlugin manifests
// add the kcv1.KongPlugin to the KICContent.KongClusterPlugins slice
// iterate content.Plugins and copy them into configurationv1.KongPlugin manifests
// add the configurationv1.KongPlugin to the KICContent.KongClusterPlugins slice
for _, plugin := range content.Plugins {
// skip this plugin instance if it is a kongconsumergroup plugin.
// It is a kongconsumergroup plugin if it has a consumer_group property
if plugin.ConsumerGroup != nil {
continue
}
var kongClusterPlugin kcv1.KongClusterPlugin
var kongClusterPlugin configurationv1.KongClusterPlugin
kongClusterPlugin.APIVersion = KICAPIVersion
kongClusterPlugin.Kind = "KongClusterPlugin"
kongClusterPlugin.ObjectMeta.Annotations = map[string]string{IngressClass: ClassName}
Expand Down Expand Up @@ -54,7 +54,7 @@ func populateKICKongClusterPlugins(content *file.Content, file *KICContent) erro
protocols[i] = *protocol
}
}
kongClusterPlugin.Protocols = kcv1.StringsToKongProtocols(protocols)
kongClusterPlugin.Protocols = configurationv1.StringsToKongProtocols(protocols)
}

// add konghq.com/tags annotation if plugin.Tags is not nil
Expand Down
Loading

0 comments on commit 96990b8

Please sign in to comment.