Skip to content

Commit a6a4bf9

Browse files
fix place where the metrics service should be scaffolded
1 parent 6c3321b commit a6a4bf9

File tree

27 files changed

+23
-101
lines changed

27 files changed

+23
-101
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
resources:
22
- manager.yaml
3+
# If you want to expose the metrics endpoint without TLS/HTTP protection, uncomment the following line.
4+
#- metrics_service.yaml

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

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ resources:
99
- role_binding.yaml
1010
- leader_election_role.yaml
1111
- leader_election_role_binding.yaml
12-
- metrics_service.yaml
1312
# For each CRD, "Editor" and "Viewer" roles are scaffolded by
1413
# default, aiding admins in cluster management. Those roles are
1514
# not used by the Project itself. You can comment the following lines
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
resources:
22
- manager.yaml
3+
# If you want to expose the metrics endpoint without TLS/HTTP protection, uncomment the following line.
4+
#- metrics_service.yaml

docs/book/src/getting-started/testdata/project/config/rbac/kustomization.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ resources:
99
- role_binding.yaml
1010
- leader_election_role.yaml
1111
- leader_election_role_binding.yaml
12-
- metrics_service.yaml
1312
# For each CRD, "Editor" and "Viewer" roles are scaffolded by
1413
# default, aiding admins in cluster management. Those roles are
1514
# not used by the Project itself. You can comment the following lines

docs/book/src/reference/metrics.md

