Skip to content

Commit

Permalink
Merge pull request #3949 from kubernetes-sigs/release-3.15
Browse files Browse the repository at this point in the history
📖 Update book-v3 with latest changes in release-v3.15 branch due release v3.15.1
  • Loading branch information
k8s-ci-robot committed May 23, 2024
2 parents 060c233 + 01f76cf commit 9b3a9f1
Show file tree
Hide file tree
Showing 63 changed files with 198 additions and 301 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test-sample-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ jobs:
run: |
KUSTOMIZATION_FILE_PATH="testdata/project-v4/config/default/kustomization.yaml"
sed -i '25s/^#//' $KUSTOMIZATION_FILE_PATH
sed -i '27s/^#//' $KUSTOMIZATION_FILE_PATH
sed -i '42s/^#//' $KUSTOMIZATION_FILE_PATH
sed -i '46,142s/^#//' $KUSTOMIZATION_FILE_PATH
sed -i '32s/^#//' $KUSTOMIZATION_FILE_PATH
sed -i '47s/^#//' $KUSTOMIZATION_FILE_PATH
sed -i '51,147s/^#//' $KUSTOMIZATION_FILE_PATH
- name: Test
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ resources:
#- ../certmanager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
#- ../prometheus
# [METRICS] To enable the controller manager metrics service, uncomment the following line.
#- metrics_service.yaml

patches:
# Uncomment the patches line if you enable Metrics, and/or are using webhooks and cert-manager
#patches:
# [METRICS] The following patch will enable the metrics endpoint. Ensure that you also protect this endpoint.
# More info: https://book.kubebuilder.io/reference/metrics
# If you want to expose the metric endpoint of your controller-manager uncomment the following line.
#- path: manager_metrics_patch.yaml
# target:
# kind: Deployment

# Mount the controller config file for loading manager configurations
# through a ComponentConfig type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
# This patch adds the args to allow exposing the metrics endpoint securely
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
spec:
template:
spec:
containers:
- name: manager
args:
- "--metrics-bind-address=0.0.0.0:8080"
- op: add
path: /spec/template/spec/containers/0/args/0
value: --metrics-bind-address=:8080
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
3 changes: 2 additions & 1 deletion docs/book/src/cronjob-tutorial/testdata/project/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func main() {
var probeAddr string
var secureMetrics bool
var enableHTTP2 bool
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metric endpoint binds to. "+
"Use the port :8080. If not set, it will be '0 in order to disable the metrics server")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ resources:
- ../certmanager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
- ../prometheus
# [METRICS] To enable the controller manager metrics service, uncomment the following line.
#- metrics_service.yaml

# Uncomment the patches line if you enable Metrics, and/or are using webhooks and cert-manager
patches:
# [METRICS] The following patch will enable the metrics endpoint. Ensure that you also protect this endpoint.
# More info: https://book.kubebuilder.io/reference/metrics
# If you want to expose the metric endpoint of your controller-manager uncomment the following line.
#- path: manager_metrics_patch.yaml
# target:
# kind: Deployment

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
# This patch adds the args to allow exposing the metrics endpoint securely
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
spec:
template:
spec:
containers:
- name: manager
args:
- "--metrics-bind-address=0.0.0.0:8080"
- op: add
path: /spec/template/spec/containers/0/args/0
value: --metrics-bind-address=:8080
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ spec:
args:
- --leader-elect
- --health-probe-bind-address=:8081
- --metrics-bind-address=0
image: controller:latest
name: manager
securityContext:
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
3 changes: 2 additions & 1 deletion docs/book/src/getting-started/testdata/project/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func main() {
var probeAddr string
var secureMetrics bool
var enableHTTP2 bool
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metric endpoint binds to. "+
"Use the port :8080. If not set, it will be '0 in order to disable the metrics server")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ resources:
#- ../certmanager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
#- ../prometheus
# [METRICS] To enable the controller manager metrics service, uncomment the following line.
#- metrics_service.yaml

patches:
# Uncomment the patches line if you enable Metrics, and/or are using webhooks and cert-manager
#patches:
# [METRICS] The following patch will enable the metrics endpoint. Ensure that you also protect this endpoint.
# More info: https://book.kubebuilder.io/reference/metrics
# If you want to expose the metric endpoint of your controller-manager uncomment the following line.
#- path: manager_metrics_patch.yaml
# target:
# kind: Deployment

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
# This patch adds the args to allow exposing the metrics endpoint securely
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
spec:
template:
spec:
containers:
- name: manager
args:
- "--metrics-bind-address=0.0.0.0:8080"
- op: add
path: /spec/template/spec/containers/0/args/0
value: --metrics-bind-address=:8080
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ spec:
args:
- --leader-elect
- --health-probe-bind-address=:8081
- --metrics-bind-address=0
image: controller:latest
name: manager
env:
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
16 changes: 12 additions & 4 deletions docs/book/src/reference/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@ Further information can be found bellow in this document.
First, you will need enable the Metrics by uncommenting the following line
in the file `config/default/kustomization.yaml`, see:

