-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add label selectors to informer's cache (#361)
* Informers caches with label selector * wip * wip * docs 2 * wip * wip * Apply suggestions from code review Co-authored-by: Iwona Langer <[email protected]> * Apply suggestions from code review Co-authored-by: Iwona Langer <[email protected]> * Apply suggestions from code review Co-authored-by: Iwona Langer <[email protected]> --------- Co-authored-by: Iwona Langer <[email protected]>
- Loading branch information
1 parent
ffe362a
commit 59029a0
Showing
16 changed files
with
249 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package controllers | ||
|
||
import ( | ||
"fmt" | ||
admissionregistrationv1 "k8s.io/api/admissionregistration/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/client-go/rest" | ||
"sigs.k8s.io/controller-runtime/pkg/cache" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func CacheCreator(conf *rest.Config, opts cache.Options) (cache.Cache, error) { | ||
labelSelector, err := labels.Parse("app.kubernetes.io/managed-by in (btp-manager,kcp-kyma-environment-broker)") | ||
if err != nil { | ||
panic(fmt.Sprintf("unable to parse label selector: %s", err)) | ||
} | ||
objSelector := cache.ObjectSelector{ | ||
Label: labelSelector, | ||
} | ||
|
||
opts.SelectorsByObject = map[client.Object]cache.ObjectSelector{ | ||
&corev1.Secret{}: objSelector, | ||
&corev1.ConfigMap{}: objSelector, | ||
&admissionregistrationv1.ValidatingWebhookConfiguration{}: objSelector, | ||
&admissionregistrationv1.MutatingWebhookConfiguration{}: objSelector, | ||
} | ||
|
||
return cache.New(conf, opts) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Informer's cache | ||
|
||
The controller manager uses informers with a cache. All observed resources (btpoperator, Secret, ConfigMap etc.) are stored in the cache. Because of the out of memory risk, the cache is configured with a label selector `app.kubernetes.io/managed-by in (btp-manager,kcp-kyma-environment-broker)`. See [cache.go](/controllers/cache.go). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
# Stress testing in regard to memory consumption - could cause OOM (but should not). | ||
# Creates btp-operator and numerous Service Instances and Service Bindings in the current context. | ||
# | ||
# The script has the following arguments: | ||
# - number of Config Maps and Secrets (the provided number is multiplied by 10) | ||
# Example (creates 1000 CMs and Secrets): | ||
# ./stress-mem.sh 100 | ||
|
||
N=${1-100} | ||
YAML_DIR=./scripts/testing/yaml | ||
|
||
echo -e "\n---Creating ${N} config maps and secrets" | ||
|
||
for ((i=1; i <= N ; i++)) | ||
do | ||
CM_NAME=cm-$i | ||
SECRET_NAME=secret-$i | ||
|
||
export CM_NAME | ||
export SECRET_NAME | ||
|
||
envsubst <${YAML_DIR}/stress-cm.yaml | kubectl apply -f - >/dev/null | ||
envsubst <${YAML_DIR}/stress-secret.yaml | kubectl apply -f - >/dev/null | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: ${CM_NAME}-001 | ||
namespace: kyma-system | ||
data: | ||
testData: "abcd" | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: ${CM_NAME}-002 | ||
namespace: kyma-system | ||
data: | ||
testData: "abcd" | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: ${CM_NAME}-003 | ||
namespace: kyma-system | ||
data: | ||
testData: "abcd" | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: ${CM_NAME}-004 | ||
namespace: kyma-system | ||
data: | ||
testData: "abcd" | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: ${CM_NAME}-005 | ||
namespace: kyma-system | ||
data: | ||
testData: "abcd" | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: ${CM_NAME}-006 | ||
namespace: kyma-system | ||
data: | ||
testData: "abcd" | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: ${CM_NAME}-007 | ||
namespace: kyma-system | ||
data: | ||
testData: "abcd" | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: ${CM_NAME}-008 | ||
namespace: kyma-system | ||
data: | ||
testData: "abcd" | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: ${CM_NAME}-009 | ||
namespace: kyma-system | ||
data: | ||
testData: "abcd" | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: ${CM_NAME}-000 | ||
namespace: kyma-system | ||
data: | ||
testData: "abcd" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
type: Opaque | ||
metadata: | ||
name: ${SECRET_NAME}-001 | ||
namespace: kyma-system | ||
data: | ||
testData: test | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
type: Opaque | ||
metadata: | ||
name: ${SECRET_NAME}-002 | ||
namespace: kyma-system | ||
data: | ||
testData: test | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
type: Opaque | ||
metadata: | ||
name: ${SECRET_NAME}-003 | ||
namespace: kyma-system | ||
data: | ||
testData: test | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
type: Opaque | ||
metadata: | ||
name: ${SECRET_NAME}-004 | ||
namespace: kyma-system | ||
data: | ||
testData: test | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
type: Opaque | ||
metadata: | ||
name: ${SECRET_NAME}-005 | ||
namespace: kyma-system | ||
data: | ||
testData: test | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
type: Opaque | ||
metadata: | ||
name: ${SECRET_NAME}-006 | ||
namespace: kyma-system | ||
data: | ||
testData: test | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
type: Opaque | ||
metadata: | ||
name: ${SECRET_NAME}-007 | ||
namespace: kyma-system | ||
data: | ||
testData: test | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
type: Opaque | ||
metadata: | ||
name: ${SECRET_NAME}-008 | ||
namespace: kyma-system | ||
data: | ||
testData: test | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
type: Opaque | ||
metadata: | ||
name: ${SECRET_NAME}-009 | ||
namespace: kyma-system | ||
data: | ||
testData: test | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
type: Opaque | ||
metadata: | ||
name: ${SECRET_NAME}-000 | ||
namespace: kyma-system | ||
data: | ||
testData: test |