fix: Use the labels used by the che-server to recognize workspace namespaces (#1359)
Use the app.kubernetes.io/part-of=che.eclipse.org and app.kubernetes.io/component=workspaces-namespace labels to mark a namespace as workspace namespace. This should bring the operator and che-server in line with how they are marking the managed namespaces.pull/1365/head
parent
b0bbf08b2a
commit
33a59db047
|
|
@ -159,7 +159,7 @@ func isLabeledAsUserSettings(obj metav1.Object) bool {
|
|||
|
||||
func (r *CheUserNamespaceReconciler) isInManagedNamespace(ctx context.Context, obj metav1.Object) bool {
|
||||
info, err := r.namespaceCache.GetNamespaceInfo(ctx, obj.GetNamespace())
|
||||
return err == nil && info != nil && info.OwnerUid != ""
|
||||
return err == nil && info != nil && info.IsWorkspaceNamespace
|
||||
}
|
||||
|
||||
func (r *CheUserNamespaceReconciler) triggerAllNamespaces() handler.EventHandler {
|
||||
|
|
@ -195,7 +195,7 @@ func (r *CheUserNamespaceReconciler) Reconcile(ctx context.Context, req ctrl.Req
|
|||
return ctrl.Result{}, err
|
||||
}
|
||||
|
||||
if info == nil || info.OwnerUid == "" {
|
||||
if info == nil || !info.IsWorkspaceNamespace {
|
||||
// we're not handling this namespace
|
||||
return ctrl.Result{}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,10 @@ const (
|
|||
workspaceNamespaceOwnerUidLabel string = "che.eclipse.org/workspace-namespace-owner-uid"
|
||||
cheNameLabel string = "che.eclipse.org/che-name"
|
||||
cheNamespaceLabel string = "che.eclipse.org/che-namespace"
|
||||
chePartOfLabel string = "app.kubernetes.io/part-of"
|
||||
chePartOfLabelValue string = "che.eclipse.org"
|
||||
cheComponentLabel string = "app.kubernetes.io/component"
|
||||
cheComponentLabelValue string = "workspaces-namespace"
|
||||
)
|
||||
|
||||
type namespaceCache struct {
|
||||
|
|
@ -39,8 +43,8 @@ type namespaceCache struct {
|
|||
}
|
||||
|
||||
type namespaceInfo struct {
|
||||
OwnerUid string
|
||||
CheCluster *types.NamespacedName
|
||||
IsWorkspaceNamespace bool
|
||||
CheCluster *types.NamespacedName
|
||||
}
|
||||
|
||||
func NewNamespaceCache() *namespaceCache {
|
||||
|
|
@ -117,12 +121,16 @@ func (c *namespaceCache) examineNamespaceUnsafe(ctx context.Context, ns string)
|
|||
labels = map[string]string{}
|
||||
}
|
||||
|
||||
// ownerUid is the legacy label that we used to use. Let's not break the existing workspace namespaces and still
|
||||
// recognize it
|
||||
ownerUid := labels[workspaceNamespaceOwnerUidLabel]
|
||||
cheName := labels[cheNameLabel]
|
||||
cheNamespace := labels[cheNamespaceLabel]
|
||||
partOfLabel := labels[chePartOfLabel]
|
||||
componentLabel := labels[cheComponentLabel]
|
||||
|
||||
ret := namespaceInfo{
|
||||
OwnerUid: ownerUid,
|
||||
IsWorkspaceNamespace: ownerUid != "" || (partOfLabel == chePartOfLabelValue && componentLabel == cheComponentLabelValue),
|
||||
CheCluster: &types.NamespacedName{
|
||||
Name: cheName,
|
||||
Namespace: cheNamespace,
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ func TestExamineUpdatesCache(t *testing.T) {
|
|||
nsi, err := nsc.GetNamespaceInfo(ctx, nsName)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Empty(t, nsi.OwnerUid, "Detected owner UID should be empty")
|
||||
assert.False(t, nsi.IsWorkspaceNamespace, "The namespace should not be found as managed")
|
||||
|
||||
assert.Contains(t, nsc.knownNamespaces, nsName, "The namespace info should have been cached")
|
||||
|
||||
|
|
@ -126,7 +126,19 @@ func TestExamineUpdatesCache(t *testing.T) {
|
|||
nsi, err = nsc.ExamineNamespace(ctx, nsName)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "uid", nsi.OwnerUid, "unexpected detected owner UID")
|
||||
assert.True(t, nsi.IsWorkspaceNamespace, "namespace should be found as managed using the legacy user UID label")
|
||||
|
||||
ns.(metav1.Object).SetLabels(map[string]string{
|
||||
chePartOfLabel: chePartOfLabelValue,
|
||||
cheComponentLabel: cheComponentLabelValue,
|
||||
})
|
||||
|
||||
assert.NoError(t, cl.Update(ctx, ns))
|
||||
|
||||
nsi, err = nsc.ExamineNamespace(ctx, nsName)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.True(t, nsi.IsWorkspaceNamespace, "namespace should be found as managed using the part-of and component labels")
|
||||
}
|
||||
|
||||
test(infrastructure.Kubernetes, &corev1.Namespace{
|
||||
|
|
|
|||
Loading…
Reference in New Issue