mirror of
https://github.com/paralus/paralus.git
synced 2026-03-03 09:30:18 +00:00
* restructure rcloud-base as a single base controller * updated master.rest * moved sentry from internal to pkg as it is used by relay * removing unused rpc and it's dependencies * Fix usermgmt tests * Don't redefine variables in rest file Co-authored-by: Abin Simon <abin.simon@rafay.co>
47 lines
1013 B
Go
47 lines
1013 B
Go
package util
|
|
|
|
import (
|
|
clusterv2 "github.com/RafaySystems/rcloud-base/proto/types/controller"
|
|
)
|
|
|
|
const (
|
|
crdKind = "CustomResourceDefinition"
|
|
clusterRoleKind = "ClusterRole"
|
|
clusterRoleBindingKind = "ClusterRoleBinding"
|
|
roleBindingKind = "RoleBinding"
|
|
roleKind = "Role"
|
|
)
|
|
|
|
// SetNamespace is a utility function setting namespace for a step objects
|
|
// it preserves namespace if already set for selective resources
|
|
func SetNamespace(so *clusterv2.StepObject, namespace string) error {
|
|
accessor, err := so.Accessor()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
kind, err := accessor.Kind()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
switch kind {
|
|
case crdKind, clusterRoleKind, clusterRoleBindingKind:
|
|
case roleKind, roleBindingKind:
|
|
ens, err := accessor.Namespace()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if ens == "" {
|
|
accessor.SetNamespace(namespace)
|
|
}
|
|
default:
|
|
accessor.SetNamespace(namespace)
|
|
}
|
|
|
|
accessor.ResetAutoFields()
|
|
so.Raw = accessor.Bytes()
|
|
|
|
return nil
|
|
}
|