Skip to content

Commit

Permalink
Cr 15540 (#641)
Browse files Browse the repository at this point in the history
* fix annotations for ingresses and add tests

* bump

* fix test

* codegen
  • Loading branch information
danielm-codefresh authored Nov 16, 2022
1 parent ac2fe72 commit 1fcf2ae
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=v0.1.6
VERSION=v0.1.7

OUT_DIR=dist
YEAR?=$(shell date +"%Y")
Expand Down
4 changes: 2 additions & 2 deletions docs/releases/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
102 changes: 102 additions & 0 deletions pkg/util/routing/common_test.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions pkg/util/routing/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
37 changes: 37 additions & 0 deletions pkg/util/routing/testdata/alb-ingress.yaml
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions pkg/util/routing/testdata/nginx-ingress.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1fcf2ae

Please sign in to comment.