-
Notifications
You must be signed in to change notification settings - Fork 83
/
cheobj_verifier.go
91 lines (78 loc) · 2.73 KB
/
cheobj_verifier.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// Copyright (c) 2019-2023 Red Hat, Inc.
// This program and the accompanying materials are made
// available under the terms of the Eclipse Public License 2.0
// which is available at https://www.eclipse.org/legal/epl-2.0/
//
// SPDX-License-Identifier: EPL-2.0
//
// Contributors:
// Red Hat, Inc. - initial API and implementation
//
package che
import (
"github.com/eclipse-che/che-operator/pkg/common/constants"
"github.com/eclipse-che/che-operator/pkg/deploy"
"github.com/eclipse-che/che-operator/pkg/deploy/tls"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)
// IsTrustedBundleConfigMap detects whether given config map is the config map with additional CA certificates to be trusted by Che
func IsTrustedBundleConfigMap(cl client.Client, watchNamespace string, obj client.Object) (bool, ctrl.Request) {
if obj.GetNamespace() == "" {
// ignore cluster scope objects
return false, ctrl.Request{}
}
checluster, _ := deploy.FindCheClusterCRInNamespace(cl, watchNamespace)
if checluster == nil {
return false, ctrl.Request{}
}
if checluster.Namespace != obj.GetNamespace() {
// ignore object in another namespace
return false, ctrl.Request{}
}
// Check for component
if value, exists := obj.GetLabels()[constants.KubernetesComponentLabelKey]; !exists || value != tls.CheCACertsConfigMapLabelValue {
// Labels do not match
return false, ctrl.Request{}
}
// Check for part-of
if value, exists := obj.GetLabels()[constants.KubernetesPartOfLabelKey]; !exists || value != constants.CheEclipseOrg {
// ignore not matched labels
return false, ctrl.Request{}
}
return true, ctrl.Request{
NamespacedName: types.NamespacedName{
Namespace: checluster.Namespace,
Name: checluster.Name,
},
}
}
// 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 obj.GetNamespace() == "" {
// ignore cluster scope objects
return false, ctrl.Request{}
}
checluster, _ := deploy.FindCheClusterCRInNamespace(cl, watchNamespace)
if checluster == nil {
return false, ctrl.Request{}
}
if checluster.Namespace != obj.GetNamespace() {
// ignore object in another namespace
return false, ctrl.Request{}
}
// Check for part-of label
if value, exists := obj.GetLabels()[constants.KubernetesPartOfLabelKey]; !exists || value != constants.CheEclipseOrg {
return false, ctrl.Request{}
}
return true, ctrl.Request{
NamespacedName: types.NamespacedName{
Namespace: checluster.Namespace,
Name: checluster.Name,
},
}
}