Skip to content

Commit 36d83cc

Browse files
feat: add support for multiple SCP composition
1 parent d02f4ec commit 36d83cc

File tree

16 files changed

+900
-311
lines changed

16 files changed

+900
-311
lines changed

config/crds/v1/all-crds.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10932,6 +10932,13 @@ spec:
1093210932
- secretName
1093310933
type: object
1093410934
type: array
10935+
weight:
10936+
default: 0
10937+
description: |-
10938+
Weight determines the priority of this policy when multiple policies target the same resource.
10939+
Lower weight values take precedence. Defaults to 0.
10940+
format: int32
10941+
type: integer
1093510942
type: object
1093610943
status:
1093710944
properties:

config/crds/v1/resources/stackconfigpolicy.k8s.elastic.co_stackconfigpolicies.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,13 @@ spec:
288288
- secretName
289289
type: object
290290
type: array
291+
weight:
292+
default: 0
293+
description: |-
294+
Weight determines the priority of this policy when multiple policies target the same resource.
295+
Lower weight values take precedence. Defaults to 0.
296+
format: int32
297+
type: integer
291298
type: object
292299
status:
293300
properties:

deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11002,6 +11002,13 @@ spec:
1100211002
- secretName
1100311003
type: object
1100411004
type: array
11005+
weight:
11006+
default: 0
11007+
description: |-
11008+
Weight determines the priority of this policy when multiple policies target the same resource.
11009+
Lower weight values take precedence. Defaults to 0.
11010+
format: int32
11011+
type: integer
1100511012
type: object
1100611013
status:
1100711014
properties:

docs/reference/api-reference/main.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,6 +2068,7 @@ StackConfigPolicy represents a StackConfigPolicy resource in a Kubernetes cluste
20682068
| Field | Description |
20692069
| --- | --- |
20702070
| *`resourceSelector`* __[LabelSelector](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#labelselector-v1-meta)__ | |
2071+
| *`weight`* __integer__ | Weight determines the priority of this policy when multiple policies target the same resource.<br>Lower weight values take precedence. Defaults to 0. |
20712072
| *`secureSettings`* __[SecretSource](#secretsource) array__ | Deprecated: SecureSettings only applies to Elasticsearch and is deprecated. It must be set per application instead. |
20722073
| *`elasticsearch`* __[ElasticsearchConfigPolicySpec](#elasticsearchconfigpolicyspec)__ | |
20732074
| *`kibana`* __[KibanaConfigPolicySpec](#kibanaconfigpolicyspec)__ | |

pkg/apis/stackconfigpolicy/v1alpha1/stackconfigpolicy_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ type StackConfigPolicyList struct {
5555

5656
type StackConfigPolicySpec struct {
5757
ResourceSelector metav1.LabelSelector `json:"resourceSelector,omitempty"`
58+
// Weight determines the priority of this policy when multiple policies target the same resource.
59+
// Lower weight values take precedence. Defaults to 0.
60+
// +kubebuilder:default=0
61+
Weight int32 `json:"weight,omitempty"`
5862
// Deprecated: SecureSettings only applies to Elasticsearch and is deprecated. It must be set per application instead.
5963
SecureSettings []commonv1.SecretSource `json:"secureSettings,omitempty"`
6064
Elasticsearch ElasticsearchConfigPolicySpec `json:"elasticsearch,omitempty"`

pkg/controller/common/annotation/constants.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ const (
2525

2626
ElasticsearchConfigAndSecretMountsHashAnnotation = "policy.k8s.elastic.co/elasticsearch-config-mounts-hash" //nolint:gosec
2727
SourceSecretAnnotationName = "policy.k8s.elastic.co/source-secret-name" //nolint:gosec
28+
29+
SoftOwnerRefsAnnotation = "eck.k8s.elastic.co/owner-refs"
2830
)

pkg/controller/common/reconciler/secret.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"github.com/elastic/cloud-on-k8s/v3/pkg/utils/maps"
2323
)
2424

25-
// labels set on secrets which cannot rely on owner references due to https://github.com/kubernetes/kubernetes/issues/65200,
25+
// labels and annotations set on secrets which cannot rely on owner references due to https://github.com/kubernetes/kubernetes/issues/65200,
2626
// but should still be garbage-collected (best-effort) by the operator upon owner deletion.
2727
const (
2828
SoftOwnerNamespaceLabel = "eck.k8s.elastic.co/owner-namespace"

pkg/controller/elasticsearch/filesettings/reconciler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var (
2929

3030
// managedAnnotations are the annotations managed by the operator for the stack config policy related secrets, which means that the operator
3131
// will always take precedence to update or remove these annotations.
32-
managedAnnotations = []string{commonannotation.SecureSettingsSecretsAnnotationName, commonannotation.SettingsHashAnnotationName, commonannotation.ElasticsearchConfigAndSecretMountsHashAnnotation, commonannotation.KibanaConfigHashAnnotation}
32+
managedAnnotations = []string{commonannotation.SecureSettingsSecretsAnnotationName, commonannotation.SettingsHashAnnotationName, commonannotation.ElasticsearchConfigAndSecretMountsHashAnnotation, commonannotation.KibanaConfigHashAnnotation, commonannotation.SoftOwnerRefsAnnotation}
3333
)
3434

3535
// ReconcileEmptyFileSettingsSecret reconciles an empty File settings Secret for the given Elasticsearch only when there is no Secret.

pkg/controller/elasticsearch/filesettings/secret.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ func newSettingsSecret(version int64, es types.NamespacedName, currentSecret *co
8585
}
8686

8787
if policy != nil {
88-
// set this policy as soft owner of this Secret
89-
SetSoftOwner(settingsSecret, *policy)
90-
9188
// add the Secure Settings Secret sources to the Settings Secret
9289
if err := setSecureSettings(settingsSecret, *policy); err != nil {
9390
return corev1.Secret{}, 0, err

0 commit comments

Comments
 (0)