Skip to content

Commit

Permalink
Fix Hub targetnamespace deletion
Browse files Browse the repository at this point in the history
This patch removes reconcilation of targetnamespace
from Hub and creates namespace incase targetnamespace is
not openshift-pipelines

if targetnamespace of hub is not openshift-pipelines
it was deleting openshift-pipelines namespace and hub
targetnamespace during targetnamespace reconcilation

Signed-off-by: Shiv Verma <[email protected]>
  • Loading branch information
pratap0007 committed Feb 7, 2024
1 parent 9ba51d8 commit 14c7d81
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions pkg/reconciler/kubernetes/tektonhub/tektonhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,8 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, th *v1alpha1.TektonHub)

th.SetDefaults(ctx)

// reconcile target namespace
if err := common.ReconcileTargetNamespace(ctx, nil, th, r.kubeClientSet); err != nil {
logger.Errorw("error on reconciling targetNamespace",
"targetNamespace", th.Spec.GetTargetNamespace(),
err,
)
tc, _ := r.operatorClientSet.OperatorV1alpha1().TektonConfigs().Get(ctx, v1alpha1.ConfigResourceName, metav1.GetOptions{})
if err := r.checkAndCreateNameSpace(ctx, th, tc.Spec.TargetNamespace); err != nil {
return err
}

Expand Down Expand Up @@ -1035,3 +1031,24 @@ func getConfigDataFromHubURL(th *v1alpha1.TektonHub) (*Data, error) {

return data, nil
}

// checks target namespace, creates namespace if not found
func (r *Reconciler) checkAndCreateNameSpace(ctx context.Context, th *v1alpha1.TektonHub, tektonConfigNamespace string) error {
if th.Spec.TargetNamespace != tektonConfigNamespace {
_, err := r.kubeClientSet.CoreV1().Namespaces().Get(ctx, th.Spec.GetTargetNamespace(), metav1.GetOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
ns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: th.Spec.TargetNamespace,
},
}
_, err := r.kubeClientSet.CoreV1().Namespaces().Create(ctx, ns, metav1.CreateOptions{})
if err != nil {
return err
}
}
}
}
return nil
}

0 comments on commit 14c7d81

Please sign in to comment.