Skip to content

Commit

Permalink
🐛 For go/v3 plugin: Use appropriate webhook version for test
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkm4ntr committed Apr 14, 2022
1 parent 08a55d1 commit ad9a02d
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (f *WebhookSuite) SetTemplateDefaults() error {

f.TemplateBody = fmt.Sprintf(webhookTestSuiteTemplate,
machinery.NewMarkerFor(f.Path, importMarker),
machinery.NewMarkerFor(f.Path, addSchemeMarker),
f.Resource.Webhooks.WebhookVersion,
machinery.NewMarkerFor(f.Path, addWebhookManagerMarker),
"%s",
"%d",
Expand All @@ -73,9 +73,6 @@ func (f *WebhookSuite) SetTemplateDefaults() error {
}

const (
// TODO: admission webhook versions should be based on the input of the user. For More Info #1664
admissionImportAlias = "admissionv1beta1"
admissionPath = "k8s.io/api/admission/v1beta1"
importMarker = "imports"
addWebhookManagerMarker = "webhook"
addSchemeMarker = "scheme"
Expand All @@ -85,7 +82,6 @@ const (
func (f *WebhookSuite) GetMarkers() []machinery.Marker {
return []machinery.Marker{
machinery.NewMarkerFor(f.Path, importMarker),
machinery.NewMarkerFor(f.Path, addSchemeMarker),
machinery.NewMarkerFor(f.Path, addWebhookManagerMarker),
}
}
Expand All @@ -108,13 +104,11 @@ func (f *WebhookSuite) GetCodeFragments() machinery.CodeFragmentsMap {
fragments := make(machinery.CodeFragmentsMap, 3)

// Generate import code fragments
admissionImportAlias := fmt.Sprintf("admission%s", f.Resource.Webhooks.WebhookVersion)
admissionPath := fmt.Sprintf("k8s.io/api/admission/%s", f.Resource.Webhooks.WebhookVersion)
imports := make([]string, 0)
imports = append(imports, fmt.Sprintf(apiImportCodeFragment, admissionImportAlias, admissionPath))

// Generate add scheme code fragments
addScheme := make([]string, 0)
addScheme = append(addScheme, fmt.Sprintf(addschemeCodeFragment, admissionImportAlias))

// Generate add webhookManager code fragments
addWebhookManager := make([]string, 0)
addWebhookManager = append(addWebhookManager, fmt.Sprintf(addWebhookManagerCodeFragment, f.Resource.Kind))
Expand All @@ -126,9 +120,6 @@ func (f *WebhookSuite) GetCodeFragments() machinery.CodeFragmentsMap {
if len(imports) != 0 {
fragments[machinery.NewMarkerFor(f.Path, importMarker)] = imports
}
if len(addScheme) != 0 {
fragments[machinery.NewMarkerFor(f.Path, addSchemeMarker)] = addScheme
}

return fragments
}
Expand Down Expand Up @@ -198,7 +189,8 @@ var _ = BeforeSuite(func() {
err = AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())
%s
err = admission%s.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme})
Expect(err).NotTo(HaveOccurred())
Expand Down
9 changes: 2 additions & 7 deletions testdata/project-v3-config/api/v1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

admissionv1beta1 "k8s.io/api/admission/v1beta1"
admissionv1 "k8s.io/api/admission/v1"
//+kubebuilder:scaffold:imports
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -81,14 +81,9 @@ var _ = BeforeSuite(func() {
err = AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

err = admissionv1beta1.AddToScheme(scheme)
err = admissionv1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

err = admissionv1beta1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

//+kubebuilder:scaffold:scheme

k8sClient, err = client.New(cfg, client.Options{Scheme: scheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

admissionv1beta1 "k8s.io/api/admission/v1beta1"
admissionv1 "k8s.io/api/admission/v1"
//+kubebuilder:scaffold:imports
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -81,11 +81,9 @@ var _ = BeforeSuite(func() {
err = AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

err = admissionv1beta1.AddToScheme(scheme)
err = admissionv1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

//+kubebuilder:scaffold:scheme

k8sClient, err = client.New(cfg, client.Options{Scheme: scheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

admissionv1beta1 "k8s.io/api/admission/v1beta1"
admissionv1 "k8s.io/api/admission/v1"
//+kubebuilder:scaffold:imports
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -81,11 +81,9 @@ var _ = BeforeSuite(func() {
err = AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

err = admissionv1beta1.AddToScheme(scheme)
err = admissionv1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

//+kubebuilder:scaffold:scheme

k8sClient, err = client.New(cfg, client.Options{Scheme: scheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

admissionv1beta1 "k8s.io/api/admission/v1beta1"
admissionv1 "k8s.io/api/admission/v1"
//+kubebuilder:scaffold:imports
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -81,11 +81,9 @@ var _ = BeforeSuite(func() {
err = AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

err = admissionv1beta1.AddToScheme(scheme)
err = admissionv1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

//+kubebuilder:scaffold:scheme

k8sClient, err = client.New(cfg, client.Options{Scheme: scheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())
Expand Down
6 changes: 2 additions & 4 deletions testdata/project-v3-multigroup/apis/v1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

admissionv1beta1 "k8s.io/api/admission/v1beta1"
admissionv1 "k8s.io/api/admission/v1"
//+kubebuilder:scaffold:imports
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -81,11 +81,9 @@ var _ = BeforeSuite(func() {
err = AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

err = admissionv1beta1.AddToScheme(scheme)
err = admissionv1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

//+kubebuilder:scaffold:scheme

k8sClient, err = client.New(cfg, client.Options{Scheme: scheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())
Expand Down
2 changes: 0 additions & 2 deletions testdata/project-v3-v1beta1/api/v1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ var _ = BeforeSuite(func() {
err = admissionv1beta1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

//+kubebuilder:scaffold:scheme

k8sClient, err = client.New(cfg, client.Options{Scheme: scheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())
Expand Down
12 changes: 2 additions & 10 deletions testdata/project-v3/api/v1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

admissionv1beta1 "k8s.io/api/admission/v1beta1"
admissionv1 "k8s.io/api/admission/v1"
//+kubebuilder:scaffold:imports
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -81,17 +81,9 @@ var _ = BeforeSuite(func() {
err = AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

err = admissionv1beta1.AddToScheme(scheme)
err = admissionv1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

err = admissionv1beta1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

err = admissionv1beta1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

//+kubebuilder:scaffold:scheme

k8sClient, err = client.New(cfg, client.Options{Scheme: scheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())
Expand Down

0 comments on commit ad9a02d

Please sign in to comment.