Skip to content

Commit

Permalink
Enable go build for common-go-libs and fix conversion webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
pubudu538 committed Mar 21, 2024
1 parent e648e97 commit 550ba22
Show file tree
Hide file tree
Showing 22 changed files with 188 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ resources:
- bases/dp.wso2.com_authentications.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patches:
patchesStrategicMerge:
# - patches/webhook_in_dp_apis.yaml
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- patches/webhook_in_ratelimitpolicies.yaml
#- path: patches/webhook_in_apis.yaml
- patches/webhook_in_dp_apis.yaml
#- patches/webhook_in_applications.yaml
#- patches/webhook_in_subscriptions.yaml
#- patches/webhook_in_applicationmappings.yaml
Expand All @@ -23,7 +24,7 @@ patches:
# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- patches/cainjection_in_ratelimitpolicies.yaml
#- path: patches/cainjection_in_apis.yaml
- patches/cainjection_in_dp_apis.yaml
#- patches/cainjection_in_applications.yaml
#- patches/cainjection_in_subscriptions.yaml
#- patches/cainjection_in_applicationmappings.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ resources:
- ../manager
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
#- ../webhook
- ../webhook
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
#- ../certmanager
- ../certmanager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
#- ../prometheus

Expand All @@ -36,12 +36,12 @@ patchesStrategicMerge:

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
#- manager_webhook_patch.yaml
- manager_webhook_patch.yaml

# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'.
# Uncomment 'CERTMANAGER' sections in crd/kustomization.yaml to enable the CA injection in the admission webhooks.
# 'CERTMANAGER' needs to be enabled to use ca injection
#- webhookcainjection_patch.yaml
- webhookcainjection_patch.yaml

# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
# Uncomment the following replacements to add the cert-manager CA injection annotations
Expand Down
23 changes: 21 additions & 2 deletions common-go-libs/apis/dp/v1alpha1/api_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ func (src *API) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.BasePath = src.Spec.BasePath
dst.Spec.Organization = src.Spec.Organization
dst.Spec.SystemAPI = src.Spec.SystemAPI