+8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ in the file `config/default/kustomization.yaml`, see:
5454
# kind: Deployment
5555
```
5656

57+
Then, you will need to enable the Metrics Service in `config/manager/kustomization.yaml`:
58+
59+
```yaml
60+
- manager.yaml
61+
# If you want to expose the metrics endpoint without TLS/HTTP protection, uncomment the following line.
62+
#- metrics_service.yaml
63+
```
64+
5765
Note that projects are scaffolded by default passing the flag `--metrics-bind-address=0`
5866
to the manager to ensure that metrics are disabled. See the [controller-runtime
5967
implementation](https://github.com/kubernetes-sigs/controller-runtime/blob/834905b07c7b5a78e86d21d764f7c2fdaa9602e0/pkg/metrics/server/server.go#L119-L122)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (s *initScaffolder) Scaffold() error {
6464

6565
templates := []machinery.Builder{
6666
&rbac.Kustomization{},
67-
&rbac.MetricsService{},
67+
&manager.MetricsService{},
6868
&rbac.RoleBinding{},
6969
// We need to create a Role because if the project
7070
// has not CRD define the controller-gen will not generate this file

pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/manager/kustomization.go

+2
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@ func (f *Kustomization) SetTemplateDefaults() error {
4444

4545
const kustomizeManagerTemplate = `resources:
4646
- manager.yaml
47+
# If you want to expose the metrics endpoint without TLS/HTTP protection, uncomment the following line.
48+
#- metrics_service.yaml
4749
`

pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/rbac/metrics_service.go pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/manager/metrics_service.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package rbac
17+
package manager
1818

1919
import (
2020
"path/filepath"
@@ -33,7 +33,7 @@ type MetricsService struct {
3333
// SetTemplateDefaults implements file.Template
3434
func (f *MetricsService) SetTemplateDefaults() error {
3535
if f.Path == "" {
36-
f.Path = filepath.Join("config", "rbac", "metrics_service.yaml")
36+
f.Path = filepath.Join("config", "manager", "metrics_service.yaml")
3737
}
3838

3939
f.TemplateBody = metricsServiceTemplate

pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/rbac/kustomization.go

-1
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,4 @@ const kustomizeRBACTemplate = `resources:
5353
- role_binding.yaml
5454
- leader_election_role.yaml
5555
- leader_election_role_binding.yaml
56-
- metrics_service.yaml
5756
`

test/e2e/v4/generate_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ func GenerateV4(kbc *utils.TestContext) {
6666
ExpectWithOffset(1, pluginutil.UncommentCode(
6767
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
6868
metricsTarget, "#")).To(Succeed())
69+
ExpectWithOffset(1, pluginutil.UncommentCode(
70+
filepath.Join(kbc.Dir, "config", "manager", "kustomization.yaml"),
71+
"#- metrics_service.yaml", "#")).To(Succeed())
6972

7073
ExpectWithOffset(1, pluginutil.UncommentCode(filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
7174
certManagerTarget, "#")).To(Succeed())
@@ -126,6 +129,9 @@ func GenerateV4WithoutWebhooks(kbc *utils.TestContext) {
126129
ExpectWithOffset(1, pluginutil.UncommentCode(
127130
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
128131
metricsTarget, "#")).To(Succeed())
132+
ExpectWithOffset(1, pluginutil.UncommentCode(
133+
filepath.Join(kbc.Dir, "config", "manager", "kustomization.yaml"),
134+
"#- metrics_service.yaml", "#")).To(Succeed())
129135

130136
if kbc.IsRestricted {
131137
By("uncomment kustomize files to ensure that pods are restricted")

testdata/project-v4-multigroup-with-deploy-image/config/rbac/kustomization.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ resources:
99
- role_binding.yaml
1010
- leader_election_role.yaml
1111
- leader_election_role_binding.yaml
12-
- metrics_service.yaml
1312
# For each CRD, "Editor" and "Viewer" roles are scaffolded by
1413
# default, aiding admins in cluster management. Those roles are
1514
# not used by the Project itself. You can comment the following lines

testdata/project-v4-multigroup-with-deploy-image/dist/install.yaml

-18
Original file line numberDiff line numberDiff line change
@@ -1474,24 +1474,6 @@ subjects:
14741474
---
14751475
apiVersion: v1
14761476
kind: Service
1477-
metadata:
1478-
labels:
1479-
app.kubernetes.io/managed-by: kustomize
1480-
app.kubernetes.io/name: project-v4-multigroup-with-deploy-image
1481-
control-plane: controller-manager
1482-
name: project-v4-multigroup-with-deploy-image-controller-manager-metrics-service
1483-
namespace: project-v4-multigroup-with-deploy-image-system
1484-
spec:
1485-
ports:
1486-
- name: http
1487-
port: 8080
1488-
protocol: TCP
1489-
targetPort: 8080
1490-
selector:
1491-
control-plane: controller-manager
1492-
---
1493-
apiVersion: v1
1494-
kind: Service
14951477
metadata:
14961478
labels:
14971479
app.kubernetes.io/managed-by: kustomize

testdata/project-v4-multigroup/config/rbac/kustomization.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ resources:
99
- role_binding.yaml
1010
- leader_election_role.yaml
1111
- leader_election_role_binding.yaml
12-
- metrics_service.yaml
1312
# For each CRD, "Editor" and "Viewer" roles are scaffolded by
1413
# default, aiding admins in cluster management. Those roles are
1514
# not used by the Project itself. You can comment the following lines

testdata/project-v4-multigroup/dist/install.yaml

-18
Original file line numberDiff line numberDiff line change
@@ -1474,24 +1474,6 @@ subjects:
14741474
---
14751475
apiVersion: v1
14761476
kind: Service
1477-
metadata:
1478-
labels:
1479-
app.kubernetes.io/managed-by: kustomize
1480-
app.kubernetes.io/name: project-v4-multigroup
1481-
control-plane: controller-manager
1482-
name: project-v4-multigroup-controller-manager-metrics-service
1483-
namespace: project-v4-multigroup-system
1484-
spec:
1485-
ports:
1486-
- name: http
1487-
port: 8080
1488-
protocol: TCP
1489-
targetPort: 8080
1490-
selector:
1491-
control-plane: controller-manager
1492-
---
1493-
apiVersion: v1
1494-
kind: Service
14951477
metadata:
14961478
labels:
14971479
app.kubernetes.io/managed-by: kustomize

testdata/project-v4-with-deploy-image/config/rbac/kustomization.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ resources:
99
- role_binding.yaml
1010
- leader_election_role.yaml
1111
- leader_election_role_binding.yaml
12-
- metrics_service.yaml
1312
# For each CRD, "Editor" and "Viewer" roles are scaffolded by
1413
# default, aiding admins in cluster management. Those roles are
1514
# not used by the Project itself. You can comment the following lines

testdata/project-v4-with-deploy-image/dist/install.yaml

-18
Original file line numberDiff line numberDiff line change
@@ -550,24 +550,6 @@ subjects:
550550
---
551551
apiVersion: v1
552552
kind: Service
553-
metadata:
554-
labels:
555-
app.kubernetes.io/managed-by: kustomize
556-
app.kubernetes.io/name: project-v4-with-deploy-image
557-
control-plane: controller-manager
558-
name: project-v4-with-deploy-image-controller-manager-metrics-service
559-
namespace: project-v4-with-deploy-image-system
560-
spec:
561-
ports:
562-
- name: http
563-
port: 8080
564-
protocol: TCP
565-
targetPort: 8080
566-
selector:
567-
control-plane: controller-manager
568-
---
569-
apiVersion: v1
570-
kind: Service
571553
metadata:
572554
labels:
573555
app.kubernetes.io/managed-by: kustomize

testdata/project-v4-with-grafana/config/rbac/kustomization.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ resources:
99
- role_binding.yaml
1010
- leader_election_role.yaml
1111
- leader_election_role_binding.yaml
12-
- metrics_service.yaml

testdata/project-v4-with-grafana/dist/install.yaml

-18
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,6 @@ subjects:
107107
name: project-v4-with-grafana-controller-manager
108108
namespace: project-v4-with-grafana-system
109109
---
110-
apiVersion: v1
111-
kind: Service
112-
metadata:
113-
labels:
114-
app.kubernetes.io/managed-by: kustomize
115-
app.kubernetes.io/name: project-v4-with-grafana
116-
control-plane: controller-manager
117-
name: project-v4-with-grafana-controller-manager-metrics-service
118-
namespace: project-v4-with-grafana-system
119-
spec:
120-
ports:
121-
- name: http
122-
port: 8080
123-
protocol: TCP
124-
targetPort: 8080
125-
selector:
126-
control-plane: controller-manager
127-
---
128110
apiVersion: apps/v1
129111
kind: Deployment
130112
metadata:

testdata/project-v4/config/rbac/kustomization.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ resources:
99
- role_binding.yaml
1010
- leader_election_role.yaml
1111
- leader_election_role_binding.yaml
12-
- metrics_service.yaml
1312
# For each CRD, "Editor" and "Viewer" roles are scaffolded by
1413
# default, aiding admins in cluster management. Those roles are
1514
# not used by the Project itself. You can comment the following lines

testdata/project-v4/dist/install.yaml

-18
Original file line numberDiff line numberDiff line change
@@ -544,24 +544,6 @@ subjects:
544544
---
545545
apiVersion: v1
546546
kind: Service
547-
metadata:
548-
labels:
549-
app.kubernetes.io/managed-by: kustomize
550-
app.kubernetes.io/name: project-v4
551-
control-plane: controller-manager
552-
name: project-v4-controller-manager-metrics-service
553-
namespace: project-v4-system
554-
spec:
555-
ports:
556-
- name: http
557-
port: 8080
558-
protocol: TCP
559-
targetPort: 8080
560-
selector:
561-
control-plane: controller-manager
562-
---
563-
apiVersion: v1
564-
kind: Service
565547
metadata:
566548
labels:
567549
app.kubernetes.io/managed-by: kustomize

0 commit comments

Comments
 (0)