Skip to content

Commit

Permalink
Fix to deploy TektonHub in custom namespace
Browse files Browse the repository at this point in the history
This commit handles target namespace deletion
erlier it was deleting operator installation target namespace
when Hub component target namespace was different

Signed-off-by: Shiv Verma <[email protected]>
  • Loading branch information
pratap0007 committed Jan 22, 2024
1 parent 8112cf2 commit 4632397
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
20 changes: 5 additions & 15 deletions pkg/reconciler/common/targetnamespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,15 @@ func ReconcileTargetNamespace(ctx context.Context, labels map[string]string, tek

var targetNamespace *corev1.Namespace
namespaceDeletionInProgress := false

for _, namespace := range nsList.Items {
if namespace.Name == tektonComponent.GetSpec().GetTargetNamespace() && namespace.DeletionTimestamp == nil {
_targetNamespace := namespace.DeepCopy()
targetNamespace = _targetNamespace
} else {
// delete irrelevant namespaces
// if deletionTimestamp is not nil, that indicates, the namespace is in deletion state
if namespace.DeletionTimestamp == nil {
if err := kubeClientSet.CoreV1().Namespaces().Delete(ctx, namespace.Name, metav1.DeleteOptions{}); err != nil {
logger.Errorw("error on deleting a namespace",
"namespace", namespace.Name,
err,
)
return err
}
} else {
logger.Infof("'%v' namespace is in deletion state", namespace.Name)
namespaceDeletionInProgress = true
}
}
if namespace.DeletionTimestamp != nil {
logger.Infof("'%v' namespace is in deletion state", namespace.Name)
namespaceDeletionInProgress = true
}
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/reconciler/common/targetnamespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/tektoncd/operator/pkg/reconciler/shared/hash"
"gotest.tools/v3/assert"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
)
Expand Down Expand Up @@ -117,7 +116,7 @@ func TestReconcileTargetNamespace(t *testing.T) {
postFunc: func(t *testing.T, fakeClientset *fake.Clientset, namespace *corev1.Namespace) {
// verify "custom-ns" is removed
_, err := fakeClientset.CoreV1().Namespaces().Get(context.TODO(), "custom-ns", metav1.GetOptions{})
assert.Equal(t, true, errors.IsNotFound(err), "'custom-ns' namespace should be deleted, but still found")
assert.Equal(t, err, nil)
},
err: nil,
},
Expand Down

0 comments on commit 4632397

Please sign in to comment.