Skip to content

Commit

Permalink
fix build pipeline
Browse files Browse the repository at this point in the history
fix Dockerfile

fix build pipeline
  • Loading branch information
gcleroux committed Sep 12, 2024
1 parent c634b83 commit 94f09c4
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=${BUILDPLATFORM} docker.io/library/golang:1.21.5 as builder
FROM --platform=${BUILDPLATFORM} docker.io/library/golang:1.21.5 AS builder

ARG LDFLAGS

Expand Down
77 changes: 64 additions & 13 deletions apex_dual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,54 @@ import (

func setupEmptyLookupFuncs() {
if resource := lookupResource("HTTPRoute"); resource != nil {
resource.lookup = func(_ []string) []netip.Addr { return []netip.Addr{} }
resource.lookup = func(_ []string) []interface{} {
addrs := []netip.Addr{}
result := make([]interface{}, len(addrs))
for i, addr := range addrs {
result[i] = addr
}
return result
}
}
if resource := lookupResource("TLSRoute"); resource != nil {
resource.lookup = func(_ []string) []netip.Addr { return []netip.Addr{} }
resource.lookup = func(_ []string) []interface{} {
addrs := []netip.Addr{}
result := make([]interface{}, len(addrs))
for i, addr := range addrs {
result[i] = addr
}
return result
}
}
if resource := lookupResource("GRPCRoute"); resource != nil {
resource.lookup = func(_ []string) []netip.Addr { return []netip.Addr{} }
resource.lookup = func(_ []string) []interface{} {
addrs := []netip.Addr{}
result := make([]interface{}, len(addrs))
for i, addr := range addrs {
result[i] = addr
}
return result
}
}
if resource := lookupResource("Ingress"); resource != nil {
resource.lookup = func(_ []string) []netip.Addr { return []netip.Addr{} }
resource.lookup = func(_ []string) []interface{} {
addrs := []netip.Addr{}
result := make([]interface{}, len(addrs))
for i, addr := range addrs {
result[i] = addr
}
return result
}
}
if resource := lookupResource("Service"); resource != nil {
resource.lookup = func(_ []string) []netip.Addr { return []netip.Addr{} }
resource.lookup = func(_ []string) []interface{} {
addrs := []netip.Addr{}
result := make([]interface{}, len(addrs))
for i, addr := range addrs {
result[i] = addr
}
return result
}
}
}

Expand Down Expand Up @@ -69,7 +104,9 @@ var testsDualNS = []test.Case{
Qname: "example.com.", Qtype: dns.TypeSOA,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.SOA("example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5"),
test.SOA(
"example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5",
),
},
},
{
Expand All @@ -88,42 +125,54 @@ var testsDualNS = []test.Case{
Qname: "example.com.", Qtype: dns.TypeSRV,
Rcode: dns.RcodeSuccess,
Ns: []dns.RR{
test.SOA("example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5"),
test.SOA(
"example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5",
),
},
},
{
Qname: "example.com.", Qtype: dns.TypeA,
Rcode: dns.RcodeSuccess,
Ns: []dns.RR{
test.SOA("example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5"),
test.SOA(
"example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5",
),
},
},
{
Qname: "dns1.kube-system.example.com.", Qtype: dns.TypeSRV,
Rcode: dns.RcodeSuccess,
Ns: []dns.RR{
test.SOA("example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5"),
test.SOA(
"example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5",
),
},
},
{
Qname: "dns1.kube-system.example.com.", Qtype: dns.TypeNS,
Rcode: dns.RcodeSuccess,
Ns: []dns.RR{
test.SOA("example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5"),
test.SOA(
"example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5",
),
},
},
{
Qname: "dns1.kube-system.example.com.", Qtype: dns.TypeSOA,
Rcode: dns.RcodeSuccess,
Ns: []dns.RR{
test.SOA("example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5"),
test.SOA(
"example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5",
),
},
},
{
Qname: "dns1.kube-system.example.com.", Qtype: dns.TypeAAAA,
Rcode: dns.RcodeSuccess,
Ns: []dns.RR{
test.SOA("example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5"),
test.SOA(
"example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5",
),
},
},
{
Expand All @@ -137,7 +186,9 @@ var testsDualNS = []test.Case{
Qname: "foo.dns1.kube-system.example.com.", Qtype: dns.TypeA,
Rcode: dns.RcodeNameError,
Ns: []dns.RR{
test.SOA("example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5"),
test.SOA(
"example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5",
),
},
},
}
Expand Down
82 changes: 63 additions & 19 deletions gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func TestLookup(t *testing.T) {
}

func TestPlugin(t *testing.T) {

ctrl := &KubeController{hasSynced: true}

gw := newGateway()
Expand Down Expand Up @@ -79,7 +78,6 @@ func TestPlugin(t *testing.T) {
}

func TestPluginFallthrough(t *testing.T) {

ctrl := &KubeController{hasSynced: true}
gw := newGateway()
gw.Zones = []string{"example.com."}
Expand All @@ -97,10 +95,16 @@ func TestPluginFallthrough(t *testing.T) {
_, err := gw.ServeDNS(ctx, w, r)

if errors.As(err, &Fallen{}) && !tc.FallthroughExpected {
t.Fatalf("Test %d query resulted unexpectedly in a fall through instead of a response", i)
t.Fatalf(
"Test %d query resulted unexpectedly in a fall through instead of a response",
i,
)
}
if err == nil && tc.FallthroughExpected {
t.Fatalf("Test %d query resulted unexpectedly in a response instead of a fall through", i)
t.Fatalf(
"Test %d query resulted unexpectedly in a response instead of a fall through",
i,
)
}
}
}
Expand Down Expand Up @@ -131,35 +135,45 @@ var tests = []test.Case{
{
Qname: "svcX.ns1.example.com.", Qtype: dns.TypeA, Rcode: dns.RcodeNameError,
Ns: []dns.RR{
test.SOA("example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5"),
test.SOA(
"example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5",
),
},
},
// Non-existing Ingress | Test 4
{
Qname: "d0main.example.com.", Qtype: dns.TypeA, Rcode: dns.RcodeNameError,
Ns: []dns.RR{
test.SOA("example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5"),
test.SOA(
"example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5",
),
},
},
// SOA for the existing domain | Test 5
{
Qname: "domain.example.com.", Qtype: dns.TypeSOA, Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.SOA("example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5"),
test.SOA(
"example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5",
),
},
},
// Service with no public addresses | Test 6
{
Qname: "svc3.ns1.example.com.", Qtype: dns.TypeA, Rcode: dns.RcodeNameError,
Ns: []dns.RR{
test.SOA("example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5"),
test.SOA(
"example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5",
),
},
},
// Real service, wrong query type | Test 7
{
Qname: "svc3.ns1.example.com.", Qtype: dns.TypeCNAME, Rcode: dns.RcodeSuccess,
Ns: []dns.RR{
test.SOA("example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5"),
test.SOA(
"example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5",
),
},
},
// Ingress FQDN == zone | Test 8
Expand Down Expand Up @@ -215,7 +229,9 @@ var tests = []test.Case{
{
Qname: "svc2.ns1.example.com.", Qtype: dns.TypeAAAA, Rcode: dns.RcodeSuccess,
Ns: []dns.RR{
test.SOA("example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5"),
test.SOA(
"example.com. 60 IN SOA dns1.kube-system.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5",
),
},
},
// Existing Service IPv6 | Test 16
Expand Down Expand Up @@ -266,15 +282,24 @@ var testsFallthrough = []FallthroughCase{
}

var testServiceIndexes = map[string][]netip.Addr{
"svc1.ns1": {netip.MustParseAddr("192.0.1.1"), netip.MustParseAddr("fd12:3456:789a:1::")},
"svc1.ns1": {
netip.MustParseAddr("192.0.1.1"),
netip.MustParseAddr("fd12:3456:789a:1::"),
},
"svc2.ns1": {netip.MustParseAddr("192.0.1.2")},
"svc3.ns1": {},
"dns1.kube-system": {netip.MustParseAddr("192.0.1.53")},
}

func testServiceLookup(keys []string) (results []netip.Addr) {
func testServiceLookup(keys []string) (results []interface{}) {
var addrs []netip.Addr
for _, key := range keys {
results = append(results, testServiceIndexes[strings.ToLower(key)]...)
addrs = append(addrs, testServiceIndexes[strings.ToLower(key)]...)
}

results = make([]interface{}, len(addrs))
for i, addr := range addrs {
results[i] = addr
}
return results
}
Expand All @@ -287,9 +312,15 @@ var testIngressIndexes = map[string][]netip.Addr{
"shadow-vs.example.com": {netip.MustParseAddr("192.0.0.5")},
}

func testIngressLookup(keys []string) (results []netip.Addr) {
func testIngressLookup(keys []string) (results []interface{}) {
var addrs []netip.Addr
for _, key := range keys {
results = append(results, testIngressIndexes[strings.ToLower(key)]...)
addrs = append(addrs, testIngressIndexes[strings.ToLower(key)]...)
}

results = make([]interface{}, len(addrs))
for i, addr := range addrs {
results[i] = addr
}
return results
}
Expand All @@ -300,9 +331,16 @@ var testVirtualServerIndexes = map[string][]netip.Addr{
"shadow-vs.example.com": {netip.MustParseAddr("192.0.3.5")},
}

func testVirtualServerLookup(keys []string) (results []netip.Addr) {
func testVirtualServerLookup(keys []string) (results []interface{}) {
var addrs []netip.Addr

for _, key := range keys {
results = append(results, testVirtualServerIndexes[strings.ToLower(key)]...)
addrs = append(addrs, testVirtualServerIndexes[strings.ToLower(key)]...)
}

results = make([]interface{}, len(addrs))
for i, addr := range addrs {
results[i] = addr
}
return results
}
Expand All @@ -312,9 +350,15 @@ var testRouteIndexes = map[string][]netip.Addr{
"shadow.example.com": {netip.MustParseAddr("192.0.2.4")},
}

func testRouteLookup(keys []string) (results []netip.Addr) {
func testRouteLookup(keys []string) (results []interface{}) {
var addrs []netip.Addr
for _, key := range keys {
results = append(results, testRouteIndexes[strings.ToLower(key)]...)
addrs = append(addrs, testRouteIndexes[strings.ToLower(key)]...)
}

results = make([]interface{}, len(addrs))
for i, addr := range addrs {
results[i] = addr
}
return results
}
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
module github.com/ori-edge/k8s_gateway
module github.com/pinax-network/k8s_gateway

go 1.22.0

toolchain go1.22.5
go 1.21

require (
github.com/cert-manager/cert-manager v1.15.3
github.com/coredns/caddy v1.1.1
github.com/coredns/coredns v1.11.3
github.com/miekg/dns v1.1.59
github.com/nginxinc/kubernetes-ingress v1.12.5
github.com/pinax-network/k8s_gateway v0.5.0
k8s.io/api v0.30.1
k8s.io/apimachinery v0.30.1
k8s.io/client-go v0.30.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ github.com/openzipkin-contrib/zipkin-go-opentracing v0.5.0 h1:uhcF5Jd7rP9DVEL10S
github.com/openzipkin-contrib/zipkin-go-opentracing v0.5.0/go.mod h1:+oCZ5GXXr7KPI/DNOQORPTq5AWHfALJj9c72b0+YsEY=
github.com/openzipkin/zipkin-go v0.4.2 h1:zjqfqHjUpPmB3c1GlCvvgsM1G4LkvqQbBDueDOCg/jA=
github.com/openzipkin/zipkin-go v0.4.2/go.mod h1:ZeVkFjuuBiSy13y8vpSDCjMi9GoI3hPpCJSBx/EYFhY=
github.com/ori-edge/k8s_gateway v0.4.0 h1:kINsea+AcuTB4Jw74SaHHYBKZ35N2ENCUF1gFItJvTc=
github.com/ori-edge/k8s_gateway v0.4.0/go.mod h1:GAVB0GKv/fzRc3Y7TGvNpISpIslVck4nmuvwTvAVWOU=
github.com/oschwald/geoip2-golang v1.9.0 h1:uvD3O6fXAXs+usU+UGExshpdP13GAqp4GBrzN7IgKZc=
github.com/oschwald/geoip2-golang v1.9.0/go.mod h1:BHK6TvDyATVQhKNbQBdrj9eAvuwOMi2zSFXizL3K81Y=
github.com/oschwald/maxminddb-golang v1.11.0 h1:aSXMqYR/EPNjGE8epgqwDay+P30hCBZIveY0WZbAWh0=
Expand Down
12 changes: 7 additions & 5 deletions kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ func addIngresses(client kubernetes.Interface) {
func addVirtualServers(client k8s_nginx.Interface) {
ctx := context.TODO()
for _, virtualServer := range testVirtualServers {
_, err := client.K8sV1().VirtualServers("ns1").Create(ctx, virtualServer, meta.CreateOptions{})
_, err := client.K8sV1().
VirtualServers("ns1").
Create(ctx, virtualServer, meta.CreateOptions{})
if err != nil {
log.Warningf("Failed to Create VirtualServer Objects :%s", err)
}
Expand Down Expand Up @@ -327,7 +329,7 @@ var testHTTPRoutes = map[string]*gatewayapi_v1.HTTPRoute{
Namespace: "ns1",
},
Spec: gatewayapi_v1.HTTPRouteSpec{
//ParentRefs: []gatewayapi_v1.ParentRef{},
// ParentRefs: []gatewayapi_v1.ParentRef{},
Hostnames: []gatewayapi_v1.Hostname{"route-1.gw-1.example.com"},
},
},
Expand All @@ -340,7 +342,7 @@ var testTLSRoutes = map[string]*gatewayapi_v1alpha2.TLSRoute{
Namespace: "ns1",
},
Spec: gatewayapi_v1alpha2.TLSRouteSpec{
//ParentRefs: []gatewayapi_v1.ParentRef{},
// ParentRefs: []gatewayapi_v1.ParentRef{},
Hostnames: []gatewayapi_v1alpha2.Hostname{
"route-1.gw-1.example.com",
},
Expand All @@ -354,8 +356,8 @@ var testGRPCRoutes = map[string]*gatewayapi_v1alpha2.GRPCRoute{
Name: "route-1",
Namespace: "ns1",
},
Spec: gatewayapi_v1alpha2.GRPCRouteSpec{
//ParentRefs: []gatewayapi_v1.ParentRef{},
Spec: gatewayapi_v1.GRPCRouteSpec{
// ParentRefs: []gatewayapi_v1.ParentRef{},
Hostnames: []gatewayapi_v1alpha2.Hostname{"route-1.gw-1.example.com"},
},
},
Expand Down

0 comments on commit 94f09c4

Please sign in to comment.