Skip to content

Commit

Permalink
add e2e tests for multigroup testdata layout and rename sample
Browse files Browse the repository at this point in the history
We need to rename the name of the sample because of:

```shell
The Service "project-v4-multigroup-with-plugins-controller-manager-metrics-service" is invalid: metadata.name: Invalid value: "project-v4-multigroup-with-plugins-controller-manager-metrics-service": must be no more than 63 characters
```

Therefore, in this we are:
- Creating jobs to run the e2e tests for all testdata samples in parallel
- Renaming the sample project-v4-multigroup-with-plugins to project-v4-multigroup to generate manifests names that can be accepted in k8s
  • Loading branch information
camilamacedo86 committed Sep 13, 2024
1 parent 29a22d1 commit 3352876
Show file tree
Hide file tree
Showing 184 changed files with 318 additions and 254 deletions.
84 changes: 73 additions & 11 deletions .github/workflows/test-e2e-samples.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
name: Testing E2E Sample
name: E2E Testdata Sample

on:
push:
paths-ignore:
- '**/*.md'
paths:
- 'testdata/**'
- '.github/workflows/test-e2e-samples.yml'
pull_request:
paths-ignore:
- '**/*.md'
paths:
- 'testdata/**'
- '.github/workflows/test-e2e-samples.yml'

jobs:
e2e-tests:
e2e-tests-project-v4:
runs-on: ubuntu-latest
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
strategy:
fail-fast: true
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- name: Checkout repository
Expand Down Expand Up @@ -48,8 +51,28 @@ jobs:
run: |
make test-e2e
- name: Teardown kind cluster
run: kind delete cluster
e2e-tests-project-v4-with-plugins:
runs-on: ubuntu-latest
strategy:
fail-fast: true
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '~1.22'

- name: Install the latest version of kind
run: |
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
- name: Verify kind installation
run: kind version

- name: Create kind cluster
run: kind create cluster
Expand All @@ -62,7 +85,6 @@ jobs:
# Uncomment only ValidatingWebhookConfiguration
# from cert-manager replaces
sed -i '55,70s/^#//' $KUSTOMIZATION_FILE_PATH
sed -i '55,70s/^#//' $KUSTOMIZATION_FILE_PATH
sed -i '79,101s/^#//' $KUSTOMIZATION_FILE_PATH
sed -i '110,151s/^#//' $KUSTOMIZATION_FILE_PATH
# Comment the injection for MutatingWebhookConfiguration
Expand All @@ -74,6 +96,46 @@ jobs:
go mod tidy
- name: Testing make test-e2e for project-v4-with-plugins
working-directory: testdata/project-v4-with-plugins
working-directory: testdata/project-v4-with-plugins/
run: |
make test-e2e
e2e-tests-project-v4-multigroup:
runs-on: ubuntu-latest
strategy:
fail-fast: true
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '~1.22'

- name: Install the latest version of kind
run: |
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
- name: Verify kind installation
run: kind version

- name: Create kind cluster
run: kind create cluster

