Skip to content

Commit 61b75cc

Browse files
committed
refactor: remove unused session management functions and streamline code
- Deleted the `ensureRunnerRolePermissions` and `updateAgenticSessionStatus` functions from the session handling logic, as they were no longer utilized. - This cleanup enhances code clarity and maintainability by eliminating redundant functions and improving the overall structure of session management. - Updated related session handling logic to reflect these changes, ensuring a more efficient and streamlined codebase.
1 parent b993a7c commit 61b75cc

File tree

3 files changed

+2
-452
lines changed

3 files changed

+2
-452
lines changed

components/backend/handlers/sessions.go

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,58 +1694,6 @@ func CloneSession(c *gin.Context) {
16941694
c.JSON(http.StatusCreated, session)
16951695
}
16961696

1697-
// ensureRunnerRolePermissions updates the runner role to ensure it has all required permissions
1698-
// This is useful for existing sessions that were created before we added new permissions
1699-
func ensureRunnerRolePermissions(c *gin.Context, reqK8s *kubernetes.Clientset, project string, sessionName string) error {
1700-
roleName := fmt.Sprintf("ambient-session-%s-role", sessionName)
1701-
1702-
// Get existing role
1703-
existingRole, err := reqK8s.RbacV1().Roles(project).Get(c.Request.Context(), roleName, v1.GetOptions{})
1704-
if err != nil {
1705-
if errors.IsNotFound(err) {
1706-
log.Printf("Role %s not found for session %s - will be created by operator", roleName, sessionName)
1707-
return nil
1708-
}
1709-
return fmt.Errorf("get role: %w", err)
1710-
}
1711-
1712-
// Check if role has selfsubjectaccessreviews permission
1713-
hasSelfSubjectAccessReview := false
1714-
for _, rule := range existingRole.Rules {
1715-
for _, apiGroup := range rule.APIGroups {
1716-
if apiGroup == "authorization.k8s.io" {
1717-
for _, resource := range rule.Resources {
1718-
if resource == "selfsubjectaccessreviews" {
1719-
hasSelfSubjectAccessReview = true
1720-
break
1721-
}
1722-
}
1723-
}
1724-
}
1725-
}
1726-
1727-
if hasSelfSubjectAccessReview {
1728-
log.Printf("Role %s already has selfsubjectaccessreviews permission", roleName)
1729-
return nil
1730-
}
1731-
1732-
// Add missing permission
1733-
log.Printf("Updating role %s to add selfsubjectaccessreviews permission", roleName)
1734-
existingRole.Rules = append(existingRole.Rules, rbacv1.PolicyRule{
1735-
APIGroups: []string{"authorization.k8s.io"},
1736-
Resources: []string{"selfsubjectaccessreviews"},
1737-
Verbs: []string{"create"},
1738-
})
1739-
1740-
_, err = reqK8s.RbacV1().Roles(project).Update(c.Request.Context(), existingRole, v1.UpdateOptions{})
1741-
if err != nil {
1742-
return fmt.Errorf("update role: %w", err)
1743-
}
1744-
1745-
log.Printf("Successfully updated role %s with selfsubjectaccessreviews permission", roleName)
1746-
return nil
1747-
}
1748-
17491697
func StartSession(c *gin.Context) {
17501698
project := c.GetString("project")
17511699
sessionName := c.Param("sessionName")

components/operator/internal/handlers/helpers.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,6 @@ func mutateAgenticSessionStatus(sessionNamespace, name string, mutator func(stat
170170
return nil
171171
}
172172

173-
// updateAgenticSessionStatus merges the provided fields into status.
174-
func updateAgenticSessionStatus(sessionNamespace, name string, statusUpdate map[string]interface{}) error {
175-
return mutateAgenticSessionStatus(sessionNamespace, name, func(status map[string]interface{}) {
176-
for key, value := range statusUpdate {
177-
status[key] = value
178-
}
179-
})
180-
}
181-
182173
// ensureSessionIsInteractive forces spec.interactive=true so sessions can be restarted.
183174
func ensureSessionIsInteractive(sessionNamespace, name string) error {
184175
gvr := types.GetAgenticSessionResource()

0 commit comments

Comments
 (0)