Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several enhancements #77

Merged
merged 6 commits into from
Jun 4, 2024
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
25 changes: 9 additions & 16 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,16 @@ jobs:
id: go
- name: Check out code
uses: actions/checkout@v3
- name: Create k8s Kind Cluster
uses: helm/[email protected]
with:
version: v0.20.0
config: utils/kind-cluster.yaml
cluster_name: ${{ env.KIND_CLUSTER_NAME }}
wait: 120s
- name: Check cluster info
run: |
kubectl cluster-info dump
- name: Run make env-setup
run: |
make env-setup
- name: Run tests
run: |
make test
- name: Report to CodeCov
uses: codecov/codecov-action@v2
- name: Upload test coverage reports to CodeCov
# more at https://github.com/codecov/codecov-action
# Only run if the feature branch is in your repo (not in a fork)
# as Tokenless uploading is rate limited for public repos
if: github.event.pull_request.head.repo.full_name == github.repository
uses: codecov/codecov-action@v4
with:
files: "*.coverprofile"
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
verbose: true
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ testbin
*.out

cmd/cmd.coverprofile
pkg/utils/utils.coverprofile
/coverage/

# Binary generated by Vim
kuadrantctl

# Dependency directories (remove the comment below to include it)
# vendor/
Expand Down
32 changes: 23 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ SHELL := /bin/bash
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
GO ?= go
KUADRANT_NAMESPACE=kuadrant-system

all: help

Expand All @@ -14,10 +13,17 @@ help: Makefile
# Ginkgo tool
GINKGO = $(PROJECT_PATH)/bin/ginkgo
$(GINKGO):
$(call go-install-tool,$(GINKGO),github.com/onsi/ginkgo/[email protected])
# In order to make sure the version of the ginkgo cli installed
# is the same as the version of go.mod,
# instead of calling go-install-tool,
# running go install from the current module will pick version from current go.mod file.
GOBIN=$(PROJECT_PATH)/bin go install github.com/onsi/ginkgo/v2/ginkgo

.PHONY: ginkgo
ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.

KIND = $(PROJECT_PATH)/bin/kind
KIND_VERSION = v0.20.0
KIND_VERSION = v0.22.0
$(KIND):
$(call go-install-tool,$(KIND),sigs.k8s.io/kind@$(KIND_VERSION))

Expand All @@ -33,10 +39,17 @@ kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.

## test: Run unit tests
.PHONY : test
jasonmadigan marked this conversation as resolved.
Show resolved Hide resolved
test: fmt vet $(GINKGO)
# huffle both the order in which specs within a suite run, and the order in which different suites run
test: clean-cov fmt vet $(GINKGO)
mkdir -p $(PROJECT_PATH)/coverage
# Shuffle both the order in which specs within a suite run, and the order in which different suites run
# You can always rerun a given ordering later by passing the --seed flag a matching seed.
$(GINKGO) --randomizeAllSpecs --randomizeSuites -v -progress --trace --cover ./...
$(GINKGO) \
--randomize-all \
--randomize-suites \
--coverpkg ./pkg/...,./cmd/... \
--output-dir $(PROJECT_PATH)/coverage \
--coverprofile cover.out \
./pkg/... ./cmd/...

## install: Build and install kuadrantctl binary ($GOBIN or GOPATH/bin)
.PHONY : install
Expand All @@ -50,10 +63,7 @@ prepare-local-cluster: $(KIND) ## Deploy locally kuadrant operator from the curr

.PHONY: env-setup
env-setup:
$(MAKE) olm-install
$(MAKE) gateway-api-install
$(MAKE) istio-install
$(MAKE) deploy-gateway

## local-setup: Sets up Kind cluster with GatewayAPI manifests and istio GW, nothing Kuadrant. Build and install kuadrantctl binary
.PHONY: local-setup
Expand All @@ -74,5 +84,9 @@ fmt:
vet:
$(GO) vet ./...

.PHONY: clean-cov
clean-cov: ## Remove coverage reports
rm -rf $(PROJECT_PATH)/coverage