```sh
# [Metrics] The following patch will enable the metrics endpoint.
# Ensure that you also protect this endpoint.
```yaml
# [METRICS] To enable the controller manager metrics service, uncomment the following line.
#- metrics_service.yaml
```

```yaml
# [METRICS] The following patch will enable the metrics endpoint. Ensure that you also protect this endpoint.
# More info: https://book.kubebuilder.io/reference/metrics
# If you want to expose the metric endpoint of your controller-manager uncomment the following line.
#- path: manager_metrics_patch.yaml
# target:
# kind: Deployment
```

Note that projects are scaffolded by default passing the flag `--metrics-bind-address=0`
Expand Down Expand Up @@ -76,7 +84,7 @@ Integrating `cert-manager` with your metrics service can secure the endpoint via

To modify your project setup to expose metrics using HTTPS with
the help of cert-manager, you'll need to change the configuration of both
the `Service` under `config/rbac/metrics_service.yaml` and
the `Service` under `config/default/metrics_service.yaml` and
the `ServiceMonitor` under `config/prometheus/monitor.yaml` to use a secure HTTPS port
and ensure the necessary certificate is applied.

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{},
&kdefault.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 @@ -71,12 +71,17 @@ resources:
#- ../certmanager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
#- ../prometheus
# [METRICS] To enable the controller manager metrics service, uncomment the following line.
#- metrics_service.yaml
patches:
# Uncomment the patches line if you enable Metrics, and/or are using webhooks and cert-manager
#patches:
# [METRICS] The following patch will enable the metrics endpoint. Ensure that you also protect this endpoint.
# More info: https://book.kubebuilder.io/reference/metrics
# If you want to expose the metric endpoint of your controller-manager uncomment the following line.
#- path: manager_metrics_patch.yaml
# target:
# kind: Deployment
{{ if .ComponentConfig -}}
# Mount the controller config file for loading manager configurations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,7 @@ func (f *ManagerMetricsPatch) SetTemplateDefaults() error {
}

const kustomizeMetricsPatchTemplate = `# This patch adds the args to allow exposing the metrics endpoint securely
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
spec:
template:
spec:
containers:
- name: manager
args:
- "--metrics-bind-address=0.0.0.0:8080"
- op: add
path: /spec/template/spec/containers/0/args/0
value: --metrics-bind-address=:8080
`
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 kdefault

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", "default", "metrics_service.yaml")
}

f.TemplateBody = metricsServiceTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ spec:
args:
- --leader-elect
- --health-probe-bind-address=:8081
- --metrics-bind-address=0
{{- end }}
image: {{ .Image }}
name: manager
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
`
9 changes: 9 additions & 0 deletions pkg/plugins/common/kustomize/v2/scaffolds/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ func (s *webhookScaffolder) Scaffold() error {
}
}

err = pluginutil.UncommentCode(kustomizeFilePath, "#patches:", `#`)
if err != nil {
hasWebHookUncommented, err := pluginutil.HasFragment(kustomizeFilePath, "patches:")
if !hasWebHookUncommented || err != nil {
log.Errorf("Unable to find the line '#patches:' to uncomment in the file "+
"%s.", kustomizeFilePath)
}
}

err = pluginutil.UncommentCode(kustomizeFilePath, "#- path: manager_webhook_patch.yaml", `#`)
if err != nil {
hasWebHookUncommented, err := pluginutil.HasFragment(kustomizeFilePath, "- path: manager_webhook_patch.yaml")
Expand Down
3 changes: 2 additions & 1 deletion pkg/plugins/golang/v4/scaffolds/internal/templates/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ func main() {
var probeAddr string
var secureMetrics bool
var enableHTTP2 bool
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metric endpoint binds to. " +
"Use the port :8080. If not set, it will be '0 in order to disable the metrics server")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. " +
Expand Down
17 changes: 15 additions & 2 deletions test/e2e/v4/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ func GenerateV4(kbc *utils.TestContext) {
"#- path: webhookcainjection_patch.yaml", "#")).To(Succeed())
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
"#- path: manager_metrics_patch.yaml", "#")).To(Succeed())
"#- metrics_service.yaml", "#")).To(Succeed())
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
metricsTarget, "#")).To(Succeed())

ExpectWithOffset(1, pluginutil.UncommentCode(filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
certManagerTarget, "#")).To(Succeed())
Expand Down Expand Up @@ -120,12 +123,18 @@ func GenerateV4WithoutWebhooks(kbc *utils.TestContext) {
initingTheProject(kbc)
creatingAPI(kbc)

ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
"#patches:", "#")).To(Succeed())
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
"#- ../prometheus", "#")).To(Succeed())
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
"#- path: manager_metrics_patch.yaml", "#")).To(Succeed())
"#- metrics_service.yaml", "#")).To(Succeed())
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
metricsTarget, "#")).To(Succeed())

if kbc.IsRestricted {
By("uncomment kustomize files to ensure that pods are restricted")
Expand Down Expand Up @@ -166,6 +175,10 @@ func initingTheProject(kbc *utils.TestContext) {
ExpectWithOffset(1, err).NotTo(HaveOccurred())
}

const metricsTarget = `#- path: manager_metrics_patch.yaml
# target:
# kind: Deployment`

//nolint:lll
const certManagerTarget = `#replacements:
# - source: # Add cert-manager annotation to ValidatingWebhookConfiguration, MutatingWebhookConfiguration and CRDs
Expand Down
Loading

0 comments on commit 9b3a9f1

Please sign in to comment.