Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Role backend implementation #467

Merged
merged 15 commits into from
Aug 4, 2024
23 changes: 23 additions & 0 deletions cyclops-ctrl/internal/cluster/k8sclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

tanbirali marked this conversation as resolved.
Show resolved Hide resolved
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"
}
Expand Down Expand Up @@ -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"
}
1 change: 0 additions & 1 deletion cyclops-ctrl/internal/controller/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
44 changes: 44 additions & 0 deletions cyclops-ctrl/internal/models/dto/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Loading