diff --git a/Makefile b/Makefile index 4686894bd..5c5dd583d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=v0.1.6 +VERSION=v0.1.7 OUT_DIR=dist YEAR?=$(shell date +"%Y") diff --git a/docs/releases/release_notes.md b/docs/releases/release_notes.md index 4d79cba84..761528005 100644 --- a/docs/releases/release_notes.md +++ b/docs/releases/release_notes.md @@ -23,7 +23,7 @@ cf version ```bash # download and extract the binary -curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.6/cf-linux-amd64.tar.gz | tar zx +curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.7/cf-linux-amd64.tar.gz | tar zx # move the binary to your $PATH mv ./cf-linux-amd64 /usr/local/bin/cf @@ -36,7 +36,7 @@ cf version ```bash # download and extract the binary -curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.6/cf-darwin-amd64.tar.gz | tar zx +curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.7/cf-darwin-amd64.tar.gz | tar zx # move the binary to your $PATH mv ./cf-darwin-amd64 /usr/local/bin/cf diff --git a/pkg/util/routing/common_test.go b/pkg/util/routing/common_test.go new file mode 100644 index 000000000..2e7ea1b4f --- /dev/null +++ b/pkg/util/routing/common_test.go @@ -0,0 +1,102 @@ +// Copyright 2022 The Codefresh Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package routing_test + +import ( + "bytes" + "log" + "os" + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/codefresh-io/cli-v2/pkg/util/routing" + v1 "k8s.io/api/networking/v1" + yamlutil "k8s.io/apimachinery/pkg/util/yaml" +) + +// TestCreateInternalRouterRoute calls routing.CreateInternalRouterRoute, checking +// that a correct route is returned. +func TestCreateInternalRouterRoute(t *testing.T) { + tests := map[string]struct { + routeOpts *routing.CreateRouteOpts + wantFilePath string + getExpected func() interface{} + }{ + string(routing.IngressControllerALB): { + routeOpts: &routing.CreateRouteOpts{ + RuntimeName: "test-runtime", + Namespace: "test-runtime", + IngressClass: "alb", + Hostname: "testing.foo.bar.com", + IngressController: routing.GetIngressController(string(routing.IngressControllerALB)), + Annotations: nil, + GatewayName: "", + GatewayNamespace: "", + }, + getExpected: func() interface{} { + ingress, err := yamlToIngress("testdata/alb-ingress.yaml") + if err != nil { + log.Fatal(err) + } + + return ingress + }, + }, + string(routing.IngressControllerNginxCommunity): { + routeOpts: &routing.CreateRouteOpts{ + RuntimeName: "test-runtime", + Namespace: "test-runtime", + IngressClass: "nginx", + Hostname: "testing.foo.bar.com", + IngressController: routing.GetIngressController(string(routing.IngressControllerNginxCommunity)), + Annotations: nil, + GatewayName: "", + GatewayNamespace: "", + }, + getExpected: func() interface{} { + ingress, err := yamlToIngress("testdata/nginx-ingress.yaml") + if err != nil { + log.Fatal(err) + } + + return ingress + }, + }, + } + + for tname, tt := range tests { + t.Run(tname, func(t *testing.T) { + _, received := routing.CreateInternalRouterRoute(tt.routeOpts, false, true, false) + assert.Equal(t, tt.getExpected(), received) + }) + } +} + +func yamlToIngress(path string) (*v1.Ingress, error) { + var want *v1.Ingress + ingressFile, err := os.ReadFile(path) + if err != nil { + return nil, err + } + + d := yamlutil.NewYAMLOrJSONDecoder(bytes.NewReader(ingressFile), 100) + err = d.Decode(&want) + if err != nil { + return nil, err + } + + return want, nil +} diff --git a/pkg/util/routing/ingress.go b/pkg/util/routing/ingress.go index efa6f50f3..a00bcacfb 100644 --- a/pkg/util/routing/ingress.go +++ b/pkg/util/routing/ingress.go @@ -95,7 +95,7 @@ func GetIngressController(name string) RoutingController { } func (ingressControllerALB) Decorate(route interface{}) { - ingress, ok := route.(netv1.Ingress) + ingress, ok := route.(*netv1.Ingress) if !ok { log.G().Error("Cant decorate, this is not an ingress!") return @@ -110,7 +110,7 @@ func (ingressControllerALB) Decorate(route interface{}) { } func (ingressControllerNginxEnterprise) Decorate(route interface{}) { - ingress, ok := route.(netv1.Ingress) + ingress, ok := route.(*netv1.Ingress) if !ok { log.G().Error("Cant decorate, this is not an ingress!") return diff --git a/pkg/util/routing/testdata/alb-ingress.yaml b/pkg/util/routing/testdata/alb-ingress.yaml new file mode 100644 index 000000000..d4a127443 --- /dev/null +++ b/pkg/util/routing/testdata/alb-ingress.yaml @@ -0,0 +1,37 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + alb.ingress.kubernetes.io/group.name: csdp-ingress + alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS": 443}]' + alb.ingress.kubernetes.io/scheme: internet-facing + alb.ingress.kubernetes.io/target-type: ip + name: test-runtime-internal-router-ingress + namespace: test-runtime +spec: + ingressClassName: alb + rules: + - host: testing.foo.bar.com + http: + paths: + - backend: + service: + name: internal-router + port: + number: 80 + path: /webhooks + pathType: Prefix + - backend: + service: + name: internal-router + port: + number: 80 + path: /workflows + pathType: Prefix + - backend: + service: + name: internal-router + port: + number: 80 + path: /app-proxy + pathType: Prefix \ No newline at end of file diff --git a/pkg/util/routing/testdata/nginx-ingress.yaml b/pkg/util/routing/testdata/nginx-ingress.yaml new file mode 100644 index 000000000..aabb0f782 --- /dev/null +++ b/pkg/util/routing/testdata/nginx-ingress.yaml @@ -0,0 +1,32 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: test-runtime-internal-router-ingress + namespace: test-runtime +spec: + ingressClassName: nginx + rules: + - host: testing.foo.bar.com + http: + paths: + - backend: + service: + name: internal-router + port: + number: 80 + path: /webhooks + pathType: Prefix + - backend: + service: + name: internal-router + port: + number: 80 + path: /workflows + pathType: Prefix + - backend: + service: + name: internal-router + port: + number: 80 + path: /app-proxy + pathType: Prefix \ No newline at end of file