Skip to content

Commit

Permalink
[codegen] Propagate ExtraPermissions into generated manifest data (#543)
Browse files Browse the repository at this point in the history
App manifest generation doesn't correctly propagate the
`extraPermissions` field into the generated JSON or YAML. Fix this in
the jenny, and add a test to ensure propagation is happening.
  • Loading branch information
IfSentient authored Dec 12, 2024
1 parent 37a344c commit 9c28e5d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions codegen/cuekind/testing/testkind.cue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import "time"
testManifest: {
appName: "test-app"
kinds: [testKind, testKind2]
extraPermissions: {
accessKinds: [{
group: "foo.bar"
resource: "foos"
actions: ["get","list","watch"]
}]
}
}

testKind: {
Expand Down
22 changes: 22 additions & 0 deletions codegen/jennies/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@ func buildManifestData(m codegen.AppManifest) (*app.ManifestData, error) {
manifest.Kinds = append(manifest.Kinds, mkind)
}

if len(m.Properties().ExtraPermissions.AccessKinds) > 0 {
perms := make([]app.KindPermission, len(m.Properties().ExtraPermissions.AccessKinds))
for i, p := range m.Properties().ExtraPermissions.AccessKinds {
perms[i] = app.KindPermission{
Group: p.Group,
Resource: p.Resource,
Actions: toKindPermissionActions(p.Actions),
}
}
manifest.ExtraPermissions = &app.Permissions{
AccessKinds: perms,
}
}

return &manifest, nil
}

Expand All @@ -208,3 +222,11 @@ func sanitizeAdmissionOperations(operations []codegen.KindAdmissionCapabilityOpe
}
return sanitized, nil
}

func toKindPermissionActions(actions []string) []app.KindPermissionAction {
a := make([]app.KindPermissionAction, len(actions))
for i, action := range actions {
a[i] = app.KindPermissionAction(strings.ToLower(action))
}
return a
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,11 @@ spec:
type: object
x-kubernetes-preserve-unknown-fields: true
conversion: false
extraPermissions:
accessKinds:
- group: foo.bar
resource: foos
actions:
- get
- list
- watch

0 comments on commit 9c28e5d

Please sign in to comment.