generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cobra and viper added. The Configuration can now be set either via flags or configuration file. Signed-off-by: Mattia Lavacca <lavacca.mattia@gmail.com>
- Loading branch information
Showing
8 changed files
with
244 additions
and
56 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
//go:build experimental | ||
// +build experimental | ||
|
||
/* | ||
Copyright 2023 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 conformance_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"gopkg.in/yaml.v2" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/utils/pointer" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/client/config" | ||
"sigs.k8s.io/gateway-api/apis/v1alpha2" | ||
"sigs.k8s.io/gateway-api/apis/v1beta1" | ||
confv1a1 "sigs.k8s.io/gateway-api/conformance/apis/v1alpha1" | ||
"sigs.k8s.io/gateway-api/conformance/tests" | ||
"sigs.k8s.io/gateway-api/conformance/utils/flags" | ||
"sigs.k8s.io/gateway-api/conformance/utils/suite" | ||
) | ||
|
||
func init() { | ||
flags.ConformanceProfiles = pointer.String("HTTP") | ||
flags.ImplementationOrganization = pointer.String("acme.org") | ||
flags.ImplementationProject = pointer.String("test") | ||
flags.ImplementationUrl = pointer.String("acme.org/test") | ||
flags.ImplementationVersion = pointer.String("0.1.0") | ||
flags.ImplementationContact = pointer.String("@mlavacca") | ||
|
||
flags.ConformanceProfiles = pointer.String("HTTP") | ||
flags.GatewayClassName = pointer.String("kong") | ||
//flags.SupportedFeatures = pointer.String("HTTPRoute,Gateway,ReferenceGrant") | ||
flags.ShowDebug = pointer.Bool(true) | ||
} | ||
|
||
func TestExperimentalConformance(t *testing.T) { | ||
cfg, err := config.GetConfig() | ||
if err != nil { | ||
t.Fatalf("Error loading Kubernetes config: %v", err) | ||
} | ||
client, err := client.New(cfg, client.Options{}) | ||
if err != nil { | ||
t.Fatalf("Error initializing Kubernetes client: %v", err) | ||
} | ||
clientset, err := kubernetes.NewForConfig(cfg) | ||
if err != nil { | ||
t.Fatalf("Error initializing Kubernetes REST client: %v", err) | ||
} | ||
|
||
v1alpha2.AddToScheme(client.Scheme()) | ||
v1beta1.AddToScheme(client.Scheme()) | ||
|
||
supportedFeatures := suite.ParseSupportedFeatures(*flags.SupportedFeatures) | ||
exemptFeatures := suite.ParseSupportedFeatures(*flags.ExemptFeatures) | ||
implementation, err := suite.ParseImplementation( | ||
*flags.ImplementationOrganization, | ||
*flags.ImplementationProject, | ||
*flags.ImplementationUrl, | ||
*flags.ImplementationVersion, | ||
*flags.ImplementationContact, | ||
) | ||
if err != nil { | ||
t.Fatalf("Error parsing implementation's details: %v", err) | ||
} | ||
conformanceProfiles, err := suite.ParseConformanceProfiles(*flags.ConformanceProfiles) | ||
if err != nil { | ||
t.Fatalf("Error parsing conformance profiles: %v", err) | ||
} | ||
|
||
namespaceLabels := suite.ParseNamespaceLabels(*flags.NamespaceLabels) | ||
|
||
t.Logf("Running conformance tests with %s GatewayClass\n cleanup: %t\n debug: %t\n enable all features: %t \n supported features: [%v]\n exempt features: [%v]", | ||
*flags.GatewayClassName, *flags.CleanupBaseResources, *flags.ShowDebug, *flags.EnableAllSupportedFeatures, *flags.SupportedFeatures, *flags.ExemptFeatures) | ||
|
||
cSuite, err := suite.NewExperimentalConformanceTestSuite( | ||
suite.ExperimentalConformanceOptions{ | ||
Options: suite.Options{ | ||
Client: client, | ||
RESTClient: clientset.CoreV1().RESTClient().(*rest.RESTClient), | ||
RestConfig: cfg, | ||
// This clientset is needed in addition to the client only because | ||
// controller-runtime client doesn't support non CRUD sub-resources yet (https://github.com/kubernetes-sigs/controller-runtime/issues/452). | ||
Clientset: clientset, | ||
GatewayClassName: *flags.GatewayClassName, | ||
Debug: *flags.ShowDebug, | ||
CleanupBaseResources: *flags.CleanupBaseResources, | ||
SupportedFeatures: supportedFeatures, | ||
ExemptFeatures: exemptFeatures, | ||
EnableAllSupportedFeatures: *flags.EnableAllSupportedFeatures, | ||
NamespaceLabels: namespaceLabels, | ||
}, | ||
Implementation: *implementation, | ||
ConformanceProfiles: conformanceProfiles, | ||
}) | ||
if err != nil { | ||
t.Fatalf("error creating experimental conformance test suite: %v", err) | ||
} | ||
|
||
cSuite.Setup(t) | ||
cSuite.Run(t, tests.ConformanceTests) | ||
report, err := cSuite.Report() | ||
if err != nil { | ||
t.Fatalf("error generating conformance profile report: %v", err) | ||
} | ||
writeReport(*report, *flags.ReportOutput) | ||
} | ||
|
||
func writeReport(report confv1a1.ConformanceReport, output string) error { | ||
rawReport, err := yaml.Marshal(report) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if output != "" { | ||
if err = os.WriteFile(output, rawReport, 0666); err != nil { | ||
return err | ||
} | ||
} | ||
fmt.Printf("report profiles report:\n %s", rawReport) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//go:build experimental | ||
// +build experimental | ||
|
||
/* | ||
Copyright 2023 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. | ||
*/ | ||
|
||
// flags contains command-line flag definitions for the conformance | ||
// profile certification. They're in this package so they can be shared | ||
// among the various suites that are all run by the same Makefile invocation. | ||
package flags | ||
|
||
import "flag" | ||
|
||
var ( | ||
ImplementationOrganization = flag.String("organization", "", "Implementation's Organization to issue conformance to") | ||
ImplementationProject = flag.String("project", "", "Implementation's project to issue conformance to") | ||
ImplementationUrl = flag.String("url", "", "Implementation's url to issue conformance to") | ||
ImplementationVersion = flag.String("version", "", "Implementation's version to issue conformance to") | ||
ImplementationContact = flag.String("contact", "", "Comma-separated list of contact information for the maintainers") | ||
ConformanceProfiles = flag.String("conformance-profiles", "", "Comma-separated list of the conformance profiles to run") | ||
ReportOutput = flag.String("report-output", "STDOUT", "The file where to write the conformance report") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters