diff --git a/pkg/reconciler/common/common.go b/pkg/reconciler/common/common.go index 50f20a9e83..faaa501cdb 100644 --- a/pkg/reconciler/common/common.go +++ b/pkg/reconciler/common/common.go @@ -43,7 +43,7 @@ func PipelineReady(informer informer.TektonPipelineInformer) (*v1alpha1.TektonPi } return nil, err } - if ppln.GetStatus() != nil && strings.Contains(ppln.GetStatus().GetCondition(apis.ConditionReady).Message, v1alpha1.UpgradePending) { + if isUpgradePending(ppln.GetStatus()) { return nil, v1alpha1.DEPENDENCY_UPGRADE_PENDING_ERR } if !ppln.Status.IsReady() { @@ -52,6 +52,18 @@ func PipelineReady(informer informer.TektonPipelineInformer) (*v1alpha1.TektonPi return ppln, nil } +// isUpgradePending checks if the component status indicates an upgrade is pending +func isUpgradePending(status v1alpha1.TektonComponentStatus) bool { + if status == nil { + return false + } + readyCondition := status.GetCondition(apis.ConditionReady) + if readyCondition == nil { + return false + } + return strings.Contains(readyCondition.Message, v1alpha1.UpgradePending) +} + func PipelineTargetNamspace(informer informer.TektonPipelineInformer) (string, error) { ppln, err := getPipelineRes(informer) if err != nil { diff --git a/pkg/reconciler/common/targetnamespace.go b/pkg/reconciler/common/targetnamespace.go index 5f3a67bcef..f5eb8fa89a 100644 --- a/pkg/reconciler/common/targetnamespace.go +++ b/pkg/reconciler/common/targetnamespace.go @@ -56,7 +56,7 @@ func ReconcileTargetNamespace(ctx context.Context, labels map[string]string, ann if namespace.Name == tektonComponent.GetSpec().GetTargetNamespace() && namespace.DeletionTimestamp == nil { _targetNamespace := namespace.DeepCopy() targetNamespace = _targetNamespace - } else { + } else if len(namespace.GetOwnerReferences()) > 0 { // delete irrelevant namespaces if the owner is the same component // if deletionTimestamp is not nil, that indicates, the namespace is in deletion state ownerReferenceName := namespace.GetOwnerReferences()[0].Name @@ -73,6 +73,8 @@ func ReconcileTargetNamespace(ctx context.Context, labels map[string]string, ann logger.Debugf("'%v' namespace is in deletion state", namespace.Name) namespaceDeletionInProgress = true } + } else { + logger.Infof("'%v' namespace is not owned by any component", namespace.Name) } } diff --git a/pkg/reconciler/common/targetnamespace_test.go b/pkg/reconciler/common/targetnamespace_test.go index cb35213910..2dd7af77fc 100644 --- a/pkg/reconciler/common/targetnamespace_test.go +++ b/pkg/reconciler/common/targetnamespace_test.go @@ -196,6 +196,32 @@ func TestReconcileTargetNamespace(t *testing.T) { // ReconcileTargetNamespace requeue event for the namespace is in deletion state err: v1alpha1.REQUEUE_EVENT_AFTER, }, + { + name: "verify-namespace-in-deletion-state-without-owner-reference", + component: &v1alpha1.TektonConfig{ + ObjectMeta: metav1.ObjectMeta{Name: "config"}, + Spec: v1alpha1.TektonConfigSpec{CommonSpec: v1alpha1.CommonSpec{TargetNamespace: namespaceTektonPipelines}}, + }, + additionalLabels: map[string]string{}, + ownerReferences: nil, + preFunc: func(t *testing.T, fakeClientset *fake.Clientset) { + // create a namespace with deletionTimestamp, it means the namespace is in deletion state + namespace := &corev1.Namespace{ + ObjectMeta: metav1.ObjectMeta{ + Name: namespaceTektonPipelines, + Labels: map[string]string{ + labelKeyTargetNamespace: "true", + }, + OwnerReferences: nil, + DeletionTimestamp: &metav1.Time{Time: time.Now()}, + }, + } + _, err := fakeClientset.CoreV1().Namespaces().Create(context.TODO(), namespace, metav1.CreateOptions{}) + assert.NilError(t, err) + }, + // ReconcileTargetNamespace requeue event for the namespace is in deletion state + err: v1alpha1.REQUEUE_EVENT_AFTER, + }, { name: "verify-existing-namespace", component: &v1alpha1.TektonConfig{