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
24 changes: 24 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,24 @@ 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
}

tanbirali marked this conversation as resolved.
Show resolved Hide resolved

return &dto.Role{
Group: group,
Version: version,
Kind: kind,
Name: role.Name,
Namespace: namespace,

}, nil
}

func isDeployment(group, version, kind string) bool {
return group == "apps" && version == "v1" && kind == "Deployment"
}
Expand Down Expand Up @@ -916,3 +936,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 == "" && version == "v1" && kind == "Role"
tanbirali marked this conversation as resolved.
Show resolved Hide resolved
}
1 change: 1 addition & 0 deletions cyclops-ctrl/internal/controller/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,3 +653,4 @@ func getTargetGeneration(generation string, module *v1alpha1.Module) (*v1alpha1.
Status: module.Status,
}, true
}

42 changes: 42 additions & 0 deletions cyclops-ctrl/internal/models/dto/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,3 +533,45 @@ 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"`
}

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