From 49cf8911d34c92c363554a52e18c5dee5b3eba65 Mon Sep 17 00:00:00 2001 From: Haley Wang Date: Tue, 19 Nov 2024 16:26:20 +0800 Subject: [PATCH] add new variable `VM_VMSERVICESCRAPEDEFAULT_ENFORCEENDPOINTSLICES` to use `endpointslices` instead of `endpoints` as discovery role for VMServiceScrape when generate scrape config for VMAgent. --- docs/CHANGELOG.md | 1 + docs/vars.md | 5 +++-- internal/config/config.go | 6 ++++++ .../controller/operator/factory/build/defaults.go | 15 ++++++++++++--- .../operator/factory/vmagent/collect_scrapes.go | 1 + 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 253f8e7b..b864f83e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -14,6 +14,7 @@ aliases: ## tip - [vmoperator](https://docs.victoriametrics.com/operator/): bump default version of VictoriaMetrics components to [1.106.1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.106.1). +- [vmoperator](https://docs.victoriametrics.com/operator/): add new variable `VM_VMSERVICESCRAPEDEFAULT_ENFORCEENDPOINTSLICES` to use `endpointslices` instead of `endpoints` as discovery role for VMServiceScrape when generate scrape config for VMAgent. ## [v0.49.1](https://github.com/VictoriaMetrics/operator/releases/tag/v0.49.1) - 11 Nov 2024 diff --git a/docs/vars.md b/docs/vars.md index 183cae3f..63d238a2 100644 --- a/docs/vars.md +++ b/docs/vars.md @@ -10,7 +10,7 @@ aliases: - /operator/vars/index.html --- - updated at Mon Nov 18 15:16:53 UTC 2024 + updated at Tue Nov 19 08:23:27 UTC 2024 | variable name | variable default value | variable required | variable description | @@ -41,6 +41,7 @@ aliases: | VM_VMALERTDEFAULT_RESOURCE_REQUEST_CPU | 50m | false | - | | VM_VMALERTDEFAULT_CONFIGRELOADERCPU | 100m | false | - | | VM_VMALERTDEFAULT_CONFIGRELOADERMEMORY | 25Mi | false | - | +| VM_VMSERVICESCRAPEDEFAULT_ENFORCEENDPOINTSLICES | false | false | Use endpointslices instead of endpoints as discovery role for vmservicescrape when generate scrape config for vmagent. | | VM_VMAGENTDEFAULT_IMAGE | victoriametrics/vmagent | false | - | | VM_VMAGENTDEFAULT_VERSION | v1.106.1 | false | - | | VM_VMAGENTDEFAULT_CONFIGRELOADIMAGE | quay.io/prometheus-operator/prometheus-config-reloader:v0.68.0 | false | - | @@ -136,4 +137,4 @@ aliases: | VM_PODWAITREADYINTERVALCHECK | 5s | false | Defines poll interval for pods ready check at statefulset rollout update | | VM_FORCERESYNCINTERVAL | 60s | false | configures force resync interval for VMAgent, VMAlert, VMAlertmanager and VMAuth. | | VM_ENABLESTRICTSECURITY | false | false | EnableStrictSecurity will add default `securityContext` to pods and containers created by operator Default PodSecurityContext include: 1. RunAsNonRoot: true 2. RunAsUser/RunAsGroup/FSGroup: 65534 '65534' refers to 'nobody' in all the used default images like alpine, busybox. If you're using customize image, please make sure '65534' is a valid uid in there or specify SecurityContext. 3. FSGroupChangePolicy: &onRootMismatch If KubeVersion>=1.20, use `FSGroupChangePolicy="onRootMismatch"` to skip the recursive permission change when the root of the volume already has the correct permissions 4. SeccompProfile: type: RuntimeDefault Use `RuntimeDefault` seccomp profile by default, which is defined by the container runtime, instead of using the Unconfined (seccomp disabled) mode. Default container SecurityContext include: 1. AllowPrivilegeEscalation: false 2. ReadOnlyRootFilesystem: true 3. Capabilities: drop: - all turn off `EnableStrictSecurity` by default, see https://github.com/VictoriaMetrics/operator/issues/749 for details | -[envconfig-sum]: 893b84674e9b463c796ec1a2077b8218 \ No newline at end of file +[envconfig-sum]: 4b951a49a01d16512392a23bf68385f2 \ No newline at end of file diff --git a/internal/config/config.go b/internal/config/config.go index d66b3353..0ad288b5 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -122,6 +122,12 @@ type BaseOperatorConf struct { ConfigReloaderMemory string `default:"25Mi"` } + VMServiceScrapeDefault struct { + // Use endpointslices instead of endpoints as discovery role + // for vmservicescrape when generate scrape config for vmagent. + EnforceEndpointslices bool `default:"false"` + } + VMAgentDefault struct { Image string `default:"victoriametrics/vmagent"` Version string `default:"v1.106.1"` diff --git a/internal/controller/operator/factory/build/defaults.go b/internal/controller/operator/factory/build/defaults.go index 4330ff4e..8ffb5f10 100644 --- a/internal/controller/operator/factory/build/defaults.go +++ b/internal/controller/operator/factory/build/defaults.go @@ -16,7 +16,7 @@ func getCfg() *config.BaseOperatorConf { return config.MustGetBaseConfig() } -// AddDefaults adds defauling functions to the runtimeScheme +// AddDefaults adds defaulting functions to the runtimeScheme func AddDefaults(scheme *runtime.Scheme) { scheme.AddTypeDefaultingFunc(&corev1.Service{}, addServiceDefaults) scheme.AddTypeDefaultingFunc(&appsv1.Deployment{}, addDeploymentDefaults) @@ -28,7 +28,7 @@ func AddDefaults(scheme *runtime.Scheme) { scheme.AddTypeDefaultingFunc(&vmv1beta1.VMAlertmanager{}, addVMAlertmanagerDefaults) scheme.AddTypeDefaultingFunc(&vmv1beta1.VMCluster{}, addVMClusterDefaults) scheme.AddTypeDefaultingFunc(&vmv1beta1.VLogs{}, addVlogsDefaults) - + scheme.AddTypeDefaultingFunc(&vmv1beta1.VMServiceScrape{}, addVMServiceScrapeDefaults) } // defaults according to @@ -526,7 +526,6 @@ func addDefaultsToCommonParams(common *vmv1beta1.CommonDefaultableParams, appDef } common.Resources = Resources(common.Resources, config.Resource(appDefaults.Resource), ptr.Deref(common.UseDefaultResources, false)) - } func addDefaluesToConfigReloader(common *vmv1beta1.CommonConfigReloaderParams, useDefaultResources bool, appDefaults *config.ApplicationDefaults) { @@ -582,5 +581,15 @@ func addDefaultsToVMBackup(cr *vmv1beta1.VMBackup, useDefaultResources bool, app } cr.Resources = Resources(cr.Resources, config.Resource(appDefaults.Resource), useDefaultResources) +} +func addVMServiceScrapeDefaults(objI interface{}) { + cr := objI.(*vmv1beta1.VMServiceScrape) + if cr == nil { + return + } + c := getCfg() + if cr.Spec.DiscoveryRole == "" && c.VMServiceScrapeDefault.EnforceEndpointslices { + cr.Spec.DiscoveryRole = "endpointslices" + } } diff --git a/internal/controller/operator/factory/vmagent/collect_scrapes.go b/internal/controller/operator/factory/vmagent/collect_scrapes.go index a50585ea..33547126 100644 --- a/internal/controller/operator/factory/vmagent/collect_scrapes.go +++ b/internal/controller/operator/factory/vmagent/collect_scrapes.go @@ -155,6 +155,7 @@ func selectServiceScrapes(ctx context.Context, cr *vmv1beta1.VMAgent, rclient cl if !item.DeletionTimestamp.IsZero() { continue } + rclient.Scheme().Default(&item) item := item serviceScrapeNamespacedNames = append(serviceScrapeNamespacedNames, fmt.Sprintf("%s/%s", item.Namespace, item.Name)) servScrapesCombined = append(servScrapesCombined, &item)