-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into commit-hash-version
- Loading branch information
Showing
38 changed files
with
948 additions
and
805 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,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)) | ||
|
||
|
@@ -34,10 +41,17 @@ kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. | |
|
||
## test: Run unit tests | ||
.PHONY : test | ||
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 | ||
|
@@ -55,10 +69,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 | ||
|
@@ -79,5 +90,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/spf13/cobra" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/utils/ptr" | ||
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
var _ = Describe("Generate HTTPRoute", func() { | ||
var ( | ||
cmd *cobra.Command | ||
cmdStdoutBuffer *bytes.Buffer | ||
cmdStderrBuffer *bytes.Buffer | ||
) | ||
|
||
BeforeEach(func() { | ||
cmd = generateGatewayApiHttpRouteCommand() | ||
cmdStdoutBuffer = bytes.NewBufferString("") | ||
cmdStderrBuffer = bytes.NewBufferString("") | ||
cmd.SetOut(cmdStdoutBuffer) | ||
cmd.SetErr(cmdStderrBuffer) | ||
}) | ||
|
||
Context("with invalid OAS", func() { | ||
It("happy path", func() { | ||
cmd.SetArgs([]string{"--oas", "testdata/invalid_oas.yaml"}) | ||
Expect(cmd.Execute()).Should(MatchError(ContainSubstring("OpenAPI validation error"))) | ||
|
||
}) | ||
}) | ||
|
||
Context("with root level kuadrant extensions", func() { | ||
It("HTTPRoute is generated", func() { | ||
cmd.SetArgs([]string{"--oas", "testdata/petstore_openapi.yaml"}) | ||
Expect(cmd.Execute()).ShouldNot(HaveOccurred()) | ||
out, err := io.ReadAll(cmdStdoutBuffer) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
|
||
var httpRoute gatewayapiv1.HTTPRoute | ||
Expect(yaml.Unmarshal(out, &httpRoute)).ShouldNot(HaveOccurred()) | ||
Expect(httpRoute.TypeMeta).To(Equal(metav1.TypeMeta{ | ||
APIVersion: gatewayapiv1.GroupVersion.String(), | ||
Kind: "HTTPRoute", | ||
})) | ||
Expect(httpRoute.ObjectMeta).To(Equal(metav1.ObjectMeta{ | ||
Name: "petstore", | ||
Namespace: "petstore-ns", | ||
})) | ||
Expect(httpRoute.Spec.CommonRouteSpec).To(Equal(gatewayapiv1.CommonRouteSpec{ | ||
ParentRefs: []gatewayapiv1.ParentReference{ | ||
{ | ||
Name: "gw", Namespace: ptr.To(gatewayapiv1.Namespace("gw-ns")), | ||
}, | ||
}, | ||
})) | ||
Expect(httpRoute.Spec.Hostnames).To(Equal([]gatewayapiv1.Hostname{ | ||
gatewayapiv1.Hostname("example.com"), | ||
})) | ||
Expect(httpRoute.Spec.Rules).To(HaveLen(3)) | ||
Expect(httpRoute.Spec.Rules).To(ContainElement( | ||
gatewayapiv1.HTTPRouteRule{ | ||
Matches: []gatewayapiv1.HTTPRouteMatch{ | ||
{ | ||
Path: &gatewayapiv1.HTTPPathMatch{ | ||
Type: ptr.To(gatewayapiv1.PathMatchExact), | ||
Value: ptr.To("/v1/cat"), | ||
}, | ||
Method: ptr.To(gatewayapiv1.HTTPMethodGet), | ||
}, | ||
}, | ||
BackendRefs: []gatewayapiv1.HTTPBackendRef{ | ||
{ | ||
BackendRef: gatewayapiv1.BackendRef{ | ||
BackendObjectReference: gatewayapiv1.BackendObjectReference{ | ||
Name: "petstore", | ||
Namespace: ptr.To(gatewayapiv1.Namespace("petstore")), | ||
Port: ptr.To(gatewayapiv1.PortNumber(80)), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
)) | ||
Expect(httpRoute.Spec.Rules).To(ContainElement( | ||
gatewayapiv1.HTTPRouteRule{ | ||
Matches: []gatewayapiv1.HTTPRouteMatch{ | ||
{ | ||
Path: &gatewayapiv1.HTTPPathMatch{ | ||
Type: ptr.To(gatewayapiv1.PathMatchExact), | ||
Value: ptr.To("/v1/dog"), | ||
}, | ||
Method: ptr.To(gatewayapiv1.HTTPMethodGet), | ||
}, | ||
}, | ||
BackendRefs: []gatewayapiv1.HTTPBackendRef{ | ||
{ | ||
BackendRef: gatewayapiv1.BackendRef{ | ||
BackendObjectReference: gatewayapiv1.BackendObjectReference{ | ||
Name: "petstore", | ||
Namespace: ptr.To(gatewayapiv1.Namespace("petstore")), | ||
Port: ptr.To(gatewayapiv1.PortNumber(80)), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
)) | ||
Expect(httpRoute.Spec.Rules).To(ContainElement( | ||
gatewayapiv1.HTTPRouteRule{ | ||
Matches: []gatewayapiv1.HTTPRouteMatch{ | ||
{ | ||
Path: &gatewayapiv1.HTTPPathMatch{ | ||
Type: ptr.To(gatewayapiv1.PathMatchExact), | ||
Value: ptr.To("/v1/dog"), | ||
}, | ||
Method: ptr.To(gatewayapiv1.HTTPMethodPost), | ||
}, | ||
}, | ||
BackendRefs: []gatewayapiv1.HTTPBackendRef{ | ||
{ | ||
BackendRef: gatewayapiv1.BackendRef{ | ||
BackendObjectReference: gatewayapiv1.BackendObjectReference{ | ||
Name: "petstore", | ||
Namespace: ptr.To(gatewayapiv1.Namespace("petstore")), | ||
Port: ptr.To(gatewayapiv1.PortNumber(80)), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
)) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.