# Include last to avoid changing MAKEFILE_LIST used above
include ./make/*.mk
20 changes: 1 addition & 19 deletions cmd/cmd_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@ package cmd
import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

var (
testK8sClient client.Client
)

func TestCommands(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Commands Suite")
Expand All @@ -27,14 +19,4 @@ var _ = BeforeSuite(func() {
By("Before suite")

logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

configuration, err := config.GetConfig()
Expect(err).NotTo(HaveOccurred())

err = apiextensionsv1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())

testK8sClient, err = client.New(configuration, client.Options{Scheme: scheme.Scheme})
Expect(err).NotTo(HaveOccurred())
Expect(testK8sClient).NotTo(BeNil())
})
12 changes: 6 additions & 6 deletions cmd/generate_gatewayapi_httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/kuadrant/kuadrantctl/pkg/utils"
"github.com/spf13/cobra"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gatewayapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)

var (
Expand Down Expand Up @@ -76,15 +76,15 @@ func runGenerateGatewayApiHttpRoute(cmd *cobra.Command, args []string) error {
return nil
}

func buildHTTPRoute(doc *openapi3.T) *gatewayapiv1beta1.HTTPRoute {
return &gatewayapiv1beta1.HTTPRoute{
func buildHTTPRoute(doc *openapi3.T) *gatewayapiv1.HTTPRoute {
return &gatewayapiv1.HTTPRoute{
TypeMeta: v1.TypeMeta{
APIVersion: "gateway.networking.k8s.io/v1beta1",
APIVersion: gatewayapiv1.GroupVersion.String(),
Kind: "HTTPRoute",
},
ObjectMeta: gatewayapi.HTTPRouteObjectMetaFromOAS(doc),
Spec: gatewayapiv1beta1.HTTPRouteSpec{
CommonRouteSpec: gatewayapiv1beta1.CommonRouteSpec{
Spec: gatewayapiv1.HTTPRouteSpec{
CommonRouteSpec: gatewayapiv1.CommonRouteSpec{
ParentRefs: gatewayapi.HTTPRouteGatewayParentRefsFromOAS(doc),
},
Hostnames: gatewayapi.HTTPRouteHostnamesFromOAS(doc),
Expand Down
20 changes: 11 additions & 9 deletions cmd/generate_kuadrant_authpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
kuadrantapiv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2"
"github.com/spf13/cobra"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/kuadrant/kuadrantctl/pkg/gatewayapi"
"github.com/kuadrant/kuadrantctl/pkg/kuadrantapi"
Expand Down Expand Up @@ -91,21 +91,23 @@ func buildAuthPolicy(doc *openapi3.T) *kuadrantapiv1beta2.AuthPolicy {
ObjectMeta: kuadrantapi.AuthPolicyObjectMetaFromOAS(doc),
Spec: kuadrantapiv1beta2.AuthPolicySpec{
TargetRef: gatewayapiv1alpha2.PolicyTargetReference{
Group: gatewayapiv1beta1.Group("gateway.networking.k8s.io"),
Kind: gatewayapiv1beta1.Kind("HTTPRoute"),
Name: gatewayapiv1beta1.ObjectName(routeMeta.Name),
Group: gatewayapiv1.GroupName,
Kind: gatewayapiv1.Kind("HTTPRoute"),
Name: gatewayapiv1.ObjectName(routeMeta.Name),
},
// Currently only authentication rules enforced
AuthScheme: kuadrantapiv1beta2.AuthSchemeSpec{
Authentication: kuadrantapi.AuthPolicyAuthenticationSchemeFromOAS(doc),
AuthPolicyCommonSpec: kuadrantapiv1beta2.AuthPolicyCommonSpec{
AuthScheme: &kuadrantapiv1beta2.AuthSchemeSpec{
Authentication: kuadrantapi.AuthPolicyAuthenticationSchemeFromOAS(doc),
},
RouteSelectors: kuadrantapi.AuthPolicyTopRouteSelectorsFromOAS(doc),
},
RouteSelectors: kuadrantapi.AuthPolicyTopRouteSelectorsFromOAS(doc),
},
}

if routeMeta.Namespace != "" {
ap.Spec.TargetRef.Namespace = &[]gatewayapiv1beta1.Namespace{
gatewayapiv1beta1.Namespace(routeMeta.Namespace),
ap.Spec.TargetRef.Namespace = &[]gatewayapiv1.Namespace{
gatewayapiv1.Namespace(routeMeta.Namespace),
}[0]
}

Expand Down
16 changes: 9 additions & 7 deletions cmd/generate_kuadrant_ratelimitpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
kuadrantapiv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2"
"github.com/spf13/cobra"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/kuadrant/kuadrantctl/pkg/gatewayapi"
"github.com/kuadrant/kuadrantctl/pkg/kuadrantapi"
Expand Down Expand Up @@ -94,17 +94,19 @@ func buildRateLimitPolicy(doc *openapi3.T) *kuadrantapiv1beta2.RateLimitPolicy {
ObjectMeta: kuadrantapi.RateLimitPolicyObjectMetaFromOAS(doc),
Spec: kuadrantapiv1beta2.RateLimitPolicySpec{
TargetRef: gatewayapiv1alpha2.PolicyTargetReference{
Group: gatewayapiv1beta1.Group("gateway.networking.k8s.io"),
Kind: gatewayapiv1beta1.Kind("HTTPRoute"),
Name: gatewayapiv1beta1.ObjectName(routeMeta.Name),
Group: gatewayapiv1.GroupName,
Kind: gatewayapiv1.Kind("HTTPRoute"),
Name: gatewayapiv1.ObjectName(routeMeta.Name),
},
RateLimitPolicyCommonSpec: kuadrantapiv1beta2.RateLimitPolicyCommonSpec{
Limits: kuadrantapi.RateLimitPolicyLimitsFromOAS(doc),
},
Limits: kuadrantapi.RateLimitPolicyLimitsFromOAS(doc),
},
}

if routeMeta.Namespace != "" {
rlp.Spec.TargetRef.Namespace = &[]gatewayapiv1beta1.Namespace{
gatewayapiv1beta1.Namespace(routeMeta.Namespace),
rlp.Spec.TargetRef.Namespace = &[]gatewayapiv1.Namespace{
gatewayapiv1.Namespace(routeMeta.Namespace),
}[0]
}

Expand Down
19 changes: 0 additions & 19 deletions config/gateway-api/gateway/gateway.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions config/gateway-api/gateway/kustomization.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion config/gateway-api/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
resources:
- github.com/kubernetes-sigs/gateway-api/config/crd?ref=v0.6.2
- github.com/kubernetes-sigs/gateway-api/config/crd?ref=v1.0.0
Loading
Loading