-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
361 changed files
with
16,046 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
Copyright 2020 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 v4 | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
// Run e2e tests using the Ginkgo runner. | ||
func TestE2E(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
fmt.Fprintf(GinkgoWriter, "Starting kubebuilder suite\n") | ||
RunSpecs(t, "Kubebuilder e2e suite") | ||
} |
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,133 @@ | ||
/* | ||
Copyright 2020 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 v4 | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
|
||
pluginutil "sigs.k8s.io/kubebuilder/v3/pkg/plugin/util" | ||
|
||
//nolint:golint | ||
//nolint:revive | ||
. "github.com/onsi/ginkgo" | ||
|
||
//nolint:golint | ||
//nolint:revive | ||
. "github.com/onsi/gomega" | ||
|
||
"sigs.k8s.io/kubebuilder/v3/test/e2e/utils" | ||
) | ||
|
||
// GenerateV4 implements a go/v4(-alpha) plugin project defined by a TestContext. | ||
func GenerateV4(kbc *utils.TestContext, crdAndWebhookVersion string) { | ||
var err error | ||
|
||
By("initializing a project") | ||
err = kbc.Init( | ||
"--plugins", "go/v4-alpha", | ||
"--project-version", "3", | ||
"--domain", kbc.Domain, | ||
"--fetch-deps=false", | ||
) | ||
ExpectWithOffset(1, err).NotTo(HaveOccurred()) | ||
|
||
By("creating API definition") | ||
err = kbc.CreateAPI( | ||
"--group", kbc.Group, | ||
"--version", kbc.Version, | ||
"--kind", kbc.Kind, | ||
"--namespaced", | ||
"--resource", | ||
"--controller", | ||
"--make=false", | ||
"--crd-version", crdAndWebhookVersion, | ||
) | ||
ExpectWithOffset(1, err).NotTo(HaveOccurred()) | ||
|
||
By("implementing the API") | ||
ExpectWithOffset(1, pluginutil.InsertCode( | ||
filepath.Join(kbc.Dir, "api", kbc.Version, fmt.Sprintf("%s_types.go", strings.ToLower(kbc.Kind))), | ||
fmt.Sprintf(`type %sSpec struct { | ||
`, kbc.Kind), | ||
` // +optional | ||
Count int `+"`"+`json:"count,omitempty"`+"`"+` | ||
`)).Should(Succeed()) | ||
|
||
By("scaffolding mutating and validating webhooks") | ||
err = kbc.CreateWebhook( | ||
"--group", kbc.Group, | ||
"--version", kbc.Version, | ||
"--kind", kbc.Kind, | ||
"--defaulting", | ||
"--programmatic-validation", | ||
"--webhook-version", crdAndWebhookVersion, | ||
) | ||
ExpectWithOffset(1, err).NotTo(HaveOccurred()) | ||
|
||
By("implementing the mutating and validating webhooks") | ||
err = pluginutil.ImplementWebhooks(filepath.Join( | ||
kbc.Dir, "api", kbc.Version, | ||
fmt.Sprintf("%s_webhook.go", strings.ToLower(kbc.Kind)))) | ||
ExpectWithOffset(1, err).NotTo(HaveOccurred()) | ||
|
||
By("uncomment kustomization.yaml to enable webhook and ca injection") | ||
ExpectWithOffset(1, pluginutil.UncommentCode( | ||
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"), | ||
"#- ../webhook", "#")).To(Succeed()) | ||
ExpectWithOffset(1, pluginutil.UncommentCode( | ||
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"), | ||
"#- ../certmanager", "#")).To(Succeed()) | ||
ExpectWithOffset(1, pluginutil.UncommentCode( | ||
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"), | ||
"#- ../prometheus", "#")).To(Succeed()) | ||
ExpectWithOffset(1, pluginutil.UncommentCode( | ||
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"), | ||
"#- manager_webhook_patch.yaml", "#")).To(Succeed()) | ||
ExpectWithOffset(1, pluginutil.UncommentCode( | ||
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"), | ||
"#- webhookcainjection_patch.yaml", "#")).To(Succeed()) | ||
ExpectWithOffset(1, pluginutil.UncommentCode(filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"), | ||
`#- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR | ||
# objref: | ||
# kind: Certificate | ||
# group: cert-manager.io | ||
# version: v1 | ||
# name: serving-cert # this name should match the one in certificate.yaml | ||
# fieldref: | ||
# fieldpath: metadata.namespace | ||
#- name: CERTIFICATE_NAME | ||
# objref: | ||
# kind: Certificate | ||
# group: cert-manager.io | ||
# version: v1 | ||
# name: serving-cert # this name should match the one in certificate.yaml | ||
#- name: SERVICE_NAMESPACE # namespace of the service | ||
# objref: | ||
# kind: Service | ||
# version: v1 | ||
# name: webhook-service | ||
# fieldref: | ||
# fieldpath: metadata.namespace | ||
#- name: SERVICE_NAME | ||
# objref: | ||
# kind: Service | ||
# version: v1 | ||
# name: webhook-service`, "#")).To(Succeed()) | ||
|
||
} |
Oops, something went wrong.