diff --git a/cyclops-ctrl/internal/cluster/k8sclient/client.go b/cyclops-ctrl/internal/cluster/k8sclient/client.go index 1a9e1253..82be69a2 100644 --- a/cyclops-ctrl/internal/cluster/k8sclient/client.go +++ b/cyclops-ctrl/internal/cluster/k8sclient/client.go @@ -355,6 +355,8 @@ func (k *KubernetesClient) GetResource(group, version, kind, name, namespace str return k.mapCronJob(group, version, kind, name, namespace) case isJob(group, version, kind): return k.mapJob(group, version, kind, name, namespace) + case isRole(group, version, kind): + return k.mapRole(group, version, kind, name, namespace) } return nil, nil @@ -877,6 +879,23 @@ func (k *KubernetesClient) isResourceNamespaced(gvk schema.GroupVersionKind) (bo return false, errors.New(fmt.Sprintf("group version kind not found: %v", gvk.String())) } +func (k *KubernetesClient) mapRole(group, version, kind, name, namespace string) (*dto.Role, error) { + role, err := k.clientset.RbacV1().Roles(namespace).Get(context.Background(), name, metav1.GetOptions{}) + + if err != nil { + return nil, err + } + + return &dto.Role{ + Group: group, + Version: version, + Kind: kind, + Name: role.Name, + Namespace: namespace, + Rules: role.Rules, + }, nil +} + func isDeployment(group, version, kind string) bool { return group == "apps" && version == "v1" && kind == "Deployment" } @@ -916,3 +935,7 @@ func isSecret(group, version, kind string) bool { func isCronJob(group, version, kind string) bool { return group == "batch" && version == "v1" && kind == "CronJob" } + +func isRole(group, version, kind string) bool { + return group == "rbac.authorization.k8s.io" && version == "v1" && kind == "Role" +} diff --git a/cyclops-ctrl/internal/controller/modules.go b/cyclops-ctrl/internal/controller/modules.go index 762c1818..30506ed6 100644 --- a/cyclops-ctrl/internal/controller/modules.go +++ b/cyclops-ctrl/internal/controller/modules.go @@ -137,7 +137,6 @@ func (m *Modules) Manifest(ctx *gin.Context) { return } - manifest, err := m.renderer.HelmTemplate(v1alpha1.Module{ ObjectMeta: metav1.ObjectMeta{ Name: ctx.Param("name"), diff --git a/cyclops-ctrl/internal/models/dto/k8s.go b/cyclops-ctrl/internal/models/dto/k8s.go index 04850cb4..3364c96c 100644 --- a/cyclops-ctrl/internal/models/dto/k8s.go +++ b/cyclops-ctrl/internal/models/dto/k8s.go @@ -2,6 +2,7 @@ package dto import ( v1 "k8s.io/api/core/v1" + rbacv1 "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -533,3 +534,46 @@ func (s *Other) GetDeleted() bool { func (s *Other) SetDeleted(deleted bool) { s.Deleted = deleted } + +type Role struct { + Group string `json:"group"` + Version string `json:"version"` + Kind string `json:"kind"` + Name string `json:"name"` + Namespace string `json:"namespace"` + Status string `json:"status"` + Deleted bool `json:"deleted"` + Rules []rbacv1.PolicyRule `json:"rules"` +} + +func (s *Role) GetGroupVersionKind() string { + return s.Group + "/" + s.Version + ", Kind=" + s.Kind +} + +func (s *Role) GetGroup() string { + return s.Group +} + +func (s *Role) GetVersion() string { + return s.Version +} + +func (s *Role) GetKind() string { + return s.Kind +} + +func (s *Role) GetName() string { + return s.Name +} + +func (s *Role) GetNamespace() string { + return s.Namespace +} + +func (s *Role) GetDeleted() bool { + return s.Deleted +} + +func (s *Role) SetDeleted(deleted bool) { + s.Deleted = deleted +}