|
| 1 | +/* |
| 2 | +Copyright 2018 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package project |
| 18 | + |
| 19 | +import ( |
| 20 | + "path/filepath" |
| 21 | + |
| 22 | + "sigs.k8s.io/kubebuilder/pkg/scaffold/input" |
| 23 | +) |
| 24 | + |
| 25 | +var _ input.File = &KustomizePrometheusMetricsPatch{} |
| 26 | + |
| 27 | +// KustomizePrometheusMetricsPatch scaffolds the patch file for enabling |
| 28 | +// prometheus metrics for manager Pod. |
| 29 | +type KustomizePrometheusMetricsPatch struct { |
| 30 | + input.Input |
| 31 | +} |
| 32 | + |
| 33 | +// GetInput implements input.File |
| 34 | +func (c *KustomizePrometheusMetricsPatch) GetInput() (input.Input, error) { |
| 35 | + if c.Path == "" { |
| 36 | + c.Path = filepath.Join("config", "default", "manager_prometheus_metrics_patch.yaml") |
| 37 | + } |
| 38 | + c.TemplateBody = kustomizePrometheusMetricsPatchTemplate |
| 39 | + c.Input.IfExistsAction = input.Error |
| 40 | + return c.Input, nil |
| 41 | +} |
| 42 | + |
| 43 | +var kustomizePrometheusMetricsPatchTemplate = `# This patch enables Prometheus scraping for the manager pod. |
| 44 | +apiVersion: apps/v1 |
| 45 | +kind: StatefulSet |
| 46 | +metadata: |
| 47 | + name: controller-manager |
| 48 | + namespace: system |
| 49 | +spec: |
| 50 | + template: |
| 51 | + metadata: |
| 52 | + annotations: |
| 53 | + prometheus.io/scrape: 'true' |
| 54 | + spec: |
| 55 | + containers: |
| 56 | + # Expose the prometheus metrics on default port |
| 57 | + - name: manager |
| 58 | + ports: |
| 59 | + - containerPort: 8080 |
| 60 | + name: metrics |
| 61 | + protocol: TCP |
| 62 | +` |
0 commit comments