@@ -45,7 +45,6 @@ import (
4545 "github.com/kubesphere/ks-devops/pkg/client/clientset/versioned/scheme"
4646 devopsClient "github.com/kubesphere/ks-devops/pkg/client/devops"
4747 "github.com/kubesphere/ks-devops/pkg/constants"
48- "github.com/kubesphere/ks-devops/pkg/utils/k8sutil"
4948 "github.com/kubesphere/ks-devops/pkg/utils/sliceutil"
5049
5150 kubesphereclient "github.com/kubesphere/ks-devops/pkg/client/clientset/versioned"
@@ -243,16 +242,8 @@ func (c *Controller) syncHandler(key string) error {
243242 }
244243 // If ns exists, but the associated attributes with the project are not set correctly,
245244 // then reset the associated attributes
246- if k8sutil .IsControlledBy (ns .OwnerReferences ,
247- devopsv1alpha3 .ResourceKindDevOpsProject , project .Name ) &&
248- ns .Labels [constants .DevOpsProjectLabelKey ] == project .Name {
249- } else {
245+ if ns .Labels [constants .DevOpsProjectLabelKey ] != project .Name {
250246 copyNs := ns .DeepCopy ()
251- err := controllerutil .SetControllerReference (copyProject , copyNs , scheme .Scheme )
252- if err != nil {
253- klog .V (8 ).Info (err , fmt .Sprintf ("failed to set ownerreference %s " , key ))
254- return err
255- }
256247 if copyNs .Labels == nil {
257248 copyNs .Labels = make (map [string ]string )
258249 }
@@ -289,15 +280,8 @@ func (c *Controller) syncHandler(key string) error {
289280 copyProject .Status .AdminNamespace = ns .Name
290281 } else if len (namespaces ) != 0 {
291282 ns := namespaces [0 ]
292- // reset ownerReferences
293- if ! k8sutil .IsControlledBy (ns .OwnerReferences ,
294- devopsv1alpha3 .ResourceKindDevOpsProject , project .Name ) {
283+ if ns .Labels [constants .DevOpsProjectLabelKey ] != project .Name {
295284 copyNs := ns .DeepCopy ()
296- err := controllerutil .SetControllerReference (copyProject , copyNs , scheme .Scheme )
297- if err != nil {
298- klog .V (8 ).Info (err , fmt .Sprintf ("failed to set ownerreference %s " , key ))
299- return err
300- }
301285 copyNs .Labels [constants .DevOpsProjectLabelKey ] = project .Name
302286 _ , err = c .client .CoreV1 ().Namespaces ().Update (context .Background (), copyNs , metav1.UpdateOptions {})
303287 if err != nil {
0 commit comments