Skip to content

Commit

Permalink
add new variable VM_VMSERVICESCRAPEDEFAULT_ENFORCEENDPOINTSLICES
Browse files Browse the repository at this point in the history
to use `endpointslices` instead of `endpoints` as discovery role for VMServiceScrape when generate scrape config for VMAgent.
  • Loading branch information
Haleygo committed Nov 19, 2024
1 parent e6e6827 commit 49cf891
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions docs/vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ aliases:
- /operator/vars/index.html
---
<!-- this doc autogenerated - don't edit it manually -->
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 |
Expand Down Expand Up @@ -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 | - |
Expand Down Expand Up @@ -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
[envconfig-sum]: 4b951a49a01d16512392a23bf68385f2
6 changes: 6 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
15 changes: 12 additions & 3 deletions internal/controller/operator/factory/build/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 49cf891

Please sign in to comment.