Skip to content

Commit 6a61d9c

Browse files
⚠️ Deprecate metrics-bind-addr flag (#70)
**What is the purpose of this pull request/Why do we need it?** See: https://cluster-api.sigs.k8s.io/developer/providers/migrations/v1.5-to-v1.6 See: kubernetes-sigs/cluster-api#9264 **Checklist:** - [x] Documentation updated - [x] Includes [emojis](https://github.com/kubernetes-sigs/kubebuilder-release-tools?tab=readme-ov-file#kubebuilder-project-versioning)
1 parent 83021c4 commit 6a61d9c

13 files changed

+189
-172
lines changed

cmd/main.go

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,25 @@ import (
2323
"os"
2424

2525
"github.com/spf13/pflag"
26-
"k8s.io/klog/v2"
27-
2826
"k8s.io/apimachinery/pkg/runtime"
2927
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3028
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
29+
"k8s.io/klog/v2"
3130
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
31+
"sigs.k8s.io/cluster-api/util/flags"
3232
ctrl "sigs.k8s.io/controller-runtime"
3333
"sigs.k8s.io/controller-runtime/pkg/healthz"
34-
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3534

3635
infrav1 "github.com/ionos-cloud/cluster-api-provider-ionoscloud/api/v1alpha1"
3736
"github.com/ionos-cloud/cluster-api-provider-ionoscloud/internal/controller"
3837
)
3938

4039
var (
41-
scheme = runtime.NewScheme()
42-
setupLog = ctrl.Log.WithName("setup")
40+
scheme = runtime.NewScheme()
41+
setupLog = ctrl.Log.WithName("setup")
42+
healthProbeAddr string
43+
enableLeaderElection bool
44+
diagnosticOptions = flags.DiagnosticsOptions{}
4345
)
4446

4547
func init() {
@@ -50,25 +52,19 @@ func init() {
5052
//+kubebuilder:scaffold:scheme
5153
}
5254

55+
// Add RBAC for the authorized diagnostics endpoint.
56+
// +kubebuilder:rbac:groups=authentication.k8s.io,resources=tokenreviews,verbs=create
57+
// +kubebuilder:rbac:groups=authorization.k8s.io,resources=subjectaccessreviews,verbs=create
58+
5359
func main() {
5460
ctrl.SetLogger(klog.Background())
55-
var metricsAddr string
56-
var enableLeaderElection bool
57-
var probeAddr string
58-
klog.InitFlags(nil)
59-
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
60-
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
61-
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
62-
"Enable leader election for controller manager. "+
63-
"Enabling this will ensure there is only one active controller manager.")
64-
65-
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
61+
initFlags()
6662
pflag.Parse()
6763

6864
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
6965
Scheme: scheme,
70-
Metrics: metricsserver.Options{BindAddress: metricsAddr},
71-
HealthProbeBindAddress: probeAddr,
66+
Metrics: flags.GetDiagnosticsOptions(diagnosticOptions),
67+
HealthProbeBindAddress: healthProbeAddr,
7268
LeaderElection: enableLeaderElection,
7369
LeaderElectionID: "15f3d3ca.cluster.x-k8s.io",
7470
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
@@ -121,3 +117,15 @@ func main() {
121117
os.Exit(1)
122118
}
123119
}
120+
121+
// initFlags parses the command line flags.
122+
func initFlags() {
123+
klog.InitFlags(nil)
124+
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
125+
flags.AddDiagnosticsOptions(pflag.CommandLine, &diagnosticOptions)
126+
pflag.StringVar(&healthProbeAddr, "health-probe-bind-address", ":8081",
127+
"The address the probe endpoint binds to.")
128+
pflag.BoolVar(&enableLeaderElection, "leader-elect", false,
129+
"Enable leader election for controller manager. "+
130+
"Enabling this will ensure there is only one active controller manager.")
131+
}

config/default/kustomization.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ resources:
1919
#- ../prometheus
2020

2121
patchesStrategicMerge:
22-
# Protect the /metrics endpoint by putting it behind auth.
23-
# If you want your controller-manager to expose the /metrics
24-
# endpoint w/o any authn/z, please comment the following line.
25-
- manager_auth_proxy_patch.yaml
2622
- manager_image_patch.yaml
2723

2824

config/default/manager_auth_proxy_patch.yaml

Lines changed: 0 additions & 39 deletions
This file was deleted.

config/manager/manager.yaml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,13 @@ spec:
6969
- command:
7070
- /manager
7171
args:
72-
- --leader-elect
72+
- "--leader-elect"
7373
image: controller:latest
7474
name: manager
75+
ports:
76+
- containerPort: 8443
77+
name: diagnostics
78+
protocol: TCP
7579
securityContext:
7680
allowPrivilegeEscalation: false
7781
capabilities:
@@ -100,3 +104,27 @@ spec:
100104
memory: 64Mi
101105
serviceAccountName: controller-manager
102106
terminationGracePeriodSeconds: 10
107+
---
108+
apiVersion: v1
109+
kind: Service
110+
metadata:
111+
namespace: system
112+
name: controller-manager-diagnostics-service
113+
labels:
114+
control-plane: controller-manager
115+
app.kubernetes.io/name: diagnostics-service
116+
app.kubernetes.io/instance: controller-manager-diagnostics-service
117+
app.kubernetes.io/component: manager
118+
app.kubernetes.io/created-by: cluster-api-provider-ionoscloud
119+
app.kubernetes.io/part-of: cluster-api-provider-ionoscloud
120+
app.kubernetes.io/managed-by: kustomize
121+
spec:
122+
selector:
123+
control-plane: controller-manager
124+
ports:
125+
- name: diagnostics-svc
126+
protocol: TCP
127+
port: 8443
128+
targetPort: diagnostics
129+
130+

config/rbac/auth_proxy_client_clusterrole.yaml

Lines changed: 0 additions & 16 deletions
This file was deleted.

config/rbac/auth_proxy_role.yaml

Lines changed: 0 additions & 24 deletions
This file was deleted.

config/rbac/auth_proxy_role_binding.yaml

Lines changed: 0 additions & 19 deletions
This file was deleted.

config/rbac/auth_proxy_service.yaml

Lines changed: 0 additions & 21 deletions
This file was deleted.

config/rbac/kustomization.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,3 @@ resources:
99
- role_binding.yaml
1010
- leader_election_role.yaml
1111
- leader_election_role_binding.yaml
12-
# Comment the following 4 lines if you want to disable
13-
# the auth proxy (https://github.com/brancz/kube-rbac-proxy)
14-
# which protects your /metrics endpoint.
15-
- auth_proxy_service.yaml
16-
- auth_proxy_role.yaml
17-
- auth_proxy_role_binding.yaml
18-
- auth_proxy_client_clusterrole.yaml

config/rbac/role.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ rules:
2323
- get
2424
- list
2525
- watch
26+
- apiGroups:
27+
- authentication.k8s.io
28+
resources:
29+
- tokenreviews
30+
verbs:
31+
- create
32+
- apiGroups:
33+
- authorization.k8s.io
34+
resources:
35+
- subjectaccessreviews
36+
verbs:
37+
- create
2638
- apiGroups:
2739
- cluster.x-k8s.io
2840
resources:

docs/quickstart.md

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
## Usage
22

3-
---
4-
53
This is a guide on how to use the Cluster API Provider for IONOS Cloud (CAPIC) to create a Kubernetes cluster
64
on IONOS Cloud. To learn more about the Cluster API, please refer
75
to the official [Cluster API book](https://cluster-api.sigs.k8s.io/).
86

97
## Table of Contents
108

11-
---
12-
139
* [Usage](#usage)
1410
* [Prerequisites](#prerequisites)
1511
* [Quickstart](#quickstart)
@@ -23,8 +19,6 @@ to the official [Cluster API book](https://cluster-api.sigs.k8s.io/).
2319

2420
## Prerequisites
2521

26-
---
27-
2822
Before you can use CAPIC, you need to have the following prerequisites:
2923

3024
* A Kubernetes cluster which can run the required providers for CAPIC.
@@ -37,29 +31,21 @@ Before you can use CAPIC, you need to have the following prerequisites:
3731

3832
## Quickstart
3933

40-
---
41-
4234
In order to install Cluster API Provider for IONOS Cloud (CAPIC), you need to have a Kubernetes cluster up and running,
4335
and `clusterctl` installed.
4436

4537
### Case 1: Using a local provider
4638

47-
---
48-
4939
If the provider is not yet added to the list of providers in `clusterctl`, you can bootstrap the management cluster
5040
using a local provider. Refer to [local provider](./local-provider.md) for more information.
5141

5242
### Case 2: The provider is already available in clusterctl
5343

54-
---
55-
5644
In this case you can simply follow the steps below. Make sure you are using a version of `clusterctl` which
5745
supports the `IONOS Cloud provider`.
5846

5947
### Configuring the management cluster
6048

61-
---
62-
6349
Before you can create a Kubernetes cluster on IONOS Cloud, you need to configure the management cluster.
6450
Currently, the controller has no need of any special configuration, so you can just run the following command:
6551

@@ -70,8 +56,6 @@ clusterctl init --infrastructure=ionoscloud
7056

7157
### Environment variables
7258

73-
---
74-
7559
CAPIC requires several environment variables to be set in order to create a Kubernetes cluster on IONOS Cloud.
7660

7761
```env
@@ -98,8 +82,6 @@ IONOSCLOUD_MACHINE_SSH_KEYS # The SSH keys to be used.
9882

9983
### Credential Secret Structure
10084

101-
---
102-
10385
The `IONOS_TOKEN` should be stored in a secret in the same namespace as the management cluster.
10486
The secret should have the following structure:
10587

@@ -118,8 +100,6 @@ stringData:
118100
119101
### Create a workload cluster
120102
121-
---
122-
123103
In order to create a new cluster, you need to generate a cluster manifest.
124104
125105
```sh
@@ -138,12 +118,16 @@ $ kubectl apply -f cluster.yaml
138118

139119
### Next Steps
140120

141-
---
142-
143121
TODO
144122

123+
### Observability
124+
125+
#### Diagnostics
126+
127+
Access to metrics is secured by default. Before using it, it is necessary to create appropriate roles and role bindings.
128+
For more information, refer to [Cluster API documentation](https://main.cluster-api.sigs.k8s.io/tasks/diagnostics).
129+
145130
### Troubleshooting
146131

147-
---
148132

149133
TODO

0 commit comments

Comments
 (0)