Skip to content

Commit

Permalink
gateway-api: run conformance tests (istio#38116)
Browse files Browse the repository at this point in the history
* gateway-api: run conformance tests

* lint

* fix rebase

* Install CRDs

* fix race

* fix

* feature label
  • Loading branch information
howardjohn authored Mar 31, 2022
1 parent df20c6b commit e3fb811
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 46 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ require (
k8s.io/kubectl v0.23.5
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
sigs.k8s.io/controller-runtime v0.11.1
sigs.k8s.io/gateway-api v0.4.2
sigs.k8s.io/gateway-api v0.4.1-0.20220325202559-704c253f29c1
sigs.k8s.io/mcs-api v0.1.0
sigs.k8s.io/yaml v1.3.0
)
Expand Down
48 changes: 22 additions & 26 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pilot/pkg/config/kube/crdclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import (
// import OIDC cluster authentication plugin, e.g. for Tectonic
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
"k8s.io/client-go/tools/cache"
gatewayapiclient "sigs.k8s.io/gateway-api/pkg/client/clientset/gateway/versioned"
gatewayapiclient "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned"

istioclient "istio.io/client-go/pkg/clientset/versioned"
"istio.io/istio/pilot/pkg/features"
Expand Down
2 changes: 1 addition & 1 deletion pilot/pkg/config/kube/crdclient/gen/types.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
gatewayapiclient "sigs.k8s.io/gateway-api/pkg/client/clientset/gateway/versioned"
gatewayapiclient "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned"

"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/schema/collections"
Expand Down
2 changes: 1 addition & 1 deletion pilot/pkg/config/kube/crdclient/types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pilot/pkg/config/kube/gateway/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func createRouteStatus(gateways []routeParentReference, obj config.Config, curre
}
// Collect all of our unique parent references. There may be multiple when we have a route without section name,
// but reference a parent with multiple sections.
seen := map[k8s.ParentRef]routeParentReference{}
failedCount := map[k8s.ParentRef]int{}
seen := map[k8s.ParentReference]routeParentReference{}
failedCount := map[k8s.ParentReference]int{}
for _, gw := range gateways {
// We will append it if it is our first occurrence, or the existing one has an error. This means
// if *any* section has no errors, we will declare Admitted
Expand Down
2 changes: 1 addition & 1 deletion pilot/pkg/config/kube/gateway/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var (
},
}
httpRouteSpec = &k8s.HTTPRouteSpec{
CommonRouteSpec: k8s.CommonRouteSpec{ParentRefs: []k8s.ParentRef{{
CommonRouteSpec: k8s.CommonRouteSpec{ParentRefs: []k8s.ParentReference{{
Name: "gwspec",
}}},
Hostnames: []k8s.Hostname{"test.cluster.local"},
Expand Down
10 changes: 5 additions & 5 deletions pilot/pkg/config/kube/gateway/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ func hostnameToStringList(h []k8s.Hostname) []string {
return res
}

func toInternalParentReference(p k8s.ParentRef, localNamespace string) (parentKey, error) {
func toInternalParentReference(p k8s.ParentReference, localNamespace string) (parentKey, error) {
empty := parentKey{}
grp := defaultIfNil((*string)(p.Group), gvk.KubernetesGateway.Group)
kind := defaultIfNil((*string)(p.Kind), gvk.KubernetesGateway.Kind)
Expand Down Expand Up @@ -533,7 +533,7 @@ func referenceAllowed(p *parentInfo, routeKind config.GroupVersionKind, parentKi
return nil
}

func extractParentReferenceInfo(gateways map[parentKey]map[k8s.SectionName]*parentInfo, routeRefs []k8s.ParentRef,
func extractParentReferenceInfo(gateways map[parentKey]map[k8s.SectionName]*parentInfo, routeRefs []k8s.ParentReference,
hostnames []k8s.Hostname, kind config.GroupVersionKind, localNamespace string) []routeParentReference {
parentRefs := []routeParentReference{}
for _, ref := range routeRefs {
Expand Down Expand Up @@ -1113,7 +1113,7 @@ var meshGVK = config.GroupVersionKind{
}

// parentKey holds info about a parentRef (ie route binding to a Gateway). This is a mirror of
// k8s.ParentRef in a form that can be stored in a map
// k8s.ParentReference in a form that can be stored in a map
type parentKey struct {
Kind config.GroupVersionKind
// Name is the original name of the resource (ie Kubernetes Gateway name)
Expand Down Expand Up @@ -1150,7 +1150,7 @@ type routeParentReference struct {
// DeniedReason, if present, indicates why the reference was not valid
DeniedReason error
// OriginalReference contains the original reference
OriginalReference k8s.ParentRef
OriginalReference k8s.ParentReference
}

// referencesToInternalNames converts valid parent references to names that can be used in VirtualService
Expand Down Expand Up @@ -1529,7 +1529,7 @@ func objectReferenceString(ref k8s.SecretObjectReference) string {
emptyIfNil((*string)(ref.Namespace)))
}

func parentRefString(ref k8s.ParentRef) string {
func parentRefString(ref k8s.ParentReference) string {
return fmt.Sprintf("%s/%s/%s/%s.%s",
emptyIfNil((*string)(ref.Group)),
emptyIfNil((*string)(ref.Kind)),
Expand Down
2 changes: 1 addition & 1 deletion pilot/pkg/config/kube/gateway/deploymentcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"
gateway "sigs.k8s.io/gateway-api/apis/v1alpha2"
"sigs.k8s.io/gateway-api/pkg/client/listers/gateway/apis/v1alpha2"
"sigs.k8s.io/gateway-api/pkg/client/listers/apis/v1alpha2"
"sigs.k8s.io/yaml"

"istio.io/istio/pkg/config"
Expand Down
4 changes: 2 additions & 2 deletions pilot/pkg/config/kube/gateway/gatewayclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
gateway "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayclient "sigs.k8s.io/gateway-api/pkg/client/clientset/gateway/versioned/typed/apis/v1alpha2"
lister "sigs.k8s.io/gateway-api/pkg/client/listers/gateway/apis/v1alpha2"
gatewayclient "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned/typed/apis/v1alpha2"
lister "sigs.k8s.io/gateway-api/pkg/client/listers/apis/v1alpha2"

"istio.io/istio/pkg/kube"
"istio.io/istio/pkg/kube/controllers"
Expand Down
6 changes: 3 additions & 3 deletions pkg/kube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ import (
kubectlDelete "k8s.io/kubectl/pkg/cmd/delete"
"k8s.io/kubectl/pkg/cmd/util"
gatewayapi "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayapiclient "sigs.k8s.io/gateway-api/pkg/client/clientset/gateway/versioned"
gatewayapifake "sigs.k8s.io/gateway-api/pkg/client/clientset/gateway/versioned/fake"
gatewayapiinformer "sigs.k8s.io/gateway-api/pkg/client/informers/gateway/externalversions"
gatewayapiclient "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned"
gatewayapifake "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned/fake"
gatewayapiinformer "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions"

"istio.io/api/label"
clientextensions "istio.io/client-go/pkg/apis/extensions/v1alpha1"
Expand Down
4 changes: 2 additions & 2 deletions pkg/kube/mock_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import (
"k8s.io/client-go/rest/fake"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
"k8s.io/kubectl/pkg/cmd/util"
serviceapisclient "sigs.k8s.io/gateway-api/pkg/client/clientset/gateway/versioned"
serviceapisinformer "sigs.k8s.io/gateway-api/pkg/client/informers/gateway/externalversions"
serviceapisclient "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned"
serviceapisinformer "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions"
mcsapisclient "sigs.k8s.io/mcs-api/pkg/client/clientset/versioned"
mcsapisinformer "sigs.k8s.io/mcs-api/pkg/client/informers/externalversions"

Expand Down
1 change: 1 addition & 0 deletions pkg/test/framework/features/features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ features:
cni:
race-condition-repair:
upgrade:
gateway:
usability:
observability:
describe:
Expand Down
102 changes: 102 additions & 0 deletions tests/integration/pilot/gateway_conformance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright Istio 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.

//go:build integ
// +build integ

// Copyright Istio 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 pilot

import (
"context"
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/gateway-api/conformance/tests"
"sigs.k8s.io/gateway-api/conformance/utils/suite"

"istio.io/istio/pkg/kube"
"istio.io/istio/pkg/test/framework"
"istio.io/istio/pkg/test/framework/resource"
"istio.io/istio/pkg/test/scopes"
"istio.io/istio/pkg/test/util/retry"
)

// GatewayConformanceInputs defines inputs to the gateway conformance test.
// The upstream build requires using `testing.T` types, which we cannot pass using our framework.
// To workaround this, we set up the inputs it TestMain.
type GatewayConformanceInputs struct {
Client kube.ExtendedClient
Cleanup bool
}

var gatewayConformanceInputs GatewayConformanceInputs

func TestGatewayConformance(t *testing.T) {
framework.
NewTest(t).
RequiresSingleCluster().
Features("traffic.gateway").
Run(func(ctx framework.TestContext) {
if !supportsCRDv1(ctx) {
t.Skip("Not supported; requires CRDv1 support.")
}
if err := ctx.ConfigIstio().File("", "testdata/gateway-api-crd.yaml").Apply(resource.NoCleanup); err != nil {
ctx.Fatal(err)
}
// Wait until our GatewayClass is ready
retry.UntilSuccessOrFail(ctx, func() error {
_, err := ctx.Clusters().Default().GatewayAPI().GatewayV1alpha2().GatewayClasses().Get(context.Background(), "istio", metav1.GetOptions{})
return err
})

mapper, _ := gatewayConformanceInputs.Client.UtilFactory().ToRESTMapper()
c, err := client.New(gatewayConformanceInputs.Client.RESTConfig(), client.Options{
Scheme: kube.IstioScheme,
Mapper: mapper,
})
if err != nil {
t.Fatal(err)
}

csuite := suite.New(suite.Options{
Client: c,
GatewayClassName: "istio",
Debug: scopes.Framework.DebugEnabled(),
Cleanup: gatewayConformanceInputs.Cleanup,
RoundTripper: nil,
})
csuite.Setup(t)

for _, ct := range tests.ConformanceTests {
t.Run(ct.ShortName, func(t *testing.T) {
ct.Run(t, csuite)
})
}
})
}
6 changes: 6 additions & 0 deletions tests/integration/pilot/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ func TestMain(m *testing.M) {
Setup(func(t resource.Context) error {
return deployment.SetupSingleNamespace(t, &apps)
}).
Setup(func(t resource.Context) error {
gatewayConformanceInputs.Client = t.Clusters().Default()
gatewayConformanceInputs.Cleanup = !t.Settings().NoCleanup

return nil
}).
Run()
}

Expand Down

0 comments on commit e3fb811

Please sign in to comment.