Skip to content

Commit 2353e4f

Browse files
cheina97adamjensenbot
authored andcommitted
Controller-Manager: propagate virtual kubelet metrics settings
1 parent 4efc2ed commit 2353e4f

File tree

13 files changed

+54
-28
lines changed

13 files changed

+54
-28
lines changed

cmd/liqo-controller-manager/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// Package main contains the main function for the Liqo controller manager.
1516
package main
1617

1718
import (
@@ -72,6 +73,7 @@ import (
7273
liqoerrors "github.com/liqotech/liqo/pkg/utils/errors"
7374
"github.com/liqotech/liqo/pkg/utils/mapper"
7475
"github.com/liqotech/liqo/pkg/utils/restcfg"
76+
"github.com/liqotech/liqo/pkg/vkMachinery"
7577
"github.com/liqotech/liqo/pkg/vkMachinery/forge"
7678
)
7779

@@ -96,6 +98,8 @@ func main() {
9698
var nodeExtraAnnotations, nodeExtraLabels argsutils.StringMap
9799
var kubeletCPURequests, kubeletCPULimits argsutils.Quantity
98100
var kubeletRAMRequests, kubeletRAMLimits argsutils.Quantity
101+
var kubeletMetricsAddress string
102+
var kubeletMetricsEnabled bool
99103

100104
webhookPort := flag.Uint("webhook-port", 9443, "The port the webhook server binds to")
101105
metricsAddr := flag.String("metrics-address", ":8080", "The address the metric endpoint binds to")
@@ -152,6 +156,8 @@ func main() {
152156
flag.Var(&kubeletCPULimits, "kubelet-cpu-limits", "CPU limits assigned to the Virtual Kubelet Pod")
153157
flag.Var(&kubeletRAMRequests, "kubelet-ram-requests", "RAM requests assigned to the Virtual Kubelet Pod")
154158
flag.Var(&kubeletRAMLimits, "kubelet-ram-limits", "RAM limits assigned to the Virtual Kubelet Pod")
159+
flag.StringVar(&kubeletMetricsAddress, "kubelet-metrics-address", vkMachinery.MetricsAddress, "The address the kubelet metrics endpoint binds to")
160+
flag.BoolVar(&kubeletMetricsEnabled, "kubelet-metrics-enabled", false, "Enable the kubelet metrics endpoint")
155161
flag.Var(&nodeExtraAnnotations, "node-extra-annotations", "Extra annotations to add to the Virtual Node")
156162
flag.Var(&nodeExtraLabels, "node-extra-labels", "Extra labels to add to the Virtual Node")
157163
kubeletIpamServer := flag.String("kubelet-ipam-server", "",
@@ -310,6 +316,8 @@ func main() {
310316
LimitsCPU: kubeletCPULimits.Quantity,
311317
LimitsRAM: kubeletRAMLimits.Quantity,
312318
IpamEndpoint: *kubeletIpamServer,
319+
MetricsAddress: kubeletMetricsAddress,
320+
MetricsEnabled: kubeletMetricsEnabled,
313321
}
314322

315323
resourceOfferReconciler := resourceoffercontroller.NewResourceOfferController(

cmd/virtual-kubelet/root/flag.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ func InstallFlags(flags *pflag.FlagSet, o *Opts) {
7272
flags.BoolVar(&o.EnableStorage, "enable-storage", false, "Enable the Liqo storage reflection")
7373
flags.StringVar(&o.VirtualStorageClassName, "virtual-storage-class-name", "liqo", "Name of the virtual storage class")
7474
flags.StringVar(&o.RemoteRealStorageClassName, "remote-real-storage-class-name", "", "Name of the real storage class to use for the actual volumes")
75-
flags.BoolVar(&o.EnableMetrics, "enable-metrics", false, "Enable the metrics server")
75+
flags.BoolVar(&o.EnableMetrics, "metrics-enabled", false, "Enable the metrics server")
76+
flags.StringVar(&o.MetricsAddress, "metrics-address", ":8080", "The address to listen to for metrics requests")
7677
flags.StringVar(&o.HomeAPIServerHost, "home-api-server-host", "",
7778
"Home cluster API server HOST, this parameter is optional and required only to override the default values")
7879
flags.StringVar(&o.HomeAPIServerPort, "home-api-server-port", "",

cmd/virtual-kubelet/root/opts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ type Opts struct {
9797
VirtualStorageClassName string
9898
RemoteRealStorageClassName string
9999
EnableMetrics bool
100+
MetricsAddress string
100101

101102
HomeAPIServerHost string
102103
HomeAPIServerPort string

cmd/virtual-kubelet/root/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func runRootCommand(ctx context.Context, c *Opts) error {
197197
}
198198

199199
if c.EnableMetrics {
200-
metrics.SetupMetricHandler()
200+
metrics.SetupMetricHandler(c.MetricsAddress)
201201
}
202202

203203
go func() {

deployments/liqo/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
| virtualKubelet.metrics.podMonitor.enabled | bool | `false` | |
139139
| virtualKubelet.metrics.podMonitor.interval | string | `""` | |
140140
| virtualKubelet.metrics.podMonitor.scrapeTimeout | string | `""` | |
141-
| virtualKubelet.metrics.port | int | `9090` | port used to expose metrics. |
141+
| virtualKubelet.metrics.port | int | `5872` | port used to expose metrics. |
142142
| virtualKubelet.virtualNode.extra.annotations | object | `{}` | virtual node extra annotations |
143143
| virtualKubelet.virtualNode.extra.labels | object | `{}` | virtual node extra labels |
144144
| webhook.failurePolicy | string | `"Fail"` | the webhook failure policy, among Ignore and Fail |

deployments/liqo/templates/liqo-controller-manager-deployment.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
{{- $vkargs = append $vkargs "--certificate-type=aws" }}
2727
{{- end }}
2828
{{- end }}
29-
{{- if not (or (has "--enable-metrics" $vkargs ) (has "--enable-metrics=true" $vkargs ) (has "--enable-metrics=false" $vkargs )) }}
30-
{{- $vkargs = append $vkargs "--enable-metrics=true" }}
31-
{{- end}}
3229

3330
apiVersion: apps/v1
3431
kind: Deployment
@@ -81,6 +78,11 @@ spec:
8178
- --enable-incoming-peering={{ .Values.discovery.config.incomingPeeringEnabled }}
8279
- --resource-sharing-percentage={{ .Values.controllerManager.config.resourceSharingPercentage }}
8380
- --kubelet-image={{ .Values.virtualKubelet.imageName }}{{ include "liqo.suffix" $ctrlManagerConfig }}:{{ include "liqo.version" $ctrlManagerConfig }}
81+
{{- if .Values.virtualKubelet.metrics.enabled }}
82+
- --kubelet-metrics-address=:{{ .Values.virtualKubelet.metrics.port }}
83+
- --kubelet-metrics-enabled={{ .Values.virtualKubelet.metrics.enabled }}
84+
{{- else }}
85+
{{- end }}
8486
{{- if .Values.networkManager.externalIPAM.enabled }}
8587
- --kubelet-ipam-server={{ .Values.networkManager.externalIPAM.url }}
8688
{{- else if not .Values.networking.internal }}

deployments/liqo/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ virtualKubelet:
319319
# -- expose metrics about virtual kubelet resources.
320320
enabled: false
321321
# -- port used to expose metrics.
322-
port: 9090
322+
port: 5872
323323
podMonitor:
324324
# # -- create a prometheus podmonitor.
325325
enabled: false

pkg/liqo-controller-manager/resourceoffer-controller/resourceoffer_controller_methods.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (r *ResourceOfferReconciler) createVirtualKubeletDeployment(
118118

119119
// forge the virtual Kubelet
120120
vkDeployment, err := forge.VirtualKubeletDeployment(
121-
&r.cluster, &remoteClusterIdentity, namespace, r.liqoNamespace,
121+
&r.cluster, &remoteClusterIdentity, namespace,
122122
r.virtualKubeletOpts, resourceOffer)
123123
if err != nil {
124124
klog.Error(err)

pkg/virtualKubelet/metrics/metrics.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ import (
2424
"k8s.io/klog/v2"
2525
)
2626

27-
const (
28-
// MetricsPort is the metrics port constant.
29-
MetricsPort = ":9090"
30-
)
31-
3227
var (
3328
// ErrorsCounter is the counter of the errors occurred during the reflection.
3429
ErrorsCounter *prometheus.CounterVec
@@ -59,7 +54,7 @@ func init() {
5954
}
6055

6156
// SetupMetricHandler sets up the metric handler.
62-
func SetupMetricHandler() {
57+
func SetupMetricHandler(metricsAddress string) {
6358
// Register the metrics to the prometheus registry.
6459
prometheus.MustRegister(ErrorsCounter)
6560
// Register the metrics to the prometheus registry.
@@ -68,10 +63,10 @@ func SetupMetricHandler() {
6863
http.Handle("/metrics", promhttp.Handler())
6964

7065
go func() {
71-
klog.Infof("Starting the virtual kubelet Metric Handler listening on %q", MetricsPort)
66+
klog.Infof("Starting the virtual kubelet Metric Handler listening on %q", metricsAddress)
7267

7368
server := &http.Server{
74-
Addr: ":1234",
69+
Addr: metricsAddress,
7570
ReadHeaderTimeout: 10 * time.Second,
7671
}
7772

pkg/vkMachinery/const.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ var KubeletBaseLabels = map[string]string{
3939
var ClusterRoleBindingLabels = map[string]string{
4040
"app.kubernetes.io/managed-by": "advertisementoperator",
4141
}
42+
43+
// MetricsAddress is the default address used to expose metrics.
44+
const MetricsAddress = ":8080"

0 commit comments

Comments
 (0)