if src.Spec.Production != nil {
src.Spec.Production = []EnvConfig{}
dst.Spec.Production = []v1alpha2.EnvConfig{}
for _, productionRef := range src.Spec.Production {
dst.Spec.Production = append(dst.Spec.Production, v1alpha2.EnvConfig{
RouteRefs: productionRef.HTTPRouteRefs,
})
}
}
if src.Spec.Sandbox != nil {
src.Spec.Sandbox = []EnvConfig{}
dst.Spec.Sandbox = []v1alpha2.EnvConfig{}
for _, sandboxRef := range src.Spec.Sandbox {
dst.Spec.Sandbox = append(dst.Spec.Sandbox, v1alpha2.EnvConfig{
RouteRefs: sandboxRef.HTTPRouteRefs,
Expand Down Expand Up @@ -87,6 +88,24 @@ func (src *API) ConvertFrom(srcRaw conversion.Hub) error {
src.Spec.Organization = dst.Spec.Organization
src.Spec.SystemAPI = dst.Spec.SystemAPI

if dst.Spec.Production != nil {
src.Spec.Production = []EnvConfig{}
for _, productionRef := range dst.Spec.Production {
src.Spec.Production = append(src.Spec.Production, EnvConfig{
HTTPRouteRefs: productionRef.RouteRefs,
})
}
}

if dst.Spec.Sandbox != nil {
src.Spec.Sandbox = []EnvConfig{}
for _, sandboxRef := range dst.Spec.Sandbox {
src.Spec.Sandbox = append(src.Spec.Sandbox, EnvConfig{
HTTPRouteRefs: sandboxRef.RouteRefs,
})
}
}

// Convert []Property to []v1alpha1.Property
var properties []Property
for _, p := range dst.Spec.APIProperties {
Expand Down
8 changes: 2 additions & 6 deletions common-go-libs/apis/dp/v1alpha1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,8 @@ var _ = BeforeSuite(func() {
// start webhook server using Manager
webhookInstallOptions := &testEnv.WebhookInstallOptions
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
LeaderElection: false,
MetricsBindAddress: "0",
Scheme: scheme,
LeaderElection: false,
})
Expect(err).NotTo(HaveOccurred())

Expand Down
9 changes: 6 additions & 3 deletions common-go-libs/apis/dp/v1alpha2/api_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ func getBasePathWithoutVersion(basePath string) string {

func validateGzip(name, namespace string) (string, string) {
configMap := &corev1.ConfigMap{}
if err := c.Get(context.Background(), types.NamespacedName{Name: string(name), Namespace: namespace}, configMap); err == nil {
var err error

if err = c.Get(context.Background(), types.NamespacedName{Name: string(name), Namespace: namespace}, configMap); err == nil {
var apiDef []byte
for _, val := range configMap.BinaryData {
// config map data key is "swagger.yaml"
Expand All @@ -274,9 +276,10 @@ func validateGzip(name, namespace string) (string, string) {
return "", "invalid gzipped content"
}
return schemaString, ""
} else {
loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2600, logging.MINOR, "ConfigMap for sdl not found: %v", err))
}

loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2600, logging.MINOR, "ConfigMap for sdl not found: %v", err))

return "", ""
}

Expand Down
1 change: 1 addition & 0 deletions common-go-libs/apis/dp/v1alpha2/authentication_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// SetupWebhookWithManager creates a new webhook builder for Authentication CRD
func (r *Authentication) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
Expand Down
8 changes: 2 additions & 6 deletions common-go-libs/apis/dp/v1alpha2/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,8 @@ var _ = BeforeSuite(func() {
// start webhook server using Manager
webhookInstallOptions := &testEnv.WebhookInstallOptions
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
LeaderElection: false,
MetricsBindAddress: "0",
Scheme: scheme,
LeaderElection: false,
})
Expect(err).NotTo(HaveOccurred())

Expand Down
16 changes: 16 additions & 0 deletions common-go-libs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ allprojects {
version = project.version
}

tasks.register('go_test', Exec) {
group 'go'
commandLine 'sh', '-c', "go test -race -coverprofile=coverage.out -covermode=atomic ./..."
}

tasks.named('go_revive_run').configure {
finalizedBy go_tidy
finalizedBy go_test
}

tasks.named('go_build').configure {
dependsOn go_revive_run
dependsOn go_vet
println("Running go build")
}

tasks.register('make_generates', Exec) {
println("Running make -C $rootDir/../common-go-libs")
Expand All @@ -52,4 +67,5 @@ tasks.register('make_manifests', Exec) {

task build{
dependsOn make_generates
dependsOn go_build
}
44 changes: 22 additions & 22 deletions common-go-libs/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.20

require (
github.com/envoyproxy/go-control-plane v0.12.0
github.com/onsi/ginkgo/v2 v2.11.0
github.com/onsi/gomega v1.27.10
github.com/onsi/ginkgo/v2 v2.14.0
github.com/onsi/gomega v1.30.0
github.com/pelletier/go-toml v1.9.5
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.4
Expand All @@ -14,10 +14,10 @@ require (
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb
google.golang.org/grpc v1.62.0
google.golang.org/protobuf v1.32.0
k8s.io/api v0.28.3
k8s.io/apimachinery v0.28.3
k8s.io/client-go v0.28.3
sigs.k8s.io/controller-runtime v0.17.2
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/client-go v0.29.0
sigs.k8s.io/controller-runtime v0.17.2
sigs.k8s.io/gateway-api v1.0.0
)

Expand All @@ -35,14 +35,14 @@ require (
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 // indirect
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.2 // indirect
github.com/evanphx/json-patch/v5 v5.7.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
Expand All @@ -54,7 +54,7 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand All @@ -65,7 +65,7 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.17.0
github.com/prometheus/client_golang v1.18.0
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
Expand All @@ -75,26 +75,26 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.16.0 // indirect
golang.org/x/tools v0.16.1 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230731190214-cbb8c96f2d6d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.28.3 // indirect
k8s.io/component-base v0.28.3 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/apiextensions-apiserver v0.29.0 // indirect
k8s.io/component-base v0.29.0 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading

0 comments on commit 550ba22

Please sign in to comment.