- name: Prepare project-v4-multigroup
run: |
KUSTOMIZATION_FILE_PATH="testdata/project-v4-multigroup/config/default/kustomization.yaml"
sed -i '25s/^#//' $KUSTOMIZATION_FILE_PATH
sed -i '51s/^#//' $KUSTOMIZATION_FILE_PATH
sed -i '55,151s/^#//' $KUSTOMIZATION_FILE_PATH
cd testdata/project-v4-multigroup
go mod tidy
- name: Testing make test-e2e for project-v4-multigroup
working-directory: testdata/project-v4-multigroup/
run: |
make test-e2e
4 changes: 3 additions & 1 deletion test/testdata/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ function scaffold_test_project {
$kb edit --plugins=grafana.kubebuilder.io/v1-alpha
fi

make all
make build-installer
# To avoid conflicts
rm -f go.sum
go mod tidy
popd
Expand All @@ -89,5 +91,5 @@ function scaffold_test_project {
build_kb

scaffold_test_project project-v4 --plugins="go/v4"
scaffold_test_project project-v4-multigroup-with-plugins --plugins="go/v4"
scaffold_test_project project-v4-multigroup --plugins="go/v4"
scaffold_test_project project-v4-with-plugins --plugins="go/v4"
2 changes: 1 addition & 1 deletion test/testdata/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ build_kb

# Project version v4-alpha
test_project project-v4
test_project project-v4-multigroup-with-plugins
test_project project-v4-multigroup
test_project project-v4-with-plugins
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
docker-buildx: ## Build and push docker image for the manager for cross-platform support
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
- $(CONTAINER_TOOL) buildx create --name project-v4-multigroup-with-plugins-builder
$(CONTAINER_TOOL) buildx use project-v4-multigroup-with-plugins-builder
- $(CONTAINER_TOOL) buildx create --name project-v4-multigroup-builder
$(CONTAINER_TOOL) buildx use project-v4-multigroup-builder
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
- $(CONTAINER_TOOL) buildx rm project-v4-multigroup-with-plugins-builder
- $(CONTAINER_TOOL) buildx rm project-v4-multigroup-builder
rm Dockerfile.cross

.PHONY: build-installer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ plugins:
image: busybox:1.36.1
version: v1alpha1
grafana.kubebuilder.io/v1-alpha: {}
projectName: project-v4-multigroup-with-plugins
repo: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins
projectName: project-v4-multigroup
repo: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup
resources:
- api:
crdVersion: v1
Expand All @@ -35,7 +35,7 @@ resources:
domain: testproject.org
group: crew
kind: Captain
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/crew/v1
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/crew/v1
version: v1
webhooks:
defaulting: true
Expand All @@ -48,7 +48,7 @@ resources:
domain: testproject.org
group: ship
kind: Frigate
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/ship/v1beta1
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/ship/v1beta1
version: v1beta1
webhooks:
conversion: true
Expand All @@ -59,7 +59,7 @@ resources:
domain: testproject.org
group: ship
kind: Destroyer
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/ship/v1
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/ship/v1
version: v1
webhooks:
defaulting: true
Expand All @@ -70,7 +70,7 @@ resources:
domain: testproject.org
group: ship
kind: Cruiser
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/ship/v2alpha1
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/ship/v2alpha1
version: v2alpha1
webhooks:
validation: true
Expand All @@ -82,7 +82,7 @@ resources:
domain: testproject.org
group: sea-creatures
kind: Kraken
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/sea-creatures/v1beta1
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/sea-creatures/v1beta1
version: v1beta1
- api:
crdVersion: v1
Expand All @@ -91,7 +91,7 @@ resources:
domain: testproject.org
group: sea-creatures
kind: Leviathan
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/sea-creatures/v1beta2
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/sea-creatures/v1beta2
version: v1beta2
- api:
crdVersion: v1
Expand All @@ -100,7 +100,7 @@ resources:
domain: testproject.org
group: foo.policy
kind: HealthCheckPolicy
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/foo.policy/v1
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/foo.policy/v1
version: v1
- controller: true
group: apps
Expand All @@ -114,7 +114,7 @@ resources:
domain: testproject.org
group: foo
kind: Bar
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/foo/v1
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/foo/v1
version: v1
- api:
crdVersion: v1
Expand All @@ -123,7 +123,7 @@ resources:
domain: testproject.org
group: fiz
kind: Bar
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/fiz/v1
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/fiz/v1
version: v1
- api:
crdVersion: v1
Expand All @@ -132,7 +132,7 @@ resources:
domain: testproject.org
group: example.com
kind: Memcached
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/example.com/v1alpha1
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/example.com/v1alpha1
version: v1alpha1
webhooks:
validation: true
Expand All @@ -144,6 +144,6 @@ resources:
domain: testproject.org
group: example.com
kind: Busybox
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/example.com/v1alpha1
path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/example.com/v1alpha1
version: v1alpha1
version: "3"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# project-v4-multigroup-with-plugins
# project-v4-multigroup
// TODO(user): Add simple overview of use/purpose

## Description
Expand All @@ -16,7 +16,7 @@
**Build and push your image to the location specified by `IMG`:**

```sh
make docker-build docker-push IMG=<some-registry>/project-v4-multigroup-with-plugins:tag
make docker-build docker-push IMG=<some-registry>/project-v4-multigroup:tag
```

**NOTE:** This image ought to be published in the personal registry you specified.
Expand All @@ -32,7 +32,7 @@ make install
**Deploy the Manager to the cluster with the image specified by `IMG`:**

```sh
make deploy IMG=<some-registry>/project-v4-multigroup-with-plugins:tag
make deploy IMG=<some-registry>/project-v4-multigroup:tag
```

> **NOTE**: If you encounter RBAC errors, you may need to grant yourself cluster-admin
Expand Down Expand Up @@ -73,7 +73,7 @@ Following are the steps to build the installer and distribute this project to us
1. Build the installer for the image built and published in the registry:

```sh
make build-installer IMG=<some-registry>/project-v4-multigroup-with-plugins:tag
make build-installer IMG=<some-registry>/project-v4-multigroup:tag
```

NOTE: The makefile target mentioned above generates an 'install.yaml'
Expand All @@ -86,7 +86,7 @@ its dependencies.
Users can just run kubectl apply -f <URL for YAML BUNDLE> to install the project, i.e.:

```sh
kubectl apply -f https://raw.githubusercontent.com/<org>/project-v4-multigroup-with-plugins/<tag or branch>/dist/install.yaml
kubectl apply -f https://raw.githubusercontent.com/<org>/project-v4-multigroup/<tag or branch>/dist/install.yaml
```

## Contributing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@ import (
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"

crewv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/crew/v1"
examplecomv1alpha1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/example.com/v1alpha1"
fizv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/fiz/v1"
foopolicyv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/foo.policy/v1"
foov1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/foo/v1"
seacreaturesv1beta1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/sea-creatures/v1beta1"
seacreaturesv1beta2 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/sea-creatures/v1beta2"
shipv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/ship/v1"
shipv1beta1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/ship/v1beta1"
shipv2alpha1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/api/ship/v2alpha1"
appscontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/internal/controller/apps"
crewcontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/internal/controller/crew"
examplecomcontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/internal/controller/example.com"
fizcontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/internal/controller/fiz"
foocontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/internal/controller/foo"
foopolicycontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/internal/controller/foo.policy"
seacreaturescontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/internal/controller/sea-creatures"
shipcontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup-with-plugins/internal/controller/ship"
crewv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/crew/v1"
examplecomv1alpha1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/example.com/v1alpha1"
fizv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/fiz/v1"
foopolicyv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/foo.policy/v1"
foov1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/foo/v1"
seacreaturesv1beta1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/sea-creatures/v1beta1"
seacreaturesv1beta2 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/sea-creatures/v1beta2"
shipv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/ship/v1"
shipv1beta1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/ship/v1beta1"
shipv2alpha1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/ship/v2alpha1"
appscontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/internal/controller/apps"
crewcontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/internal/controller/crew"
examplecomcontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/internal/controller/example.com"
fizcontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/internal/controller/fiz"
foocontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/internal/controller/foo"
foopolicycontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/internal/controller/foo.policy"
seacreaturescontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/internal/controller/sea-creatures"
shipcontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/internal/controller/ship"
// +kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -151,7 +151,7 @@ func main() {
WebhookServer: webhookServer,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "f0637429.testproject.org",
LeaderElectionID: "3e9f67a9.testproject.org",
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
// when the Manager ends. This requires the binary to immediately end when the
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
labels:
app.kubernetes.io/name: project-v4-multigroup-with-plugins
app.kubernetes.io/name: project-v4-multigroup
app.kubernetes.io/managed-by: kustomize
name: selfsigned-issuer
namespace: system
Expand All @@ -19,8 +19,8 @@ metadata:
app.kubernetes.io/name: certificate
app.kubernetes.io/instance: serving-cert
app.kubernetes.io/component: certificate
app.kubernetes.io/created-by: project-v4-multigroup-with-plugins
app.kubernetes.io/part-of: project-v4-multigroup-with-plugins
app.kubernetes.io/created-by: project-v4-multigroup
app.kubernetes.io/part-of: project-v4-multigroup
app.kubernetes.io/managed-by: kustomize
name: serving-cert # this name should match the one appeared in kustomizeconfig.yaml
namespace: system
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Adds namespace to all resources.
namespace: project-v4-multigroup-with-plugins-system
namespace: project-v4-multigroup-system

# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
# "wordpress" becomes "alices-wordpress".
# Note that it should also match with the prefix (text before '-') of the namespace
# field above.
namePrefix: project-v4-multigroup-with-plugins-
namePrefix: project-v4-multigroup-

# Labels to add to all resources and selectors.
#labels:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: controller-manager
namespace: system
labels:
app.kubernetes.io/name: project-v4-multigroup-with-plugins
app.kubernetes.io/name: project-v4-multigroup
app.kubernetes.io/managed-by: kustomize
spec:
template:
Expand Down
Loading

0 comments on commit 3352876

Please sign in to comment.