-
Notifications
You must be signed in to change notification settings - Fork 65
/
space_spacerequest_mapper.go
34 lines (31 loc) · 1.24 KB
/
space_spacerequest_mapper.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
package spacerequest
import (
toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
"k8s.io/apimachinery/pkg/types"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
// MapSubSpaceToSpaceRequest checks whether a space was created from a spacerequest, in case it finds the required labels,
// triggers an event for the given spacerequest associated with the space.
func MapSubSpaceToSpaceRequest() func(object runtimeclient.Object) []reconcile.Request {
return func(obj runtimeclient.Object) []reconcile.Request {
// get eventual spaceRequest name and namespace associated with current Space
spaceRequestName, spaceRequestExists := obj.GetLabels()[toolchainv1alpha1.SpaceRequestLabelKey]
spaceRequestNamespace, spaceRequestNamespaceExists := obj.GetLabels()[toolchainv1alpha1.SpaceRequestNamespaceLabelKey]
if spaceRequestNamespaceExists &&
spaceRequestExists &&
spaceRequestName != "" &&
spaceRequestNamespace != "" {
// reconcile associated spacerequest
return []reconcile.Request{
{
NamespacedName: types.NamespacedName{
Namespace: spaceRequestNamespace,
Name: spaceRequestName,
},
},
}
}
return []reconcile.Request{}
}
}