Skip to content

Commit

Permalink
tests(fix): conformance tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
programmer04 committed May 20, 2024
1 parent e4d70de commit ac45eec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 53 deletions.
2 changes: 1 addition & 1 deletion controller/gateway/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
return ctrl.Result{}, nil // requeue will be triggered by the update of the controlplane status
}

// if the controlplane wasnt't ready before this reconciliation loop and now is ready, log this event
// if the controlplane wasn't ready before this reconciliation loop and now is ready, log this event
if !k8sutils.IsConditionTrue(ControlPlaneReadyType, oldGwConditionsAware) {
log.Debug(logger, "controlplane is ready", gateway)
}
Expand Down
76 changes: 25 additions & 51 deletions test/conformance/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ package conformance

import (
"fmt"
"os"
"path"
"testing"

"github.com/google/uuid"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
"sigs.k8s.io/gateway-api/conformance"
conformancev1 "sigs.k8s.io/gateway-api/conformance/apis/v1"
"sigs.k8s.io/gateway-api/conformance/tests"
"sigs.k8s.io/gateway-api/conformance/utils/flags"
"sigs.k8s.io/gateway-api/conformance/utils/suite"

"github.com/kong/gateway-operator/internal/metadata"
Expand All @@ -30,6 +28,11 @@ var skippedTests = []string{

// httproute
tests.HTTPRouteHeaderMatching.ShortName,
tests.HTTPRouteHTTPSListener.ShortName,
tests.HTTPRouteHostnameIntersection.ShortName,
tests.HTTPRouteInvalidBackendRefUnknownKind.ShortName,
tests.HTTPRouteListenerHostnameMatching.ShortName,
tests.HTTPRouteObservedGenerationBump.ShortName,
}

func TestGatewayConformance(t *testing.T) {
Expand All @@ -53,56 +56,27 @@ func TestGatewayConformance(t *testing.T) {
// still run the conformance test suite setup to ensure that the
// GatewayClass gets accepted.
t.Log("starting the gateway conformance test suite")
conformanceTestsBaseManifests := fmt.Sprintf("%s/conformance/base/manifests.yaml", testutils.GatewayRawRepoURL)
const reportFileName = "kong-gateway-operator.yaml" // TODO: https://github.com/Kong/gateway-operator/issues/268

cSuite, err := suite.NewConformanceTestSuite(
suite.ConformanceOptions{
Client: clients.MgrClient,
GatewayClassName: gwc.Name,
Debug: *flags.ShowDebug,
CleanupBaseResources: *flags.CleanupBaseResources,
BaseManifests: conformanceTestsBaseManifests,
SkipTests: skippedTests,
ConformanceProfiles: sets.New(
suite.GatewayHTTPConformanceProfileName,
),
Implementation: conformancev1.Implementation{
Organization: metadata.Organization,
Project: metadata.ProjectName,
URL: metadata.ProjectURL,
Version: metadata.Release,
Contact: []string{
path.Join(metadata.ProjectURL, "/issues/new/choose"),
},
},
},
opts := conformance.DefaultOptions(t)
opts.ReportOutputPath = "../../" + reportFileName
opts.Client = clients.MgrClient
opts.GatewayClassName = gwc.Name
opts.BaseManifests = fmt.Sprintf("%s/conformance/base/manifests.yaml", testutils.GatewayRawRepoURL)
opts.SkipTests = skippedTests
opts.ConformanceProfiles = sets.New(
suite.GatewayHTTPConformanceProfileName,
)
require.NoError(t, err)
opts.Implementation = conformancev1.Implementation{
Organization: metadata.Organization,
Project: metadata.ProjectName,
URL: metadata.ProjectURL,
Version: metadata.Release,
Contact: []string{
path.Join(metadata.ProjectURL, "/issues/new/choose"),
},
}

t.Log("starting the gateway conformance test suite")
cSuite.Setup(t, tests.ConformanceTests)

// To work with individual tests only, you can disable the normal Run call and construct a slice containing a
// single test only, e.g.:
//
// cSuite.Run(t, []suite.ConformanceTest{tests.GatewayClassObservedGenerationBump})
// To work with individual tests only, you can disable the normal Run call and construct a slice containing a
// single test only, e.g.:
//
// cSuite.Run(t, []suite.ConformanceTest{tests.HTTPRouteRedirectPortAndScheme})
require.NoError(t, cSuite.Run(t, tests.ConformanceTests))

// In the future we'll likely change the file name as https://github.com/kubernetes-sigs/gateway-api/issues/2740 will be implemented.
// The day it will happen, we'll have to change the .gitignore entry as well.
const reportFileName = "kong-gateway-operator.yaml"

t.Log("saving the gateway conformance test report to file:", reportFileName)
report, err := cSuite.Report()
require.NoError(t, err)
rawReport, err := yaml.Marshal(report)
require.NoError(t, err)
fmt.Println("INFO: final report")
fmt.Println(string(rawReport))
// Save report in root of the repository, file name is in .gitignore.
require.NoError(t, os.WriteFile("../../"+reportFileName, rawReport, 0o600))
conformance.RunConformanceWithOptions(t, opts)
}
5 changes: 4 additions & 1 deletion test/conformance/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/kong/kubernetes-testing-framework/pkg/clusters"
"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/metallb"
"github.com/kong/kubernetes-testing-framework/pkg/environments"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -78,7 +79,9 @@ func TestMain(m *testing.M) {
// Gateway API conformance tests do not create resources like NetworkPolicy
// that would allow e.g. cross namespace traffic.
// Related upstream discussion: https://github.com/kubernetes-sigs/gateway-api/discussions/2137
env, err = testutils.BuildEnvironment(ctx, existingCluster)
env, err = testutils.BuildEnvironment(ctx, existingCluster, func(b *environments.Builder, t clusters.Type) {
b.WithAddons(metallb.New())
})
exitOnErr(err)

fmt.Printf("INFO: waiting for cluster %s and all addons to become ready\n", env.Cluster().Name())
Expand Down

0 comments on commit ac45eec

Please sign in to comment.