Skip to content

Commit

Permalink
feat: Use custom cache function in Che Operator (#1166)
Browse files Browse the repository at this point in the history
Use custom cache function to limit memory consumption of operator

Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
  • Loading branch information
mmorhun committed Nov 19, 2021
1 parent 18cdc63 commit 021031f
Show file tree
Hide file tree
Showing 64 changed files with 683 additions and 262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ metadata:
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/eclipse-che/che-operator
support: Eclipse Foundation
name: eclipse-che-preview-openshift.v7.40.0-370.next
name: eclipse-che-preview-openshift.v7.40.0-373.next
namespace: placeholder
spec:
apiservicedefinitions: {}
Expand Down Expand Up @@ -1068,6 +1068,7 @@ spec:
app.kubernetes.io/instance: che
app.kubernetes.io/managed-by: olm
app.kubernetes.io/name: che
app.kubernetes.io/part-of: che.eclipse.org
spec:
containers:
- args:
Expand Down Expand Up @@ -1426,4 +1427,4 @@ spec:
maturity: stable
provider:
name: Eclipse Foundation
version: 7.40.0-370.next
version: 7.40.0-373.next
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ metadata:
app.kubernetes.io/component: che-operator
app.kubernetes.io/instance: che
app.kubernetes.io/name: che
app.kubernetes.io/part-of: che.eclipse.org
name: che-operator
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ metadata:
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/eclipse-che/che-operator
support: Eclipse Foundation
name: eclipse-che-preview-kubernetes.v7.40.0-331.next
name: eclipse-che-preview-kubernetes.v7.40.0-334.next
namespace: placeholder
spec:
apiservicedefinitions: {}
Expand Down Expand Up @@ -1055,6 +1055,7 @@ spec:
app.kubernetes.io/instance: che
app.kubernetes.io/managed-by: olm
app.kubernetes.io/name: che
app.kubernetes.io/part-of: che.eclipse.org
spec:
containers:
- args:
Expand Down Expand Up @@ -1083,7 +1084,7 @@ spec:
- name: RELATED_IMAGE_devfile_registry
value: quay.io/eclipse/che-devfile-registry:next
- name: RELATED_IMAGE_che_tls_secrets_creation_job
value: quay.io/eclipse/che-tls-secret-creator:alpine-d1ed4ad
value: quay.io/eclipse/che-tls-secret-creator:alpine-01a4c34
- name: RELATED_IMAGE_pvc_jobs
value: registry.access.redhat.com/ubi8-minimal:8.5-204
- name: RELATED_IMAGE_postgres
Expand Down Expand Up @@ -1393,4 +1394,4 @@ spec:
maturity: stable
provider:
name: Eclipse Foundation
version: 7.40.0-331.next
version: 7.40.0-334.next
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ metadata:
app.kubernetes.io/component: che-operator
app.kubernetes.io/instance: che
app.kubernetes.io/name: che
app.kubernetes.io/part-of: che.eclipse.org
name: che-operator
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ metadata:
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/eclipse-che/che-operator
support: Eclipse Foundation
name: eclipse-che-preview-openshift.v7.40.0-338.next
name: eclipse-che-preview-openshift.v7.40.0-341.next
namespace: placeholder
spec:
apiservicedefinitions: {}
Expand Down Expand Up @@ -1068,6 +1068,7 @@ spec:
app.kubernetes.io/instance: che
app.kubernetes.io/managed-by: olm
app.kubernetes.io/name: che
app.kubernetes.io/part-of: che.eclipse.org
spec:
containers:
- args:
Expand Down Expand Up @@ -1426,4 +1427,4 @@ spec:
maturity: stable
provider:
name: Eclipse Foundation
version: 7.40.0-338.next
version: 7.40.0-341.next
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ metadata:
app.kubernetes.io/component: che-operator
app.kubernetes.io/instance: che
app.kubernetes.io/name: che
app.kubernetes.io/part-of: che.eclipse.org
name: che-operator
4 changes: 3 additions & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ metadata:
app: che-operator
app.kubernetes.io/name: che
app.kubernetes.io/instance: che
app.kubernetes.io/part-of: che.eclipse.org
app.kubernetes.io/component: che-operator
spec:
replicas: 1
Expand All @@ -33,6 +34,7 @@ spec:
app: che-operator
app.kubernetes.io/name: che
app.kubernetes.io/instance: che
app.kubernetes.io/part-of: che.eclipse.org
app.kubernetes.io/component: che-operator
spec:
containers:
Expand Down Expand Up @@ -68,7 +70,7 @@ spec:
- name: RELATED_IMAGE_devfile_registry
value: quay.io/eclipse/che-devfile-registry:next
- name: RELATED_IMAGE_che_tls_secrets_creation_job
value: quay.io/eclipse/che-tls-secret-creator:alpine-d1ed4ad
value: quay.io/eclipse/che-tls-secret-creator:alpine-01a4c34
- name: RELATED_IMAGE_pvc_jobs
value: registry.access.redhat.com/ubi8-minimal:8.5-204
- name: RELATED_IMAGE_postgres
Expand Down
1 change: 1 addition & 0 deletions config/rbac/cluster_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ metadata:
labels:
app.kubernetes.io/name: che
app.kubernetes.io/instance: che
app.kubernetes.io/part-of: che.eclipse.org
app.kubernetes.io/component: che-operator
rules:
### CHE-OPERATOR ROLES ONLY: BEGIN
Expand Down
1 change: 1 addition & 0 deletions config/rbac/cluster_rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ metadata:
labels:
app.kubernetes.io/name: che
app.kubernetes.io/instance: che
app.kubernetes.io/part-of: che.eclipse.org
app.kubernetes.io/component: che-operator
subjects:
- kind: ServiceAccount
Expand Down
1 change: 1 addition & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ metadata:
labels:
app.kubernetes.io/component: che-operator
app.kubernetes.io/instance: che
app.kubernetes.io/part-of: che.eclipse.org
app.kubernetes.io/name: che
name: che-operator
rules:
Expand Down
1 change: 1 addition & 0 deletions config/rbac/role_binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ metadata:
labels:
app.kubernetes.io/name: che
app.kubernetes.io/instance: che
app.kubernetes.io/part-of: che.eclipse.org
app.kubernetes.io/component: che-operator
roleRef:
apiGroup: rbac.authorization.k8s.io
Expand Down
1 change: 1 addition & 0 deletions config/rbac/service_account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ metadata:
labels:
app.kubernetes.io/name: che
app.kubernetes.io/instance: che
app.kubernetes.io/part-of: che.eclipse.org
app.kubernetes.io/component: che-operator
6 changes: 3 additions & 3 deletions controllers/che/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ func TestGetBackupServerConfigurationNameForBackupBeforeUpdate(t *testing.T) {
deployContext := &deploy.DeployContext{
CheCluster: testCase.cheCluster,
ClusterAPI: deploy.ClusterAPI{
Client: cli,
NonCachedClient: cli,
Scheme: scheme,
Client: cli,
NonCachingClient: cli,
Scheme: scheme,
},
}

Expand Down
10 changes: 6 additions & 4 deletions controllers/che/checluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/eclipse-che/che-operator/pkg/deploy/devfileregistry"
"github.com/eclipse-che/che-operator/pkg/deploy/gateway"
imagepuller "github.com/eclipse-che/che-operator/pkg/deploy/image-puller"
"github.com/eclipse-che/che-operator/pkg/deploy/migration"
openshiftoauth "github.com/eclipse-che/che-operator/pkg/deploy/openshift-oauth"
"github.com/eclipse-che/che-operator/pkg/deploy/pluginregistry"
"github.com/eclipse-che/che-operator/pkg/deploy/postgres"
Expand Down Expand Up @@ -87,6 +88,7 @@ func NewReconciler(

// order does matter
if !util.IsTestMode() {
reconcileManager.RegisterReconciler(migration.NewMigrator())
reconcileManager.RegisterReconciler(NewCheClusterValidator())
}
reconcileManager.RegisterReconciler(imagepuller.NewImagePuller())
Expand Down Expand Up @@ -222,10 +224,10 @@ func (r *CheClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)

tests := r.tests
clusterAPI := deploy.ClusterAPI{
Client: r.client,
NonCachedClient: r.nonCachedClient,
DiscoveryClient: r.discoveryClient,
Scheme: r.Scheme,
Client: r.client,
NonCachingClient: r.nonCachedClient,
DiscoveryClient: r.discoveryClient,
Scheme: r.Scheme,
}

// Fetch the CheCluster instance
Expand Down
6 changes: 3 additions & 3 deletions controllers/che/checluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,9 @@ func TestCheController(t *testing.T) {
}

clusterAPI := deploy.ClusterAPI{
Client: r.client,
NonCachedClient: r.client,
Scheme: r.Scheme,
Client: r.client,
NonCachingClient: r.client,
Scheme: r.Scheme,
}

deployContext := &deploy.DeployContext{
Expand Down
26 changes: 19 additions & 7 deletions controllers/che/cheobj_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ func IsTrustedBundleConfigMap(cl client.Client, watchNamespace string, obj clien
// ignore not matched labels
return false, ctrl.Request{}
}

// Check for instance label
if value, exists := obj.GetLabels()[deploy.KubernetesInstanceLabelKey]; !exists || value != deploy.DefaultCheFlavor(checluster) {
// Ignore config map with missing instance label
return false, ctrl.Request{}
}
}

return true, ctrl.Request{
Expand All @@ -66,14 +72,10 @@ func IsTrustedBundleConfigMap(cl client.Client, watchNamespace string, obj clien
}
}

// isEclipseCheRelatedObj indicates if there is a object with
// the label 'app.kubernetes.io/part-of=che.eclipse.org' in a che namespace
// isEclipseCheRelatedObj indicates if there is an object in a che namespace with the labels:
// - 'app.kubernetes.io/part-of=che.eclipse.org'
// - 'app.kubernetes.io/instance=che'
func IsEclipseCheRelatedObj(cl client.Client, watchNamespace string, obj client.Object) (bool, ctrl.Request) {
if value, exists := obj.GetLabels()[deploy.KubernetesPartOfLabelKey]; !exists || value != deploy.CheEclipseOrg {
// ignore not matched labels
return false, ctrl.Request{}
}

if obj.GetNamespace() == "" {
// ignore cluster scope objects
return false, ctrl.Request{}
Expand All @@ -92,6 +94,16 @@ func IsEclipseCheRelatedObj(cl client.Client, watchNamespace string, obj client.
return false, ctrl.Request{}
}

// Check for part-of label
if value, exists := obj.GetLabels()[deploy.KubernetesPartOfLabelKey]; !exists || value != deploy.CheEclipseOrg {
return false, ctrl.Request{}
}

// Check for instance label
if value, exists := obj.GetLabels()[deploy.KubernetesInstanceLabelKey]; !exists || value != deploy.DefaultCheFlavor(checluster) {
return false, ctrl.Request{}
}

return true, ctrl.Request{
NamespacedName: types.NamespacedName{
Namespace: checluster.Namespace,
Expand Down
19 changes: 13 additions & 6 deletions controllers/che/cheobj_verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ func TestIsTrustedBundleConfigMap(t *testing.T) {
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Labels: map[string]string{"app.kubernetes.io/part-of": "che.eclipse.org", "app.kubernetes.io/component": "ca-bundle"},
Name: "test",
Labels: map[string]string{
"app.kubernetes.io/part-of": "che.eclipse.org",
"app.kubernetes.io/component": "ca-bundle",
"app.kubernetes.io/instance": "che",
},
},
}

Expand Down Expand Up @@ -134,7 +138,7 @@ func TestIsTrustedBundleConfigMap(t *testing.T) {
newTestObject.ObjectMeta.Labels = testCase.objLabels
}

isEclipseCheObj, req := IsTrustedBundleConfigMap(deployContext.ClusterAPI.NonCachedClient, testCase.watchNamespace, newTestObject)
isEclipseCheObj, req := IsTrustedBundleConfigMap(deployContext.ClusterAPI.NonCachingClient, testCase.watchNamespace, newTestObject)

assert.Equal(t, testCase.expectedIsEclipseCheObj, isEclipseCheObj)
if isEclipseCheObj {
Expand All @@ -160,8 +164,11 @@ func TestIsEclipseCheRelatedObj(t *testing.T) {
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Labels: map[string]string{"app.kubernetes.io/part-of": "che.eclipse.org"},
Name: "test",
Labels: map[string]string{
"app.kubernetes.io/part-of": "che.eclipse.org",
"app.kubernetes.io/instance": "che",
},
},
}

Expand Down Expand Up @@ -225,7 +232,7 @@ func TestIsEclipseCheRelatedObj(t *testing.T) {
deployContext := deploy.GetTestDeployContext(nil, testCase.initObjects)

testObject.ObjectMeta.Namespace = testCase.objNamespace
isEclipseCheObj, req := IsEclipseCheRelatedObj(deployContext.ClusterAPI.NonCachedClient, testCase.watchNamespace, testObject)
isEclipseCheObj, req := IsEclipseCheRelatedObj(deployContext.ClusterAPI.NonCachingClient, testCase.watchNamespace, testObject)

assert.Equal(t, testCase.expectedIsEclipseCheObj, isEclipseCheObj)
if isEclipseCheObj {
Expand Down
12 changes: 6 additions & 6 deletions controllers/che/configmap_cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func TestSyncTrustStoreConfigMapToCluster(t *testing.T) {
},
},
ClusterAPI: deploy.ClusterAPI{
Client: cli,
NonCachedClient: cli,
Scheme: scheme.Scheme,
Client: cli,
NonCachingClient: cli,
Scheme: scheme.Scheme,
},
}

Expand Down Expand Up @@ -81,9 +81,9 @@ func TestSyncExistedTrustStoreConfigMapToCluster(t *testing.T) {
},
},
ClusterAPI: deploy.ClusterAPI{
Client: cli,
NonCachedClient: cli,
Scheme: scheme.Scheme,
Client: cli,
NonCachingClient: cli,
Scheme: scheme.Scheme,
},
}

Expand Down
6 changes: 3 additions & 3 deletions controllers/che/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ func TestReadProxyConfiguration(t *testing.T) {
deployContext := &deploy.DeployContext{
CheCluster: testCase.cheCluster,
ClusterAPI: deploy.ClusterAPI{
Client: cli,
NonCachedClient: cli,
Scheme: scheme,
Client: cli,
NonCachingClient: cli,
Scheme: scheme,
},
}

Expand Down
6 changes: 1 addition & 5 deletions controllers/checlusterbackup/backup_data_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,7 @@ func backupConfigMaps(bctx *BackupContext, destDir string) (bool, error) {
return true, err
}

fakeDeployContext := &deploy.DeployContext{
ClusterAPI: deploy.ClusterAPI{Client: bctx.r.nonCachingClient},
CheCluster: bctx.cheCR,
}
caBundlesConfigmaps, err := deploy.GetCACertsConfigMaps(fakeDeployContext)
caBundlesConfigmaps, err := deploy.GetCACertsConfigMaps(bctx.r.nonCachingClient, bctx.cheCR.GetNamespace())
if err != nil {
return false, err
}
Expand Down
8 changes: 4 additions & 4 deletions controllers/usernamespace/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ func (r *CheUserNamespaceReconciler) Reconcile(ctx context.Context, req ctrl.Req
deployContext := &deploy.DeployContext{
CheCluster: org.AsV1(checluster),
ClusterAPI: deploy.ClusterAPI{
Client: r.client,
NonCachedClient: r.client,
DiscoveryClient: nil,
Scheme: r.scheme,
Client: r.client,
NonCachingClient: r.client,
DiscoveryClient: nil,
Scheme: r.scheme,
},
}

Expand Down
Loading

0 comments on commit 021031f

Please sign in to comment.