Skip to content

Commit 1fcf2ae

Browse files
Cr 15540 (#641)
* fix annotations for ingresses and add tests * bump * fix test * codegen
1 parent ac2fe72 commit 1fcf2ae

File tree

6 files changed

+176
-5
lines changed

6 files changed

+176
-5
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.1.6
1+
VERSION=v0.1.7
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cf version
2323

2424
```bash
2525
# download and extract the binary
26-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.6/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.7/cf-linux-amd64.tar.gz | tar zx
2727

2828
# move the binary to your $PATH
2929
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -36,7 +36,7 @@ cf version
3636

3737
```bash
3838
# download and extract the binary
39-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.6/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.7/cf-darwin-amd64.tar.gz | tar zx
4040

4141
# move the binary to your $PATH
4242
mv ./cf-darwin-amd64 /usr/local/bin/cf

pkg/util/routing/common_test.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Copyright 2022 The Codefresh Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package routing_test
16+
17+
import (
18+
"bytes"
19+
"log"
20+
"os"
21+
"testing"
22+
23+
"github.com/stretchr/testify/assert"
24+
25+
"github.com/codefresh-io/cli-v2/pkg/util/routing"
26+
v1 "k8s.io/api/networking/v1"
27+
yamlutil "k8s.io/apimachinery/pkg/util/yaml"
28+
)
29+
30+
// TestCreateInternalRouterRoute calls routing.CreateInternalRouterRoute, checking
31+
// that a correct route is returned.
32+
func TestCreateInternalRouterRoute(t *testing.T) {
33+
tests := map[string]struct {
34+
routeOpts *routing.CreateRouteOpts
35+
wantFilePath string
36+
getExpected func() interface{}
37+
}{
38+
string(routing.IngressControllerALB): {
39+
routeOpts: &routing.CreateRouteOpts{
40+
RuntimeName: "test-runtime",
41+
Namespace: "test-runtime",
42+
IngressClass: "alb",
43+
Hostname: "testing.foo.bar.com",
44+
IngressController: routing.GetIngressController(string(routing.IngressControllerALB)),
45+
Annotations: nil,
46+
GatewayName: "",
47+
GatewayNamespace: "",
48+
},
49+
getExpected: func() interface{} {
50+
ingress, err := yamlToIngress("testdata/alb-ingress.yaml")
51+
if err != nil {
52+
log.Fatal(err)
53+
}
54+
55+
return ingress
56+
},
57+
},
58+
string(routing.IngressControllerNginxCommunity): {
59+
routeOpts: &routing.CreateRouteOpts{
60+
RuntimeName: "test-runtime",
61+
Namespace: "test-runtime",
62+
IngressClass: "nginx",
63+
Hostname: "testing.foo.bar.com",
64+
IngressController: routing.GetIngressController(string(routing.IngressControllerNginxCommunity)),
65+
Annotations: nil,
66+
GatewayName: "",
67+
GatewayNamespace: "",
68+
},
69+
getExpected: func() interface{} {
70+
ingress, err := yamlToIngress("testdata/nginx-ingress.yaml")
71+
if err != nil {
72+
log.Fatal(err)
73+
}
74+
75+
return ingress
76+
},
77+
},
78+
}
79+
80+
for tname, tt := range tests {
81+
t.Run(tname, func(t *testing.T) {
82+
_, received := routing.CreateInternalRouterRoute(tt.routeOpts, false, true, false)
83+
assert.Equal(t, tt.getExpected(), received)
84+
})
85+
}
86+
}
87+
88+
func yamlToIngress(path string) (*v1.Ingress, error) {
89+
var want *v1.Ingress
90+
ingressFile, err := os.ReadFile(path)
91+
if err != nil {
92+
return nil, err
93+
}
94+
95+
d := yamlutil.NewYAMLOrJSONDecoder(bytes.NewReader(ingressFile), 100)
96+
err = d.Decode(&want)
97+
if err != nil {
98+
return nil, err
99+
}
100+
101+
return want, nil
102+
}

pkg/util/routing/ingress.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func GetIngressController(name string) RoutingController {
9595
}
9696

9797
func (ingressControllerALB) Decorate(route interface{}) {
98-
ingress, ok := route.(netv1.Ingress)
98+
ingress, ok := route.(*netv1.Ingress)
9999
if !ok {
100100
log.G().Error("Cant decorate, this is not an ingress!")
101101
return
@@ -110,7 +110,7 @@ func (ingressControllerALB) Decorate(route interface{}) {
110110
}
111111

112112
func (ingressControllerNginxEnterprise) Decorate(route interface{}) {
113-
ingress, ok := route.(netv1.Ingress)
113+
ingress, ok := route.(*netv1.Ingress)
114114
if !ok {
115115
log.G().Error("Cant decorate, this is not an ingress!")
116116
return
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
annotations:
5+
alb.ingress.kubernetes.io/group.name: csdp-ingress
6+
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS": 443}]'
7+
alb.ingress.kubernetes.io/scheme: internet-facing
8+
alb.ingress.kubernetes.io/target-type: ip
9+
name: test-runtime-internal-router-ingress
10+
namespace: test-runtime
11+
spec:
12+
ingressClassName: alb
13+
rules:
14+
- host: testing.foo.bar.com
15+
http:
16+
paths:
17+
- backend:
18+
service:
19+
name: internal-router
20+
port:
21+
number: 80
22+
path: /webhooks
23+
pathType: Prefix
24+
- backend:
25+
service:
26+
name: internal-router
27+
port:
28+
number: 80
29+
path: /workflows
30+
pathType: Prefix
31+
- backend:
32+
service:
33+
name: internal-router
34+
port:
35+
number: 80
36+
path: /app-proxy
37+
pathType: Prefix
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
name: test-runtime-internal-router-ingress
5+
namespace: test-runtime
6+
spec:
7+
ingressClassName: nginx
8+
rules:
9+
- host: testing.foo.bar.com
10+
http:
11+
paths:
12+
- backend:
13+
service:
14+
name: internal-router
15+
port:
16+
number: 80
17+
path: /webhooks
18+
pathType: Prefix
19+
- backend:
20+
service:
21+
name: internal-router
22+
port:
23+
number: 80
24+
path: /workflows
25+
pathType: Prefix
26+
- backend:
27+
service:
28+
name: internal-router
29+
port:
30+
number: 80
31+
path: /app-proxy
32+
pathType: Prefix

0 commit comments

Comments
 (0)