Skip to content

Commit

Permalink
fix place where the metrics service should be scaffolded
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed May 22, 2024
1 parent 6c3321b commit a6a4bf9
Show file tree
Hide file tree
Showing 27 changed files with 23 additions and 101 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
resources:
- manager.yaml
# If you want to expose the metrics endpoint without TLS/HTTP protection, uncomment the following line.
#- metrics_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ resources:
- role_binding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
- metrics_service.yaml
# For each CRD, "Editor" and "Viewer" roles are scaffolded by
# default, aiding admins in cluster management. Those roles are
# not used by the Project itself. You can comment the following lines
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
resources:
- manager.yaml
# If you want to expose the metrics endpoint without TLS/HTTP protection, uncomment the following line.
#- metrics_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ resources:
- role_binding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
- metrics_service.yaml
# For each CRD, "Editor" and "Viewer" roles are scaffolded by
# default, aiding admins in cluster management. Those roles are
# not used by the Project itself. You can comment the following lines
Expand Down
8 changes: 8 additions & 0 deletions docs/book/src/reference/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ in the file `config/default/kustomization.yaml`, see:
# kind: Deployment
```

Then, you will need to enable the Metrics Service in `config/manager/kustomization.yaml`:

```yaml
- manager.yaml
# If you want to expose the metrics endpoint without TLS/HTTP protection, uncomment the following line.
#- metrics_service.yaml
```

Note that projects are scaffolded by default passing the flag `--metrics-bind-address=0`
to the manager to ensure that metrics are disabled. See the [controller-runtime
implementation](https://github.com/kubernetes-sigs/controller-runtime/blob/834905b07c7b5a78e86d21d764f7c2fdaa9602e0/pkg/metrics/server/server.go#L119-L122)
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/common/kustomize/v2/scaffolds/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *initScaffolder) Scaffold() error {

templates := []machinery.Builder{
&rbac.Kustomization{},
&rbac.MetricsService{},
&manager.MetricsService{},
&rbac.RoleBinding{},
// We need to create a Role because if the project
// has not CRD define the controller-gen will not generate this file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ func (f *Kustomization) SetTemplateDefaults() error {

const kustomizeManagerTemplate = `resources:
- manager.yaml
# If you want to expose the metrics endpoint without TLS/HTTP protection, uncomment the following line.
#- metrics_service.yaml
`
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package rbac
package manager

import (
"path/filepath"
Expand All @@ -33,7 +33,7 @@ type MetricsService struct {
// SetTemplateDefaults implements file.Template
func (f *MetricsService) SetTemplateDefaults() error {
if f.Path == "" {
f.Path = filepath.Join("config", "rbac", "metrics_service.yaml")
f.Path = filepath.Join("config", "manager", "metrics_service.yaml")
}

f.TemplateBody = metricsServiceTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@ const kustomizeRBACTemplate = `resources:
- role_binding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
- metrics_service.yaml
`
6 changes: 6 additions & 0 deletions test/e2e/v4/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ func GenerateV4(kbc *utils.TestContext) {
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
metricsTarget, "#")).To(Succeed())
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "manager", "kustomization.yaml"),
"#- metrics_service.yaml", "#")).To(Succeed())

ExpectWithOffset(1, pluginutil.UncommentCode(filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
certManagerTarget, "#")).To(Succeed())
Expand Down Expand Up @@ -126,6 +129,9 @@ func GenerateV4WithoutWebhooks(kbc *utils.TestContext) {
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
metricsTarget, "#")).To(Succeed())
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "manager", "kustomization.yaml"),
"#- metrics_service.yaml", "#")).To(Succeed())

if kbc.IsRestricted {
By("uncomment kustomize files to ensure that pods are restricted")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ resources:
- role_binding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
- metrics_service.yaml
# For each CRD, "Editor" and "Viewer" roles are scaffolded by
# default, aiding admins in cluster management. Those roles are
# not used by the Project itself. You can comment the following lines
Expand Down
18 changes: 0 additions & 18 deletions testdata/project-v4-multigroup-with-deploy-image/dist/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1474,24 +1474,6 @@ subjects:
---
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/name: project-v4-multigroup-with-deploy-image
control-plane: controller-manager
name: project-v4-multigroup-with-deploy-image-controller-manager-metrics-service
namespace: project-v4-multigroup-with-deploy-image-system
spec:
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
selector:
control-plane: controller-manager
---
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/managed-by: kustomize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ resources:
- role_binding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
- metrics_service.yaml
# For each CRD, "Editor" and "Viewer" roles are scaffolded by
# default, aiding admins in cluster management. Those roles are
# not used by the Project itself. You can comment the following lines
Expand Down
18 changes: 0 additions & 18 deletions testdata/project-v4-multigroup/dist/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1474,24 +1474,6 @@ subjects:
---
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/name: project-v4-multigroup
control-plane: controller-manager
name: project-v4-multigroup-controller-manager-metrics-service
namespace: project-v4-multigroup-system
spec:
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
selector:
control-plane: controller-manager
---
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/managed-by: kustomize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ resources:
- role_binding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
- metrics_service.yaml
# For each CRD, "Editor" and "Viewer" roles are scaffolded by
# default, aiding admins in cluster management. Those roles are
# not used by the Project itself. You can comment the following lines
Expand Down
18 changes: 0 additions & 18 deletions testdata/project-v4-with-deploy-image/dist/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -550,24 +550,6 @@ subjects:
---
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/name: project-v4-with-deploy-image
control-plane: controller-manager
name: project-v4-with-deploy-image-controller-manager-metrics-service
namespace: project-v4-with-deploy-image-system
spec:
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
selector:
control-plane: controller-manager
---
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/managed-by: kustomize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ resources:
- role_binding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
- metrics_service.yaml
18 changes: 0 additions & 18 deletions testdata/project-v4-with-grafana/dist/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,6 @@ subjects:
name: project-v4-with-grafana-controller-manager
namespace: project-v4-with-grafana-system
---
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/name: project-v4-with-grafana
control-plane: controller-manager
name: project-v4-with-grafana-controller-manager-metrics-service
namespace: project-v4-with-grafana-system
spec:
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
selector:
control-plane: controller-manager
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down
1 change: 0 additions & 1 deletion testdata/project-v4/config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ resources:
- role_binding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
- metrics_service.yaml
# For each CRD, "Editor" and "Viewer" roles are scaffolded by
# default, aiding admins in cluster management. Those roles are
# not used by the Project itself. You can comment the following lines
Expand Down
18 changes: 0 additions & 18 deletions testdata/project-v4/dist/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -544,24 +544,6 @@ subjects:
---
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/name: project-v4
control-plane: controller-manager
name: project-v4-controller-manager-metrics-service
namespace: project-v4-system
spec:
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
selector:
control-plane: controller-manager
---
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/managed-by: kustomize
Expand Down

0 comments on commit a6a4bf9

Please sign in to comment.