Skip to content

Commit c199e69

Browse files
authored
Merge pull request #2552 from NikhilSharmaWe/newPlugin
✨(go/v4-alpha): add new golang plugin which uses the default golang base v3 and the new alpha kustomze/v2-alpha
2 parents 44718e7 + 41628fe commit c199e69

File tree

361 files changed

+16046
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

361 files changed

+16046
-4
lines changed

cmd/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
cfgv2 "sigs.k8s.io/kubebuilder/v3/pkg/config/v2"
2626
cfgv3 "sigs.k8s.io/kubebuilder/v3/pkg/config/v3"
2727
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
28+
"sigs.k8s.io/kubebuilder/v3/pkg/model/stage"
2829
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
2930
kustomizecommonv1 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/common/kustomize/v1"
3031
kustomizecommonv2 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/common/kustomize/v2"
@@ -41,6 +42,11 @@ func main() {
4142
kustomizecommonv1.Plugin{},
4243
golangv3.Plugin{},
4344
)
45+
// Bundle plugin which built the golang projects scaffold by Kubebuilder go/v3 with kustomize alpha-v2
46+
gov4Bundle, _ := plugin.NewBundle(golang.DefaultNameQualifier, plugin.Version{Number: 4, Stage: stage.Alpha},
47+
kustomizecommonv2.Plugin{},
48+
golangv3.Plugin{},
49+
)
4450

4551
fs := machinery.Filesystem{
4652
FS: afero.NewOsFs(),
@@ -57,6 +63,7 @@ func main() {
5763
golangv2.Plugin{},
5864
golangv3.Plugin{},
5965
gov3Bundle,
66+
gov4Bundle,
6067
&kustomizecommonv1.Plugin{},
6168
&kustomizecommonv2.Plugin{},
6269
&declarativev1.Plugin{},

test/e2e/v4/e2e_suite_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v4
18+
19+
import (
20+
"fmt"
21+
"testing"
22+
23+
. "github.com/onsi/ginkgo"
24+
. "github.com/onsi/gomega"
25+
)
26+
27+
// Run e2e tests using the Ginkgo runner.
28+
func TestE2E(t *testing.T) {
29+
RegisterFailHandler(Fail)
30+
fmt.Fprintf(GinkgoWriter, "Starting kubebuilder suite\n")
31+
RunSpecs(t, "Kubebuilder e2e suite")
32+
}

test/e2e/v4/generate_test.go

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v4
18+
19+
import (
20+
"fmt"
21+
"path/filepath"
22+
"strings"
23+
24+
pluginutil "sigs.k8s.io/kubebuilder/v3/pkg/plugin/util"
25+
26+
//nolint:golint
27+
//nolint:revive
28+
. "github.com/onsi/ginkgo"
29+
30+
//nolint:golint
31+
//nolint:revive
32+
. "github.com/onsi/gomega"
33+
34+
"sigs.k8s.io/kubebuilder/v3/test/e2e/utils"
35+
)
36+
37+
// GenerateV4 implements a go/v4(-alpha) plugin project defined by a TestContext.
38+
func GenerateV4(kbc *utils.TestContext, crdAndWebhookVersion string) {
39+
var err error
40+
41+
By("initializing a project")
42+
err = kbc.Init(
43+
"--plugins", "go/v4-alpha",
44+
"--project-version", "3",
45+
"--domain", kbc.Domain,
46+
"--fetch-deps=false",
47+
)
48+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
49+
50+
By("creating API definition")
51+
err = kbc.CreateAPI(
52+
"--group", kbc.Group,
53+
"--version", kbc.Version,
54+
"--kind", kbc.Kind,
55+
"--namespaced",
56+
"--resource",
57+
"--controller",
58+
"--make=false",
59+
"--crd-version", crdAndWebhookVersion,
60+
)
61+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
62+
63+
By("implementing the API")
64+
ExpectWithOffset(1, pluginutil.InsertCode(
65+
filepath.Join(kbc.Dir, "api", kbc.Version, fmt.Sprintf("%s_types.go", strings.ToLower(kbc.Kind))),
66+
fmt.Sprintf(`type %sSpec struct {
67+
`, kbc.Kind),
68+
` // +optional
69+
Count int `+"`"+`json:"count,omitempty"`+"`"+`
70+
`)).Should(Succeed())
71+
72+
By("scaffolding mutating and validating webhooks")
73+
err = kbc.CreateWebhook(
74+
"--group", kbc.Group,
75+
"--version", kbc.Version,
76+
"--kind", kbc.Kind,
77+
"--defaulting",
78+
"--programmatic-validation",
79+
"--webhook-version", crdAndWebhookVersion,
80+
)
81+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
82+
83+
By("implementing the mutating and validating webhooks")
84+
err = pluginutil.ImplementWebhooks(filepath.Join(
85+
kbc.Dir, "api", kbc.Version,
86+
fmt.Sprintf("%s_webhook.go", strings.ToLower(kbc.Kind))))
87+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
88+
89+
By("uncomment kustomization.yaml to enable webhook and ca injection")
90+
ExpectWithOffset(1, pluginutil.UncommentCode(
91+
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
92+
"#- ../webhook", "#")).To(Succeed())
93+
ExpectWithOffset(1, pluginutil.UncommentCode(
94+
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
95+
"#- ../certmanager", "#")).To(Succeed())
96+
ExpectWithOffset(1, pluginutil.UncommentCode(
97+
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
98+
"#- ../prometheus", "#")).To(Succeed())
99+
ExpectWithOffset(1, pluginutil.UncommentCode(
100+
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
101+
"#- manager_webhook_patch.yaml", "#")).To(Succeed())
102+
ExpectWithOffset(1, pluginutil.UncommentCode(
103+
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
104+
"#- webhookcainjection_patch.yaml", "#")).To(Succeed())
105+
ExpectWithOffset(1, pluginutil.UncommentCode(filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
106+
`#- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
107+
# objref:
108+
# kind: Certificate
109+
# group: cert-manager.io
110+
# version: v1
111+
# name: serving-cert # this name should match the one in certificate.yaml
112+
# fieldref:
113+
# fieldpath: metadata.namespace
114+
#- name: CERTIFICATE_NAME
115+
# objref:
116+
# kind: Certificate
117+
# group: cert-manager.io
118+
# version: v1
119+
# name: serving-cert # this name should match the one in certificate.yaml
120+
#- name: SERVICE_NAMESPACE # namespace of the service
121+
# objref:
122+
# kind: Service
123+
# version: v1
124+
# name: webhook-service
125+
# fieldref:
126+
# fieldpath: metadata.namespace
127+
#- name: SERVICE_NAME
128+
# objref:
129+
# kind: Service
130+
# version: v1
131+
# name: webhook-service`, "#")).To(Succeed())
132+
133+
}

0 commit comments

Comments
 (0)