-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from pratikjagrut/set.owner.ref
enchancment: set ownerReference on synced resources in accordance to vcluster behavior
- Loading branch information
Showing
3 changed files
with
45 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package util | ||
|
||
import ( | ||
"github.com/loft-sh/vcluster-sdk/syncer/context" | ||
"github.com/loft-sh/vcluster-sdk/translate" | ||
"github.com/pkg/errors" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/klog" | ||
) | ||
|
||
// FindOwner finds the owner of the synced resources and sets it, unless SetOwner is set to false | ||
func FindOwner(ctx *context.RegisterContext) error { | ||
if ctx.CurrentNamespace != ctx.Options.TargetNamespace { | ||
if ctx.Options.SetOwner { | ||
klog.Warningf("Skip setting owner, because current namespace %s != target namespace %s", ctx.CurrentNamespace, ctx.Options.TargetNamespace) | ||
} | ||
return nil | ||
} | ||
|
||
if ctx.Options.SetOwner { | ||
service := &corev1.Service{} | ||
err := ctx.CurrentNamespaceClient.Get(ctx.Context, types.NamespacedName{Namespace: ctx.CurrentNamespace, Name: ctx.Options.ServiceName}, service) | ||
if err != nil { | ||
return errors.Wrap(err, "get vcluster service") | ||
} | ||
|
||
translate.Owner = service | ||
return nil | ||
} | ||
|
||
return nil | ||
} |