diff --git a/cmd/print.go b/cmd/print.go index a8cf3b04..180c8dd5 100644 --- a/cmd/print.go +++ b/cmd/print.go @@ -25,6 +25,8 @@ import ( "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw" "github.com/samber/lo" "github.com/spf13/cobra" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime/serializer/json" "k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/printers" "k8s.io/client-go/tools/clientcmd" @@ -179,6 +181,17 @@ func (pr *PrintRunner) outputResult(gatewayResources []i2gw.GatewayResources) { } } + for _, r := range gatewayResources { + resourceCount += len(r.GatewayExtensions) + for _, gatewayExtension := range r.GatewayExtensions { + gatewayExtension := gatewayExtension + fmt.Println("---") + if err := PrintUnstructuredAsYaml(&gatewayExtension); err != nil { + fmt.Printf("# Error printing %s gatewayExtension: %v\n", gatewayExtension.GetName(), err) + } + } + } + if resourceCount == 0 { msg := "No resources found" if pr.namespaceFilter != "" { @@ -310,3 +323,21 @@ func (pr *PrintRunner) getProviderSpecificFlags() map[string]map[string]string { } return providerSpecificFlags } + +func PrintUnstructuredAsYaml(obj *unstructured.Unstructured) error { + // Create a YAML serializer + serializer := json.NewSerializerWithOptions(json.DefaultMetaFactory, nil, nil, + json.SerializerOptions{ + Yaml: true, + Pretty: true, // Optional: for better readability + Strict: true, + }) + + // Encode the unstructured object to YAML + err := serializer.Encode(obj, os.Stdout) + if err != nil { + return err + } + + return nil +} diff --git a/go.mod b/go.mod index 945ca8f1..7a6834e6 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/kubernetes-sigs/ingress2gateway go 1.22.0 require ( + github.com/GoogleCloudPlatform/gke-gateway-api v1.3.0 github.com/getkin/kin-openapi v0.124.0 github.com/google/go-cmp v0.6.0 github.com/kong/kubernetes-ingress-controller/v2 v2.12.3 @@ -11,39 +12,38 @@ require ( github.com/spf13/cobra v1.8.0 github.com/stretchr/testify v1.9.0 istio.io/api v1.20.0 - k8s.io/api v0.30.0 - k8s.io/apimachinery v0.30.0 + k8s.io/api v0.30.1 + k8s.io/apimachinery v0.30.1 k8s.io/cli-runtime v0.29.0 k8s.io/client-go v0.30.0 k8s.io/ingress-gce v1.30.0 k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 - sigs.k8s.io/controller-runtime v0.16.3 - sigs.k8s.io/gateway-api v1.0.0 + sigs.k8s.io/controller-runtime v0.18.0 + sigs.k8s.io/gateway-api v1.1.0 ) require ( github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect github.com/invopop/yaml v0.2.0 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect - github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/perimeterx/marshmallow v1.1.5 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/rivo/uniseg v0.2.0 // indirect - golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect + golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect ) require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/emicklei/go-restful/v3 v3.11.0 // indirect + github.com/emicklei/go-restful/v3 v3.12.0 // indirect github.com/evanphx/json-patch v5.7.0+incompatible // indirect - github.com/evanphx/json-patch/v5 v5.7.0 // indirect + github.com/evanphx/json-patch/v5 v5.9.0 // indirect github.com/go-errors/errors v1.5.1 // indirect github.com/go-logr/logr v1.4.1 // indirect - github.com/go-openapi/jsonpointer v0.20.2 // indirect - github.com/go-openapi/jsonreference v0.20.2 // indirect - github.com/go-openapi/swag v0.22.8 // indirect + github.com/go-openapi/jsonpointer v0.21.0 // indirect + github.com/go-openapi/jsonreference v0.21.0 // indirect + github.com/go-openapi/swag v0.23.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/google/btree v1.1.2 // indirect @@ -67,14 +67,13 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/xlab/treeprint v1.2.0 // indirect go.starlark.net v0.0.0-20231121155337-90ade8b19d09 // indirect - golang.org/x/net v0.23.0 // indirect - golang.org/x/oauth2 v0.14.0 // indirect - golang.org/x/sync v0.5.0 // indirect - golang.org/x/sys v0.18.0 // indirect - golang.org/x/term v0.18.0 // indirect - golang.org/x/text v0.14.0 // indirect - golang.org/x/time v0.4.0 // indirect - google.golang.org/appengine v1.6.8 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/oauth2 v0.19.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/term v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect + golang.org/x/time v0.5.0 // indirect google.golang.org/genproto v0.0.0-20231120223509-83a465c0220f // indirect google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f // indirect google.golang.org/protobuf v1.33.0 @@ -84,7 +83,7 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect istio.io/client-go v1.19.0-alpha.1.0.20231130185426-9f1859c8ff42 k8s.io/klog/v2 v2.120.1 - k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect + k8s.io/kube-openapi v0.0.0-20240423202451-8948a665c108 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/kustomize/api v0.15.0 // indirect sigs.k8s.io/kustomize/kyaml v0.15.0 // indirect diff --git a/go.sum b/go.sum index 43222e77..30922486 100644 --- a/go.sum +++ b/go.sum @@ -1,64 +1,54 @@ github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= -github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= -github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= -github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/GoogleCloudPlatform/gke-gateway-api v1.3.0 h1:4WjH6dFtnezCFiYlbmq0SBF2f8PIQD3rV99m5FRb/UM= +github.com/GoogleCloudPlatform/gke-gateway-api v1.3.0/go.mod h1:IFDp1XhE20jjqWG3o2ocYoz33nCH6HC4rJ6Hdag4y1M= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= -github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/emicklei/go-restful/v3 v3.12.0 h1:y2DdzBAURM29NFF94q6RaY4vjIH1rtwDapwQtU84iWk= +github.com/emicklei/go-restful/v3 v3.12.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ2tG6yudJd8LBksgI= github.com/evanphx/json-patch v5.7.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= -github.com/evanphx/json-patch/v5 v5.7.0 h1:nJqP7uwL84RJInrohHfW0Fx3awjbm8qZeFv0nW9SYGc= -github.com/evanphx/json-patch/v5 v5.7.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= -github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= -github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg= +github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= github.com/getkin/kin-openapi v0.124.0 h1:VSFNMB9C9rTKBnQ/fpyDU8ytMTr4dWI9QovSKj9kz/M= github.com/getkin/kin-openapi v0.124.0/go.mod h1:wb1aSZA/iWmorQP9KTAS/phLj/t17B5jT7+fS8ed9NM= github.com/go-errors/errors v1.5.1 h1:ZwEMSLRCapFLflTpT7NKaAc7ukJ8ZPEjzlxt8rPN8bk= github.com/go-errors/errors v1.5.1/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= -github.com/go-logr/zapr v1.2.4 h1:QHVo+6stLbfJmYGkQ7uGHUCu5hnAFAj6mDe6Ea0SeOo= -github.com/go-logr/zapr v1.2.4/go.mod h1:FyHWQIzQORZ0QVE1BtVHv3cKtNLuXsbNLtpuhNapBOA= -github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= -github.com/go-openapi/jsonpointer v0.20.2 h1:mQc3nmndL8ZBzStEo3JYF8wzmeWffDH4VbXz58sAx6Q= -github.com/go-openapi/jsonpointer v0.20.2/go.mod h1:bHen+N0u1KEO3YlmqOjTT9Adn1RfD91Ar825/PuiRVs= -github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= -github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= -github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= -github.com/go-openapi/swag v0.22.8 h1:/9RjDSQ0vbFR+NyjGMkFTsA1IA0fmhKSThmfGZjicbw= -github.com/go-openapi/swag v0.22.8/go.mod h1:6QT22icPLEqAM/z/TChgb4WAveCHF92+2gF0CNjHpPI= +github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ= +github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg= +github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= +github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= +github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ= +github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4= +github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= +github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM= github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU= github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 h1:0VpGH+cDhbDtdcweoyCVsF3fhN8kejK6rFe/2FFX2nU= github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49/go.mod h1:BkkQ4L1KS1xMt2aWSPStnn55ChGC0DPOn2FQYj+f25M= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/pprof v0.0.0-20211214055906-6f57359322fd h1:1FjCyPC+syAzJ5/2S8fqdZK1R22vvA0J7JZKcuOIQ7Y= -github.com/google/pprof v0.0.0-20211214055906-6f57359322fd/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg= +github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= +github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -79,11 +69,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kong/kubernetes-ingress-controller/v2 v2.12.3 h1:HxQA6vp14rNMC4cIo81SMuNXD2vCUNMihPlQveTT9K4= github.com/kong/kubernetes-ingress-controller/v2 v2.12.3/go.mod h1:f2wIi3/yrwBYT+C/jtpB8tA+kEzewqLwOUGUwE5n+nk= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0= @@ -93,8 +80,6 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= -github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= github.com/moby/term v0.0.0-20221205130635-1aeaba878587 h1:HfkjXDfhgVaN5rmueG8cL8KKeFNecRCXFhaJ2qZ5SKA= github.com/moby/term v0.0.0-20221205130635-1aeaba878587/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -111,10 +96,10 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= -github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY= -github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM= -github.com/onsi/gomega v1.31.0 h1:54UJxxj6cPInHS3a35wm6BK/F9nHYueZ1NVujHDrnXE= -github.com/onsi/gomega v1.31.0/go.mod h1:DW9aCi7U6Yi40wNVAvT6kzFnEVEI5n3DloYBiKiT6zk= +github.com/onsi/ginkgo/v2 v2.17.1 h1:V++EzdbhI4ZV4ev0UTIj0PzhzOcReJFyJaLjtSF55M8= +github.com/onsi/ginkgo/v2 v2.17.1/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs= +github.com/onsi/gomega v1.32.0 h1:JRYU78fJ1LPxlckP6Txi/EYqJvjtMrDC04/MM5XRHPk= +github.com/onsi/gomega v1.32.0/go.mod h1:a4x4gW6Pz2yK1MAmvluYme5lvYTn61afQ2ETw/8n4Lg= github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s= github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= @@ -124,14 +109,6 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q= -github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY= -github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= -github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= -github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM= -github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY= -github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= -github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= @@ -146,15 +123,10 @@ github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyh github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= @@ -163,7 +135,6 @@ github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ= github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.starlark.net v0.0.0-20231121155337-90ade8b19d09 h1:hzy3LFnSN8kuQK8h9tHl4ndF6UruMj47OqwqsS+/Ai4= go.starlark.net v0.0.0-20231121155337-90ade8b19d09/go.mod h1:LcLNIzVOMp4oV+uusnpk+VU+SzXaJakUuBjoCSWH5dM= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= @@ -173,71 +144,51 @@ go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= -golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= +golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f h1:99ci1mjWVBWwJiEKYY6jWa4d2nTQVIEhZIptnrVb1XY= +golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= -golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= -golang.org/x/oauth2 v0.14.0 h1:P0Vrf/2538nmC0H+pEQ3MNFRRnVR7RlqyVw+bvm26z0= -golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/oauth2 v0.19.0 h1:9+E/EZBCbTLNrbN35fHv/a/d/mOBatymz1zbtQrXpIg= +golang.org/x/oauth2 v0.19.0/go.mod h1:vYi7skDa1x015PmRRYZ7+s1cWyPgrPiSYRe4rnsexc8= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= -golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= -golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/time v0.4.0 h1:Z81tqI5ddIoXDPvVQ7/7CC9TnLM7ubaFG2qXYd5BbYY= -golang.org/x/time v0.4.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= -golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= +golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw= +golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw= -gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY= -google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= -google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/genproto v0.0.0-20231120223509-83a465c0220f h1:Vn+VyHU5guc9KjB5KrjI2q0wCOWEOIh0OEsleqakHJg= google.golang.org/genproto v0.0.0-20231120223509-83a465c0220f/go.mod h1:nWSwAFPb+qfNJXsoeO3Io7zf4tMSfN8EA8RlDA04GhY= google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f h1:2yNACc1O40tTnrsbk9Cv6oxiW8pxI/pXj0wRtdlYmgY= google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f/go.mod h1:Uy9bTZJqmfrw2rIBxgGLnamc78euZULUBrLZ9XTITKI= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -258,12 +209,12 @@ istio.io/api v1.20.0 h1:heE1eQoMsuZlwWOf7Xm8TKqKLNKVs11G/zMe5QyR1u4= istio.io/api v1.20.0/go.mod h1:hm1PE/mGdIAsjCDkTIAplP53H7TjO5LUQCiVvF26SVg= istio.io/client-go v1.19.0-alpha.1.0.20231130185426-9f1859c8ff42 h1:YOTiFclrIEagVGbM2oHdD579+j6koeblvoOYGVMmzpE= istio.io/client-go v1.19.0-alpha.1.0.20231130185426-9f1859c8ff42/go.mod h1:yifta8BCYPNw5wFf42Jqt55cnGocIW0DxGlltwQUAaM= -k8s.io/api v0.30.0 h1:siWhRq7cNjy2iHssOB9SCGNCl2spiF1dO3dABqZ8niA= -k8s.io/api v0.30.0/go.mod h1:OPlaYhoHs8EQ1ql0R/TsUgaRPhpKNxIMrKQfWUp8QSE= -k8s.io/apiextensions-apiserver v0.28.3 h1:Od7DEnhXHnHPZG+W9I97/fSQkVpVPQx2diy+2EtmY08= -k8s.io/apiextensions-apiserver v0.28.3/go.mod h1:NE1XJZ4On0hS11aWWJUTNkmVB03j9LM7gJSisbRt8Lc= -k8s.io/apimachinery v0.30.0 h1:qxVPsyDM5XS96NIh9Oj6LavoVFYff/Pon9cZeDIkHHA= -k8s.io/apimachinery v0.30.0/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= +k8s.io/api v0.30.1 h1:kCm/6mADMdbAxmIh0LBjS54nQBE+U4KmbCfIkF5CpJY= +k8s.io/api v0.30.1/go.mod h1:ddbN2C0+0DIiPntan/bye3SW3PdwLa11/0yqwvuRrJM= +k8s.io/apiextensions-apiserver v0.30.0 h1:jcZFKMqnICJfRxTgnC4E+Hpcq8UEhT8B2lhBcQ+6uAs= +k8s.io/apiextensions-apiserver v0.30.0/go.mod h1:N9ogQFGcrbWqAY9p2mUAL5mGxsLqwgtUce127VtRX5Y= +k8s.io/apimachinery v0.30.1 h1:ZQStsEfo4n65yAdlGTfP/uSHMQSoYzU/oeEbkmF7P2U= +k8s.io/apimachinery v0.30.1/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= k8s.io/cli-runtime v0.29.0 h1:q2kC3cex4rOBLfPOnMSzV2BIrrQlx97gxHJs21KxKS4= k8s.io/cli-runtime v0.29.0/go.mod h1:VKudXp3X7wR45L+nER85YUzOQIru28HQpXr0mTdeCrk= k8s.io/client-go v0.30.0 h1:sB1AGGlhY/o7KCyCEQ0bPWzYDL0pwOZO4vAtTSh/gJQ= @@ -272,14 +223,14 @@ k8s.io/ingress-gce v1.30.0 h1:t3TChtmeLWJTX4sqBErvtJD1q+7836WRjM5g05q8xyE= k8s.io/ingress-gce v1.30.0/go.mod h1:IodeDa6NxJL40x4HkNlATPHRF3zI4oA/X4CpSMPax1E= k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw= k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= -k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag= -k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98= +k8s.io/kube-openapi v0.0.0-20240423202451-8948a665c108 h1:Q8Z7VlGhcJgBHJHYugJ/K/7iB8a2eSxCyxdVjJp+lLY= +k8s.io/kube-openapi v0.0.0-20240423202451-8948a665c108/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98= k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 h1:jgGTlFYnhF1PM1Ax/lAlxUPE+KfCIXHaathvJg1C3ak= k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -sigs.k8s.io/controller-runtime v0.16.3 h1:2TuvuokmfXvDUamSx1SuAOO3eTyye+47mJCigwG62c4= -sigs.k8s.io/controller-runtime v0.16.3/go.mod h1:j7bialYoSn142nv9sCOJmQgDXQXxnroFU4VnX/brVJ0= -sigs.k8s.io/gateway-api v1.0.0 h1:iPTStSv41+d9p0xFydll6d7f7MOBGuqXM6p2/zVYMAs= -sigs.k8s.io/gateway-api v1.0.0/go.mod h1:4cUgr0Lnp5FZ0Cdq8FdRwCvpiWws7LVhLHGIudLlf4c= +sigs.k8s.io/controller-runtime v0.18.0 h1:Z7jKuX784TQSUL1TIyeuF7j8KXZ4RtSX0YgtjKcSTME= +sigs.k8s.io/controller-runtime v0.18.0/go.mod h1:tuAt1+wbVsXIT8lPtk5RURxqAnq7xkpv2Mhttslg7Hw= +sigs.k8s.io/gateway-api v1.1.0 h1:DsLDXCi6jR+Xz8/xd0Z1PYl2Pn0TyaFMOPPZIj4inDM= +sigs.k8s.io/gateway-api v1.1.0/go.mod h1:ZH4lHrL2sDi0FHZ9jjneb8kKnGzFWyrTya35sWUTrRs= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= sigs.k8s.io/kustomize/api v0.15.0 h1:6Ca88kEOBVotHDw+y2IsIMYtg9Pvv7MKpW9JMyF/OH4= diff --git a/pkg/i2gw/ingress2gateway.go b/pkg/i2gw/ingress2gateway.go index 643a66a9..418da193 100644 --- a/pkg/i2gw/ingress2gateway.go +++ b/pkg/i2gw/ingress2gateway.go @@ -22,6 +22,8 @@ import ( "maps" "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/notifications" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/validation/field" "sigs.k8s.io/controller-runtime/pkg/client" @@ -198,3 +200,13 @@ func mergeGateways(gatewaResources []GatewayResources) (map[types.NamespacedName return newGateways, errs } + +func CastToUnstructured(obj runtime.Object) (*unstructured.Unstructured, error) { + // Convert the Kubernetes object to unstructured.Unstructured + unstructuredObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj) + if err != nil { + return nil, err + } + + return &unstructured.Unstructured{Object: unstructuredObj}, nil +} diff --git a/pkg/i2gw/intermediate/provider_gce.go b/pkg/i2gw/intermediate/provider_gce.go index fd82398f..ebd9b512 100644 --- a/pkg/i2gw/intermediate/provider_gce.go +++ b/pkg/i2gw/intermediate/provider_gce.go @@ -20,7 +20,13 @@ type GceGatewayIR struct { EnableHTTPSRedirect bool } type GceHTTPRouteIR struct{} -type GceServiceIR struct{} +type GceServiceIR struct { + SessionAffinity *SessionAffinityConfig +} +type SessionAffinityConfig struct { + AffinityType string + CookieTTLSec *int64 +} func mergeGceGatewayIR(current, existing *GceGatewayIR) *GceGatewayIR { // If either GceGatewayIR is nil, return the other one as the merged result. diff --git a/pkg/i2gw/provider.go b/pkg/i2gw/provider.go index c7141998..c6cd0d5f 100644 --- a/pkg/i2gw/provider.go +++ b/pkg/i2gw/provider.go @@ -21,6 +21,7 @@ import ( "sync" networkingv1 "k8s.io/api/networking/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/validation/field" "sigs.k8s.io/controller-runtime/pkg/client" @@ -88,7 +89,8 @@ type ProviderImplementationSpecificOptions struct { ToImplementationSpecificHTTPPathTypeMatch ImplementationSpecificHTTPPathTypeMatchConverter } -// GatewayResources contains all Gateway-API objects. +// GatewayResources contains all Gateway-API objects and provider Gateway +// extensions. type GatewayResources struct { Gateways map[types.NamespacedName]gatewayv1.Gateway GatewayClasses map[types.NamespacedName]gatewayv1.GatewayClass @@ -99,6 +101,8 @@ type GatewayResources struct { UDPRoutes map[types.NamespacedName]gatewayv1alpha2.UDPRoute ReferenceGrants map[types.NamespacedName]gatewayv1beta1.ReferenceGrant + + GatewayExtensions []unstructured.Unstructured } // FeatureParser is a function that reads the Ingresses, and applies diff --git a/pkg/i2gw/providers/common/converter.go b/pkg/i2gw/providers/common/converter.go index 5e9bee4b..9546327b 100644 --- a/pkg/i2gw/providers/common/converter.go +++ b/pkg/i2gw/providers/common/converter.go @@ -23,6 +23,7 @@ import ( "strings" "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw" + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/intermediate" networkingv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" @@ -67,6 +68,42 @@ func ToGateway(ingresses []networkingv1.Ingress, options i2gw.ProviderImplementa }, nil } +// ToIR converts the received ingresses to i2gw.IR without taking into +// consideration any provider specific logic. +func ToIR(ingresses []networkingv1.Ingress, options i2gw.ProviderImplementationSpecificOptions) (intermediate.IR, field.ErrorList) { + aggregator := ingressAggregator{ruleGroups: map[ruleGroupKey]*ingressRuleGroup{}} + + var errs field.ErrorList + for _, ingress := range ingresses { + aggregator.addIngress(ingress) + } + if len(errs) > 0 { + return intermediate.IR{}, errs + } + + routes, gateways, errs := aggregator.toHTTPRoutesAndGateways(options) + if len(errs) > 0 { + return intermediate.IR{}, errs + } + + routeByKey := make(map[types.NamespacedName]intermediate.HTTPRouteContext) + for _, route := range routes { + key := types.NamespacedName{Namespace: route.Namespace, Name: route.Name} + routeByKey[key] = intermediate.HTTPRouteContext{HTTPRoute: route} + } + + gatewayByKey := make(map[types.NamespacedName]intermediate.GatewayContext) + for _, gateway := range gateways { + key := types.NamespacedName{Namespace: gateway.Namespace, Name: gateway.Name} + gatewayByKey[key] = intermediate.GatewayContext{Gateway: gateway} + } + + return intermediate.IR{ + Gateways: gatewayByKey, + HTTPRoutes: routeByKey, + }, nil +} + var ( GatewayGVK = schema.GroupVersionKind{ Group: "gateway.networking.k8s.io", diff --git a/pkg/i2gw/providers/common/gateway_converter.go b/pkg/i2gw/providers/common/gateway_converter.go new file mode 100644 index 00000000..4926c258 --- /dev/null +++ b/pkg/i2gw/providers/common/gateway_converter.go @@ -0,0 +1,46 @@ +/* +Copyright 2024 The Kubernetes 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 common + +import ( + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw" + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/intermediate" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/validation/field" + gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" +) + +// ToGatewayResources converts the received i2gw.IR to i2gw.GatewayResource +// without taking into consideration any provider specific logic. +func ToGatewayResources(ir intermediate.IR) (i2gw.GatewayResources, field.ErrorList) { + gatewayResources := i2gw.GatewayResources{ + Gateways: make(map[types.NamespacedName]gatewayv1.Gateway), + HTTPRoutes: make(map[types.NamespacedName]gatewayv1.HTTPRoute), + GatewayClasses: ir.GatewayClasses, + TLSRoutes: ir.TLSRoutes, + TCPRoutes: ir.TCPRoutes, + UDPRoutes: ir.UDPRoutes, + ReferenceGrants: ir.ReferenceGrants, + } + for key, gatewayContext := range ir.Gateways { + gatewayResources.Gateways[key] = gatewayContext.Gateway + } + for key, httpRouteContext := range ir.HTTPRoutes { + gatewayResources.HTTPRoutes[key] = httpRouteContext.HTTPRoute + } + return gatewayResources, nil +} diff --git a/pkg/i2gw/providers/gce/converter_test.go b/pkg/i2gw/providers/gce/converter_test.go deleted file mode 100644 index 9974f41b..00000000 --- a/pkg/i2gw/providers/gce/converter_test.go +++ /dev/null @@ -1,622 +0,0 @@ -/* -Copyright 2024 The Kubernetes 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 gce - -import ( - "errors" - "fmt" - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw" - "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/common" - networkingv1 "k8s.io/api/networking/v1" - networkingv1beta1 "k8s.io/api/networking/v1beta1" - apiequality "k8s.io/apimachinery/pkg/api/equality" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/validation/field" - gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" -) - -func Test_ToGateway(t *testing.T) { - testNamespace := "default" - testHost := "test.mydomain.com" - testBackendServiceName := "test" - iPrefix := networkingv1.PathTypePrefix - implSpecificPathType := networkingv1.PathTypeImplementationSpecific - - gPathPrefix := gatewayv1.PathMatchPathPrefix - gExact := gatewayv1.PathMatchExact - - extIngClassIngressName := "gce-ingress-class" - intIngClassIngressName := "gce-internal-ingress-class" - noIngClassIngressName := "no-ingress-class" - - testCases := []struct { - name string - ingresses map[types.NamespacedName]*networkingv1.Ingress - expectedGatewayResources i2gw.GatewayResources - expectedErrors field.ErrorList - }{ - { - name: "gce ingress class", - ingresses: map[types.NamespacedName]*networkingv1.Ingress{ - {Namespace: testNamespace, Name: extIngClassIngressName}: { - ObjectMeta: metav1.ObjectMeta{ - Name: extIngClassIngressName, - Namespace: testNamespace, - Annotations: map[string]string{networkingv1beta1.AnnotationIngressClass: gceIngressClass}, - }, - Spec: networkingv1.IngressSpec{ - Rules: []networkingv1.IngressRule{{ - Host: testHost, - IngressRuleValue: networkingv1.IngressRuleValue{ - HTTP: &networkingv1.HTTPIngressRuleValue{ - Paths: []networkingv1.HTTPIngressPath{{ - Path: "/", - PathType: &iPrefix, - Backend: networkingv1.IngressBackend{ - Service: &networkingv1.IngressServiceBackend{ - Name: testBackendServiceName, - Port: networkingv1.ServiceBackendPort{ - Number: 80, - }, - }, - }, - }}, - }, - }, - }}, - }, - }, - }, - expectedGatewayResources: i2gw.GatewayResources{ - Gateways: map[types.NamespacedName]gatewayv1.Gateway{ - {Namespace: testNamespace, Name: gceIngressClass}: { - ObjectMeta: metav1.ObjectMeta{Name: gceIngressClass, Namespace: testNamespace}, - Spec: gatewayv1.GatewaySpec{ - GatewayClassName: gceL7GlobalExternalManagedGatewayClass, - Listeners: []gatewayv1.Listener{{ - Name: "test-mydomain-com-http", - Port: 80, - Protocol: gatewayv1.HTTPProtocolType, - Hostname: ptrTo(gatewayv1.Hostname(testHost)), - }}, - }, - }, - }, - HTTPRoutes: map[types.NamespacedName]gatewayv1.HTTPRoute{ - {Namespace: testNamespace, Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName)}: { - ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName), Namespace: testNamespace}, - Spec: gatewayv1.HTTPRouteSpec{ - CommonRouteSpec: gatewayv1.CommonRouteSpec{ - ParentRefs: []gatewayv1.ParentReference{{ - Name: gceIngressClass, - }}, - }, - Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, - Rules: []gatewayv1.HTTPRouteRule{ - { - Matches: []gatewayv1.HTTPRouteMatch{ - { - Path: &gatewayv1.HTTPPathMatch{ - Type: &gPathPrefix, - Value: ptrTo("/"), - }, - }, - }, - BackendRefs: []gatewayv1.HTTPBackendRef{ - { - BackendRef: gatewayv1.BackendRef{ - BackendObjectReference: gatewayv1.BackendObjectReference{ - Name: gatewayv1.ObjectName(testBackendServiceName), - Port: ptrTo(gatewayv1.PortNumber(80)), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - expectedErrors: field.ErrorList{}, - }, - { - name: "gce-internal ingress class", - ingresses: map[types.NamespacedName]*networkingv1.Ingress{ - {Namespace: testNamespace, Name: intIngClassIngressName}: { - ObjectMeta: metav1.ObjectMeta{ - Name: intIngClassIngressName, - Namespace: testNamespace, - Annotations: map[string]string{networkingv1beta1.AnnotationIngressClass: gceL7ILBIngressClass}, - }, - Spec: networkingv1.IngressSpec{ - Rules: []networkingv1.IngressRule{{ - Host: testHost, - IngressRuleValue: networkingv1.IngressRuleValue{ - HTTP: &networkingv1.HTTPIngressRuleValue{ - Paths: []networkingv1.HTTPIngressPath{{ - Path: "/", - PathType: &iPrefix, - Backend: networkingv1.IngressBackend{ - Service: &networkingv1.IngressServiceBackend{ - Name: testBackendServiceName, - Port: networkingv1.ServiceBackendPort{ - Number: 80, - }, - }, - }, - }}, - }, - }, - }}, - }, - }, - }, - expectedGatewayResources: i2gw.GatewayResources{ - Gateways: map[types.NamespacedName]gatewayv1.Gateway{ - {Namespace: testNamespace, Name: gceL7ILBIngressClass}: { - ObjectMeta: metav1.ObjectMeta{Name: gceL7ILBIngressClass, Namespace: testNamespace}, - Spec: gatewayv1.GatewaySpec{ - GatewayClassName: gceL7RegionalInternalGatewayClass, - Listeners: []gatewayv1.Listener{{ - Name: "test-mydomain-com-http", - Port: 80, - Protocol: gatewayv1.HTTPProtocolType, - Hostname: ptrTo(gatewayv1.Hostname(testHost)), - }}, - }, - }, - }, - HTTPRoutes: map[types.NamespacedName]gatewayv1.HTTPRoute{ - {Namespace: testNamespace, Name: "gce-internal-ingress-class-test-mydomain-com"}: { - ObjectMeta: metav1.ObjectMeta{Name: "gce-internal-ingress-class-test-mydomain-com", Namespace: testNamespace}, - Spec: gatewayv1.HTTPRouteSpec{ - CommonRouteSpec: gatewayv1.CommonRouteSpec{ - ParentRefs: []gatewayv1.ParentReference{{ - Name: gceL7ILBIngressClass, - }}, - }, - Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, - Rules: []gatewayv1.HTTPRouteRule{ - { - Matches: []gatewayv1.HTTPRouteMatch{ - { - Path: &gatewayv1.HTTPPathMatch{ - Type: &gPathPrefix, - Value: ptrTo("/"), - }, - }, - }, - BackendRefs: []gatewayv1.HTTPBackendRef{ - { - BackendRef: gatewayv1.BackendRef{ - BackendObjectReference: gatewayv1.BackendObjectReference{ - Name: gatewayv1.ObjectName(testBackendServiceName), - Port: ptrTo(gatewayv1.PortNumber(80)), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - expectedErrors: field.ErrorList{}, - }, - { - name: "empty ingress class, default to gce ingress class", - ingresses: map[types.NamespacedName]*networkingv1.Ingress{ - {Namespace: testNamespace, Name: noIngClassIngressName}: { - ObjectMeta: metav1.ObjectMeta{ - Name: noIngClassIngressName, - Namespace: testNamespace, - }, - Spec: networkingv1.IngressSpec{ - Rules: []networkingv1.IngressRule{{ - Host: testHost, - IngressRuleValue: networkingv1.IngressRuleValue{ - HTTP: &networkingv1.HTTPIngressRuleValue{ - Paths: []networkingv1.HTTPIngressPath{{ - Path: "/", - PathType: &iPrefix, - Backend: networkingv1.IngressBackend{ - Service: &networkingv1.IngressServiceBackend{ - Name: testBackendServiceName, - Port: networkingv1.ServiceBackendPort{ - Number: 80, - }, - }, - }, - }}, - }, - }, - }}, - }, - }, - }, - expectedGatewayResources: i2gw.GatewayResources{ - Gateways: map[types.NamespacedName]gatewayv1.Gateway{ - {Namespace: testNamespace, Name: gceIngressClass}: { - ObjectMeta: metav1.ObjectMeta{Name: gceIngressClass, Namespace: testNamespace}, - Spec: gatewayv1.GatewaySpec{ - GatewayClassName: gceL7GlobalExternalManagedGatewayClass, - Listeners: []gatewayv1.Listener{{ - Name: "test-mydomain-com-http", - Port: 80, - Protocol: gatewayv1.HTTPProtocolType, - Hostname: ptrTo(gatewayv1.Hostname(testHost)), - }}, - }, - }, - }, - HTTPRoutes: map[types.NamespacedName]gatewayv1.HTTPRoute{ - {Namespace: testNamespace, Name: fmt.Sprintf("%s-test-mydomain-com", noIngClassIngressName)}: { - ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-test-mydomain-com", noIngClassIngressName), Namespace: testNamespace}, - Spec: gatewayv1.HTTPRouteSpec{ - CommonRouteSpec: gatewayv1.CommonRouteSpec{ - ParentRefs: []gatewayv1.ParentReference{{ - Name: gceIngressClass, - }}, - }, - Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, - Rules: []gatewayv1.HTTPRouteRule{ - { - Matches: []gatewayv1.HTTPRouteMatch{ - { - Path: &gatewayv1.HTTPPathMatch{ - Type: &gPathPrefix, - Value: ptrTo("/"), - }, - }, - }, - BackendRefs: []gatewayv1.HTTPBackendRef{ - { - BackendRef: gatewayv1.BackendRef{ - BackendObjectReference: gatewayv1.BackendObjectReference{ - Name: gatewayv1.ObjectName(testBackendServiceName), - Port: ptrTo(gatewayv1.PortNumber(80)), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - expectedErrors: field.ErrorList{}, - }, - { - name: "gce implementation-specific with /*, map to / Prefix", - ingresses: map[types.NamespacedName]*networkingv1.Ingress{ - {Namespace: testNamespace, Name: extIngClassIngressName}: { - ObjectMeta: metav1.ObjectMeta{ - Name: extIngClassIngressName, - Namespace: testNamespace, - Annotations: map[string]string{networkingv1beta1.AnnotationIngressClass: gceIngressClass}, - }, - Spec: networkingv1.IngressSpec{ - Rules: []networkingv1.IngressRule{{ - Host: testHost, - IngressRuleValue: networkingv1.IngressRuleValue{ - HTTP: &networkingv1.HTTPIngressRuleValue{ - Paths: []networkingv1.HTTPIngressPath{{ - Path: "/*", - PathType: &implSpecificPathType, - Backend: networkingv1.IngressBackend{ - Service: &networkingv1.IngressServiceBackend{ - Name: testBackendServiceName, - Port: networkingv1.ServiceBackendPort{ - Number: 80, - }, - }, - }, - }}, - }, - }, - }}, - }, - }, - }, - expectedGatewayResources: i2gw.GatewayResources{ - Gateways: map[types.NamespacedName]gatewayv1.Gateway{ - {Namespace: testNamespace, Name: gceIngressClass}: { - ObjectMeta: metav1.ObjectMeta{Name: gceIngressClass, Namespace: testNamespace}, - Spec: gatewayv1.GatewaySpec{ - GatewayClassName: gceL7GlobalExternalManagedGatewayClass, - Listeners: []gatewayv1.Listener{{ - Name: "test-mydomain-com-http", - Port: 80, - Protocol: gatewayv1.HTTPProtocolType, - Hostname: ptrTo(gatewayv1.Hostname(testHost)), - }}, - }, - }, - }, - HTTPRoutes: map[types.NamespacedName]gatewayv1.HTTPRoute{ - {Namespace: testNamespace, Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName)}: { - ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName), Namespace: testNamespace}, - Spec: gatewayv1.HTTPRouteSpec{ - CommonRouteSpec: gatewayv1.CommonRouteSpec{ - ParentRefs: []gatewayv1.ParentReference{{ - Name: gceIngressClass, - }}, - }, - Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, - Rules: []gatewayv1.HTTPRouteRule{ - { - Matches: []gatewayv1.HTTPRouteMatch{ - { - Path: &gatewayv1.HTTPPathMatch{ - Type: &gPathPrefix, - Value: ptrTo("/"), - }, - }, - }, - BackendRefs: []gatewayv1.HTTPBackendRef{ - { - BackendRef: gatewayv1.BackendRef{ - BackendObjectReference: gatewayv1.BackendObjectReference{ - Name: gatewayv1.ObjectName(testBackendServiceName), - Port: ptrTo(gatewayv1.PortNumber(80)), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - expectedErrors: field.ErrorList{}, - }, - { - name: "gce implementation-specific with /foo/*, converted to /foo", - ingresses: map[types.NamespacedName]*networkingv1.Ingress{ - {Namespace: testNamespace, Name: extIngClassIngressName}: { - ObjectMeta: metav1.ObjectMeta{ - Name: extIngClassIngressName, - Namespace: testNamespace, - Annotations: map[string]string{networkingv1beta1.AnnotationIngressClass: gceIngressClass}, - }, - Spec: networkingv1.IngressSpec{ - Rules: []networkingv1.IngressRule{{ - Host: testHost, - IngressRuleValue: networkingv1.IngressRuleValue{ - HTTP: &networkingv1.HTTPIngressRuleValue{ - Paths: []networkingv1.HTTPIngressPath{{ - Path: "/foo/*", - PathType: &implSpecificPathType, - Backend: networkingv1.IngressBackend{ - Service: &networkingv1.IngressServiceBackend{ - Name: testBackendServiceName, - Port: networkingv1.ServiceBackendPort{ - Number: 80, - }, - }, - }, - }}, - }, - }, - }}, - }, - }, - }, - expectedGatewayResources: i2gw.GatewayResources{ - Gateways: map[types.NamespacedName]gatewayv1.Gateway{ - {Namespace: testNamespace, Name: gceIngressClass}: { - ObjectMeta: metav1.ObjectMeta{Name: gceIngressClass, Namespace: testNamespace}, - Spec: gatewayv1.GatewaySpec{ - GatewayClassName: gceL7GlobalExternalManagedGatewayClass, - Listeners: []gatewayv1.Listener{{ - Name: "test-mydomain-com-http", - Port: 80, - Protocol: gatewayv1.HTTPProtocolType, - Hostname: ptrTo(gatewayv1.Hostname(testHost)), - }}, - }, - }, - }, - HTTPRoutes: map[types.NamespacedName]gatewayv1.HTTPRoute{ - {Namespace: testNamespace, Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName)}: { - ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName), Namespace: testNamespace}, - Spec: gatewayv1.HTTPRouteSpec{ - CommonRouteSpec: gatewayv1.CommonRouteSpec{ - ParentRefs: []gatewayv1.ParentReference{{ - Name: gceIngressClass, - }}, - }, - Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, - Rules: []gatewayv1.HTTPRouteRule{ - { - Matches: []gatewayv1.HTTPRouteMatch{ - { - Path: &gatewayv1.HTTPPathMatch{ - Type: &gPathPrefix, - Value: ptrTo("/foo"), - }, - }, - }, - BackendRefs: []gatewayv1.HTTPBackendRef{ - { - BackendRef: gatewayv1.BackendRef{ - BackendObjectReference: gatewayv1.BackendObjectReference{ - Name: gatewayv1.ObjectName(testBackendServiceName), - Port: ptrTo(gatewayv1.PortNumber(80)), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - expectedErrors: nil, - }, - { - name: "gce implementation-specific without wildcard path, map to Prefix", - ingresses: map[types.NamespacedName]*networkingv1.Ingress{ - {Namespace: testNamespace, Name: extIngClassIngressName}: { - ObjectMeta: metav1.ObjectMeta{ - Name: extIngClassIngressName, - Namespace: testNamespace, - Annotations: map[string]string{networkingv1beta1.AnnotationIngressClass: gceIngressClass}, - }, - Spec: networkingv1.IngressSpec{ - Rules: []networkingv1.IngressRule{{ - Host: testHost, - IngressRuleValue: networkingv1.IngressRuleValue{ - HTTP: &networkingv1.HTTPIngressRuleValue{ - Paths: []networkingv1.HTTPIngressPath{{ - Path: "/foo", - PathType: &implSpecificPathType, - Backend: networkingv1.IngressBackend{ - Service: &networkingv1.IngressServiceBackend{ - Name: testBackendServiceName, - Port: networkingv1.ServiceBackendPort{ - Number: 80, - }, - }, - }, - }}, - }, - }, - }}, - }, - }, - }, - expectedGatewayResources: i2gw.GatewayResources{ - Gateways: map[types.NamespacedName]gatewayv1.Gateway{ - {Namespace: testNamespace, Name: gceIngressClass}: { - ObjectMeta: metav1.ObjectMeta{Name: gceIngressClass, Namespace: testNamespace}, - Spec: gatewayv1.GatewaySpec{ - GatewayClassName: gceL7GlobalExternalManagedGatewayClass, - Listeners: []gatewayv1.Listener{{ - Name: "test-mydomain-com-http", - Port: 80, - Protocol: gatewayv1.HTTPProtocolType, - Hostname: ptrTo(gatewayv1.Hostname(testHost)), - }}, - }, - }, - }, - HTTPRoutes: map[types.NamespacedName]gatewayv1.HTTPRoute{ - {Namespace: testNamespace, Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName)}: { - ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName), Namespace: testNamespace}, - Spec: gatewayv1.HTTPRouteSpec{ - CommonRouteSpec: gatewayv1.CommonRouteSpec{ - ParentRefs: []gatewayv1.ParentReference{{ - Name: gceIngressClass, - }}, - }, - Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, - Rules: []gatewayv1.HTTPRouteRule{ - { - Matches: []gatewayv1.HTTPRouteMatch{ - { - Path: &gatewayv1.HTTPPathMatch{ - Type: &gExact, - Value: ptrTo("/foo"), - }, - }, - }, - BackendRefs: []gatewayv1.HTTPBackendRef{ - { - BackendRef: gatewayv1.BackendRef{ - BackendObjectReference: gatewayv1.BackendObjectReference{ - Name: gatewayv1.ObjectName(testBackendServiceName), - Port: ptrTo(gatewayv1.PortNumber(80)), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - expectedErrors: field.ErrorList{}, - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - - provider := NewProvider(&i2gw.ProviderConf{}) - gceProvider := provider.(*Provider) - gceProvider.storage = newResourcesStorage() - gceProvider.storage.Ingresses = tc.ingresses - - // TODO(#113) we pass an empty i2gw.InputResources temporarily until we change ToGatewayAPI function on the interface - gatewayResources, errs := provider.ToGatewayAPI() - - if len(errs) != len(tc.expectedErrors) { - t.Errorf("Expected %d errors, got %d: %+v", len(tc.expectedErrors), len(errs), errs) - } else { - for i, e := range errs { - if errors.Is(e, tc.expectedErrors[i]) { - t.Errorf("Unexpected error message at %d index. Got %s, want: %s", i, e, tc.expectedErrors[i]) - } - } - } - - if len(gatewayResources.HTTPRoutes) != len(tc.expectedGatewayResources.HTTPRoutes) { - t.Errorf("Expected %d HTTPRoutes, got %d: %+v", - len(tc.expectedGatewayResources.HTTPRoutes), len(gatewayResources.HTTPRoutes), gatewayResources.HTTPRoutes) - } else { - for i, got := range gatewayResources.HTTPRoutes { - key := types.NamespacedName{Namespace: got.Namespace, Name: got.Name} - want := tc.expectedGatewayResources.HTTPRoutes[key] - want.SetGroupVersionKind(common.HTTPRouteGVK) - if !apiequality.Semantic.DeepEqual(got, want) { - t.Errorf("Expected HTTPRoute %s to be %+v\n Got: %+v\n Diff: %s", i, want, got, cmp.Diff(want, got)) - } - } - } - - if len(gatewayResources.Gateways) != len(tc.expectedGatewayResources.Gateways) { - t.Errorf("Expected %d Gateways, got %d: %+v", - len(tc.expectedGatewayResources.Gateways), len(gatewayResources.Gateways), gatewayResources.Gateways) - } else { - for i, got := range gatewayResources.Gateways { - key := types.NamespacedName{Namespace: got.Namespace, Name: got.Name} - want := tc.expectedGatewayResources.Gateways[key] - want.SetGroupVersionKind(common.GatewayGVK) - if !apiequality.Semantic.DeepEqual(got, want) { - t.Errorf("Expected Gateway %s to be %+v\n Got: %+v\n Diff: %s", i, want, got, cmp.Diff(want, got)) - } - } - } - - }) - } -} - -func ptrTo[T any](a T) *T { - return &a -} diff --git a/pkg/i2gw/providers/gce/gateway_converter.go b/pkg/i2gw/providers/gce/gateway_converter.go new file mode 100644 index 00000000..1ab09951 --- /dev/null +++ b/pkg/i2gw/providers/gce/gateway_converter.go @@ -0,0 +1,40 @@ +/* +Copyright 2024 The Kubernetes 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 gce + +import ( + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw" + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/intermediate" + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/common" + "k8s.io/apimachinery/pkg/util/validation/field" +) + +type irToGatewayResourcesConverter struct{} + +// newIRToGatewayResourcesConverter returns an gce irToGatewayResourcesConverter instance. +func newIRToGatewayResourcesConverter() irToGatewayResourcesConverter { + return irToGatewayResourcesConverter{} +} + +func (c *irToGatewayResourcesConverter) irToGateway(ir intermediate.IR) (i2gw.GatewayResources, field.ErrorList) { + gatewayResources, errs := common.ToGatewayResources(ir) + if len(errs) != 0 { + return i2gw.GatewayResources{}, errs + } + buildGceServiceExtensions(ir, &gatewayResources) + return gatewayResources, nil +} diff --git a/pkg/i2gw/providers/gce/gateway_converter_test.go b/pkg/i2gw/providers/gce/gateway_converter_test.go new file mode 100644 index 00000000..7b4de538 --- /dev/null +++ b/pkg/i2gw/providers/gce/gateway_converter_test.go @@ -0,0 +1,291 @@ +/* +Copyright 2024 The Kubernetes 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 gce + +import ( + "errors" + "testing" + + gkegatewayv1 "github.com/GoogleCloudPlatform/gke-gateway-api/apis/networking/v1" + "github.com/google/go-cmp/cmp" + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw" + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/intermediate" + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/common" + apiequality "k8s.io/apimachinery/pkg/api/equality" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/validation/field" + + gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" + "sigs.k8s.io/gateway-api/apis/v1alpha2" +) + +func Test_irToGateway(t *testing.T) { + testNamespace := "default" + testHost := "test.mydomain.com" + testServiceName := "test-service" + testGatewayName := "test-gateway" + testHTTPRouteName := "test-http-route" + + gPathPrefix := gatewayv1.PathMatchPathPrefix + saTypeClientIP := "CLIENT_IP" + testCookieTTLSec := int64(10) + saTypeCookie := "GENERATED_COOKIE" + + testGateway := gatewayv1.Gateway{ + ObjectMeta: metav1.ObjectMeta{Name: testGatewayName, Namespace: testNamespace}, + Spec: gatewayv1.GatewaySpec{ + GatewayClassName: gceL7GlobalExternalManagedGatewayClass, + Listeners: []gatewayv1.Listener{{ + Name: "test-mydomain-com-http", + Port: 80, + Protocol: gatewayv1.HTTPProtocolType, + Hostname: ptrTo(gatewayv1.Hostname(testHost)), + }}, + }, + } + + testHTTPRoute := gatewayv1.HTTPRoute{ + ObjectMeta: metav1.ObjectMeta{Name: testHTTPRouteName, Namespace: testNamespace}, + Spec: gatewayv1.HTTPRouteSpec{ + CommonRouteSpec: gatewayv1.CommonRouteSpec{ + ParentRefs: []gatewayv1.ParentReference{{ + Name: gatewayv1.ObjectName(testGatewayName), + }}, + }, + Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, + Rules: []gatewayv1.HTTPRouteRule{ + { + Matches: []gatewayv1.HTTPRouteMatch{ + { + Path: &gatewayv1.HTTPPathMatch{ + Type: &gPathPrefix, + Value: ptrTo("/"), + }, + }, + }, + BackendRefs: []gatewayv1.HTTPBackendRef{ + { + BackendRef: gatewayv1.BackendRef{ + BackendObjectReference: gatewayv1.BackendObjectReference{ + Name: gatewayv1.ObjectName(testServiceName), + Port: ptrTo(gatewayv1.PortNumber(80)), + }, + }, + }, + }, + }, + }, + }, + } + + testSaBackendPolicyName := testServiceName + testSaGCPBackendPolicyCookie := gkegatewayv1.GCPBackendPolicy{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: testNamespace, + Name: testSaBackendPolicyName, + }, + Spec: gkegatewayv1.GCPBackendPolicySpec{ + Default: &gkegatewayv1.GCPBackendPolicyConfig{ + SessionAffinity: &gkegatewayv1.SessionAffinityConfig{ + Type: ptrTo("GENERATED_COOKIE"), + CookieTTLSec: &testCookieTTLSec, + }, + }, + TargetRef: v1alpha2.NamespacedPolicyTargetReference{ + Group: "", + Kind: "Service", + Name: gatewayv1.ObjectName(testServiceName), + }, + }, + } + testSaGCPBackendPolicyCookie.SetGroupVersionKind(GCPBackendPolicyGVK) + testSaGCPBackendPolicyCookieUnstructured, err := i2gw.CastToUnstructured(&testSaGCPBackendPolicyCookie) + if err != nil { + t.Errorf("Failed to generate unstructured GCP Backend Policy with Cookie-based session affinity feature: %v", err) + } + + testSaGCPBackendPolicyClientIP := gkegatewayv1.GCPBackendPolicy{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: testNamespace, + Name: testSaBackendPolicyName, + }, + Spec: gkegatewayv1.GCPBackendPolicySpec{ + Default: &gkegatewayv1.GCPBackendPolicyConfig{ + SessionAffinity: &gkegatewayv1.SessionAffinityConfig{ + Type: ptrTo("CLIENT_IP"), + }, + }, + TargetRef: v1alpha2.NamespacedPolicyTargetReference{ + Group: "", + Kind: "Service", + Name: gatewayv1.ObjectName(testServiceName), + }, + }, + } + testSaGCPBackendPolicyClientIP.SetGroupVersionKind(GCPBackendPolicyGVK) + testSaGCPBackendPolicyClientIPUnstructured, err := i2gw.CastToUnstructured(&testSaGCPBackendPolicyClientIP) + if err != nil { + t.Errorf("Failed to generate unstructured GCP Backend Policy with ClientIP-based session affinity feature: %v", err) + } + testCases := []struct { + name string + ir intermediate.IR + expectedGatewayResources i2gw.GatewayResources + expectedErrors field.ErrorList + }{ + { + name: "ingress with a Backend Config specifying CLIENT_IP type session affinity config", + ir: intermediate.IR{ + Gateways: map[types.NamespacedName]intermediate.GatewayContext{ + {Namespace: testNamespace, Name: testGatewayName}: { + Gateway: testGateway, + }, + }, + HTTPRoutes: map[types.NamespacedName]intermediate.HTTPRouteContext{ + {Namespace: testNamespace, Name: testHTTPRouteName}: { + HTTPRoute: testHTTPRoute, + }, + }, + Services: map[types.NamespacedName]intermediate.ProviderSpecificServiceIR{ + {Namespace: testNamespace, Name: testServiceName}: { + Gce: &intermediate.GceServiceIR{ + SessionAffinity: &intermediate.SessionAffinityConfig{ + AffinityType: saTypeClientIP, + }, + }, + }, + }, + }, + expectedGatewayResources: i2gw.GatewayResources{ + Gateways: map[types.NamespacedName]gatewayv1.Gateway{ + {Namespace: testNamespace, Name: testGatewayName}: testGateway, + }, + HTTPRoutes: map[types.NamespacedName]gatewayv1.HTTPRoute{ + {Namespace: testNamespace, Name: testHTTPRouteName}: testHTTPRoute, + }, + GatewayExtensions: []unstructured.Unstructured{ + *testSaGCPBackendPolicyClientIPUnstructured, + }, + }, + expectedErrors: field.ErrorList{}, + }, + { + name: "ingress with a Backend Config specifying GENERATED_COOKIE type session affinity config", + ir: intermediate.IR{ + Gateways: map[types.NamespacedName]intermediate.GatewayContext{ + {Namespace: testNamespace, Name: testGatewayName}: { + Gateway: testGateway, + }, + }, + HTTPRoutes: map[types.NamespacedName]intermediate.HTTPRouteContext{ + {Namespace: testNamespace, Name: testHTTPRouteName}: { + HTTPRoute: testHTTPRoute, + }, + }, + Services: map[types.NamespacedName]intermediate.ProviderSpecificServiceIR{ + {Namespace: testNamespace, Name: testServiceName}: { + Gce: &intermediate.GceServiceIR{ + SessionAffinity: &intermediate.SessionAffinityConfig{ + AffinityType: saTypeCookie, + CookieTTLSec: &testCookieTTLSec, + }, + }, + }, + }, + }, + expectedGatewayResources: i2gw.GatewayResources{ + Gateways: map[types.NamespacedName]gatewayv1.Gateway{ + {Namespace: testNamespace, Name: testGatewayName}: testGateway, + }, + HTTPRoutes: map[types.NamespacedName]gatewayv1.HTTPRoute{ + {Namespace: testNamespace, Name: testHTTPRouteName}: testHTTPRoute, + }, + GatewayExtensions: []unstructured.Unstructured{ + *testSaGCPBackendPolicyCookieUnstructured, + }, + }, + expectedErrors: field.ErrorList{}, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + + provider := NewProvider(&i2gw.ProviderConf{}) + gceProvider := provider.(*Provider) + gatewayResources, errs := gceProvider.gatewayConverter.irToGateway(tc.ir) + + if len(errs) != len(tc.expectedErrors) { + t.Errorf("Expected %d errors, got %d: %+v", len(tc.expectedErrors), len(errs), errs) + } else { + for i, e := range errs { + if errors.Is(e, tc.expectedErrors[i]) { + t.Errorf("Unexpected error message at %d index. Got %s, want: %s", i, e, tc.expectedErrors[i]) + } + } + } + + if len(gatewayResources.HTTPRoutes) != len(tc.expectedGatewayResources.HTTPRoutes) { + t.Errorf("Expected %d HTTPRoutes, got %d: %+v", + len(tc.expectedGatewayResources.HTTPRoutes), len(gatewayResources.HTTPRoutes), gatewayResources.HTTPRoutes) + } else { + for i, got := range gatewayResources.HTTPRoutes { + got.SetGroupVersionKind(common.HTTPRouteGVK) + key := types.NamespacedName{Namespace: got.Namespace, Name: got.Name} + want := tc.expectedGatewayResources.HTTPRoutes[key] + want.SetGroupVersionKind(common.HTTPRouteGVK) + if !apiequality.Semantic.DeepEqual(got, want) { + t.Errorf("Expected HTTPRoute %s to be %+v\n Got: %+v\n Diff: %s", i, want, got, cmp.Diff(want, got)) + } + } + } + + if len(gatewayResources.Gateways) != len(tc.expectedGatewayResources.Gateways) { + t.Errorf("Expected %d Gateways, got %d: %+v", + len(tc.expectedGatewayResources.Gateways), len(gatewayResources.Gateways), gatewayResources.Gateways) + } else { + for i, got := range gatewayResources.Gateways { + got.SetGroupVersionKind(common.GatewayGVK) + key := types.NamespacedName{Namespace: got.Namespace, Name: got.Name} + want := tc.expectedGatewayResources.Gateways[key] + want.SetGroupVersionKind(common.GatewayGVK) + if !apiequality.Semantic.DeepEqual(got, want) { + t.Errorf("Expected Gateway %s to be %+v\n Got: %+v\n Diff: %s", i, want, got, cmp.Diff(want, got)) + } + } + } + + if len(gatewayResources.GatewayExtensions) != len(tc.expectedGatewayResources.GatewayExtensions) { + t.Errorf("Expected %d GatewayExtensions, got %d: %+v", + len(tc.expectedGatewayResources.GatewayExtensions), len(gatewayResources.GatewayExtensions), gatewayResources.GatewayExtensions) + } else { + for _, got := range gatewayResources.GatewayExtensions { + for _, want := range tc.expectedGatewayResources.GatewayExtensions { + if got.GetNamespace() != want.GetNamespace() || got.GetName() != want.GetName() { + continue + } + if !apiequality.Semantic.DeepEqual(got, want) { + t.Errorf("Expected GatewayExtension %s/%s to be %+v\n Got: %+v\n Diff: %s", got.GetNamespace(), got.GetName(), want, got, cmp.Diff(want, got)) + } + } + } + } + }) + } +} diff --git a/pkg/i2gw/providers/gce/gce.go b/pkg/i2gw/providers/gce/gce.go index 602a0c5b..5c1dcd97 100644 --- a/pkg/i2gw/providers/gce/gce.go +++ b/pkg/i2gw/providers/gce/gce.go @@ -21,7 +21,9 @@ import ( "fmt" "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw" + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/notifications" "k8s.io/apimachinery/pkg/util/validation/field" + backendconfigv1 "k8s.io/ingress-gce/pkg/apis/backendconfig/v1" ) const ProviderName = "gce" @@ -32,16 +34,25 @@ func init() { // Provider implements the i2gw.Provider interface. type Provider struct { - storage *storage - reader reader - converter converter + storage *storage + reader reader + irConverter resourcesToIRConverter + gatewayConverter irToGatewayResourcesConverter } func NewProvider(conf *i2gw.ProviderConf) i2gw.Provider { + // Add BackendConfig to Schema when reading in-cluster so these resources + // can be recognized. + if conf.Client != nil { + if err := backendconfigv1.AddToScheme(conf.Client.Scheme()); err != nil { + notify(notifications.ErrorNotification, "Failed to add v1 BackendConfig Scheme") + } + } return &Provider{ - storage: newResourcesStorage(), - reader: newResourceReader(conf), - converter: newConverter(conf), + storage: newResourcesStorage(), + reader: newResourceReader(conf), + irConverter: newResourceToIRConverter(conf), + gatewayConverter: newIRToGatewayResourcesConverter(), } } @@ -67,5 +78,9 @@ func (p *Provider) ReadResourcesFromFile(_ context.Context, filename string) err // ToGatewayAPI converts stored Ingress GCE API entities to // i2gw.GatewayResources including the ingress-gce specific features. func (p *Provider) ToGatewayAPI() (i2gw.GatewayResources, field.ErrorList) { - return p.converter.convert(p.storage) + ir, err := p.irConverter.convertToIR(p.storage) + if err != nil { + return i2gw.GatewayResources{}, err + } + return p.gatewayConverter.irToGateway(ir) } diff --git a/pkg/i2gw/providers/gce/gce_extensions.go b/pkg/i2gw/providers/gce/gce_extensions.go new file mode 100644 index 00000000..d566d575 --- /dev/null +++ b/pkg/i2gw/providers/gce/gce_extensions.go @@ -0,0 +1,198 @@ +/* +Copyright 2024 The Kubernetes 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 gce + +import ( + "context" + "encoding/json" + + gkegatewayv1 "github.com/GoogleCloudPlatform/gke-gateway-api/apis/networking/v1" + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw" + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/intermediate" + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/notifications" + apiv1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + backendconfigv1 "k8s.io/ingress-gce/pkg/apis/backendconfig/v1" + gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" + gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" +) + +type serviceNames []types.NamespacedName + +func buildGceServiceIR(ctx context.Context, storage *storage, ir *intermediate.IR) { + if ir.Services == nil { + ir.Services = make(map[types.NamespacedName]intermediate.ProviderSpecificServiceIR) + } + + beConfigToSvcs := getBackendConfigMapping(ctx, storage) + for beConfigKey, beConfig := range storage.BackendConfigs { + if beConfig == nil { + continue + } + gceServiceIR := beConfigToGceServiceIR(beConfig) + services := beConfigToSvcs[beConfigKey] + for _, svcKey := range services { + serviceIR := ir.Services[svcKey] + serviceIR.Gce = &gceServiceIR + ir.Services[svcKey] = serviceIR + } + } +} + +func getBackendConfigMapping(ctx context.Context, storage *storage) map[types.NamespacedName]serviceNames { + beConfigToSvcs := make(map[types.NamespacedName]serviceNames) + + for _, service := range storage.Services { + svc := types.NamespacedName{Namespace: service.Namespace, Name: service.Name} + ctx = context.WithValue(ctx, serviceKey, service) + + // Read BackendConfig based on v1 BackendConfigKey. + beConfigName, exists := getBackendConfigName(ctx, service, backendConfigKey) + if exists { + beConfigKey := types.NamespacedName{Namespace: service.Namespace, Name: beConfigName} + beConfigToSvcs[beConfigKey] = append(beConfigToSvcs[beConfigKey], svc) + continue + } + + // Read BackendConfig based on v1beta1 BackendConfigKey. + beConfigName, exists = getBackendConfigName(ctx, service, betaBackendConfigKey) + if exists { + beConfigKey := types.NamespacedName{Namespace: service.Namespace, Name: beConfigName} + beConfigToSvcs[beConfigKey] = append(beConfigToSvcs[beConfigKey], svc) + continue + } + } + return beConfigToSvcs +} + +// Get names of the BackendConfig in the cluster based on the BackendConfig +// annotation on k8s Services. +func getBackendConfigName(ctx context.Context, service *apiv1.Service, backendConfigKey string) (string, bool) { + val, exists := getBackendConfigAnnotation(service, backendConfigKey) + if !exists { + return "", false + } + + return parseBackendConfigName(ctx, val) +} + +// Get the backend config annotation from the K8s service if it exists. +func getBackendConfigAnnotation(service *apiv1.Service, backendConfigKey string) (string, bool) { + val, ok := service.Annotations[backendConfigKey] + if ok { + return val, ok + } + return "", false +} + +type backendConfigs struct { + Default string `json:"default,omitempty"` + Ports map[string]string `json:"ports,omitempty"` +} + +// Parse the name of the BackendConfig based on the annotation. +// If different BackendConfigs are used on the same service, pick the one with +// the alphabetically smallest name. +func parseBackendConfigName(ctx context.Context, val string) (string, bool) { + service := ctx.Value(serviceKey).(*apiv1.Service) + + var configs backendConfigs + if err := json.Unmarshal([]byte(val), &configs); err != nil { + notify(notifications.ErrorNotification, "BackendConfig annotation is invalid json", service) + return "", false + } + + if configs.Default == "" && len(configs.Ports) == 0 { + notify(notifications.ErrorNotification, "No BackendConfig's found in annotation", service) + return "", false + } + + if len(configs.Ports) != 0 { + notify(notifications.ErrorNotification, "HealthCheckPolicy and GCPBackendPolicy can only be attached on the whole service, so having a dedicate policy for each port is not yet supported. Picking the first BackendConfig to translate to corresponding Gateway policy.", service) + // Return the BackendConfig associated with the alphabetically smallest port. + var backendConfigName string + var lowestPort string + for p, name := range configs.Ports { + if lowestPort == "" || p < lowestPort { + backendConfigName = name + lowestPort = p + } + } + return backendConfigName, true + } + return configs.Default, true +} + +func beConfigToGceServiceIR(beConfig *backendconfigv1.BackendConfig) intermediate.GceServiceIR { + var gceServiceIR intermediate.GceServiceIR + if beConfig.Spec.SessionAffinity != nil { + saConfig := intermediate.SessionAffinityConfig{ + AffinityType: beConfig.Spec.SessionAffinity.AffinityType, + CookieTTLSec: beConfig.Spec.SessionAffinity.AffinityCookieTtlSec, + } + gceServiceIR.SessionAffinity = &saConfig + } + + return gceServiceIR +} + +func buildGceServiceExtensions(ir intermediate.IR, gatewayResources *i2gw.GatewayResources) { + for svcKey, serviceIR := range ir.Services { + bePolicy := addBackendPolicyIfConfigured(svcKey, serviceIR) + if bePolicy == nil { + continue + } + obj, err := i2gw.CastToUnstructured(bePolicy) + if err != nil { + notify(notifications.ErrorNotification, "Failed to cast GCPBackendPolicy to unstructured", bePolicy) + continue + } + gatewayResources.GatewayExtensions = append(gatewayResources.GatewayExtensions, *obj) + } +} + +func addBackendPolicyIfConfigured(serviceNamespacedName types.NamespacedName, serviceIR intermediate.ProviderSpecificServiceIR) *gkegatewayv1.GCPBackendPolicy { + if serviceIR.Gce == nil || serviceIR.Gce.SessionAffinity == nil { + return nil + } + affinityType := serviceIR.Gce.SessionAffinity.AffinityType + backendPolicy := gkegatewayv1.GCPBackendPolicy{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: serviceNamespacedName.Namespace, + Name: serviceNamespacedName.Name, + }, + Spec: gkegatewayv1.GCPBackendPolicySpec{ + Default: &gkegatewayv1.GCPBackendPolicyConfig{ + SessionAffinity: &gkegatewayv1.SessionAffinityConfig{ + Type: &affinityType, + }, + }, + TargetRef: gatewayv1alpha2.NamespacedPolicyTargetReference{ + Group: "", + Kind: "Service", + Name: gatewayv1.ObjectName(serviceNamespacedName.Name), + }, + }, + } + if affinityType == "GENERATED_COOKIE" { + backendPolicy.Spec.Default.SessionAffinity.CookieTTLSec = serviceIR.Gce.SessionAffinity.CookieTTLSec + } + + backendPolicy.SetGroupVersionKind(GCPBackendPolicyGVK) + return &backendPolicy +} diff --git a/pkg/i2gw/providers/gce/gce_extensions_test.go b/pkg/i2gw/providers/gce/gce_extensions_test.go new file mode 100644 index 00000000..49ddb5cc --- /dev/null +++ b/pkg/i2gw/providers/gce/gce_extensions_test.go @@ -0,0 +1,239 @@ +/* +Copyright 2024 The Kubernetes 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 gce + +import ( + "context" + "reflect" + "testing" + + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw" + apiv1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + backendconfigv1 "k8s.io/ingress-gce/pkg/apis/backendconfig/v1" +) + +func TestGetBackendConfigMapping(t *testing.T) { + t.Parallel() + testNamespace := "test-namespace" + + testServiceName := "test-service" + testBeConfigName1 := "backendconfig-1" + testBeConfigName2 := "backendconfig-2" + backendConfigs := map[types.NamespacedName]*backendconfigv1.BackendConfig{ + {Namespace: testNamespace, Name: testBeConfigName1}: {}, + {Namespace: testNamespace, Name: testBeConfigName2}: {}, + } + expectedServices := serviceNames{ + {Namespace: testNamespace, Name: testServiceName}, + } + + testCases := []struct { + desc string + services map[types.NamespacedName]*apiv1.Service + expectedServices serviceNames + }{ + { + desc: "Specify BackendConfig with cloud.google.com/backend-config annotation, using the same BackendConfig for all ports", + services: map[types.NamespacedName]*apiv1.Service{ + {Namespace: testNamespace, Name: testServiceName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: testServiceName, + Namespace: testNamespace, + Annotations: map[string]string{ + backendConfigKey: `{"default":"backendconfig-1"}`, + }, + }, + }, + }, + expectedServices: expectedServices, + }, + { + desc: "Specify BackendConfig with beta.cloud.google.com/backend-config annotation, using the same BackendConfig for all ports", + services: map[types.NamespacedName]*apiv1.Service{ + {Namespace: testNamespace, Name: testServiceName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: testServiceName, + Namespace: testNamespace, + Annotations: map[string]string{ + betaBackendConfigKey: `{"default":"backendconfig-1"}`, + }, + }, + }, + }, + expectedServices: expectedServices, + }, + { + desc: "Specify BackendConfig with both cloud.google.com/backend-config and beta.cloud.google.com/backend-config annotation, using the same BackendConfig for all ports, cloud.google.com/backend-config should have precedence over the beta one", + services: map[types.NamespacedName]*apiv1.Service{ + {Namespace: testNamespace, Name: testServiceName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: testServiceName, + Namespace: testNamespace, + Annotations: map[string]string{ + backendConfigKey: `{"default":"backendconfig-1"}`, + betaBackendConfigKey: `{"ports": {"port1": "backendconfig-1", "port2": "backendconfig-2"}}`, + }, + }, + }, + }, + expectedServices: expectedServices, + }, + { + desc: "Specify BackendConfig with cloud.google.com/backend-config annotation, using different BackendConfigs for each port, service will be associated with the BackendConfig for the alphabetically smallest port", + services: map[types.NamespacedName]*apiv1.Service{ + {Namespace: testNamespace, Name: testServiceName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: testServiceName, + Namespace: testNamespace, + Annotations: map[string]string{ + backendConfigKey: `{"ports": {"port1": "backendconfig-1", "port2": "backendconfig-2"}}`, + }, + }, + }, + }, + expectedServices: expectedServices, + }, + { + desc: "Specify BackendConfig with beta.cloud.google.com/backend-config annotation, using different BackendConfigs for each port, service will be associated with the BackendConfig for the alphabetically smallest port", + services: map[types.NamespacedName]*apiv1.Service{ + {Namespace: testNamespace, Name: testServiceName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: testServiceName, + Namespace: testNamespace, + Annotations: map[string]string{ + betaBackendConfigKey: `{"ports": {"port1": "backendconfig-1", "port2": "backendconfig-2"}}`, + }, + }, + }, + }, + expectedServices: expectedServices, + }, + { + desc: "Specify BackendConfig with both cloud.google.com/backend-config and beta.cloud.google.com/backend-config annotation, using different BackendConfigs for each port, service will be associated with the BackendConfig for the alphabetically smallest port, cloud.google.com/backend-config should have precedence over the beta one", + services: map[types.NamespacedName]*apiv1.Service{ + {Namespace: testNamespace, Name: testServiceName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: testServiceName, + Namespace: testNamespace, + Annotations: map[string]string{ + backendConfigKey: `{"ports": {"port1": "backendconfig-1", "port2": "backendconfig-2"}}`, + betaBackendConfigKey: `{"default":"backendconfig-1"}`, + }, + }, + }, + }, + expectedServices: expectedServices, + }, + } + + for _, tc := range testCases { + t.Run(tc.desc, func(t *testing.T) { + provider := NewProvider(&i2gw.ProviderConf{}) + gceProvider := provider.(*Provider) + gceProvider.storage = newResourcesStorage() + gceProvider.storage.Services = tc.services + gceProvider.storage.BackendConfigs = backendConfigs + + beConfigToSvcs := getBackendConfigMapping(context.TODO(), gceProvider.storage) + backendConfigKey := types.NamespacedName{Namespace: testNamespace, Name: testBeConfigName1} + gotServiceList := beConfigToSvcs[backendConfigKey] + if len(gotServiceList) != len(tc.expectedServices) { + t.Errorf("Got BackendConfig mapped to %d services, expected %d", len(gotServiceList), len(tc.expectedServices)) + } + if !reflect.DeepEqual(gotServiceList, tc.expectedServices) { + t.Errorf("Got BackendConfig mapped to %v, expected %v", gotServiceList, tc.expectedServices) + } + }) + } +} + +func TestGetBackendConfigName(t *testing.T) { + t.Parallel() + + testNamespace := "test-namespace" + testServiceName := "test-service" + testBeConfigName := "backendconfig-1" + + testCases := []struct { + desc string + service *apiv1.Service + beConfigKey string + expectedName string + expectedExists bool + }{ + { + desc: "Service using cloud.google.com/backend-config, using default Config over all ports", + service: &apiv1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: testServiceName, + Namespace: testNamespace, + Annotations: map[string]string{ + backendConfigKey: `{"default":"backendconfig-1"}`, + }, + }, + }, + beConfigKey: backendConfigKey, + expectedName: testBeConfigName, + expectedExists: true, + }, + { + desc: "Service using beta.cloud.google.com/backend-config annotation, using default Config over all ports", + service: &apiv1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: testServiceName, + Namespace: testNamespace, + Annotations: map[string]string{ + betaBackendConfigKey: `{"default":"backendconfig-1"}`, + }, + }, + }, + beConfigKey: betaBackendConfigKey, + expectedName: testBeConfigName, + expectedExists: true, + }, + { + desc: "Service using cloud.google.com/backend-config, using Port Config, pick the BackendConfig with the alphabetically smallest port", + service: &apiv1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: testServiceName, + Namespace: testNamespace, + Annotations: map[string]string{ + backendConfigKey: `{"ports": {"port1": "backendconfig-1", "port2": "backendconfig-2"}}`, + }, + }, + }, + beConfigKey: backendConfigKey, + expectedName: "backendconfig-1", + expectedExists: true, + }, + } + for _, tc := range testCases { + t.Run(tc.desc, func(t *testing.T) { + ctx := context.TODO() + ctx = context.WithValue(ctx, serviceKey, tc.service) + gotName, gotExists := getBackendConfigName(ctx, tc.service, tc.beConfigKey) + if gotExists != tc.expectedExists { + t.Errorf("getBackendConfigName() got exist = %v, expected %v", gotExists, tc.expectedExists) + } + if gotName != tc.expectedName { + t.Errorf("getBackendConfigName() got exist = %v, expected %v", gotName, tc.expectedName) + } + }) + } +} diff --git a/pkg/i2gw/providers/gce/converter.go b/pkg/i2gw/providers/gce/ir_converter.go similarity index 65% rename from pkg/i2gw/providers/gce/converter.go rename to pkg/i2gw/providers/gce/ir_converter.go index e5d183f7..83e7c51b 100644 --- a/pkg/i2gw/providers/gce/converter.go +++ b/pkg/i2gw/providers/gce/ir_converter.go @@ -17,33 +17,42 @@ limitations under the License. package gce import ( + "context" + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw" + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/intermediate" "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/common" networkingv1 "k8s.io/api/networking/v1" networkingv1beta1 "k8s.io/api/networking/v1beta1" "k8s.io/apimachinery/pkg/util/validation/field" ) +type contextKey int + +const ( + serviceKey contextKey = iota +) + // converter implements the ToGatewayAPI function of i2gw.ResourceConverter interface. -type converter struct { +type resourcesToIRConverter struct { conf *i2gw.ProviderConf - featureParsers []i2gw.FeatureParser implementationSpecificOptions i2gw.ProviderImplementationSpecificOptions + ctx context.Context } -// newConverter returns an ingress-gce converter instance. -func newConverter(conf *i2gw.ProviderConf) converter { - return converter{ - conf: conf, - featureParsers: []i2gw.FeatureParser{}, +// newConverter returns an ingress-gce resourcesToIRConverter instance. +func newResourceToIRConverter(conf *i2gw.ProviderConf) resourcesToIRConverter { + return resourcesToIRConverter{ + conf: conf, implementationSpecificOptions: i2gw.ProviderImplementationSpecificOptions{ ToImplementationSpecificHTTPPathTypeMatch: implementationSpecificHTTPPathTypeMatch, }, + ctx: context.Background(), } } -func (c *converter) convert(storage *storage) (i2gw.GatewayResources, field.ErrorList) { +func (c *resourcesToIRConverter) convertToIR(storage *storage) (intermediate.IR, field.ErrorList) { ingressList := []networkingv1.Ingress{} for _, ing := range storage.Ingresses { if ing != nil && common.GetIngressClass(*ing) == "" { @@ -57,22 +66,15 @@ func (c *converter) convert(storage *storage) (i2gw.GatewayResources, field.Erro // Convert plain ingress resources to gateway resources, ignoring all // provider-specific features. - gatewayResources, errs := common.ToGateway(ingressList, c.implementationSpecificOptions) + ir, errs := common.ToIR(ingressList, c.implementationSpecificOptions) if len(errs) > 0 { - return i2gw.GatewayResources{}, errs + return intermediate.IR{}, errs } - errs = setGCEGatewayClasses(ingressList, &gatewayResources) + errs = setGCEGatewayClasses(ingressList, ir.Gateways) if len(errs) > 0 { - return i2gw.GatewayResources{}, errs + return intermediate.IR{}, errs } - - for _, parseFeatureFunc := range c.featureParsers { - // Apply the feature parsing function to the gateway resources, one by one. - parseErrs := parseFeatureFunc(ingressList, &gatewayResources) - // Append the parsing errors to the error list. - errs = append(errs, parseErrs...) - } - - return gatewayResources, errs + buildGceServiceIR(c.ctx, storage, &ir) + return ir, errs } diff --git a/pkg/i2gw/providers/gce/ir_converter_test.go b/pkg/i2gw/providers/gce/ir_converter_test.go new file mode 100644 index 00000000..d4e88a0f --- /dev/null +++ b/pkg/i2gw/providers/gce/ir_converter_test.go @@ -0,0 +1,1547 @@ +/* +Copyright 2024 The Kubernetes 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 gce + +import ( + "errors" + "fmt" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw" + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/intermediate" + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/common" + apiv1 "k8s.io/api/core/v1" + networkingv1 "k8s.io/api/networking/v1" + networkingv1beta1 "k8s.io/api/networking/v1beta1" + apiequality "k8s.io/apimachinery/pkg/api/equality" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/validation/field" + backendconfigv1 "k8s.io/ingress-gce/pkg/apis/backendconfig/v1" + gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" +) + +func Test_ToGateway(t *testing.T) { + testNamespace := "default" + testHost := "test.mydomain.com" + testBackendServiceName := "test" + iPrefix := networkingv1.PathTypePrefix + implSpecificPathType := networkingv1.PathTypeImplementationSpecific + + gPathPrefix := gatewayv1.PathMatchPathPrefix + gExact := gatewayv1.PathMatchExact + + extIngClassIngressName := "gce-ingress-class" + intIngClassIngressName := "gce-internal-ingress-class" + noIngClassIngressName := "no-ingress-class" + + testCases := []struct { + name string + ingresses map[types.NamespacedName]*networkingv1.Ingress + expectedGatewayResources i2gw.GatewayResources + expectedErrors field.ErrorList + }{ + { + name: "gce ingress class", + ingresses: map[types.NamespacedName]*networkingv1.Ingress{ + {Namespace: testNamespace, Name: extIngClassIngressName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: extIngClassIngressName, + Namespace: testNamespace, + Annotations: map[string]string{networkingv1beta1.AnnotationIngressClass: gceIngressClass}, + }, + Spec: networkingv1.IngressSpec{ + Rules: []networkingv1.IngressRule{{ + Host: testHost, + IngressRuleValue: networkingv1.IngressRuleValue{ + HTTP: &networkingv1.HTTPIngressRuleValue{ + Paths: []networkingv1.HTTPIngressPath{{ + Path: "/", + PathType: &iPrefix, + Backend: networkingv1.IngressBackend{ + Service: &networkingv1.IngressServiceBackend{ + Name: testBackendServiceName, + Port: networkingv1.ServiceBackendPort{ + Number: 80, + }, + }, + }, + }}, + }, + }, + }}, + }, + }, + }, + expectedGatewayResources: i2gw.GatewayResources{ + Gateways: map[types.NamespacedName]gatewayv1.Gateway{ + {Namespace: testNamespace, Name: gceIngressClass}: { + ObjectMeta: metav1.ObjectMeta{Name: gceIngressClass, Namespace: testNamespace}, + Spec: gatewayv1.GatewaySpec{ + GatewayClassName: gceL7GlobalExternalManagedGatewayClass, + Listeners: []gatewayv1.Listener{{ + Name: "test-mydomain-com-http", + Port: 80, + Protocol: gatewayv1.HTTPProtocolType, + Hostname: ptrTo(gatewayv1.Hostname(testHost)), + }}, + }, + }, + }, + HTTPRoutes: map[types.NamespacedName]gatewayv1.HTTPRoute{ + {Namespace: testNamespace, Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName)}: { + ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName), Namespace: testNamespace}, + Spec: gatewayv1.HTTPRouteSpec{ + CommonRouteSpec: gatewayv1.CommonRouteSpec{ + ParentRefs: []gatewayv1.ParentReference{{ + Name: gceIngressClass, + }}, + }, + Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, + Rules: []gatewayv1.HTTPRouteRule{ + { + Matches: []gatewayv1.HTTPRouteMatch{ + { + Path: &gatewayv1.HTTPPathMatch{ + Type: &gPathPrefix, + Value: ptrTo("/"), + }, + }, + }, + BackendRefs: []gatewayv1.HTTPBackendRef{ + { + BackendRef: gatewayv1.BackendRef{ + BackendObjectReference: gatewayv1.BackendObjectReference{ + Name: gatewayv1.ObjectName(testBackendServiceName), + Port: ptrTo(gatewayv1.PortNumber(80)), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + expectedErrors: field.ErrorList{}, + }, + { + name: "gce-internal ingress class", + ingresses: map[types.NamespacedName]*networkingv1.Ingress{ + {Namespace: testNamespace, Name: intIngClassIngressName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: intIngClassIngressName, + Namespace: testNamespace, + Annotations: map[string]string{networkingv1beta1.AnnotationIngressClass: gceL7ILBIngressClass}, + }, + Spec: networkingv1.IngressSpec{ + Rules: []networkingv1.IngressRule{{ + Host: testHost, + IngressRuleValue: networkingv1.IngressRuleValue{ + HTTP: &networkingv1.HTTPIngressRuleValue{ + Paths: []networkingv1.HTTPIngressPath{{ + Path: "/", + PathType: &iPrefix, + Backend: networkingv1.IngressBackend{ + Service: &networkingv1.IngressServiceBackend{ + Name: testBackendServiceName, + Port: networkingv1.ServiceBackendPort{ + Number: 80, + }, + }, + }, + }}, + }, + }, + }}, + }, + }, + }, + expectedGatewayResources: i2gw.GatewayResources{ + Gateways: map[types.NamespacedName]gatewayv1.Gateway{ + {Namespace: testNamespace, Name: gceL7ILBIngressClass}: { + ObjectMeta: metav1.ObjectMeta{Name: gceL7ILBIngressClass, Namespace: testNamespace}, + Spec: gatewayv1.GatewaySpec{ + GatewayClassName: gceL7RegionalInternalGatewayClass, + Listeners: []gatewayv1.Listener{{ + Name: "test-mydomain-com-http", + Port: 80, + Protocol: gatewayv1.HTTPProtocolType, + Hostname: ptrTo(gatewayv1.Hostname(testHost)), + }}, + }, + }, + }, + HTTPRoutes: map[types.NamespacedName]gatewayv1.HTTPRoute{ + {Namespace: testNamespace, Name: "gce-internal-ingress-class-test-mydomain-com"}: { + ObjectMeta: metav1.ObjectMeta{Name: "gce-internal-ingress-class-test-mydomain-com", Namespace: testNamespace}, + Spec: gatewayv1.HTTPRouteSpec{ + CommonRouteSpec: gatewayv1.CommonRouteSpec{ + ParentRefs: []gatewayv1.ParentReference{{ + Name: gceL7ILBIngressClass, + }}, + }, + Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, + Rules: []gatewayv1.HTTPRouteRule{ + { + Matches: []gatewayv1.HTTPRouteMatch{ + { + Path: &gatewayv1.HTTPPathMatch{ + Type: &gPathPrefix, + Value: ptrTo("/"), + }, + }, + }, + BackendRefs: []gatewayv1.HTTPBackendRef{ + { + BackendRef: gatewayv1.BackendRef{ + BackendObjectReference: gatewayv1.BackendObjectReference{ + Name: gatewayv1.ObjectName(testBackendServiceName), + Port: ptrTo(gatewayv1.PortNumber(80)), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + expectedErrors: field.ErrorList{}, + }, + { + name: "empty ingress class, default to gce ingress class", + ingresses: map[types.NamespacedName]*networkingv1.Ingress{ + {Namespace: testNamespace, Name: noIngClassIngressName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: noIngClassIngressName, + Namespace: testNamespace, + }, + Spec: networkingv1.IngressSpec{ + Rules: []networkingv1.IngressRule{{ + Host: testHost, + IngressRuleValue: networkingv1.IngressRuleValue{ + HTTP: &networkingv1.HTTPIngressRuleValue{ + Paths: []networkingv1.HTTPIngressPath{{ + Path: "/", + PathType: &iPrefix, + Backend: networkingv1.IngressBackend{ + Service: &networkingv1.IngressServiceBackend{ + Name: testBackendServiceName, + Port: networkingv1.ServiceBackendPort{ + Number: 80, + }, + }, + }, + }}, + }, + }, + }}, + }, + }, + }, + expectedGatewayResources: i2gw.GatewayResources{ + Gateways: map[types.NamespacedName]gatewayv1.Gateway{ + {Namespace: testNamespace, Name: gceIngressClass}: { + ObjectMeta: metav1.ObjectMeta{Name: gceIngressClass, Namespace: testNamespace}, + Spec: gatewayv1.GatewaySpec{ + GatewayClassName: gceL7GlobalExternalManagedGatewayClass, + Listeners: []gatewayv1.Listener{{ + Name: "test-mydomain-com-http", + Port: 80, + Protocol: gatewayv1.HTTPProtocolType, + Hostname: ptrTo(gatewayv1.Hostname(testHost)), + }}, + }, + }, + }, + HTTPRoutes: map[types.NamespacedName]gatewayv1.HTTPRoute{ + {Namespace: testNamespace, Name: fmt.Sprintf("%s-test-mydomain-com", noIngClassIngressName)}: { + ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-test-mydomain-com", noIngClassIngressName), Namespace: testNamespace}, + Spec: gatewayv1.HTTPRouteSpec{ + CommonRouteSpec: gatewayv1.CommonRouteSpec{ + ParentRefs: []gatewayv1.ParentReference{{ + Name: gceIngressClass, + }}, + }, + Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, + Rules: []gatewayv1.HTTPRouteRule{ + { + Matches: []gatewayv1.HTTPRouteMatch{ + { + Path: &gatewayv1.HTTPPathMatch{ + Type: &gPathPrefix, + Value: ptrTo("/"), + }, + }, + }, + BackendRefs: []gatewayv1.HTTPBackendRef{ + { + BackendRef: gatewayv1.BackendRef{ + BackendObjectReference: gatewayv1.BackendObjectReference{ + Name: gatewayv1.ObjectName(testBackendServiceName), + Port: ptrTo(gatewayv1.PortNumber(80)), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + expectedErrors: field.ErrorList{}, + }, + { + name: "gce implementation-specific with /*, map to / Prefix", + ingresses: map[types.NamespacedName]*networkingv1.Ingress{ + {Namespace: testNamespace, Name: extIngClassIngressName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: extIngClassIngressName, + Namespace: testNamespace, + Annotations: map[string]string{networkingv1beta1.AnnotationIngressClass: gceIngressClass}, + }, + Spec: networkingv1.IngressSpec{ + Rules: []networkingv1.IngressRule{{ + Host: testHost, + IngressRuleValue: networkingv1.IngressRuleValue{ + HTTP: &networkingv1.HTTPIngressRuleValue{ + Paths: []networkingv1.HTTPIngressPath{{ + Path: "/*", + PathType: &implSpecificPathType, + Backend: networkingv1.IngressBackend{ + Service: &networkingv1.IngressServiceBackend{ + Name: testBackendServiceName, + Port: networkingv1.ServiceBackendPort{ + Number: 80, + }, + }, + }, + }}, + }, + }, + }}, + }, + }, + }, + expectedGatewayResources: i2gw.GatewayResources{ + Gateways: map[types.NamespacedName]gatewayv1.Gateway{ + {Namespace: testNamespace, Name: gceIngressClass}: { + ObjectMeta: metav1.ObjectMeta{Name: gceIngressClass, Namespace: testNamespace}, + Spec: gatewayv1.GatewaySpec{ + GatewayClassName: gceL7GlobalExternalManagedGatewayClass, + Listeners: []gatewayv1.Listener{{ + Name: "test-mydomain-com-http", + Port: 80, + Protocol: gatewayv1.HTTPProtocolType, + Hostname: ptrTo(gatewayv1.Hostname(testHost)), + }}, + }, + }, + }, + HTTPRoutes: map[types.NamespacedName]gatewayv1.HTTPRoute{ + {Namespace: testNamespace, Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName)}: { + ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName), Namespace: testNamespace}, + Spec: gatewayv1.HTTPRouteSpec{ + CommonRouteSpec: gatewayv1.CommonRouteSpec{ + ParentRefs: []gatewayv1.ParentReference{{ + Name: gceIngressClass, + }}, + }, + Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, + Rules: []gatewayv1.HTTPRouteRule{ + { + Matches: []gatewayv1.HTTPRouteMatch{ + { + Path: &gatewayv1.HTTPPathMatch{ + Type: &gPathPrefix, + Value: ptrTo("/"), + }, + }, + }, + BackendRefs: []gatewayv1.HTTPBackendRef{ + { + BackendRef: gatewayv1.BackendRef{ + BackendObjectReference: gatewayv1.BackendObjectReference{ + Name: gatewayv1.ObjectName(testBackendServiceName), + Port: ptrTo(gatewayv1.PortNumber(80)), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + expectedErrors: field.ErrorList{}, + }, + { + name: "gce implementation-specific with /foo/*, converted to /foo", + ingresses: map[types.NamespacedName]*networkingv1.Ingress{ + {Namespace: testNamespace, Name: extIngClassIngressName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: extIngClassIngressName, + Namespace: testNamespace, + Annotations: map[string]string{networkingv1beta1.AnnotationIngressClass: gceIngressClass}, + }, + Spec: networkingv1.IngressSpec{ + Rules: []networkingv1.IngressRule{{ + Host: testHost, + IngressRuleValue: networkingv1.IngressRuleValue{ + HTTP: &networkingv1.HTTPIngressRuleValue{ + Paths: []networkingv1.HTTPIngressPath{{ + Path: "/foo/*", + PathType: &implSpecificPathType, + Backend: networkingv1.IngressBackend{ + Service: &networkingv1.IngressServiceBackend{ + Name: testBackendServiceName, + Port: networkingv1.ServiceBackendPort{ + Number: 80, + }, + }, + }, + }}, + }, + }, + }}, + }, + }, + }, + expectedGatewayResources: i2gw.GatewayResources{ + Gateways: map[types.NamespacedName]gatewayv1.Gateway{ + {Namespace: testNamespace, Name: gceIngressClass}: { + ObjectMeta: metav1.ObjectMeta{Name: gceIngressClass, Namespace: testNamespace}, + Spec: gatewayv1.GatewaySpec{ + GatewayClassName: gceL7GlobalExternalManagedGatewayClass, + Listeners: []gatewayv1.Listener{{ + Name: "test-mydomain-com-http", + Port: 80, + Protocol: gatewayv1.HTTPProtocolType, + Hostname: ptrTo(gatewayv1.Hostname(testHost)), + }}, + }, + }, + }, + HTTPRoutes: map[types.NamespacedName]gatewayv1.HTTPRoute{ + {Namespace: testNamespace, Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName)}: { + ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName), Namespace: testNamespace}, + Spec: gatewayv1.HTTPRouteSpec{ + CommonRouteSpec: gatewayv1.CommonRouteSpec{ + ParentRefs: []gatewayv1.ParentReference{{ + Name: gceIngressClass, + }}, + }, + Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, + Rules: []gatewayv1.HTTPRouteRule{ + { + Matches: []gatewayv1.HTTPRouteMatch{ + { + Path: &gatewayv1.HTTPPathMatch{ + Type: &gPathPrefix, + Value: ptrTo("/foo"), + }, + }, + }, + BackendRefs: []gatewayv1.HTTPBackendRef{ + { + BackendRef: gatewayv1.BackendRef{ + BackendObjectReference: gatewayv1.BackendObjectReference{ + Name: gatewayv1.ObjectName(testBackendServiceName), + Port: ptrTo(gatewayv1.PortNumber(80)), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + expectedErrors: nil, + }, + { + name: "gce implementation-specific without wildcard path, map to Prefix", + ingresses: map[types.NamespacedName]*networkingv1.Ingress{ + {Namespace: testNamespace, Name: extIngClassIngressName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: extIngClassIngressName, + Namespace: testNamespace, + Annotations: map[string]string{networkingv1beta1.AnnotationIngressClass: gceIngressClass}, + }, + Spec: networkingv1.IngressSpec{ + Rules: []networkingv1.IngressRule{{ + Host: testHost, + IngressRuleValue: networkingv1.IngressRuleValue{ + HTTP: &networkingv1.HTTPIngressRuleValue{ + Paths: []networkingv1.HTTPIngressPath{{ + Path: "/foo", + PathType: &implSpecificPathType, + Backend: networkingv1.IngressBackend{ + Service: &networkingv1.IngressServiceBackend{ + Name: testBackendServiceName, + Port: networkingv1.ServiceBackendPort{ + Number: 80, + }, + }, + }, + }}, + }, + }, + }}, + }, + }, + }, + expectedGatewayResources: i2gw.GatewayResources{ + Gateways: map[types.NamespacedName]gatewayv1.Gateway{ + {Namespace: testNamespace, Name: gceIngressClass}: { + ObjectMeta: metav1.ObjectMeta{Name: gceIngressClass, Namespace: testNamespace}, + Spec: gatewayv1.GatewaySpec{ + GatewayClassName: gceL7GlobalExternalManagedGatewayClass, + Listeners: []gatewayv1.Listener{{ + Name: "test-mydomain-com-http", + Port: 80, + Protocol: gatewayv1.HTTPProtocolType, + Hostname: ptrTo(gatewayv1.Hostname(testHost)), + }}, + }, + }, + }, + HTTPRoutes: map[types.NamespacedName]gatewayv1.HTTPRoute{ + {Namespace: testNamespace, Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName)}: { + ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName), Namespace: testNamespace}, + Spec: gatewayv1.HTTPRouteSpec{ + CommonRouteSpec: gatewayv1.CommonRouteSpec{ + ParentRefs: []gatewayv1.ParentReference{{ + Name: gceIngressClass, + }}, + }, + Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, + Rules: []gatewayv1.HTTPRouteRule{ + { + Matches: []gatewayv1.HTTPRouteMatch{ + { + Path: &gatewayv1.HTTPPathMatch{ + Type: &gExact, + Value: ptrTo("/foo"), + }, + }, + }, + BackendRefs: []gatewayv1.HTTPBackendRef{ + { + BackendRef: gatewayv1.BackendRef{ + BackendObjectReference: gatewayv1.BackendObjectReference{ + Name: gatewayv1.ObjectName(testBackendServiceName), + Port: ptrTo(gatewayv1.PortNumber(80)), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + expectedErrors: field.ErrorList{}, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + + provider := NewProvider(&i2gw.ProviderConf{}) + gceProvider := provider.(*Provider) + gceProvider.storage = newResourcesStorage() + gceProvider.storage.Ingresses = tc.ingresses + + // TODO(#113) we pass an empty i2gw.InputResources temporarily until we change ToGatewayAPI function on the interface + gatewayResources, errs := provider.ToGatewayAPI() + + if len(errs) != len(tc.expectedErrors) { + t.Errorf("Expected %d errors, got %d: %+v", len(tc.expectedErrors), len(errs), errs) + } else { + for i, e := range errs { + if errors.Is(e, tc.expectedErrors[i]) { + t.Errorf("Unexpected error message at %d index. Got %s, want: %s", i, e, tc.expectedErrors[i]) + } + } + } + + if len(gatewayResources.HTTPRoutes) != len(tc.expectedGatewayResources.HTTPRoutes) { + t.Errorf("Expected %d HTTPRoutes, got %d: %+v", + len(tc.expectedGatewayResources.HTTPRoutes), len(gatewayResources.HTTPRoutes), gatewayResources.HTTPRoutes) + } else { + for i, got := range gatewayResources.HTTPRoutes { + key := types.NamespacedName{Namespace: got.Namespace, Name: got.Name} + want := tc.expectedGatewayResources.HTTPRoutes[key] + want.SetGroupVersionKind(common.HTTPRouteGVK) + if !apiequality.Semantic.DeepEqual(got, want) { + t.Errorf("Expected HTTPRoute %s to be %+v\n Got: %+v\n Diff: %s", i, want, got, cmp.Diff(want, got)) + } + } + } + + if len(gatewayResources.Gateways) != len(tc.expectedGatewayResources.Gateways) { + t.Errorf("Expected %d Gateways, got %d: %+v", + len(tc.expectedGatewayResources.Gateways), len(gatewayResources.Gateways), gatewayResources.Gateways) + } else { + for i, got := range gatewayResources.Gateways { + key := types.NamespacedName{Namespace: got.Namespace, Name: got.Name} + want := tc.expectedGatewayResources.Gateways[key] + want.SetGroupVersionKind(common.GatewayGVK) + if !apiequality.Semantic.DeepEqual(got, want) { + t.Errorf("Expected Gateway %s to be %+v\n Got: %+v\n Diff: %s", i, want, got, cmp.Diff(want, got)) + } + } + } + + }) + } +} + +func Test_convertToIR(t *testing.T) { + testNamespace := "default" + testHost := "test.mydomain.com" + testServiceName := "test-service" + testBackendConfigName := "test-backendconfig" + iPrefix := networkingv1.PathTypePrefix + implSpecificPathType := networkingv1.PathTypeImplementationSpecific + + gPathPrefix := gatewayv1.PathMatchPathPrefix + gExact := gatewayv1.PathMatchExact + + extIngClassIngressName := "gce-ingress-class" + intIngClassIngressName := "gce-internal-ingress-class" + noIngClassIngressName := "no-ingress-class" + + saTypeClientIP := "CLIENT_IP" + testCookieTTLSec := int64(10) + saTypeCookie := "GENERATED_COOKIE" + + testCases := []struct { + name string + ingresses map[types.NamespacedName]*networkingv1.Ingress + services map[types.NamespacedName]*apiv1.Service + backendConfigs map[types.NamespacedName]*backendconfigv1.BackendConfig + expectedIR intermediate.IR + expectedErrors field.ErrorList + }{ + { + name: "gce ingress class", + ingresses: map[types.NamespacedName]*networkingv1.Ingress{ + {Namespace: testNamespace, Name: extIngClassIngressName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: extIngClassIngressName, + Namespace: testNamespace, + Annotations: map[string]string{networkingv1beta1.AnnotationIngressClass: gceIngressClass}, + }, + Spec: networkingv1.IngressSpec{ + Rules: []networkingv1.IngressRule{{ + Host: testHost, + IngressRuleValue: networkingv1.IngressRuleValue{ + HTTP: &networkingv1.HTTPIngressRuleValue{ + Paths: []networkingv1.HTTPIngressPath{{ + Path: "/", + PathType: &iPrefix, + Backend: networkingv1.IngressBackend{ + Service: &networkingv1.IngressServiceBackend{ + Name: testServiceName, + Port: networkingv1.ServiceBackendPort{ + Number: 80, + }, + }, + }, + }}, + }, + }, + }}, + }, + }, + }, + services: map[types.NamespacedName]*apiv1.Service{ + {Namespace: testNamespace, Name: testServiceName}: { + ObjectMeta: metav1.ObjectMeta{ + Namespace: testNamespace, + Name: testServiceName, + }, + }, + }, + expectedIR: intermediate.IR{ + Gateways: map[types.NamespacedName]intermediate.GatewayContext{ + {Namespace: testNamespace, Name: gceIngressClass}: { + Gateway: gatewayv1.Gateway{ + ObjectMeta: metav1.ObjectMeta{Name: gceIngressClass, Namespace: testNamespace}, + Spec: gatewayv1.GatewaySpec{ + GatewayClassName: gceL7GlobalExternalManagedGatewayClass, + Listeners: []gatewayv1.Listener{{ + Name: "test-mydomain-com-http", + Port: 80, + Protocol: gatewayv1.HTTPProtocolType, + Hostname: ptrTo(gatewayv1.Hostname(testHost)), + }}, + }}, + }, + }, + HTTPRoutes: map[types.NamespacedName]intermediate.HTTPRouteContext{ + {Namespace: testNamespace, Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName)}: { + HTTPRoute: gatewayv1.HTTPRoute{ + ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName), Namespace: testNamespace}, + Spec: gatewayv1.HTTPRouteSpec{ + CommonRouteSpec: gatewayv1.CommonRouteSpec{ + ParentRefs: []gatewayv1.ParentReference{{ + Name: gceIngressClass, + }}, + }, + Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, + Rules: []gatewayv1.HTTPRouteRule{ + { + Matches: []gatewayv1.HTTPRouteMatch{ + { + Path: &gatewayv1.HTTPPathMatch{ + Type: &gPathPrefix, + Value: ptrTo("/"), + }, + }, + }, + BackendRefs: []gatewayv1.HTTPBackendRef{ + { + BackendRef: gatewayv1.BackendRef{ + BackendObjectReference: gatewayv1.BackendObjectReference{ + Name: gatewayv1.ObjectName(testServiceName), + Port: ptrTo(gatewayv1.PortNumber(80)), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + expectedErrors: field.ErrorList{}, + }, + { + name: "gce-internal ingress class", + ingresses: map[types.NamespacedName]*networkingv1.Ingress{ + {Namespace: testNamespace, Name: intIngClassIngressName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: intIngClassIngressName, + Namespace: testNamespace, + Annotations: map[string]string{networkingv1beta1.AnnotationIngressClass: gceL7ILBIngressClass}, + }, + Spec: networkingv1.IngressSpec{ + Rules: []networkingv1.IngressRule{{ + Host: testHost, + IngressRuleValue: networkingv1.IngressRuleValue{ + HTTP: &networkingv1.HTTPIngressRuleValue{ + Paths: []networkingv1.HTTPIngressPath{{ + Path: "/", + PathType: &iPrefix, + Backend: networkingv1.IngressBackend{ + Service: &networkingv1.IngressServiceBackend{ + Name: testServiceName, + Port: networkingv1.ServiceBackendPort{ + Number: 80, + }, + }, + }, + }}, + }, + }, + }}, + }, + }, + }, + services: map[types.NamespacedName]*apiv1.Service{ + {Namespace: testNamespace, Name: testServiceName}: { + ObjectMeta: metav1.ObjectMeta{ + Namespace: testNamespace, + Name: testServiceName, + }, + }, + }, + expectedIR: intermediate.IR{ + Gateways: map[types.NamespacedName]intermediate.GatewayContext{ + {Namespace: testNamespace, Name: gceL7ILBIngressClass}: { + Gateway: gatewayv1.Gateway{ + ObjectMeta: metav1.ObjectMeta{Name: gceL7ILBIngressClass, Namespace: testNamespace}, + Spec: gatewayv1.GatewaySpec{ + GatewayClassName: gceL7RegionalInternalGatewayClass, + Listeners: []gatewayv1.Listener{{ + Name: "test-mydomain-com-http", + Port: 80, + Protocol: gatewayv1.HTTPProtocolType, + Hostname: ptrTo(gatewayv1.Hostname(testHost)), + }}, + }, + }, + }, + }, + HTTPRoutes: map[types.NamespacedName]intermediate.HTTPRouteContext{ + {Namespace: testNamespace, Name: "gce-internal-ingress-class-test-mydomain-com"}: { + HTTPRoute: gatewayv1.HTTPRoute{ + ObjectMeta: metav1.ObjectMeta{Name: "gce-internal-ingress-class-test-mydomain-com", Namespace: testNamespace}, + Spec: gatewayv1.HTTPRouteSpec{ + CommonRouteSpec: gatewayv1.CommonRouteSpec{ + ParentRefs: []gatewayv1.ParentReference{{ + Name: gceL7ILBIngressClass, + }}, + }, + Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, + Rules: []gatewayv1.HTTPRouteRule{ + { + Matches: []gatewayv1.HTTPRouteMatch{ + { + Path: &gatewayv1.HTTPPathMatch{ + Type: &gPathPrefix, + Value: ptrTo("/"), + }, + }, + }, + BackendRefs: []gatewayv1.HTTPBackendRef{ + { + BackendRef: gatewayv1.BackendRef{ + BackendObjectReference: gatewayv1.BackendObjectReference{ + Name: gatewayv1.ObjectName(testServiceName), + Port: ptrTo(gatewayv1.PortNumber(80)), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + expectedErrors: field.ErrorList{}, + }, + { + name: "empty ingress class, default to gce ingress class", + ingresses: map[types.NamespacedName]*networkingv1.Ingress{ + {Namespace: testNamespace, Name: noIngClassIngressName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: noIngClassIngressName, + Namespace: testNamespace, + }, + Spec: networkingv1.IngressSpec{ + Rules: []networkingv1.IngressRule{{ + Host: testHost, + IngressRuleValue: networkingv1.IngressRuleValue{ + HTTP: &networkingv1.HTTPIngressRuleValue{ + Paths: []networkingv1.HTTPIngressPath{{ + Path: "/", + PathType: &iPrefix, + Backend: networkingv1.IngressBackend{ + Service: &networkingv1.IngressServiceBackend{ + Name: testServiceName, + Port: networkingv1.ServiceBackendPort{ + Number: 80, + }, + }, + }, + }}, + }, + }, + }}, + }, + }, + }, + services: map[types.NamespacedName]*apiv1.Service{ + {Namespace: testNamespace, Name: testServiceName}: { + ObjectMeta: metav1.ObjectMeta{ + Namespace: testNamespace, + Name: testServiceName, + }, + }, + }, + expectedIR: intermediate.IR{ + Gateways: map[types.NamespacedName]intermediate.GatewayContext{ + {Namespace: testNamespace, Name: gceIngressClass}: { + Gateway: gatewayv1.Gateway{ + ObjectMeta: metav1.ObjectMeta{Name: gceIngressClass, Namespace: testNamespace}, + Spec: gatewayv1.GatewaySpec{ + GatewayClassName: gceL7GlobalExternalManagedGatewayClass, + Listeners: []gatewayv1.Listener{{ + Name: "test-mydomain-com-http", + Port: 80, + Protocol: gatewayv1.HTTPProtocolType, + Hostname: ptrTo(gatewayv1.Hostname(testHost)), + }}, + }, + }, + }, + }, + HTTPRoutes: map[types.NamespacedName]intermediate.HTTPRouteContext{ + {Namespace: testNamespace, Name: fmt.Sprintf("%s-test-mydomain-com", noIngClassIngressName)}: { + HTTPRoute: gatewayv1.HTTPRoute{ + ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-test-mydomain-com", noIngClassIngressName), Namespace: testNamespace}, + Spec: gatewayv1.HTTPRouteSpec{ + CommonRouteSpec: gatewayv1.CommonRouteSpec{ + ParentRefs: []gatewayv1.ParentReference{{ + Name: gceIngressClass, + }}, + }, + Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, + Rules: []gatewayv1.HTTPRouteRule{ + { + Matches: []gatewayv1.HTTPRouteMatch{ + { + Path: &gatewayv1.HTTPPathMatch{ + Type: &gPathPrefix, + Value: ptrTo("/"), + }, + }, + }, + BackendRefs: []gatewayv1.HTTPBackendRef{ + { + BackendRef: gatewayv1.BackendRef{ + BackendObjectReference: gatewayv1.BackendObjectReference{ + Name: gatewayv1.ObjectName(testServiceName), + Port: ptrTo(gatewayv1.PortNumber(80)), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + expectedErrors: field.ErrorList{}, + }, + { + name: "gce implementation-specific with /*, map to / Prefix", + ingresses: map[types.NamespacedName]*networkingv1.Ingress{ + {Namespace: testNamespace, Name: extIngClassIngressName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: extIngClassIngressName, + Namespace: testNamespace, + Annotations: map[string]string{networkingv1beta1.AnnotationIngressClass: gceIngressClass}, + }, + Spec: networkingv1.IngressSpec{ + Rules: []networkingv1.IngressRule{{ + Host: testHost, + IngressRuleValue: networkingv1.IngressRuleValue{ + HTTP: &networkingv1.HTTPIngressRuleValue{ + Paths: []networkingv1.HTTPIngressPath{{ + Path: "/*", + PathType: &implSpecificPathType, + Backend: networkingv1.IngressBackend{ + Service: &networkingv1.IngressServiceBackend{ + Name: testServiceName, + Port: networkingv1.ServiceBackendPort{ + Number: 80, + }, + }, + }, + }}, + }, + }, + }}, + }, + }, + }, + services: map[types.NamespacedName]*apiv1.Service{ + {Namespace: testNamespace, Name: testServiceName}: { + ObjectMeta: metav1.ObjectMeta{ + Namespace: testNamespace, + Name: testServiceName, + }, + }, + }, + expectedIR: intermediate.IR{ + Gateways: map[types.NamespacedName]intermediate.GatewayContext{ + {Namespace: testNamespace, Name: gceIngressClass}: { + Gateway: gatewayv1.Gateway{ + ObjectMeta: metav1.ObjectMeta{Name: gceIngressClass, Namespace: testNamespace}, + Spec: gatewayv1.GatewaySpec{ + GatewayClassName: gceL7GlobalExternalManagedGatewayClass, + Listeners: []gatewayv1.Listener{{ + Name: "test-mydomain-com-http", + Port: 80, + Protocol: gatewayv1.HTTPProtocolType, + Hostname: ptrTo(gatewayv1.Hostname(testHost)), + }}, + }, + }, + }, + }, + HTTPRoutes: map[types.NamespacedName]intermediate.HTTPRouteContext{ + {Namespace: testNamespace, Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName)}: { + HTTPRoute: gatewayv1.HTTPRoute{ + ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName), Namespace: testNamespace}, + Spec: gatewayv1.HTTPRouteSpec{ + CommonRouteSpec: gatewayv1.CommonRouteSpec{ + ParentRefs: []gatewayv1.ParentReference{{ + Name: gceIngressClass, + }}, + }, + Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, + Rules: []gatewayv1.HTTPRouteRule{ + { + Matches: []gatewayv1.HTTPRouteMatch{ + { + Path: &gatewayv1.HTTPPathMatch{ + Type: &gPathPrefix, + Value: ptrTo("/"), + }, + }, + }, + BackendRefs: []gatewayv1.HTTPBackendRef{ + { + BackendRef: gatewayv1.BackendRef{ + BackendObjectReference: gatewayv1.BackendObjectReference{ + Name: gatewayv1.ObjectName(testServiceName), + Port: ptrTo(gatewayv1.PortNumber(80)), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + expectedErrors: field.ErrorList{}, + }, + { + name: "gce implementation-specific with /foo/*, converted to /foo", + ingresses: map[types.NamespacedName]*networkingv1.Ingress{ + {Namespace: testNamespace, Name: extIngClassIngressName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: extIngClassIngressName, + Namespace: testNamespace, + Annotations: map[string]string{networkingv1beta1.AnnotationIngressClass: gceIngressClass}, + }, + Spec: networkingv1.IngressSpec{ + Rules: []networkingv1.IngressRule{{ + Host: testHost, + IngressRuleValue: networkingv1.IngressRuleValue{ + HTTP: &networkingv1.HTTPIngressRuleValue{ + Paths: []networkingv1.HTTPIngressPath{{ + Path: "/foo/*", + PathType: &implSpecificPathType, + Backend: networkingv1.IngressBackend{ + Service: &networkingv1.IngressServiceBackend{ + Name: testServiceName, + Port: networkingv1.ServiceBackendPort{ + Number: 80, + }, + }, + }, + }}, + }, + }, + }}, + }, + }, + }, + services: map[types.NamespacedName]*apiv1.Service{ + {Namespace: testNamespace, Name: testServiceName}: { + ObjectMeta: metav1.ObjectMeta{ + Namespace: testNamespace, + Name: testServiceName, + }, + }, + }, + expectedIR: intermediate.IR{ + Gateways: map[types.NamespacedName]intermediate.GatewayContext{ + {Namespace: testNamespace, Name: gceIngressClass}: { + Gateway: gatewayv1.Gateway{ + ObjectMeta: metav1.ObjectMeta{Name: gceIngressClass, Namespace: testNamespace}, + Spec: gatewayv1.GatewaySpec{ + GatewayClassName: gceL7GlobalExternalManagedGatewayClass, + Listeners: []gatewayv1.Listener{{ + Name: "test-mydomain-com-http", + Port: 80, + Protocol: gatewayv1.HTTPProtocolType, + Hostname: ptrTo(gatewayv1.Hostname(testHost)), + }}, + }, + }, + }, + }, + HTTPRoutes: map[types.NamespacedName]intermediate.HTTPRouteContext{ + {Namespace: testNamespace, Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName)}: { + HTTPRoute: gatewayv1.HTTPRoute{ + ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName), Namespace: testNamespace}, + Spec: gatewayv1.HTTPRouteSpec{ + CommonRouteSpec: gatewayv1.CommonRouteSpec{ + ParentRefs: []gatewayv1.ParentReference{{ + Name: gceIngressClass, + }}, + }, + Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, + Rules: []gatewayv1.HTTPRouteRule{ + { + Matches: []gatewayv1.HTTPRouteMatch{ + { + Path: &gatewayv1.HTTPPathMatch{ + Type: &gPathPrefix, + Value: ptrTo("/foo"), + }, + }, + }, + BackendRefs: []gatewayv1.HTTPBackendRef{ + { + BackendRef: gatewayv1.BackendRef{ + BackendObjectReference: gatewayv1.BackendObjectReference{ + Name: gatewayv1.ObjectName(testServiceName), + Port: ptrTo(gatewayv1.PortNumber(80)), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + expectedErrors: nil, + }, + { + name: "gce implementation-specific without wildcard path, map to Prefix", + ingresses: map[types.NamespacedName]*networkingv1.Ingress{ + {Namespace: testNamespace, Name: extIngClassIngressName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: extIngClassIngressName, + Namespace: testNamespace, + Annotations: map[string]string{networkingv1beta1.AnnotationIngressClass: gceIngressClass}, + }, + Spec: networkingv1.IngressSpec{ + Rules: []networkingv1.IngressRule{{ + Host: testHost, + IngressRuleValue: networkingv1.IngressRuleValue{ + HTTP: &networkingv1.HTTPIngressRuleValue{ + Paths: []networkingv1.HTTPIngressPath{{ + Path: "/foo", + PathType: &implSpecificPathType, + Backend: networkingv1.IngressBackend{ + Service: &networkingv1.IngressServiceBackend{ + Name: testServiceName, + Port: networkingv1.ServiceBackendPort{ + Number: 80, + }, + }, + }, + }}, + }, + }, + }}, + }, + }, + }, + services: map[types.NamespacedName]*apiv1.Service{ + {Namespace: testNamespace, Name: testServiceName}: { + ObjectMeta: metav1.ObjectMeta{ + Namespace: testNamespace, + Name: testServiceName, + }, + }, + }, + expectedIR: intermediate.IR{ + Gateways: map[types.NamespacedName]intermediate.GatewayContext{ + {Namespace: testNamespace, Name: gceIngressClass}: { + Gateway: gatewayv1.Gateway{ + ObjectMeta: metav1.ObjectMeta{Name: gceIngressClass, Namespace: testNamespace}, + Spec: gatewayv1.GatewaySpec{ + GatewayClassName: gceL7GlobalExternalManagedGatewayClass, + Listeners: []gatewayv1.Listener{{ + Name: "test-mydomain-com-http", + Port: 80, + Protocol: gatewayv1.HTTPProtocolType, + Hostname: ptrTo(gatewayv1.Hostname(testHost)), + }}, + }, + }, + }, + }, + HTTPRoutes: map[types.NamespacedName]intermediate.HTTPRouteContext{ + {Namespace: testNamespace, Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName)}: { + HTTPRoute: gatewayv1.HTTPRoute{ + ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName), Namespace: testNamespace}, + Spec: gatewayv1.HTTPRouteSpec{ + CommonRouteSpec: gatewayv1.CommonRouteSpec{ + ParentRefs: []gatewayv1.ParentReference{{ + Name: gceIngressClass, + }}, + }, + Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, + Rules: []gatewayv1.HTTPRouteRule{ + { + Matches: []gatewayv1.HTTPRouteMatch{ + { + Path: &gatewayv1.HTTPPathMatch{ + Type: &gExact, + Value: ptrTo("/foo"), + }, + }, + }, + BackendRefs: []gatewayv1.HTTPBackendRef{ + { + BackendRef: gatewayv1.BackendRef{ + BackendObjectReference: gatewayv1.BackendObjectReference{ + Name: gatewayv1.ObjectName(testServiceName), + Port: ptrTo(gatewayv1.PortNumber(80)), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + expectedErrors: field.ErrorList{}, + }, + { + name: "ingress with a Backend Config specifying CLIENT_IP type session affinity config", + ingresses: map[types.NamespacedName]*networkingv1.Ingress{ + {Namespace: testNamespace, Name: extIngClassIngressName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: extIngClassIngressName, + Namespace: testNamespace, + Annotations: map[string]string{networkingv1beta1.AnnotationIngressClass: gceIngressClass}, + }, + Spec: networkingv1.IngressSpec{ + Rules: []networkingv1.IngressRule{{ + Host: testHost, + IngressRuleValue: networkingv1.IngressRuleValue{ + HTTP: &networkingv1.HTTPIngressRuleValue{ + Paths: []networkingv1.HTTPIngressPath{{ + Path: "/", + PathType: &iPrefix, + Backend: networkingv1.IngressBackend{ + Service: &networkingv1.IngressServiceBackend{ + Name: testServiceName, + Port: networkingv1.ServiceBackendPort{ + Number: 80, + }, + }, + }, + }}, + }, + }, + }}, + }, + }, + }, + services: map[types.NamespacedName]*apiv1.Service{ + {Namespace: testNamespace, Name: testServiceName}: { + ObjectMeta: metav1.ObjectMeta{ + Namespace: testNamespace, + Name: testServiceName, + Annotations: map[string]string{ + backendConfigKey: `{"default":"test-backendconfig"}`, + }, + }, + }, + }, + backendConfigs: map[types.NamespacedName]*backendconfigv1.BackendConfig{ + {Namespace: testNamespace, Name: testBackendConfigName}: { + ObjectMeta: metav1.ObjectMeta{ + Namespace: testNamespace, + Name: testBackendConfigName, + }, + Spec: backendconfigv1.BackendConfigSpec{ + SessionAffinity: &backendconfigv1.SessionAffinityConfig{ + AffinityType: saTypeClientIP, + }, + }, + }, + }, + expectedIR: intermediate.IR{ + Gateways: map[types.NamespacedName]intermediate.GatewayContext{ + {Namespace: testNamespace, Name: gceIngressClass}: { + Gateway: gatewayv1.Gateway{ + ObjectMeta: metav1.ObjectMeta{Name: gceIngressClass, Namespace: testNamespace}, + Spec: gatewayv1.GatewaySpec{ + GatewayClassName: gceL7GlobalExternalManagedGatewayClass, + Listeners: []gatewayv1.Listener{{ + Name: "test-mydomain-com-http", + Port: 80, + Protocol: gatewayv1.HTTPProtocolType, + Hostname: ptrTo(gatewayv1.Hostname(testHost)), + }}, + }, + }, + }, + }, + HTTPRoutes: map[types.NamespacedName]intermediate.HTTPRouteContext{ + {Namespace: testNamespace, Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName)}: { + HTTPRoute: gatewayv1.HTTPRoute{ + ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName), Namespace: testNamespace}, + Spec: gatewayv1.HTTPRouteSpec{ + CommonRouteSpec: gatewayv1.CommonRouteSpec{ + ParentRefs: []gatewayv1.ParentReference{{ + Name: gceIngressClass, + }}, + }, + Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, + Rules: []gatewayv1.HTTPRouteRule{ + { + Matches: []gatewayv1.HTTPRouteMatch{ + { + Path: &gatewayv1.HTTPPathMatch{ + Type: &gPathPrefix, + Value: ptrTo("/"), + }, + }, + }, + BackendRefs: []gatewayv1.HTTPBackendRef{ + { + BackendRef: gatewayv1.BackendRef{ + BackendObjectReference: gatewayv1.BackendObjectReference{ + Name: gatewayv1.ObjectName(testServiceName), + Port: ptrTo(gatewayv1.PortNumber(80)), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + Services: map[types.NamespacedName]intermediate.ProviderSpecificServiceIR{ + {Namespace: testNamespace, Name: testServiceName}: { + Gce: &intermediate.GceServiceIR{ + SessionAffinity: &intermediate.SessionAffinityConfig{ + AffinityType: saTypeClientIP, + }, + }, + }, + }, + }, + expectedErrors: field.ErrorList{}, + }, + { + name: "ingress with a Backend Config specifying GENERATED_COOKIE type session affinity config", + ingresses: map[types.NamespacedName]*networkingv1.Ingress{ + {Namespace: testNamespace, Name: extIngClassIngressName}: { + ObjectMeta: metav1.ObjectMeta{ + Name: extIngClassIngressName, + Namespace: testNamespace, + Annotations: map[string]string{networkingv1beta1.AnnotationIngressClass: gceIngressClass}, + }, + Spec: networkingv1.IngressSpec{ + Rules: []networkingv1.IngressRule{{ + Host: testHost, + IngressRuleValue: networkingv1.IngressRuleValue{ + HTTP: &networkingv1.HTTPIngressRuleValue{ + Paths: []networkingv1.HTTPIngressPath{{ + Path: "/", + PathType: &iPrefix, + Backend: networkingv1.IngressBackend{ + Service: &networkingv1.IngressServiceBackend{ + Name: testServiceName, + Port: networkingv1.ServiceBackendPort{ + Number: 80, + }, + }, + }, + }}, + }, + }, + }}, + }, + }, + }, + services: map[types.NamespacedName]*apiv1.Service{ + {Namespace: testNamespace, Name: testServiceName}: { + ObjectMeta: metav1.ObjectMeta{ + Namespace: testNamespace, + Name: testServiceName, + Annotations: map[string]string{ + backendConfigKey: `{"default":"test-backendconfig"}`, + }, + }, + }, + }, + backendConfigs: map[types.NamespacedName]*backendconfigv1.BackendConfig{ + {Namespace: testNamespace, Name: testBackendConfigName}: { + ObjectMeta: metav1.ObjectMeta{ + Namespace: testNamespace, + Name: testBackendConfigName, + }, + Spec: backendconfigv1.BackendConfigSpec{ + SessionAffinity: &backendconfigv1.SessionAffinityConfig{ + AffinityType: saTypeCookie, + AffinityCookieTtlSec: &testCookieTTLSec, + }, + }, + }, + }, + expectedIR: intermediate.IR{ + Gateways: map[types.NamespacedName]intermediate.GatewayContext{ + {Namespace: testNamespace, Name: gceIngressClass}: { + Gateway: gatewayv1.Gateway{ + ObjectMeta: metav1.ObjectMeta{Name: gceIngressClass, Namespace: testNamespace}, + Spec: gatewayv1.GatewaySpec{ + GatewayClassName: gceL7GlobalExternalManagedGatewayClass, + Listeners: []gatewayv1.Listener{{ + Name: "test-mydomain-com-http", + Port: 80, + Protocol: gatewayv1.HTTPProtocolType, + Hostname: ptrTo(gatewayv1.Hostname(testHost)), + }}, + }, + }, + }, + }, + HTTPRoutes: map[types.NamespacedName]intermediate.HTTPRouteContext{ + {Namespace: testNamespace, Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName)}: { + HTTPRoute: gatewayv1.HTTPRoute{ + ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s-test-mydomain-com", extIngClassIngressName), Namespace: testNamespace}, + Spec: gatewayv1.HTTPRouteSpec{ + CommonRouteSpec: gatewayv1.CommonRouteSpec{ + ParentRefs: []gatewayv1.ParentReference{{ + Name: gceIngressClass, + }}, + }, + Hostnames: []gatewayv1.Hostname{gatewayv1.Hostname(testHost)}, + Rules: []gatewayv1.HTTPRouteRule{ + { + Matches: []gatewayv1.HTTPRouteMatch{ + { + Path: &gatewayv1.HTTPPathMatch{ + Type: &gPathPrefix, + Value: ptrTo("/"), + }, + }, + }, + BackendRefs: []gatewayv1.HTTPBackendRef{ + { + BackendRef: gatewayv1.BackendRef{ + BackendObjectReference: gatewayv1.BackendObjectReference{ + Name: gatewayv1.ObjectName(testServiceName), + Port: ptrTo(gatewayv1.PortNumber(80)), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + Services: map[types.NamespacedName]intermediate.ProviderSpecificServiceIR{ + {Namespace: testNamespace, Name: testServiceName}: { + Gce: &intermediate.GceServiceIR{ + SessionAffinity: &intermediate.SessionAffinityConfig{ + AffinityType: saTypeCookie, + CookieTTLSec: &testCookieTTLSec, + }, + }, + }, + }, + }, + expectedErrors: field.ErrorList{}, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + + provider := NewProvider(&i2gw.ProviderConf{}) + gceProvider := provider.(*Provider) + gceProvider.storage = newResourcesStorage() + gceProvider.storage.Ingresses = tc.ingresses + gceProvider.storage.Services = tc.services + gceProvider.storage.BackendConfigs = tc.backendConfigs + + // TODO(#113) we pass an empty i2gw.InputResources temporarily until we change ToIR function on the interface + ir, errs := gceProvider.irConverter.convertToIR(gceProvider.storage) + + if len(errs) != len(tc.expectedErrors) { + t.Errorf("Expected %d errors, got %d: %+v", len(tc.expectedErrors), len(errs), errs) + } else { + for i, e := range errs { + if errors.Is(e, tc.expectedErrors[i]) { + t.Errorf("Unexpected error message at %d index. Got %s, want: %s", i, e, tc.expectedErrors[i]) + } + } + } + + if len(ir.HTTPRoutes) != len(tc.expectedIR.HTTPRoutes) { + t.Errorf("Expected %d HTTPRoutes, got %d: %+v", + len(tc.expectedIR.HTTPRoutes), len(ir.HTTPRoutes), ir.HTTPRoutes) + } else { + for i, gotHTTPRouteContext := range ir.HTTPRoutes { + key := types.NamespacedName{Namespace: gotHTTPRouteContext.HTTPRoute.Namespace, Name: gotHTTPRouteContext.HTTPRoute.Name} + wantHTTPRouteContext := tc.expectedIR.HTTPRoutes[key] + wantHTTPRouteContext.HTTPRoute.SetGroupVersionKind(common.HTTPRouteGVK) + if !apiequality.Semantic.DeepEqual(gotHTTPRouteContext.HTTPRoute, wantHTTPRouteContext.HTTPRoute) { + t.Errorf("Expected HTTPRoute %s to be %+v\n Got: %+v\n Diff: %s", i, wantHTTPRouteContext.HTTPRoute, gotHTTPRouteContext.HTTPRoute, cmp.Diff(wantHTTPRouteContext.HTTPRoute, gotHTTPRouteContext.HTTPRoute)) + } + } + } + + if len(ir.Gateways) != len(tc.expectedIR.Gateways) { + t.Errorf("Expected %d Gateways, got %d: %+v", + len(tc.expectedIR.Gateways), len(ir.Gateways), ir.Gateways) + } else { + for i, gotGatewayContext := range ir.Gateways { + key := types.NamespacedName{Namespace: gotGatewayContext.Gateway.Namespace, Name: gotGatewayContext.Gateway.Name} + wantGatewayContext := tc.expectedIR.Gateways[key] + wantGatewayContext.Gateway.SetGroupVersionKind(common.GatewayGVK) + if !apiequality.Semantic.DeepEqual(gotGatewayContext.Gateway, wantGatewayContext.Gateway) { + t.Errorf("Expected Gateway %s to be %+v\n Got: %+v\n Diff: %s", i, wantGatewayContext.Gateway, gotGatewayContext.Gateway, cmp.Diff(wantGatewayContext.Gateway, gotGatewayContext.Gateway)) + } + } + } + + if len(ir.Services) != len(tc.expectedIR.Services) { + t.Errorf("Expected %d ServiceIR, got %d: %+v", + len(tc.expectedIR.Services), len(ir.Services), ir.Services) + } else { + for svcKey, gotServiceIR := range ir.Services { + key := types.NamespacedName{Namespace: svcKey.Namespace, Name: svcKey.Name} + wantServiceIR := tc.expectedIR.Services[key] + if !apiequality.Semantic.DeepEqual(gotServiceIR, wantServiceIR) { + t.Errorf("Expected ServiceIR %s to be %+v\n Got: %+v\n Diff: %s", svcKey, wantServiceIR, gotServiceIR, cmp.Diff(wantServiceIR, gotServiceIR)) + } + } + } + }) + } +} + +func ptrTo[T any](a T) *T { + return &a +} diff --git a/pkg/i2gw/providers/gce/storage.go b/pkg/i2gw/providers/gce/storage.go index faf1a282..71fac57a 100644 --- a/pkg/i2gw/providers/gce/storage.go +++ b/pkg/i2gw/providers/gce/storage.go @@ -25,12 +25,12 @@ import ( type storage struct { Ingresses map[types.NamespacedName]*networkingv1.Ingress + Services map[types.NamespacedName]*apiv1.Service // BackendConfig is a GKE Ingress extension, and it is associated to an GKE // Ingress through specifying `cloud.google.com/backend-config` or - // `beta.cloud.google.com/backend-config` annotation on its Backend Services. - - Services map[types.NamespacedName]*apiv1.Service + // `beta.cloud.google.com/backend-config` annotation on its Services. + // BackendConfig map is keyed by the namespaced name of the BackendConfig. BackendConfigs map[types.NamespacedName]*backendconfigv1.BackendConfig } diff --git a/pkg/i2gw/providers/gce/types.go b/pkg/i2gw/providers/gce/types.go index 08b00be8..974bb745 100644 --- a/pkg/i2gw/providers/gce/types.go +++ b/pkg/i2gw/providers/gce/types.go @@ -16,10 +16,20 @@ limitations under the License. package gce +import "k8s.io/apimachinery/pkg/runtime/schema" + const ( gceIngressClass = "gce" gceL7ILBIngressClass = "gce-internal" gceL7GlobalExternalManagedGatewayClass = "gke-l7-global-external-managed" gceL7RegionalInternalGatewayClass = "gke-l7-rilb" + backendConfigKey = "cloud.google.com/backend-config" + betaBackendConfigKey = "beta.cloud.google.com/backend-config" ) + +var GCPBackendPolicyGVK = schema.GroupVersionKind{ + Group: "networking.gke.io", + Version: "v1", + Kind: "GCPBackendPolicy", +} diff --git a/pkg/i2gw/providers/gce/utils.go b/pkg/i2gw/providers/gce/utils.go index ef431d53..513ed31f 100644 --- a/pkg/i2gw/providers/gce/utils.go +++ b/pkg/i2gw/providers/gce/utils.go @@ -19,7 +19,7 @@ package gce import ( "fmt" - "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw" + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/intermediate" "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/common" networkingv1 "k8s.io/api/networking/v1" "k8s.io/apimachinery/pkg/types" @@ -28,7 +28,7 @@ import ( ) // setGCEGatewayClasses updates the list of Gateways to use GCE GatewayClass. -func setGCEGatewayClasses(ingresses []networkingv1.Ingress, gatewayResources *i2gw.GatewayResources) field.ErrorList { +func setGCEGatewayClasses(ingresses []networkingv1.Ingress, gatewayContexts map[types.NamespacedName]intermediate.GatewayContext) field.ErrorList { var errs field.ErrorList // Since we already validated ingress resources when reading, there are @@ -40,13 +40,13 @@ func setGCEGatewayClasses(ingresses []networkingv1.Ingress, gatewayResources *i2 // mapped to `gke-l7-global-external-managed`. for _, ingress := range ingresses { gwKey := types.NamespacedName{Namespace: ingress.Namespace, Name: common.GetIngressClass(ingress)} - existingGateway := gatewayResources.Gateways[gwKey] + existingGateway := gatewayContexts[gwKey].Gateway newGateway, err := setGCEGatewayClass(ingress, existingGateway) if err != nil { errs = append(errs, err) } - gatewayResources.Gateways[gwKey] = newGateway + gatewayContexts[gwKey] = intermediate.GatewayContext{Gateway: newGateway} } if len(errs) > 0 { return errs