-
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.
test added to default scaffold and added to ci
Signed-off-by: Lauquik <[email protected]>
- Loading branch information
Showing
38 changed files
with
2,551 additions
and
9 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,51 @@ | ||
name: project-v4-sample | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
name: Run on Ubuntu | ||
runs-on: ubuntu-latest | ||
env: | ||
KIND_K8S_VERSION: v1.28.0 | ||
tools_k8s_version: 1.28.0 | ||
kind_version: 0.15.0 | ||
steps: | ||
- name: Clone the code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '~1.20' | ||
|
||
- name: Install Kind | ||
run: go install sigs.k8s.io/kind@v$kind_version | ||
|
||
|
||
- name: Install setup-envtest | ||
run: go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest | ||
|
||
- name: Install e2e tools with setup-envtest | ||
run: setup-envtest use $tools_k8s_version | ||
|
||
- name: Create kind cluster | ||
run: kind create cluster | ||
|
||
- name: Prepare the environment | ||
run: | | ||
KUSTOMIZATION_FILE_PATH="testdata/project-v4/config/default/kustomization.yaml" | ||
sed -i '25s/^#//' $KUSTOMIZATION_FILE_PATH | ||
sed -i '27s/^#//' $KUSTOMIZATION_FILE_PATH | ||
sed -i '42s/^#//' $KUSTOMIZATION_FILE_PATH | ||
sed -i '46,143s/^#//' $KUSTOMIZATION_FILE_PATH | ||
- name: Test | ||
run: | | ||
cd testdata/project-v4 | ||
go get -u ./... | ||
go mod tidy | ||
make test-e2e | ||
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 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
32 changes: 32 additions & 0 deletions
32
docs/book/src/component-config-tutorial/testdata/project/test/e2e/e2e_suite_test.go
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 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 e2e | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
// Run e2e tests using the Ginkgo runner. | ||
func TestE2E(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
fmt.Fprintf(GinkgoWriter, "Starting project suite\n") | ||
RunSpecs(t, "e2e suite") | ||
} |
121 changes: 121 additions & 0 deletions
121
docs/book/src/component-config-tutorial/testdata/project/test/e2e/e2e_test.go
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,121 @@ | ||
/* | ||
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 e2e | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"tutorial.kubebuilder.io/project/test/utils" | ||
) | ||
|
||
const namespace = "project-system" | ||
|
||
var _ = Describe("controller", Ordered, func() { | ||
BeforeAll(func() { | ||
By("installing prometheus operator") | ||
Expect(utils.InstallPrometheusOperator()).To(Succeed()) | ||
|
||
By("installing the cert-manager") | ||
Expect(utils.InstallCertManager()).To(Succeed()) | ||
|
||
By("creating manager namespace") | ||
cmd := exec.Command("kubectl", "create", "ns", namespace) | ||
_, _ = utils.Run(cmd) | ||
}) | ||
|
||
AfterAll(func() { | ||
By("uninstalling the Prometheus manager bundle") | ||
utils.UninstallPrometheusOperator() | ||
|
||
By("uninstalling the cert-manager bundle") | ||
utils.UninstallCertManager() | ||
|
||
By("removing manager namespace") | ||
cmd := exec.Command("kubectl", "delete", "ns", namespace) | ||
_, _ = utils.Run(cmd) | ||
}) | ||
|
||
Context("Operator", func() { | ||
It("should run successfully", func() { | ||
var controllerPodName string | ||
var err error | ||
|
||
// projectimage stores the name of the image used in the example | ||
var projectimage = "example.com/project:v0.0.1" | ||
|
||
By("building the manager(Operator) image") | ||
cmd := exec.Command("make", "docker-build", fmt.Sprintf("IMG=%s", projectimage)) | ||
_, err = utils.Run(cmd) | ||
ExpectWithOffset(1, err).NotTo(HaveOccurred()) | ||
|
||
By("loading the the manager(Operator) image on Kind") | ||
err = utils.LoadImageToKindClusterWithName(projectimage) | ||
ExpectWithOffset(1, err).NotTo(HaveOccurred()) | ||
|
||
By("installing CRDs") | ||
cmd = exec.Command("make", "install") | ||
_, err = utils.Run(cmd) | ||
|
||
By("deploying the controller-manager") | ||
cmd = exec.Command("make", "deploy", fmt.Sprintf("IMG=%s", projectimage)) | ||
_, err = utils.Run(cmd) | ||
ExpectWithOffset(1, err).NotTo(HaveOccurred()) | ||
|
||
By("validating that the controller-manager pod is running as expected") | ||
verifyControllerUp := func() error { | ||
// Get pod name | ||
|
||
cmd = exec.Command("kubectl", "get", | ||
"pods", "-l", "control-plane=controller-manager", | ||
"-o", "go-template={{ range .items }}"+ | ||
"{{ if not .metadata.deletionTimestamp }}"+ | ||
"{{ .metadata.name }}"+ | ||
"{{ \"\\n\" }}{{ end }}{{ end }}", | ||
"-n", namespace, | ||
) | ||
|
||
podOutput, err := utils.Run(cmd) | ||
ExpectWithOffset(2, err).NotTo(HaveOccurred()) | ||
podNames := utils.GetNonEmptyLines(string(podOutput)) | ||
if len(podNames) != 1 { | ||
return fmt.Errorf("expect 1 controller pods running, but got %d", len(podNames)) | ||
} | ||
controllerPodName = podNames[0] | ||
ExpectWithOffset(2, controllerPodName).Should(ContainSubstring("controller-manager")) | ||
|
||
// Validate pod status | ||
cmd = exec.Command("kubectl", "get", | ||
"pods", controllerPodName, "-o", "jsonpath={.status.phase}", | ||
"-n", namespace, | ||
) | ||
status, err := utils.Run(cmd) | ||
ExpectWithOffset(2, err).NotTo(HaveOccurred()) | ||
if string(status) != "Running" { | ||
return fmt.Errorf("controller pod in %s status", status) | ||
} | ||
return nil | ||
} | ||
EventuallyWithOffset(1, verifyControllerUp, time.Minute, time.Second).Should(Succeed()) | ||
|
||
}) | ||
}) | ||
}) |
Oops, something went wrong.